[client] Add NB_SKIP_SOCKET_MARK & fix crash instead of returing an error (#2899)

* dialer: fix crash instead of returning error

* add NB_SKIP_SOCKET_MARK
This commit is contained in:
Krzysztof Nazarewski (kdn)
2024-11-19 14:14:58 +01:00
committed by GitHub
parent 52ea2e84e9
commit eb5d0569ae
4 changed files with 21 additions and 4 deletions

View File

@ -4,9 +4,14 @@ package net
import (
"fmt"
"os"
"syscall"
log "github.com/sirupsen/logrus"
)
const EnvSkipSocketMark = "NB_SKIP_SOCKET_MARK"
// SetSocketMark sets the SO_MARK option on the given socket connection
func SetSocketMark(conn syscall.Conn) error {
sysconn, err := conn.SyscallConn()
@ -36,6 +41,13 @@ func SetRawSocketMark(conn syscall.RawConn) error {
func SetSocketOpt(fd int) error {
if CustomRoutingDisabled() {
log.Infof("Custom routing is disabled, skipping SO_MARK")
return nil
}
// Check for the new environment variable
if skipSocketMark := os.Getenv(EnvSkipSocketMark); skipSocketMark == "true" {
log.Info("NB_SKIP_SOCKET_MARK is set to true, skipping SO_MARK")
return nil
}