diff --git a/inlet/flow/input/udp/socket.go b/inlet/flow/input/udp/socket.go index 40363f67..979f9b7f 100644 --- a/inlet/flow/input/udp/socket.go +++ b/inlet/flow/input/udp/socket.go @@ -14,6 +14,23 @@ import ( "golang.org/x/sys/unix" ) +// commonUDPSocketOptions are the options common to all OS. +var commonUDPSocketOptions = []socketOption{ + { + // Allow a listener to bind again to a socket that was just closed + Name: "SO_REUSEADDR", + Level: unix.SOL_SOCKET, + Option: unix.SO_REUSEADDR, + Mandatory: true, + }, { + // Allow multiple listeners to bind to the same port + Name: "SO_REUSEPORT", + Level: unix.SOL_SOCKET, + Option: unix.SO_REUSEPORT, + Mandatory: true, + }, +} + type oobMessage struct { Drops uint32 Received time.Time diff --git a/inlet/flow/input/udp/socket_linux.go b/inlet/flow/input/udp/socket_linux.go index 63b98ba8..7a631d89 100644 --- a/inlet/flow/input/udp/socket_linux.go +++ b/inlet/flow/input/udp/socket_linux.go @@ -15,31 +15,17 @@ import ( var ( oobLength = syscall.CmsgLen(4) + syscall.CmsgLen(16) // uint32 + 2*int64 - udpSocketOptions = []socketOption{ - { - // Allow multiple listeners to bind to the same IP - Name: "SO_REUSEADDR", - Level: unix.SOL_SOCKET, - Option: unix.SO_REUSEADDR, - Mandatory: true, - }, { - // Allow multiple listeners to bind to the same port - Name: "SO_REUSEPORT", - Level: unix.SOL_SOCKET, - Option: unix.SO_REUSEPORT, - Mandatory: true, - }, { - // Get the number of dropped packets - Name: "SO_RXQ_OVFL", - Level: unix.SOL_SOCKET, - Option: unix.SO_RXQ_OVFL, - }, { - // Ask the kernel to timestamp incoming packets - Name: "SO_TIMESTAMP_NEW", - Level: unix.SOL_SOCKET, - Option: unix.SO_TIMESTAMP_NEW | unix.SOF_TIMESTAMPING_RX_SOFTWARE, - }, - } + udpSocketOptions = append(commonUDPSocketOptions, socketOption{ + // Get the number of dropped packets + Name: "SO_RXQ_OVFL", + Level: unix.SOL_SOCKET, + Option: unix.SO_RXQ_OVFL, + }, socketOption{ + // Ask the kernel to timestamp incoming packets + Name: "SO_TIMESTAMP_NEW", + Level: unix.SOL_SOCKET, + Option: unix.SO_TIMESTAMP_NEW | unix.SOF_TIMESTAMPING_RX_SOFTWARE, + }) ) // parseSocketControlMessage parses b and extract the number of drops diff --git a/inlet/flow/input/udp/socket_others.go b/inlet/flow/input/udp/socket_others.go index 7a98dc23..f7d00b72 100644 --- a/inlet/flow/input/udp/socket_others.go +++ b/inlet/flow/input/udp/socket_others.go @@ -7,27 +7,11 @@ package udp import ( "errors" - - "golang.org/x/sys/unix" ) var ( oobLength = 0 - udpSocketOptions = []socketOption{ - { - // Allow multiple listeners to bind to the same IP - Name: "SO_REUSEADDR", - Level: unix.SOL_SOCKET, - Option: unix.SO_REUSEADDR, - Mandatory: true, - }, { - // Allow multiple listeners to bind to the same port - Name: "SO_REUSEPORT", - Level: unix.SOL_SOCKET, - Option: unix.SO_REUSEPORT, - Mandatory: true, - }, - } + udpSocketOptions = commonUDPSocketOptions ) // parseSocketControlMessage always returns 0.