diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-06-01 04:59:11 +0000 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-06-01 05:06:37 +0000 |
commit | addc3902e85959e525a6e577de174dc1229551ac (patch) | |
tree | 6e906d49bec9056a68739ea86b65f44d6613faf6 /server/sockopt_linux.go | |
parent | 4c9cd88c61cb848e36a45657b7cbc63b9c783dc4 (diff) |
server: support peering with ipv6 link local address
fix DialTCPTimeoutWithMD5Sig to handle ipv6 scope-id
also update ipv6 test to test this feature
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server/sockopt_linux.go')
-rw-r--r-- | server/sockopt_linux.go | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/server/sockopt_linux.go b/server/sockopt_linux.go index c764eb04..d1b08ace 100644 --- a/server/sockopt_linux.go +++ b/server/sockopt_linux.go @@ -28,30 +28,30 @@ func DialTCPTimeoutWithMD5Sig(host string, port int, localAddr, key string, msec var family int var ra, la syscall.Sockaddr - ip := net.ParseIP(host) - if ip == nil { - return nil, fmt.Errorf("invalid ip: %s", host) + ip, err := net.ResolveIPAddr("ip", host) + if err != nil { + return nil, fmt.Errorf("invalid ip: %s", err) } - l := net.ParseIP(localAddr) + l, err := net.ResolveIPAddr("ip", localAddr) if l == nil { - return nil, fmt.Errorf("invalid local ip: %s", localAddr) + return nil, fmt.Errorf("invalid local ip: %s", err) } - if (ip.To4() != nil) != (l.To4() != nil) { + if (ip.IP.To4() != nil) != (l.IP.To4() != nil) { return nil, fmt.Errorf("remote and local ip address family is not same") } switch { - case ip.To4() != nil: + case ip.IP.To4() != nil: family = syscall.AF_INET i := &syscall.SockaddrInet4{ Port: port, } for idx, _ := range i.Addr { - i.Addr[idx] = ip.To4()[idx] + i.Addr[idx] = ip.IP.To4()[idx] } ra = i j := &syscall.SockaddrInet4{} for idx, _ := range j.Addr { - j.Addr[idx] = l.To4()[idx] + j.Addr[idx] = l.IP.To4()[idx] } la = j default: @@ -60,12 +60,22 @@ func DialTCPTimeoutWithMD5Sig(host string, port int, localAddr, key string, msec Port: port, } for idx, _ := range i.Addr { - i.Addr[idx] = ip[idx] + i.Addr[idx] = ip.IP[idx] } ra = i - j := &syscall.SockaddrInet6{} + var zone uint32 + if l.Zone != "" { + intf, err := net.InterfaceByName(l.Zone) + if err != nil { + return nil, err + } + zone = uint32(intf.Index) + } + j := &syscall.SockaddrInet6{ + ZoneId: zone, + } for idx, _ := range j.Addr { - j.Addr[idx] = l[idx] + j.Addr[idx] = l.IP[idx] } la = j } |