3
0

udp_bsd.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //go:build (openbsd || freebsd) && !e2e_testing
  2. // +build openbsd freebsd
  3. // +build !e2e_testing
  4. package udp
  5. // FreeBSD support is primarily implemented in udp_generic, besides NewListenConfig
  6. import (
  7. "fmt"
  8. "net"
  9. "net/netip"
  10. "syscall"
  11. "github.com/sirupsen/logrus"
  12. "golang.org/x/sys/unix"
  13. )
  14. func NewListener(l *logrus.Logger, ip netip.Addr, port int, multi bool, batch int) (Conn, error) {
  15. return NewGenericListener(l, ip, port, multi, batch)
  16. }
  17. func NewListenConfig(multi bool) net.ListenConfig {
  18. return net.ListenConfig{
  19. Control: func(network, address string, c syscall.RawConn) error {
  20. if multi {
  21. var controlErr error
  22. err := c.Control(func(fd uintptr) {
  23. if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
  24. controlErr = fmt.Errorf("SO_REUSEPORT failed: %v", err)
  25. return
  26. }
  27. })
  28. if err != nil {
  29. return err
  30. }
  31. if controlErr != nil {
  32. return controlErr
  33. }
  34. }
  35. return nil
  36. },
  37. }
  38. }
  39. func (u *GenericConn) Rebind() error {
  40. return nil
  41. }