socket.go | 8 ++++++++ sockopts_unix.go | 4 ++++ sockopts_wasm.go | 4 ++++ sockopts_windows.go | 4 ++++ diff --git a/socket.go b/socket.go index 606665e2e65b03f8493254d469faaf8e2082c8a1..8512da99e720b75c40c02cd34c988a93897a8735 100644 --- a/socket.go +++ b/socket.go @@ -44,11 +44,16 @@ // client. Instead, this should be a last resort if we need to use holepunching, and only then to // connect to other clients that actually try to holepunch TCP. const dialTcpFromListenPort = false +var SocketIPTypeOfService = 0 + var tcpListenConfig = net.ListenConfig{ Control: func(network, address string, c syscall.RawConn) (err error) { controlErr := c.Control(func(fd uintptr) { if dialTcpFromListenPort { err = setReusePortSockOpts(fd) + } + if err == nil && SocketIPTypeOfService != 0 { + err = setSockIPTOS(fd, SocketIPTypeOfService) } }) if err != nil { @@ -87,6 +92,9 @@ // allow dialling out from the client's listen port, but that doesn't really work. I // think Linux older than ~2013 doesn't support SO_REUSEPORT. if dialTcpFromListenPort { err = setReusePortSockOpts(fd) + } + if err == nil && SocketIPTypeOfService != 0 { + err = setSockIPTOS(fd, SocketIPTypeOfService) } }) if err == nil { diff --git a/sockopts_unix.go b/sockopts_unix.go index 52ec9e8d371a3fdf7a6cc1ec479b5c0bc4f6c324..ffffddd6ec2a7ffd175eb3620dab40dba3ca2c51 100644 --- a/sockopts_unix.go +++ b/sockopts_unix.go @@ -27,3 +27,7 @@ func setSockNoLinger(fd uintptr) (err error) { return syscall.SetsockoptLinger(int(fd), syscall.SOL_SOCKET, syscall.SO_LINGER, &lingerOffVal) } + +func setSockIPTOS(fd uintptr, val int) (err error) { + return syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IP, syscall.IP_TOS, val) +} diff --git a/sockopts_wasm.go b/sockopts_wasm.go index 9705b914201b5501ad026058cdbdad94a18de9ca..8411affe1fd93ad074ff47fceb61d4b99f8fcce0 100644 --- a/sockopts_wasm.go +++ b/sockopts_wasm.go @@ -10,3 +10,7 @@ func setSockNoLinger(fd uintptr) error { return nil } + +func setSockIPTOS(fd uintptr, val int) (err error) { + return nil +} diff --git a/sockopts_windows.go b/sockopts_windows.go index c3c0ab0494760af60cf8701e32a47ac804876b0e..9d8061a9eb3ec6d1371ddb80e263cb39ddee0854 100644 --- a/sockopts_windows.go +++ b/sockopts_windows.go @@ -13,3 +13,7 @@ func setSockNoLinger(fd uintptr) (err error) { return syscall.SetsockoptLinger(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_LINGER, &lingerOffVal) } + +func setSockIPTOS(fd uintptr, val int) (err error) { + return nil +}