Always color output and fold settled values into constants

This commit is contained in:
flamingcow
2026-07-25 18:20:34 -07:00
parent 29c6ce0b56
commit 3ba68952bb
5 changed files with 29 additions and 79 deletions
+9 -4
View File
@@ -31,7 +31,12 @@ func sockBufSize(fd, opt int) int {
return v
}
func openTxSocket(ifindex, sndbuf int) (int, error) {
const (
sndbufBytes = 8 << 20
rcvbufBytes = 64 << 20
)
func openTxSocket(ifindex int) (int, error) {
fd, err := unix.Socket(unix.AF_PACKET, unix.SOCK_RAW, 0)
if err != nil {
return -1, fmt.Errorf("socket: %w", err)
@@ -44,20 +49,20 @@ func openTxSocket(ifindex, sndbuf int) (int, error) {
unix.Close(fd)
return -1, fmt.Errorf("qdisc bypass: %w", err)
}
if err := setBufForce(fd, unix.SO_SNDBUFFORCE, unix.SO_SNDBUF, sndbuf); err != nil {
if err := setBufForce(fd, unix.SO_SNDBUFFORCE, unix.SO_SNDBUF, sndbufBytes); err != nil {
unix.Close(fd)
return -1, fmt.Errorf("sndbuf: %w", err)
}
return fd, nil
}
func openRxSocket(ifindex, rcvbuf, fanoutID, fanoutMode int) (int, error) {
func openRxSocket(ifindex, fanoutID, fanoutMode int) (int, error) {
proto := int(htons(etherType))
fd, err := unix.Socket(unix.AF_PACKET, unix.SOCK_RAW, proto)
if err != nil {
return -1, fmt.Errorf("socket: %w", err)
}
if err := setBufForce(fd, unix.SO_RCVBUFFORCE, unix.SO_RCVBUF, rcvbuf); err != nil {
if err := setBufForce(fd, unix.SO_RCVBUFFORCE, unix.SO_RCVBUF, rcvbufBytes); err != nil {
unix.Close(fd)
return -1, fmt.Errorf("rcvbuf: %w", err)
}