You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
662 B
34 lines
662 B
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build linux
|
|
|
|
package udprelay
|
|
|
|
import (
|
|
"net"
|
|
"syscall"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func trySetReusePort(_ string, _ string, c syscall.RawConn) {
|
|
c.Control(func(fd uintptr) {
|
|
unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
|
|
})
|
|
}
|
|
|
|
func isReusableSocket(uc *net.UDPConn) bool {
|
|
rc, err := uc.SyscallConn()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
var reusable bool
|
|
rc.Control(func(fd uintptr) {
|
|
val, err := unix.GetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT)
|
|
if err == nil && val == 1 {
|
|
reusable = true
|
|
}
|
|
})
|
|
return reusable
|
|
}
|
|
|