summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2021-02-23 22:36:50 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2021-11-03 22:19:39 +0100
commit94e20c34249558152e75c785fa1e0a44cc1a6561 (patch)
tree74d25491a3d8ded81bb01c3cbd72365d351b7de5
parent52704c4b928889f88b1c8effcd02788000e2a780 (diff)
netstack: add support for IPv6 addresses with zones
Use unspecified NIC (0) by default. Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
-rw-r--r--tun/netstack/tun.go23
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)