diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-08-02 10:22:09 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-08-02 10:22:09 +0900 |
commit | 26513c438e279b22a56ec9250395f3d0a0ea65b8 (patch) | |
tree | e8feb8ae0b4ee030dfeae136fc5b17d361a245a4 /server/sockopt_bsd.go | |
parent | 07196197675c07c712eba0c24a934dcbe20783e4 (diff) |
server: add sockopt ttl support to darwin
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/sockopt_bsd.go')
-rw-r--r-- | server/sockopt_bsd.go | 61 |
1 files changed, 4 insertions, 57 deletions
diff --git a/server/sockopt_bsd.go b/server/sockopt_bsd.go index 108c1458..651e4e58 100644 --- a/server/sockopt_bsd.go +++ b/server/sockopt_bsd.go @@ -17,12 +17,9 @@ package server import ( - "fmt" "net" "os" "syscall" - - log "github.com/sirupsen/logrus" ) const ( @@ -35,7 +32,7 @@ func setsockoptTcpMD5Sig(fd int, address string, key string) error { return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, TCP_MD5SIG, 1)) } -func SetTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error { +func setTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error { fi, _, err := extractFileAndFamilyFromTCPListener(l) defer fi.Close() if err != nil { @@ -54,7 +51,7 @@ func setsockoptIpTtl(fd int, family int, value int) error { return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, level, name, value)) } -func SetListenTcpTTLSockopt(l *net.TCPListener, ttl int) error { +func setListenTcpTTLSockopt(l *net.TCPListener, ttl int) error { fi, family, err := extractFileAndFamilyFromTCPListener(l) defer fi.Close() if err != nil { @@ -63,7 +60,7 @@ func SetListenTcpTTLSockopt(l *net.TCPListener, ttl int) error { return setsockoptIpTtl(int(fi.Fd()), family, ttl) } -func SetTcpTTLSockopt(conn *net.TCPConn, ttl int) error { +func setTcpTTLSockopt(conn *net.TCPConn, ttl int) error { fi, family, err := extractFileAndFamilyFromTCPConn(conn) defer fi.Close() if err != nil { @@ -82,7 +79,7 @@ func setsockoptIpMinTtl(fd int, family int, value int) error { return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, level, name, value)) } -func SetTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error { +func setTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error { fi, family, err := extractFileAndFamilyFromTCPConn(conn) defer fi.Close() if err != nil { @@ -90,53 +87,3 @@ func SetTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error { } return setsockoptIpMinTtl(int(fi.Fd()), family, ttl) } - -type TCPDialer struct { - net.Dialer - - // MD5 authentication password. - AuthPassword string - - // The TTL value to set outgoing connection. - Ttl uint8 - - // The minimum TTL value for incoming packets. - TtlMin uint8 -} - -func (d *TCPDialer) DialTCP(addr string, port int) (*net.TCPConn, error) { - if d.AuthPassword != "" { - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": addr, - }).Warn("setting md5 for active connection is not supported") - } - if d.Ttl != 0 { - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": addr, - }).Warn("setting ttl for active connection is not supported") - } - if d.TtlMin != 0 { - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": addr, - }).Warn("setting min ttl for active connection is not supported") - } - - raddr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(addr, fmt.Sprintf("%d", port))) - if err != nil { - return nil, fmt.Errorf("invalid remote address: %s", err) - } - laddr, err := net.ResolveTCPAddr("tcp", d.LocalAddr.String()) - if err != nil { - return nil, fmt.Errorf("invalid local address: %s", err) - } - - dialer := net.Dialer{LocalAddr: laddr, Timeout: d.Timeout} - conn, err := dialer.Dial("tcp", raddr.String()) - if err != nil { - return nil, err - } - return conn.(*net.TCPConn), nil -} |