summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-08-02 10:22:09 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-08-02 10:22:09 +0900
commit26513c438e279b22a56ec9250395f3d0a0ea65b8 (patch)
treee8feb8ae0b4ee030dfeae136fc5b17d361a245a4
parent07196197675c07c712eba0c24a934dcbe20783e4 (diff)
server: add sockopt ttl support to darwin
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--server/sockopt.go10
-rw-r--r--server/sockopt_bsd.go61
-rw-r--r--server/sockopt_darwin.go60
-rw-r--r--server/sockopt_stub.go38
4 files changed, 107 insertions, 62 deletions
diff --git a/server/sockopt.go b/server/sockopt.go
index 4f42e59c..e1c9c467 100644
--- a/server/sockopt.go
+++ b/server/sockopt.go
@@ -12,7 +12,7 @@
// implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-// +build !linux,!dragonfly,!freebsd,!netbsd,!openbsd
+// +build !linux,!openbsd
package server
@@ -24,19 +24,19 @@ import (
)
func SetTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error {
- return fmt.Errorf("setting md5 is not supported")
+ return setTcpMD5SigSockopt(l, address, key)
}
func SetListenTcpTTLSockopt(l *net.TCPListener, ttl int) error {
- return fmt.Errorf("setting ttl is not supported")
+ return setListenTcpTTLSockopt(l, ttl)
}
func SetTcpTTLSockopt(conn *net.TCPConn, ttl int) error {
- return fmt.Errorf("setting ttl is not supported")
+ return setTcpTTLSockopt(conn, ttl)
}
func SetTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error {
- return fmt.Errorf("setting min ttl is not supported")
+ return setTcpMinTTLSockopt(conn, ttl)
}
type TCPDialer struct {
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
-}
diff --git a/server/sockopt_darwin.go b/server/sockopt_darwin.go
new file mode 100644
index 00000000..47cebe44
--- /dev/null
+++ b/server/sockopt_darwin.go
@@ -0,0 +1,60 @@
+// Copyright (C) 2016-2017 Nippon Telegraph and Telephone Corporation.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+// implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// +build darwin
+
+package server
+
+import (
+ "fmt"
+ "net"
+ "os"
+ "syscall"
+)
+
+func setTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error {
+ return fmt.Errorf("setting md5 is not supported")
+}
+
+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))
+}
+
+func setListenTcpTTLSockopt(l *net.TCPListener, ttl int) error {
+ fi, family, err := extractFileAndFamilyFromTCPListener(l)
+ defer fi.Close()
+ if err != nil {
+ return err
+ }
+ return setsockoptIpTtl(int(fi.Fd()), family, ttl)
+}
+
+func setTcpTTLSockopt(conn *net.TCPConn, ttl int) error {
+ fi, family, err := extractFileAndFamilyFromTCPConn(conn)
+ defer fi.Close()
+ if err != nil {
+ return err
+ }
+ return setsockoptIpTtl(int(fi.Fd()), family, ttl)
+}
+
+func setTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error {
+ return fmt.Errorf("setting min ttl is not supported")
+}
diff --git a/server/sockopt_stub.go b/server/sockopt_stub.go
new file mode 100644
index 00000000..9e888dc5
--- /dev/null
+++ b/server/sockopt_stub.go
@@ -0,0 +1,38 @@
+// Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+// implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// +build !linux,!dragonfly,!freebsd,!netbsd,!openbsd,!darwin
+
+package server
+
+import (
+ "fmt"
+ "net"
+)
+
+func setTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error {
+ return fmt.Errorf("setting md5 is not supported")
+}
+
+func setListenTcpTTLSockopt(l *net.TCPListener, ttl int) error {
+ return fmt.Errorf("setting ttl is not supported")
+}
+
+func setTcpTTLSockopt(conn *net.TCPConn, ttl int) error {
+ return fmt.Errorf("setting ttl is not supported")
+}
+
+func setTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error {
+ return fmt.Errorf("setting min ttl is not supported")
+}