diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-02-27 11:54:38 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-02-29 15:41:37 -0800 |
commit | 7dd4813776f4ef12b2b76d42e519d7193956fe3a (patch) | |
tree | f7abc92daf0435acfe12f3a5576432bd73045693 | |
parent | e2171a0ca07b38932a3478dea0dfd2d9fb97b83f (diff) |
server: remove reflect
see https://groups.google.com/forum/#!topic/golang-nuts/dm86z8rfIbA
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | server/sockopt.go | 37 | ||||
-rw-r--r-- | test/scenario_test/route_server_test.py | 4 |
2 files changed, 20 insertions, 21 deletions
diff --git a/server/sockopt.go b/server/sockopt.go index 429063b2..43602036 100644 --- a/server/sockopt.go +++ b/server/sockopt.go @@ -3,7 +3,6 @@ package server import ( "net" "os" - "reflect" "strings" "syscall" "unsafe" @@ -39,25 +38,17 @@ func buildTcpMD5Sig(address string, key string) (tcpmd5sig, error) { return t, nil } -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(listenerToFd(l)), + fi, err := l.File() + defer fi.Close() + if err != nil { + return err + } + if l, err := net.FileListener(fi); err == nil { + defer l.Close() + } + _, _, e := syscall.Syscall6(syscall.SYS_SETSOCKOPT, fi.Fd(), uintptr(syscall.IPPROTO_TCP), uintptr(TCP_MD5SIG), uintptr(unsafe.Pointer(&t)), unsafe.Sizeof(t), 0) return e @@ -70,5 +61,13 @@ 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)) + fi, err := conn.File() + defer fi.Close() + if err != nil { + return err + } + if conn, err := net.FileConn(fi); err == nil { + defer conn.Close() + } + return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(int(fi.Fd()), level, name, ttl)) } diff --git a/test/scenario_test/route_server_test.py b/test/scenario_test/route_server_test.py index 5311f9ed..a470716a 100644 --- a/test/scenario_test/route_server_test.py +++ b/test/scenario_test/route_server_test.py @@ -59,8 +59,8 @@ class GoBGPTestBase(unittest.TestCase): time.sleep(initial_wait_time) for rs_client in rs_clients: - g1.add_peer(rs_client, is_rs_client=True) - rs_client.add_peer(g1) + g1.add_peer(rs_client, is_rs_client=True, passwd='passwd', passive=True) + rs_client.add_peer(g1, passwd='passwd') cls.gobgp = g1 cls.quaggas = {'q1': q1, 'q2': q2, 'q3': q3} |