mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
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
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:
@@ -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
|
||||||
|
|||||||
@@ -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{
|
||||||
{
|
// Get the number of dropped packets
|
||||||
// Allow multiple listeners to bind to the same IP
|
Name: "SO_RXQ_OVFL",
|
||||||
Name: "SO_REUSEADDR",
|
Level: unix.SOL_SOCKET,
|
||||||
Level: unix.SOL_SOCKET,
|
Option: unix.SO_RXQ_OVFL,
|
||||||
Option: unix.SO_REUSEADDR,
|
}, socketOption{
|
||||||
Mandatory: true,
|
// Ask the kernel to timestamp incoming packets
|
||||||
}, {
|
Name: "SO_TIMESTAMP_NEW",
|
||||||
// Allow multiple listeners to bind to the same port
|
Level: unix.SOL_SOCKET,
|
||||||
Name: "SO_REUSEPORT",
|
Option: unix.SO_TIMESTAMP_NEW | unix.SOF_TIMESTAMPING_RX_SOFTWARE,
|
||||||
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,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// parseSocketControlMessage parses b and extract the number of drops
|
// parseSocketControlMessage parses b and extract the number of drops
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user