summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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
+}