diff --git a/adapter/router.go b/adapter/router.go index f18faf11..ad667636 100644 --- a/adapter/router.go +++ b/adapter/router.go @@ -36,6 +36,7 @@ type Router interface { AutoDetectInterface() bool AutoDetectInterfaceName() string AutoDetectInterfaceIndex() int + DefaultMark() int Rules() []Rule SetTrafficController(controller TrafficController) diff --git a/common/dialer/default.go b/common/dialer/default.go index 0a69e43d..c9f1df89 100644 --- a/common/dialer/default.go +++ b/common/dialer/default.go @@ -49,6 +49,9 @@ func NewDefault(router adapter.Router, options option.DialerOptions) *DefaultDia if options.RoutingMark != 0 { dialer.Control = control.Append(dialer.Control, control.RoutingMark(options.RoutingMark)) listener.Control = control.Append(listener.Control, control.RoutingMark(options.RoutingMark)) + } else if router.DefaultMark() != 0 { + dialer.Control = control.Append(dialer.Control, control.RoutingMark(router.DefaultMark())) + listener.Control = control.Append(listener.Control, control.RoutingMark(router.DefaultMark())) } if options.ReuseAddr { listener.Control = control.Append(listener.Control, control.ReuseAddr()) diff --git a/common/process/searcher_without_name.go b/common/process/searcher_without_name.go index 6b22d0c7..c3d542e6 100644 --- a/common/process/searcher_without_name.go +++ b/common/process/searcher_without_name.go @@ -1,4 +1,4 @@ -//go:build !cgo || !linux || android +//go:build !(cgo && linux && !android) package process diff --git a/option/route.go b/option/route.go index 1b9cea34..8a942fa9 100644 --- a/option/route.go +++ b/option/route.go @@ -16,12 +16,18 @@ type RouteOptions struct { FindProcess bool `json:"find_process,omitempty"` AutoDetectInterface bool `json:"auto_detect_interface,omitempty"` DefaultInterface string `json:"default_interface,omitempty"` + DefaultMark int `json:"default_mark,omitempty"` } func (o RouteOptions) Equals(other RouteOptions) bool { return common.ComparablePtrEquals(o.GeoIP, other.GeoIP) && common.ComparablePtrEquals(o.Geosite, other.Geosite) && - common.SliceEquals(o.Rules, other.Rules) + common.SliceEquals(o.Rules, other.Rules) && + o.Final == other.Final && + o.FindProcess == other.FindProcess && + o.AutoDetectInterface == other.AutoDetectInterface && + o.DefaultInterface == other.DefaultInterface && + o.DefaultMark == other.DefaultMark } type GeoIPOptions struct { diff --git a/route/router.go b/route/router.go index 634e8cf0..3bb1a9e4 100644 --- a/route/router.go +++ b/route/router.go @@ -68,6 +68,7 @@ type Router struct { autoDetectInterface bool defaultInterface string interfaceMonitor DefaultInterfaceMonitor + defaultMark int trafficController adapter.TrafficController urlTestHistoryStorage *urltest.HistoryStorage processSearcher process.Searcher @@ -92,6 +93,7 @@ func NewRouter(ctx context.Context, logger log.ContextLogger, dnsLogger log.Cont interfaceBindManager: control.NewBindManager(), autoDetectInterface: options.AutoDetectInterface, defaultInterface: options.DefaultInterface, + defaultMark: options.DefaultMark, } for i, ruleOptions := range options.Rules { routeRule, err := NewRule(router, logger, ruleOptions) @@ -637,6 +639,10 @@ func (r *Router) AutoDetectInterfaceIndex() int { return r.interfaceMonitor.DefaultInterfaceIndex() } +func (r *Router) DefaultMark() int { + return r.defaultMark +} + func (r *Router) Rules() []adapter.Rule { return r.rules }