mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-10 02:53:12 +00:00
Add route.default_mark option
This commit is contained in:
parent
7d340e7ef9
commit
fe8e984608
|
@ -36,6 +36,7 @@ type Router interface {
|
|||
AutoDetectInterface() bool
|
||||
AutoDetectInterfaceName() string
|
||||
AutoDetectInterfaceIndex() int
|
||||
DefaultMark() int
|
||||
|
||||
Rules() []Rule
|
||||
SetTrafficController(controller TrafficController)
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//go:build !cgo || !linux || android
|
||||
//go:build !(cgo && linux && !android)
|
||||
|
||||
package process
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue