Add route.default_mark option

This commit is contained in:
世界 2022-07-24 17:46:25 +08:00
parent 7d340e7ef9
commit fe8e984608
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
5 changed files with 18 additions and 2 deletions

View file

@ -36,6 +36,7 @@ type Router interface {
AutoDetectInterface() bool
AutoDetectInterfaceName() string
AutoDetectInterfaceIndex() int
DefaultMark() int
Rules() []Rule
SetTrafficController(controller TrafficController)

View file

@ -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())

View file

@ -1,4 +1,4 @@
//go:build !cgo || !linux || android
//go:build !(cgo && linux && !android)
package process

View file

@ -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 {

View file

@ -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
}