[client] Check for fwmark support and use fallback routing if not supported (#3220)

This commit is contained in:
Viktor Liu
2025-02-11 13:09:17 +01:00
committed by GitHub
parent 44407a158a
commit 18f84f0df5
10 changed files with 163 additions and 56 deletions

View File

@ -5,13 +5,11 @@ package net
import (
"fmt"
"syscall"
log "github.com/sirupsen/logrus"
)
// SetSocketMark sets the SO_MARK option on the given socket connection
func SetSocketMark(conn syscall.Conn) error {
if isSocketMarkDisabled() {
if !AdvancedRouting() {
return nil
}
@ -25,7 +23,7 @@ func SetSocketMark(conn syscall.Conn) error {
// SetSocketOpt sets the SO_MARK option on the given file descriptor
func SetSocketOpt(fd int) error {
if isSocketMarkDisabled() {
if !AdvancedRouting() {
return nil
}
@ -36,7 +34,7 @@ func setRawSocketMark(conn syscall.RawConn) error {
var setErr error
err := conn.Control(func(fd uintptr) {
if isSocketMarkDisabled() {
if !AdvancedRouting() {
return
}
setErr = setSocketOptInt(int(fd))
@ -55,15 +53,3 @@ func setRawSocketMark(conn syscall.RawConn) error {
func setSocketOptInt(fd int) error {
return syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_MARK, NetbirdFwmark)
}
func isSocketMarkDisabled() bool {
if CustomRoutingDisabled() {
log.Infof("Custom routing is disabled, skipping SO_MARK")
return true
}
if SkipSocketMark() {
return true
}
return false
}