inlet/flow: avoid repeating common socket options for Linux and others
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Update Nix dependency hashes / Update dependency hashes (push) Has been cancelled
Update Go toolchain / Update Go toolchain (push) Has been cancelled
Update Nix flake.lock / Update Nix lockfile (asn2org) (push) Has been cancelled
Update Nix flake.lock / Update Nix lockfile (iana-assignments) (push) Has been cancelled
Update Nix flake.lock / Update Nix lockfile (nixpkgs) (push) Has been cancelled

Also, fix the description for `SO_REUSEADDR`.
This commit is contained in:
Vincent Bernat
2025-11-02 15:16:18 +01:00
parent 39340d9f8d
commit 49b42f6055
3 changed files with 29 additions and 42 deletions

View File

@@ -14,6 +14,23 @@ import (
"golang.org/x/sys/unix" "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 { type oobMessage struct {
Drops uint32 Drops uint32
Received time.Time Received time.Time

View File

@@ -15,31 +15,17 @@ import (
var ( var (
oobLength = syscall.CmsgLen(4) + syscall.CmsgLen(16) // uint32 + 2*int64 oobLength = syscall.CmsgLen(4) + syscall.CmsgLen(16) // uint32 + 2*int64
udpSocketOptions = []socketOption{ udpSocketOptions = append(commonUDPSocketOptions, 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 // Get the number of dropped packets
Name: "SO_RXQ_OVFL", Name: "SO_RXQ_OVFL",
Level: unix.SOL_SOCKET, Level: unix.SOL_SOCKET,
Option: unix.SO_RXQ_OVFL, Option: unix.SO_RXQ_OVFL,
}, { }, socketOption{
// Ask the kernel to timestamp incoming packets // Ask the kernel to timestamp incoming packets
Name: "SO_TIMESTAMP_NEW", Name: "SO_TIMESTAMP_NEW",
Level: unix.SOL_SOCKET, Level: unix.SOL_SOCKET,
Option: unix.SO_TIMESTAMP_NEW | unix.SOF_TIMESTAMPING_RX_SOFTWARE, Option: unix.SO_TIMESTAMP_NEW | unix.SOF_TIMESTAMPING_RX_SOFTWARE,
}, })
}
) )
// parseSocketControlMessage parses b and extract the number of drops // parseSocketControlMessage parses b and extract the number of drops

View File

@@ -7,27 +7,11 @@ package udp
import ( import (
"errors" "errors"
"golang.org/x/sys/unix"
) )
var ( var (
oobLength = 0 oobLength = 0
udpSocketOptions = []socketOption{ udpSocketOptions = commonUDPSocketOptions
{
// 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,
},
}
) )
// parseSocketControlMessage always returns 0. // parseSocketControlMessage always returns 0.