Skip to content

Commit

Permalink
ipn/wg: egress is packetconn if hopping over netstack gonet
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Nov 30, 2024
1 parent 4e94ea4 commit 68e4e3e
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions intra/ipn/wg/wgconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (s *StdNetBind) RemoteAddr() netip.AddrPort {
return s.sendAddr.Load()
}

func (s *StdNetBind) listenNet(network string, port int) (*net.UDPConn, int, error) {
func (s *StdNetBind) listenNet(network string, port int) (net.PacketConn, int, error) {
anyaddr := anyaddr6
if network == "udp4" {
anyaddr = anyaddr4
Expand Down Expand Up @@ -247,12 +247,7 @@ func (s *StdNetBind) listenNet(network string, port int) (*net.UDPConn, int, err
}
log.V("wg: bind: %s %s: listen(%v)", s.id, network, laddr)
// typecast is safe, because "network" is always udp[4|6]; see: Open
if udpconn, ok := conn.(*net.UDPConn); ok {
return udpconn, uaddr.Port, nil
} else {
clos(conn)
return nil, 0, errNotUDP
}
return conn, uaddr.Port, nil
}

func (bind *StdNetBind) Open(uport uint16) ([]conn.ReceiveFunc, uint16, error) {
Expand Down Expand Up @@ -305,7 +300,8 @@ again:
fns = append(fns, bind.makeReceiveFn(ipv6))
}

log.I("wg: bind: %s opened port(%d) for v4? %t v6? %t", bind.id, port, ipv4 != nil, ipv6 != nil)
log.I("wg: bind: %s opened port(%d) for v4? %t v6? %t",
bind.id, port, ipv4 != nil, ipv6 != nil)
if len(fns) == 0 {
return nil, 0, syscall.EAFNOSUPPORT
}
Expand Down

0 comments on commit 68e4e3e

Please sign in to comment.