mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 18:11:28 +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
|
AutoDetectInterface() bool
|
||||||
AutoDetectInterfaceName() string
|
AutoDetectInterfaceName() string
|
||||||
AutoDetectInterfaceIndex() int
|
AutoDetectInterfaceIndex() int
|
||||||
|
DefaultMark() int
|
||||||
|
|
||||||
Rules() []Rule
|
Rules() []Rule
|
||||||
SetTrafficController(controller TrafficController)
|
SetTrafficController(controller TrafficController)
|
||||||
|
|
|
@ -49,6 +49,9 @@ func NewDefault(router adapter.Router, options option.DialerOptions) *DefaultDia
|
||||||
if options.RoutingMark != 0 {
|
if options.RoutingMark != 0 {
|
||||||
dialer.Control = control.Append(dialer.Control, control.RoutingMark(options.RoutingMark))
|
dialer.Control = control.Append(dialer.Control, control.RoutingMark(options.RoutingMark))
|
||||||
listener.Control = control.Append(listener.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 {
|
if options.ReuseAddr {
|
||||||
listener.Control = control.Append(listener.Control, control.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
|
package process
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,18 @@ type RouteOptions struct {
|
||||||
FindProcess bool `json:"find_process,omitempty"`
|
FindProcess bool `json:"find_process,omitempty"`
|
||||||
AutoDetectInterface bool `json:"auto_detect_interface,omitempty"`
|
AutoDetectInterface bool `json:"auto_detect_interface,omitempty"`
|
||||||
DefaultInterface string `json:"default_interface,omitempty"`
|
DefaultInterface string `json:"default_interface,omitempty"`
|
||||||
|
DefaultMark int `json:"default_mark,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o RouteOptions) Equals(other RouteOptions) bool {
|
func (o RouteOptions) Equals(other RouteOptions) bool {
|
||||||
return common.ComparablePtrEquals(o.GeoIP, other.GeoIP) &&
|
return common.ComparablePtrEquals(o.GeoIP, other.GeoIP) &&
|
||||||
common.ComparablePtrEquals(o.Geosite, other.Geosite) &&
|
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 {
|
type GeoIPOptions struct {
|
||||||
|
|
|
@ -68,6 +68,7 @@ type Router struct {
|
||||||
autoDetectInterface bool
|
autoDetectInterface bool
|
||||||
defaultInterface string
|
defaultInterface string
|
||||||
interfaceMonitor DefaultInterfaceMonitor
|
interfaceMonitor DefaultInterfaceMonitor
|
||||||
|
defaultMark int
|
||||||
trafficController adapter.TrafficController
|
trafficController adapter.TrafficController
|
||||||
urlTestHistoryStorage *urltest.HistoryStorage
|
urlTestHistoryStorage *urltest.HistoryStorage
|
||||||
processSearcher process.Searcher
|
processSearcher process.Searcher
|
||||||
|
@ -92,6 +93,7 @@ func NewRouter(ctx context.Context, logger log.ContextLogger, dnsLogger log.Cont
|
||||||
interfaceBindManager: control.NewBindManager(),
|
interfaceBindManager: control.NewBindManager(),
|
||||||
autoDetectInterface: options.AutoDetectInterface,
|
autoDetectInterface: options.AutoDetectInterface,
|
||||||
defaultInterface: options.DefaultInterface,
|
defaultInterface: options.DefaultInterface,
|
||||||
|
defaultMark: options.DefaultMark,
|
||||||
}
|
}
|
||||||
for i, ruleOptions := range options.Rules {
|
for i, ruleOptions := range options.Rules {
|
||||||
routeRule, err := NewRule(router, logger, ruleOptions)
|
routeRule, err := NewRule(router, logger, ruleOptions)
|
||||||
|
@ -637,6 +639,10 @@ func (r *Router) AutoDetectInterfaceIndex() int {
|
||||||
return r.interfaceMonitor.DefaultInterfaceIndex()
|
return r.interfaceMonitor.DefaultInterfaceIndex()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Router) DefaultMark() int {
|
||||||
|
return r.defaultMark
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Router) Rules() []adapter.Rule {
|
func (r *Router) Rules() []adapter.Rule {
|
||||||
return r.rules
|
return r.rules
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue