From 879c38351b026079fbbf0e7c5d92ac494568869a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 29 Mar 2023 10:30:31 +0800 Subject: [PATCH] Accept "any" outbound in dns rule --- route/rule_outbound.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/route/rule_outbound.go b/route/rule_outbound.go index 952e1b64..4b3e16fc 100644 --- a/route/rule_outbound.go +++ b/route/rule_outbound.go @@ -12,17 +12,25 @@ var _ RuleItem = (*OutboundItem)(nil) type OutboundItem struct { outbounds []string outboundMap map[string]bool + matchAny bool } func NewOutboundRule(outbounds []string) *OutboundItem { - rule := &OutboundItem{outbounds, make(map[string]bool)} + rule := &OutboundItem{outbounds: outbounds, outboundMap: make(map[string]bool)} for _, outbound := range outbounds { - rule.outboundMap[outbound] = true + if outbound == "any" { + rule.matchAny = true + } else { + rule.outboundMap[outbound] = true + } } return rule } func (r *OutboundItem) Match(metadata *adapter.InboundContext) bool { + if r.matchAny && metadata.Outbound != "" { + return true + } return r.outboundMap[metadata.Outbound] }