Skip to content

Commit 8f6e1f7

Browse files
committed
ipn/wg: serve may open conn even in paused state
1 parent 54834b9 commit 8f6e1f7

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

intra/ipn/proxy.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,17 @@ func candial(state *core.Volatile[int]) error {
744744
return candial2(state.Load())
745745
}
746746

747+
func candserve2(st int) error {
748+
if st == END {
749+
return errProxyStopped
750+
}
751+
return nil
752+
}
753+
754+
func canserve(state *core.Volatile[int]) error {
755+
return candserve2(state.Load())
756+
}
757+
747758
func usevia(viaID *core.Volatile[string]) bool {
748759
return viaID != nil && len(viaID.Load()) > 0
749760
}

intra/ipn/wg/wgconn.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ func (s *StdNetBind) makeReceiveFn(uc net.PacketConn) conn.ReceiveFunc {
423423
s.observer(op, err)
424424
}()
425425

426-
usingamz := s.amnezia.Load().Set()
426+
amnezia := s.amnezia.Load()
427+
usingamz := amnezia.Set()
427428
overwritten := false
428429

429430
numMsgs := 0
@@ -432,7 +433,7 @@ func (s *StdNetBind) makeReceiveFn(uc net.PacketConn) conn.ReceiveFunc {
432433
extend(uc, wgtimeout)
433434
n, addr, err := uc.ReadFrom(b)
434435
if err == nil {
435-
b, overwritten = s.amnezia.Load().recv(b, n)
436+
b, overwritten = amnezia.recv(b, n)
436437
numMsgs++
437438
}
438439

@@ -518,14 +519,15 @@ func (s *StdNetBind) Send(buf [][]byte, peer conn.Endpoint) (err error) {
518519
return syscall.EAFNOSUPPORT
519520
}
520521

522+
amnezia := s.amnezia.Load()
521523
anyProcessed = true
522524
anyTransportTyp = anyTransportTyp || transportType(data)
523525

524526
datalen := len(data) // grab the length before we overwrite it
525527

526-
overwritten = s.amnezia.Load().send(&data)
528+
overwritten = amnezia.send(&data)
527529

528-
if !flooded && (floodWg || s.amnezia.Load().Set()) {
530+
if !flooded && (floodWg || amnezia.Set()) {
529531
if datalen == device.MessageInitiationSize {
530532
s.flood(uc, ep, fkHandshake) // was probably a handshake
531533
flooded = true

intra/ipn/wgproxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ func (h *wgtun) Contains(ippOrCidr string) bool {
15381538
}
15391539

15401540
func (h *wgtun) serve(network, local string) (pc net.PacketConn, err error) {
1541-
if err := candial(h.status); err != nil {
1541+
if err := canserve(h.status); err != nil {
15421542
return nil, err
15431543
}
15441544

0 commit comments

Comments
 (0)