github.com/slackhq/nebula@v1.9.0/udp/udp_windows.go (about)

     1  //go:build !e2e_testing
     2  // +build !e2e_testing
     3  
     4  package udp
     5  
     6  import (
     7  	"fmt"
     8  	"net"
     9  	"syscall"
    10  
    11  	"github.com/sirupsen/logrus"
    12  )
    13  
    14  func NewListener(l *logrus.Logger, ip net.IP, port int, multi bool, batch int) (Conn, error) {
    15  	if multi {
    16  		//NOTE: Technically we can support it with RIO but it wouldn't be at the socket level
    17  		// The udp stack would need to be reworked to hide away the implementation differences between
    18  		// Windows and Linux
    19  		return nil, fmt.Errorf("multiple udp listeners not supported on windows")
    20  	}
    21  
    22  	rc, err := NewRIOListener(l, ip, port)
    23  	if err == nil {
    24  		return rc, nil
    25  	}
    26  
    27  	l.WithError(err).Error("Falling back to standard udp sockets")
    28  	return NewGenericListener(l, ip, port, multi, batch)
    29  }
    30  
    31  func NewListenConfig(multi bool) net.ListenConfig {
    32  	return net.ListenConfig{
    33  		Control: func(network, address string, c syscall.RawConn) error {
    34  			if multi {
    35  				// There is no way to support multiple listeners safely on Windows:
    36  				// https://docs.microsoft.com/en-us/windows/desktop/winsock/using-so-reuseaddr-and-so-exclusiveaddruse
    37  				return fmt.Errorf("multiple udp listeners not supported on windows")
    38  			}
    39  			return nil
    40  		},
    41  	}
    42  }
    43  
    44  func (u *GenericConn) Rebind() error {
    45  	return nil
    46  }