From a0221bf897330647f024d4854b053970854ecd7d Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Thu, 17 Feb 2022 14:23:47 +0800 Subject: [PATCH] Fix: `routing-mark` should effect on root --- component/dialer/dialer.go | 2 ++ component/dialer/options.go | 5 +++-- config/config.go | 19 +++++++++++-------- hub/executor/executor.go | 1 + 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/component/dialer/dialer.go b/component/dialer/dialer.go index c84fcaa4..d2b56959 100644 --- a/component/dialer/dialer.go +++ b/component/dialer/dialer.go @@ -38,6 +38,7 @@ func DialContext(ctx context.Context, network, address string, options ...Option func ListenPacket(ctx context.Context, network, address string, options ...Option) (net.PacketConn, error) { cfg := &option{ interfaceName: DefaultInterface.Load(), + routingMark: int(DefaultRoutingMark.Load()), } for _, o := range DefaultOptions { @@ -69,6 +70,7 @@ func ListenPacket(ctx context.Context, network, address string, options ...Optio func dialContext(ctx context.Context, network string, destination net.IP, port string, options []Option) (net.Conn, error) { opt := &option{ interfaceName: DefaultInterface.Load(), + routingMark: int(DefaultRoutingMark.Load()), } for _, o := range DefaultOptions { diff --git a/component/dialer/options.go b/component/dialer/options.go index b3cca810..2d884094 100644 --- a/component/dialer/options.go +++ b/component/dialer/options.go @@ -3,8 +3,9 @@ package dialer import "go.uber.org/atomic" var ( - DefaultOptions []Option - DefaultInterface = atomic.NewString("") + DefaultOptions []Option + DefaultInterface = atomic.NewString("") + DefaultRoutingMark = atomic.NewInt32(0) ) type option struct { diff --git a/config/config.go b/config/config.go index a9abe71f..c6c83d11 100644 --- a/config/config.go +++ b/config/config.go @@ -29,10 +29,11 @@ import ( type General struct { Inbound Controller - Mode T.TunnelMode `json:"mode"` - LogLevel log.LogLevel `json:"log-level"` - IPv6 bool `json:"ipv6"` - Interface string `json:"-"` + Mode T.TunnelMode `json:"mode"` + LogLevel log.LogLevel `json:"log-level"` + IPv6 bool `json:"ipv6"` + Interface string `json:"-"` + RoutingMark int `json:"-"` } // Inbound @@ -137,6 +138,7 @@ type RawConfig struct { ExternalUI string `yaml:"external-ui"` Secret string `yaml:"secret"` Interface string `yaml:"interface-name"` + RoutingMark int `yaml:"routing-mark"` ProxyProvider map[string]map[string]interface{} `yaml:"proxy-providers"` Hosts map[string]string `yaml:"hosts"` @@ -265,10 +267,11 @@ func parseGeneral(cfg *RawConfig) (*General, error) { ExternalUI: cfg.ExternalUI, Secret: cfg.Secret, }, - Mode: cfg.Mode, - LogLevel: cfg.LogLevel, - IPv6: cfg.IPv6, - Interface: cfg.Interface, + Mode: cfg.Mode, + LogLevel: cfg.LogLevel, + IPv6: cfg.IPv6, + Interface: cfg.Interface, + RoutingMark: cfg.RoutingMark, }, nil } diff --git a/hub/executor/executor.go b/hub/executor/executor.go index 1405e81b..9a9cc81b 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -162,6 +162,7 @@ func updateGeneral(general *config.General, force bool) { resolver.DisableIPv6 = !general.IPv6 dialer.DefaultInterface.Store(general.Interface) + dialer.DefaultRoutingMark.Store(int32(general.RoutingMark)) iface.FlushCache()