summaryrefslogtreecommitdiffhomepage
path: root/pkg/server/sockopt_bsd.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/server/sockopt_bsd.go')
-rw-r--r--pkg/server/sockopt_bsd.go52
1 files changed, 16 insertions, 36 deletions
diff --git a/pkg/server/sockopt_bsd.go b/pkg/server/sockopt_bsd.go
index 651e4e58..488a203e 100644
--- a/pkg/server/sockopt_bsd.go
+++ b/pkg/server/sockopt_bsd.go
@@ -18,7 +18,6 @@ package server
import (
"net"
- "os"
"syscall"
)
@@ -27,63 +26,44 @@ const (
IPV6_MINHOPCOUNT = 73 // Generalized TTL Security Mechanism (RFC5082)
)
-func setsockoptTcpMD5Sig(fd int, address string, key string) error {
- // always enable and assumes that the configuration is done by setkey()
- return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, TCP_MD5SIG, 1))
-}
-
func setTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error {
- fi, _, err := extractFileAndFamilyFromTCPListener(l)
- defer fi.Close()
+ sc, err := l.SyscallConn()
if err != nil {
return err
}
- return setsockoptTcpMD5Sig(int(fi.Fd()), address, key)
-}
-
-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))
+ // always enable and assumes that the configuration is done by setkey()
+ return setsockOptInt(sc, syscall.IPPROTO_TCP, TCP_MD5SIG, 1)
}
func setListenTcpTTLSockopt(l *net.TCPListener, ttl int) error {
- fi, family, err := extractFileAndFamilyFromTCPListener(l)
- defer fi.Close()
+ family := extractFamilyFromTCPListener(l)
+ sc, err := l.SyscallConn()
if err != nil {
return err
}
- return setsockoptIpTtl(int(fi.Fd()), family, ttl)
+ return setsockoptIpTtl(sc, family, ttl)
}
func setTcpTTLSockopt(conn *net.TCPConn, ttl int) error {
- fi, family, err := extractFileAndFamilyFromTCPConn(conn)
- defer fi.Close()
+ family := extractFamilyFromTCPConn(conn)
+ sc, err := conn.SyscallConn()
if err != nil {
return err
}
- return setsockoptIpTtl(int(fi.Fd()), family, ttl)
+ return setsockoptIpTtl(sc, family, ttl)
}
-func setsockoptIpMinTtl(fd int, family int, value int) error {
+func setTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error {
+ family := extractFamilyFromTCPConn(conn)
+ sc, err := conn.SyscallConn()
+ if err != nil {
+ return err
+ }
level := syscall.IPPROTO_IP
name := syscall.IP_MINTTL
if family == syscall.AF_INET6 {
level = syscall.IPPROTO_IPV6
name = IPV6_MINHOPCOUNT
}
- return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, level, name, value))
-}
-
-func setTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error {
- fi, family, err := extractFileAndFamilyFromTCPConn(conn)
- defer fi.Close()
- if err != nil {
- return err
- }
- return setsockoptIpMinTtl(int(fi.Fd()), family, ttl)
+ return setsockOptInt(sc, level, name, ttl)
}