summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-07 22:39:31 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-07 22:39:31 +0900
commitd92b22f2c69b1ecdddbe2e3f477ae6551a51b9fb (patch)
treef23e73be8dee79cd3a9939809dee191dcc470a63
parentbeb39354e51eb74ab0a13d93dfde9e66e85d5bb6 (diff)
server: set ttl to 1
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--server/server.go3
-rw-r--r--server/sockopt.go15
2 files changed, 18 insertions, 0 deletions
diff --git a/server/server.go b/server/server.go
index 3275e5dc..bc4274de 100644
--- a/server/server.go
+++ b/server/server.go
@@ -92,6 +92,9 @@ func listenAndAccept(proto string, port int, ch chan *net.TCPConn) (*net.TCPList
log.Info(err)
continue
}
+ // TODO: check ebgp or not
+ ttl := 1
+ SetTcpTTLSockopts(conn, ttl)
ch <- conn
}
}()
diff --git a/server/sockopt.go b/server/sockopt.go
index 10b3c186..2392cdf4 100644
--- a/server/sockopt.go
+++ b/server/sockopt.go
@@ -2,6 +2,7 @@ package server
import (
"net"
+ "strings"
"syscall"
"unsafe"
)
@@ -43,3 +44,17 @@ func SetTcpMD5SigSockopts(fd int, address string, key string) error {
uintptr(unsafe.Pointer(&t)), unsafe.Sizeof(t), 0)
return e
}
+
+func SetTcpTTLSockopts(conn *net.TCPConn, ttl int) error {
+ level := syscall.IPPROTO_IP
+ name := syscall.IP_TTL
+ if strings.Contains(conn.RemoteAddr().String(), "[") {
+ level = syscall.IPPROTO_IPV6
+ name = syscall.IPV6_UNICAST_HOPS
+ }
+ file, _ := conn.File()
+ _, _, e := syscall.Syscall6(syscall.SYS_SETSOCKOPT, uintptr(int(file.Fd())),
+ uintptr(level), uintptr(name),
+ uintptr(unsafe.Pointer(&ttl)), unsafe.Sizeof(ttl), 0)
+ return e
+}