diff options
Diffstat (limited to 'tun/netstack')
-rw-r--r-- | tun/netstack/tun.go | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/tun/netstack/tun.go b/tun/netstack/tun.go index 24d0835..44b5f04 100644 --- a/tun/netstack/tun.go +++ b/tun/netstack/tun.go @@ -202,16 +202,23 @@ 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 != "" { + zoneId, _ := strconv.Atoi(zone) + nic = tcpip.NICID(zoneId) + } + 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 @@ -222,7 +229,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) } @@ -230,7 +237,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) } @@ -238,7 +245,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) } @@ -247,12 +254,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) |