mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
If the kernel is too old for timestamping, it should not be fatal. I prefer to not accept SO_TIMESTAMP_OLD as the size of the timestamp is arch-dependent. Fix #1978
50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
// SPDX-FileCopyrightText: 2022 Free Mobile
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package udp
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"syscall"
|
|
"time"
|
|
|
|
"akvorado/common/reporter"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
type oobMessage struct {
|
|
Drops uint32
|
|
Received time.Time
|
|
}
|
|
|
|
// socketOption describes a socket option to be applied.
|
|
type socketOption struct {
|
|
Name string
|
|
Level int
|
|
Option int
|
|
Mandatory bool
|
|
}
|
|
|
|
// listenConfig configures a listening socket with the udpSocketOptions.
|
|
var listenConfig = func(r *reporter.Reporter, opts []socketOption) *net.ListenConfig {
|
|
return &net.ListenConfig{
|
|
Control: func(_, _ string, c syscall.RawConn) error {
|
|
var err error
|
|
for _, opt := range opts {
|
|
c.Control(func(fd uintptr) {
|
|
err = unix.SetsockoptInt(int(fd), opt.Level, opt.Option, 1)
|
|
})
|
|
if err != nil {
|
|
if opt.Mandatory {
|
|
return fmt.Errorf("cannot set option %s: %w", opt.Name, err)
|
|
}
|
|
r.Warn().Err(err).Msgf("cannot set option %s", opt.Name)
|
|
}
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
}
|