yggdrasil-go/src/multicast/multicast_unix.go

35 lines
832 B
Go
Raw Normal View History

2021-09-23 09:34:58 +00:00
//go:build linux || netbsd || freebsd || openbsd || dragonflybsd
2019-01-13 18:08:41 +00:00
// +build linux netbsd freebsd openbsd dragonflybsd
2018-12-05 22:39:04 +00:00
package multicast
2018-12-05 22:39:04 +00:00
2022-04-17 17:02:25 +00:00
import (
"syscall"
"golang.org/x/sys/unix"
)
2018-12-05 22:39:04 +00:00
func (m *Multicast) _multicastStarted() {
}
func (m *Multicast) multicastReuse(network string, address string, c syscall.RawConn) error {
2018-12-05 22:39:04 +00:00
var control error
2022-10-26 17:25:48 +00:00
var reuseaddr error
2018-12-05 22:39:04 +00:00
control = c.Control(func(fd uintptr) {
2022-10-26 17:25:48 +00:00
// Previously we used SO_REUSEPORT here, but that meant that machines running
// Yggdrasil nodes as different users would inevitably fail with EADDRINUSE.
// The behaviour for multicast is similar with both, so we'll use SO_REUSEADDR
// instead.
reuseaddr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1)
2018-12-05 22:39:04 +00:00
})
switch {
2022-10-26 17:25:48 +00:00
case reuseaddr != nil:
return reuseaddr
2018-12-05 22:39:04 +00:00
default:
return control
}
}