yggdrasil-go/src/multicast/multicast_unix.go

35 lines
832 B
Go
Raw Normal View History

2021-09-23 12:34:58 +03:00
//go:build linux || netbsd || freebsd || openbsd || dragonflybsd
2019-01-13 21:08:41 +03:00
// +build linux netbsd freebsd openbsd dragonflybsd
2018-12-06 01:39:04 +03:00
package multicast
2018-12-06 01:39:04 +03:00
2022-04-17 20:02:25 +03:00
import (
"syscall"
"golang.org/x/sys/unix"
)
2018-12-06 01:39:04 +03:00
func (m *Multicast) _multicastStarted() {
}
func (m *Multicast) multicastReuse(network string, address string, c syscall.RawConn) error {
2018-12-06 01:39:04 +03:00
var control error
2022-10-26 20:25:48 +03:00
var reuseaddr error
2018-12-06 01:39:04 +03:00
control = c.Control(func(fd uintptr) {
2022-10-26 20:25:48 +03: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-06 01:39:04 +03:00
})
switch {
2022-10-26 20:25:48 +03:00
case reuseaddr != nil:
return reuseaddr
2018-12-06 01:39:04 +03:00
default:
return control
}
}