Răsfoiți Sursa

Accept "any" outbound in dns rule

世界 2 ani în urmă
părinte
comite
b3fb86d415

+ 3 - 15
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.
+Included default rules.

+ 3 - 15
docs/configuration/dns/rule.zh.md

@@ -231,6 +231,8 @@ DNS 查询类型。值可以为整数或者类型名称字符串。
 
 匹配出站。
 
+`any` 可作为值用于匹配任意出站。
+
 #### server
 
 ==必填==
@@ -253,18 +255,4 @@ DNS 查询类型。值可以为整数或者类型名称字符串。
 
 #### rules
 
-包括的默认规则。
-
-#### invert
-
-反选匹配结果。
-
-#### server
-
-==必填==
-
-目标 DNS 服务器的标签。
-
-#### disable_cache
-
-在此查询中禁用缓存。
+包括的默认规则。

+ 4 - 1
docs/examples/tun.md

@@ -23,7 +23,10 @@
         "disable_cache": true
       },
       {
-        "domain": "mydomain.com",
+        "outbound": "any",
+        "server": "local"
+      },
+      {
         "geosite": "cn",
         "server": "local"
       }

+ 10 - 2
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]
 }