diff --git a/docs/configuration/dns/rule.md b/docs/configuration/dns/rule.md index 5132253b..256408b2 100644 --- a/docs/configuration/dns/rule.md +++ b/docs/configuration/dns/rule.md @@ -232,6 +232,8 @@ Invert match result. Match outbound. +`any` can be used as a value to match any outbound. + #### server ==Required== @@ -254,18 +256,4 @@ Disable cache and save cache in this query. #### rules -Included default rules. - -#### invert - -Invert match result. - -#### server - -==Required== - -Tag of the target dns server. - -#### disable_cache - -Disable cache and save cache in this query. \ No newline at end of file +Included default rules. \ No newline at end of file diff --git a/docs/configuration/dns/rule.zh.md b/docs/configuration/dns/rule.zh.md index f3ea1c01..45e1e9c3 100644 --- a/docs/configuration/dns/rule.zh.md +++ b/docs/configuration/dns/rule.zh.md @@ -231,6 +231,8 @@ DNS 查询类型。值可以为整数或者类型名称字符串。 匹配出站。 +`any` 可作为值用于匹配任意出站。 + #### server ==必填== @@ -253,18 +255,4 @@ DNS 查询类型。值可以为整数或者类型名称字符串。 #### rules -包括的默认规则。 - -#### invert - -反选匹配结果。 - -#### server - -==必填== - -目标 DNS 服务器的标签。 - -#### disable_cache - -在此查询中禁用缓存。 \ No newline at end of file +包括的默认规则。 \ No newline at end of file diff --git a/docs/examples/tun.md b/docs/examples/tun.md index e4273a8d..8671ef76 100644 --- a/docs/examples/tun.md +++ b/docs/examples/tun.md @@ -23,7 +23,10 @@ "disable_cache": true }, { - "domain": "mydomain.com", + "outbound": "any", + "server": "local" + }, + { "geosite": "cn", "server": "local" } 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] }