summaryrefslogtreecommitdiffhomepage
path: root/server/sockopt.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-05-27 11:02:07 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-05-27 11:02:07 +0900
commit637b5f9ba663b739de54069d91b1d87ddd3b4855 (patch)
tree9471595dcb17489b4a4ad4b2562262b056370563 /server/sockopt.go
parentb00a45b094ffb70db90a4e67d8599e939ca6857e (diff)
server: fix File() misuse for md5 setsockopt
Fixed TCPListener.File() misuse. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/sockopt.go')
-rw-r--r--server/sockopt.go31
1 files changed, 19 insertions, 12 deletions
diff --git a/server/sockopt.go b/server/sockopt.go
index 2d26c588..429063b2 100644
--- a/server/sockopt.go
+++ b/server/sockopt.go
@@ -39,23 +39,30 @@ func buildTcpMD5Sig(address string, key string) (tcpmd5sig, error) {
return t, nil
}
-func SetTcpMD5SigSockopts(fd int, address string, key string) error {
+func connToFd(v reflect.Value) int {
+ fd := v.FieldByName("fd")
+ p := reflect.Indirect(fd)
+ sysfd := p.FieldByName("sysfd")
+ return int(sysfd.Int())
+}
+
+func listenerToFd(l *net.TCPListener) int {
+ return connToFd(reflect.ValueOf(*l))
+}
+
+func tcpConnToFd(tcp *net.TCPConn) int {
+ n := reflect.ValueOf(*tcp)
+ return connToFd(n.FieldByName("conn"))
+}
+
+func SetTcpMD5SigSockopts(l *net.TCPListener, address string, key string) error {
t, _ := buildTcpMD5Sig(address, key)
- _, _, e := syscall.Syscall6(syscall.SYS_SETSOCKOPT, uintptr(fd),
+ _, _, e := syscall.Syscall6(syscall.SYS_SETSOCKOPT, uintptr(listenerToFd(l)),
uintptr(syscall.IPPROTO_TCP), uintptr(TCP_MD5SIG),
uintptr(unsafe.Pointer(&t)), unsafe.Sizeof(t), 0)
return e
}
-func TCPConnToFd(tcp *net.TCPConn) int {
- n := reflect.ValueOf(*tcp)
- conn := n.FieldByName("conn")
- fd := conn.FieldByName("fd")
- p := reflect.Indirect(fd)
- sysfd := p.FieldByName("sysfd")
- return int(sysfd.Int())
-}
-
func SetTcpTTLSockopts(conn *net.TCPConn, ttl int) error {
level := syscall.IPPROTO_IP
name := syscall.IP_TTL
@@ -63,5 +70,5 @@ func SetTcpTTLSockopts(conn *net.TCPConn, ttl int) error {
level = syscall.IPPROTO_IPV6
name = syscall.IPV6_UNICAST_HOPS
}
- return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(TCPConnToFd(conn), level, name, ttl))
+ return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(tcpConnToFd(conn), level, name, ttl))
}