summaryrefslogtreecommitdiffhomepage
path: root/tun/netstack/tun.go
diff options
context:
space:
mode:
Diffstat (limited to 'tun/netstack/tun.go')
-rw-r--r--tun/netstack/tun.go22
1 files changed, 14 insertions, 8 deletions
diff --git a/tun/netstack/tun.go b/tun/netstack/tun.go
index 6efa45f..21f7cd5 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)