mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 00:21:30 +00:00
Accept "any" outbound in dns rule
This commit is contained in:
parent
88fafd4e30
commit
b3fb86d415
|
@ -232,6 +232,8 @@ Invert match result.
|
|||
|
||||
Match outbound.
|
||||
|
||||
`any` can be used as a value to match any outbound.
|
||||
|
||||
#### server
|
||||
|
||||
==Required==
|
||||
|
@ -255,17 +257,3 @@ 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.
|
|
@ -231,6 +231,8 @@ DNS 查询类型。值可以为整数或者类型名称字符串。
|
|||
|
||||
匹配出站。
|
||||
|
||||
`any` 可作为值用于匹配任意出站。
|
||||
|
||||
#### server
|
||||
|
||||
==必填==
|
||||
|
@ -254,17 +256,3 @@ DNS 查询类型。值可以为整数或者类型名称字符串。
|
|||
#### rules
|
||||
|
||||
包括的默认规则。
|
||||
|
||||
#### invert
|
||||
|
||||
反选匹配结果。
|
||||
|
||||
#### server
|
||||
|
||||
==必填==
|
||||
|
||||
目标 DNS 服务器的标签。
|
||||
|
||||
#### disable_cache
|
||||
|
||||
在此查询中禁用缓存。
|
|
@ -23,7 +23,10 @@
|
|||
"disable_cache": true
|
||||
},
|
||||
{
|
||||
"domain": "mydomain.com",
|
||||
"outbound": "any",
|
||||
"server": "local"
|
||||
},
|
||||
{
|
||||
"geosite": "cn",
|
||||
"server": "local"
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue