From c79c4cff1000ec0ee15b270e2e7aa68676ced969 Mon Sep 17 00:00:00 2001 From: Sage <49195270+sagerenn@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:14:00 +0000 Subject: [PATCH] set outbound tag of the selector for dns route --- outbound/selector.go | 3 +++ route/router.go | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/outbound/selector.go b/outbound/selector.go index e801daea..02f9a94d 100644 --- a/outbound/selector.go +++ b/outbound/selector.go @@ -153,6 +153,9 @@ func (s *Selector) NewPacketConnection(ctx context.Context, conn N.PacketConn, m } func RealTag(detour adapter.Outbound) string { + if s, ok := detour.(*Selector); ok { + return RealTag(s.selected) + } if group, isGroup := detour.(adapter.OutboundGroup); isGroup { return group.Now() } diff --git a/route/router.go b/route/router.go index c8fe94be..e32815ee 100644 --- a/route/router.go +++ b/route/router.go @@ -20,16 +20,17 @@ import ( "github.com/sagernet/sing-box/common/process" "github.com/sagernet/sing-box/common/sniff" "github.com/sagernet/sing-box/common/taskmonitor" + "github.com/sagernet/sing-box/constant" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/experimental/libbox/platform" "github.com/sagernet/sing-box/log" "github.com/sagernet/sing-box/option" "github.com/sagernet/sing-box/outbound" "github.com/sagernet/sing-box/transport/fakeip" - "github.com/sagernet/sing-dns" - "github.com/sagernet/sing-mux" - "github.com/sagernet/sing-tun" - "github.com/sagernet/sing-vmess" + dns "github.com/sagernet/sing-dns" + mux "github.com/sagernet/sing-mux" + tun "github.com/sagernet/sing-tun" + vmess "github.com/sagernet/sing-vmess" "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/buf" "github.com/sagernet/sing/common/bufio" @@ -1113,6 +1114,10 @@ func (r *Router) match(ctx context.Context, metadata *adapter.InboundContext, de } } ctx = outbound.ContextWithTag(ctx, matchOutbound.Tag()) + if matchOutbound.Type() == constant.TypeSelector { + tag := outbound.RealTag(matchOutbound) + metadata.Outbound = tag + } return ctx, matchRule, matchOutbound, nil }