diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-02-03 23:00:50 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-02-03 23:00:50 +0100 |
commit | 069c5ec96ad7a4bba9fa4ffb6407cea08a976f09 (patch) | |
tree | 93ad224d6e9fee78a5b60b6e5433d6b2819a5e41 /tun/netstack/tun.go | |
parent | 3f068cc9cec2688b246b0baaa42cd7643e6685de (diff) | |
parent | 858f933917014f710343aea93f2b643f5e05dfec (diff) |
Merge branch 'tun-net-with-stack' into build
Diffstat (limited to 'tun/netstack/tun.go')
-rw-r--r-- | tun/netstack/tun.go | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/tun/netstack/tun.go b/tun/netstack/tun.go index 7a3f4f6..8f5ae6e 100644 --- a/tun/netstack/tun.go +++ b/tun/netstack/tun.go @@ -181,16 +181,22 @@ func (tun *netTun) MTU() (int, error) { return tun.mtu, nil } -func convertToFullAddr(ip net.IP, port int) (tcpip.FullAddress, tcpip.NetworkProtocolNumber) { +func convertToFullAddr(ip net.IP, port int, zone string) (tcpip.FullAddress, tcpip.NetworkProtocolNumber) { + var nic tcpip.NICID = 0 + + if zone != "" { + nic, _ = strconv.Atoi(zone) + } + if ip4 := ip.To4(); ip4 != nil { return tcpip.FullAddress{ - NIC: 1, + NIC: nic, Addr: tcpip.Address(ip4), Port: uint16(port), }, ipv4.ProtocolNumber } else { return tcpip.FullAddress{ - NIC: 1, + NIC: nic, Addr: tcpip.Address(ip), Port: uint16(port), }, ipv6.ProtocolNumber @@ -219,7 +225,7 @@ func (net *Net) DialContextTCP(ctx context.Context, addr *net.TCPAddr) (*gonet.T if addr == nil { panic("todo: deal with auto addr semantics for nil addr") } - fa, pn := convertToFullAddr(addr.IP, addr.Port) + fa, pn := convertToFullAddr(addr.IP, addr.Port, addr.Zone) return gonet.DialContextTCP(ctx, net.stack, fa, pn) } @@ -227,7 +233,7 @@ func (net *Net) DialTCP(addr *net.TCPAddr) (*gonet.TCPConn, error) { if addr == nil { panic("todo: deal with auto addr semantics for nil addr") } - fa, pn := convertToFullAddr(addr.IP, addr.Port) + fa, pn := convertToFullAddr(addr.IP, addr.Port, addr.Zone) return gonet.DialTCP(net.stack, fa, pn) } @@ -235,7 +241,7 @@ func (net *Net) ListenTCP(addr *net.TCPAddr) (*gonet.TCPListener, error) { if addr == nil { panic("todo: deal with auto addr semantics for nil addr") } - fa, pn := convertToFullAddr(addr.IP, addr.Port) + fa, pn := convertToFullAddr(addr.IP, addr.Port, addr.Zone) return gonet.ListenTCP(net.stack, fa, pn) } @@ -244,12 +250,12 @@ func (net *Net) DialUDP(laddr, raddr *net.UDPAddr) (*gonet.UDPConn, error) { var pn tcpip.NetworkProtocolNumber if laddr != nil { var addr tcpip.FullAddress - addr, pn = convertToFullAddr(laddr.IP, laddr.Port) + addr, pn = convertToFullAddr(laddr.IP, laddr.Port, laddr.Zone) lfa = &addr } if raddr != nil { var addr tcpip.FullAddress - addr, pn = convertToFullAddr(raddr.IP, raddr.Port) + addr, pn = convertToFullAddr(raddr.IP, raddr.Port, raddr.Zone) rfa = &addr } return gonet.DialUDP(net.stack, lfa, rfa, pn) |