Skip to content

Commit 8ecd91d

Browse files
committed
ipn/wg: m add close observer state
1 parent 6a455ff commit 8ecd91d

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

intra/ipn/wg/wgconn.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const (
108108
Csn PktDir = "nots" // not transport data (send)
109109
Con PktDir = "conn" // e.g. dial, announce, accept
110110
Opn PktDir = "open" // open conn to the wg endpoint
111+
Clo PktDir = "clos" // close conn to the wg endpoint
111112
Drp PktDir = "drop" // ignored packet
112113
)
113114

@@ -399,6 +400,8 @@ func (s *StdNetBind) Close() error {
399400
s.blackhole4 = false
400401
s.blackhole6 = false
401402

403+
s.observer(Clo, nil)
404+
402405
log.I("wg: bind: %s close; addrs %s + %s; err4? %v err6? %v", s.id, addr1, addr2, err1, err2)
403406
return core.JoinErr(err1, err2)
404407
}

intra/ipn/wgproxy.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,7 @@ func (h *wgtun) serve(network, local string) (pc net.PacketConn, err error) {
15891589

15901590
func (h *wgtun) listener(op wg.PktDir, err error) {
15911591
s := h.status.Load()
1592+
cur := s
15921593
if op.Read() {
15931594
h.latestRxErr.Store(err)
15941595
} else if op.Write() {
@@ -1610,16 +1611,20 @@ func (h *wgtun) listener(op wg.PktDir, err error) {
16101611

16111612
defer func() {
16121613
h.statusReason.Store(why)
1613-
cur := h.status.Load()
1614-
stoppedOrPaused := cur == END || cur == TPU
16151614
updated := false
1616-
if !stoppedOrPaused {
1615+
if cur != s {
16171616
updated = h.status.Cas(cur, s)
16181617
}
1619-
logeif(!updated)("wg: %s listener: %s; status %s => %s; end/pause? %t, statusupdated? %t, why: %s",
1620-
h.tag(), op, pxstatus(cur), pxstatus(s), stoppedOrPaused, !updated, why)
1618+
logeif(!updated)("wg: %s listener: %s; status %s => %s; transition? %t, statusupdated? %t, why: %s",
1619+
h.tag(), op, pxstatus(cur), pxstatus(s), cur != s, !updated, why)
16211620
}()
16221621

1622+
if op == wg.Clo {
1623+
why = "TNT: closed; prev: " + pxstatus(s).String()
1624+
s = TNT
1625+
return
1626+
}
1627+
16231628
now := now()
16241629
age := now - h.since
16251630
if err != nil { // failing

0 commit comments

Comments
 (0)