diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-08-31 11:23:13 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-08-31 11:23:13 +0900 |
commit | 9a0323419e9481186340a6455553fbc515969258 (patch) | |
tree | 9438edaa0de065ef627fa998c433e25232aab23d /pkg/server/sockopt_bsd.go | |
parent | 475818dd3ccaa613fdd972097cf689ff9a4a6012 (diff) |
fix closing listening socket blocked
with go v1.11, closing a listening socket is blocked and unittests
fail due to timeout.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'pkg/server/sockopt_bsd.go')
-rw-r--r-- | pkg/server/sockopt_bsd.go | 52 |
1 files changed, 16 insertions, 36 deletions
diff --git a/pkg/server/sockopt_bsd.go b/pkg/server/sockopt_bsd.go index 651e4e58..488a203e 100644 --- a/pkg/server/sockopt_bsd.go +++ b/pkg/server/sockopt_bsd.go @@ -18,7 +18,6 @@ package server import ( "net" - "os" "syscall" ) @@ -27,63 +26,44 @@ const ( IPV6_MINHOPCOUNT = 73 // Generalized TTL Security Mechanism (RFC5082) ) -func setsockoptTcpMD5Sig(fd int, address string, key string) error { - // always enable and assumes that the configuration is done by setkey() - return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, TCP_MD5SIG, 1)) -} - func setTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error { - fi, _, err := extractFileAndFamilyFromTCPListener(l) - defer fi.Close() + sc, err := l.SyscallConn() if err != nil { return err } - return setsockoptTcpMD5Sig(int(fi.Fd()), address, key) -} - -func setsockoptIpTtl(fd int, family int, value int) error { - level := syscall.IPPROTO_IP - name := syscall.IP_TTL - if family == syscall.AF_INET6 { - level = syscall.IPPROTO_IPV6 - name = syscall.IPV6_UNICAST_HOPS - } - return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, level, name, value)) + // always enable and assumes that the configuration is done by setkey() + return setsockOptInt(sc, syscall.IPPROTO_TCP, TCP_MD5SIG, 1) } func setListenTcpTTLSockopt(l *net.TCPListener, ttl int) error { - fi, family, err := extractFileAndFamilyFromTCPListener(l) - defer fi.Close() + family := extractFamilyFromTCPListener(l) + sc, err := l.SyscallConn() if err != nil { return err } - return setsockoptIpTtl(int(fi.Fd()), family, ttl) + return setsockoptIpTtl(sc, family, ttl) } func setTcpTTLSockopt(conn *net.TCPConn, ttl int) error { - fi, family, err := extractFileAndFamilyFromTCPConn(conn) - defer fi.Close() + family := extractFamilyFromTCPConn(conn) + sc, err := conn.SyscallConn() if err != nil { return err } - return setsockoptIpTtl(int(fi.Fd()), family, ttl) + return setsockoptIpTtl(sc, family, ttl) } -func setsockoptIpMinTtl(fd int, family int, value int) error { +func setTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error { + family := extractFamilyFromTCPConn(conn) + sc, err := conn.SyscallConn() + if err != nil { + return err + } level := syscall.IPPROTO_IP name := syscall.IP_MINTTL if family == syscall.AF_INET6 { level = syscall.IPPROTO_IPV6 name = IPV6_MINHOPCOUNT } - return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, level, name, value)) -} - -func setTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error { - fi, family, err := extractFileAndFamilyFromTCPConn(conn) - defer fi.Close() - if err != nil { - return err - } - return setsockoptIpMinTtl(int(fi.Fd()), family, ttl) + return setsockOptInt(sc, level, name, ttl) } |