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