Skip to content

Commit

Permalink
add NB_SKIP_SOCKET_MARK
Browse files Browse the repository at this point in the history
fix created during investigation of #2530
  • Loading branch information
nazarewk committed Nov 19, 2024
1 parent ed45da3 commit 634596a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/internal/routemanager/systemops/systemops_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type ruleParams struct {

// isLegacy determines whether to use the legacy routing setup
func isLegacy() bool {
return os.Getenv("NB_USE_LEGACY_ROUTING") == "true" || nbnet.CustomRoutingDisabled()
return os.Getenv("NB_USE_LEGACY_ROUTING") == "true" || nbnet.CustomRoutingDisabled() || os.Getenv(nbnet.EnvSkipSocketMark) == "true"
}

// setIsLegacy sets the legacy routing setup
Expand Down
2 changes: 1 addition & 1 deletion util/net/dialer_nonios.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.

conn, err := d.Dialer.DialContext(ctx, network, address)
if err != nil {
return nil, fmt.Errorf("dial: %w", err)
return nil, fmt.Errorf("d.Dialer.DialContext: %w", err)
}

// Wrap the connection in Conn to handle Close with hooks
Expand Down
12 changes: 12 additions & 0 deletions util/net/net_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 634596a

Please sign in to comment.