Skip to content

Commit cdee827

Browse files
committed
Un-deprecate ip_accept_any DNS rule item
1 parent 53c14cf commit cdee827

10 files changed

Lines changed: 24 additions & 69 deletions

File tree

dns/router.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -841,10 +841,10 @@ func (r *Router) ResetNetwork() {
841841
}
842842

843843
func defaultRuleNeedsLegacyDNSModeFromAddressFilter(rule option.DefaultDNSRule) bool {
844-
if rule.IPAcceptAny || rule.RuleSetIPCIDRAcceptEmpty { //nolint:staticcheck
844+
if rule.RuleSetIPCIDRAcceptEmpty { //nolint:staticcheck
845845
return true
846846
}
847-
return !rule.MatchResponse && (len(rule.IPCIDR) > 0 || rule.IPIsPrivate)
847+
return !rule.MatchResponse && (rule.IPAcceptAny || len(rule.IPCIDR) > 0 || rule.IPIsPrivate)
848848
}
849849

850850
func hasResponseMatchFields(rule option.DefaultDNSRule) bool {
@@ -1049,17 +1049,14 @@ func validateLegacyDNSModeDisabledRuleTree(rule option.DNSRule) (bool, error) {
10491049

10501050
func validateLegacyDNSModeDisabledDefaultRule(rule option.DefaultDNSRule) (bool, error) {
10511051
hasResponseRecords := hasResponseMatchFields(rule)
1052-
if (hasResponseRecords || len(rule.IPCIDR) > 0 || rule.IPIsPrivate) && !rule.MatchResponse {
1053-
return false, E.New("Response Match Fields (ip_cidr, ip_is_private, response_rcode, response_answer, response_ns, response_extra) require match_response to be enabled")
1052+
if (hasResponseRecords || len(rule.IPCIDR) > 0 || rule.IPIsPrivate || rule.IPAcceptAny) && !rule.MatchResponse {
1053+
return false, E.New("Response Match Fields (ip_cidr, ip_is_private, ip_accept_any, response_rcode, response_answer, response_ns, response_extra) require match_response to be enabled")
10541054
}
10551055
// Intentionally do not reject rule_set here. A referenced rule set may mix
10561056
// destination-IP predicates with pre-response predicates such as domain items.
10571057
// When match_response is false, those destination-IP branches fail closed during
10581058
// pre-response evaluation instead of consuming DNS response state, while sibling
10591059
// non-response branches remain matchable.
1060-
if rule.IPAcceptAny { //nolint:staticcheck
1061-
return false, E.New(deprecated.OptionIPAcceptAny.MessageWithLink())
1062-
}
10631060
if rule.RuleSetIPCIDRAcceptEmpty { //nolint:staticcheck
10641061
return false, E.New(deprecated.OptionRuleSetIPCIDRAcceptEmpty.MessageWithLink())
10651062
}

docs/configuration/dns/rule.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ icon: material/alert-decagram
88
:material-plus: [source_hostname](#source_hostname)
99
:material-plus: [match_response](#match_response)
1010
:material-delete-clock: [rule_set_ip_cidr_accept_empty](#rule_set_ip_cidr_accept_empty)
11-
:material-delete-clock: [ip_accept_any](#ip_accept_any)
1211
:material-plus: [response_rcode](#response_rcode)
1312
:material-plus: [response_answer](#response_answer)
1413
:material-plus: [response_ns](#response_ns)
@@ -178,6 +177,7 @@ icon: material/alert-decagram
178177
"192.168.0.1"
179178
],
180179
"ip_is_private": false,
180+
"ip_accept_any": false,
181181
"response_rcode": "",
182182
"response_answer": [],
183183
"response_ns": [],
@@ -191,7 +191,6 @@ icon: material/alert-decagram
191191

192192
// Deprecated
193193

194-
"ip_accept_any": false,
195194
"rule_set_ip_cidr_accept_empty": false,
196195
"rule_set_ipcidr_match_source": false,
197196
"geosite": [
@@ -500,7 +499,13 @@ instead of only matching the original query.
500499
The evaluated response can also be returned directly by a later [`respond`](/configuration/dns/rule_action/#respond) action.
501500

502501
Required for Response Match Fields (`response_rcode`, `response_answer`, `response_ns`, `response_extra`).
503-
Also required for `ip_cidr` and `ip_is_private` when used with `evaluate` or Response Match Fields.
502+
Also required for `ip_cidr`, `ip_is_private`, and `ip_accept_any` when used with `evaluate` or Response Match Fields.
503+
504+
#### ip_accept_any
505+
506+
!!! question "Since sing-box 1.12.0"
507+
508+
Match when the DNS query response contains at least one address.
504509

505510
#### invert
506511

@@ -600,17 +605,6 @@ check [Migration](/migration/#migrate-address-filter-fields-to-response-matching
600605

601606
Make `ip_cidr` rules in rule-sets accept empty query response.
602607

603-
#### ip_accept_any
604-
605-
!!! question "Since sing-box 1.12.0"
606-
607-
!!! failure "Deprecated in sing-box 1.14.0"
608-
609-
`ip_accept_any` is deprecated and will be removed in sing-box 1.16.0,
610-
check [Migration](/migration/#migrate-address-filter-fields-to-response-matching).
611-
612-
Match any IP with query response.
613-
614608
### Response Match Fields
615609

616610
!!! question "Since sing-box 1.14.0"

docs/configuration/dns/rule.zh.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ icon: material/alert-decagram
88
:material-plus: [source_hostname](#source_hostname)
99
:material-plus: [match_response](#match_response)
1010
:material-delete-clock: [rule_set_ip_cidr_accept_empty](#rule_set_ip_cidr_accept_empty)
11-
:material-delete-clock: [ip_accept_any](#ip_accept_any)
1211
:material-plus: [response_rcode](#response_rcode)
1312
:material-plus: [response_answer](#response_answer)
1413
:material-plus: [response_ns](#response_ns)
@@ -178,6 +177,7 @@ icon: material/alert-decagram
178177
"192.168.0.1"
179178
],
180179
"ip_is_private": false,
180+
"ip_accept_any": false,
181181
"response_rcode": "",
182182
"response_answer": [],
183183
"response_ns": [],
@@ -191,7 +191,6 @@ icon: material/alert-decagram
191191

192192
// 已弃用
193193

194-
"ip_accept_any": false,
195194
"rule_set_ip_cidr_accept_empty": false,
196195
"rule_set_ipcidr_match_source": false,
197196
"geosite": [
@@ -498,7 +497,13 @@ Available values: `wifi`, `cellular`, `ethernet` and `other`.
498497
该已评估的响应也可以被后续的 [`respond`](/zh/configuration/dns/rule_action/#respond) 动作直接返回。
499498

500499
响应匹配字段(`response_rcode``response_answer``response_ns``response_extra`)需要此选项。
501-
当与 `evaluate` 或响应匹配字段一起使用时,`ip_cidr``ip_is_private` 也需要此选项。
500+
当与 `evaluate` 或响应匹配字段一起使用时,`ip_cidr``ip_is_private``ip_accept_any` 也需要此选项。
501+
502+
#### ip_accept_any
503+
504+
!!! question "自 sing-box 1.12.0 起"
505+
506+
当 DNS 查询响应包含至少一个地址时匹配。
502507

503508
#### invert
504509

@@ -599,17 +604,6 @@ Available values: `wifi`, `cellular`, `ethernet` and `other`.
599604

600605
使规则集中的 `ip_cidr` 规则接受空查询响应。
601606

602-
#### ip_accept_any
603-
604-
!!! question "自 sing-box 1.12.0 起"
605-
606-
!!! failure "已在 sing-box 1.14.0 废弃"
607-
608-
`ip_accept_any` 已废弃且将在 sing-box 1.16.0 中被移除,
609-
参阅[迁移指南](/zh/migration/#迁移地址筛选字段到响应匹配)。
610-
611-
匹配任意 IP。
612-
613607
### 响应匹配字段
614608

615609
!!! question "自 sing-box 1.14.0 起"

docs/deprecated.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ check [Migration](../migration/#migrate-dns-rule-action-strategy-to-rule-items).
2121

2222
Old fields will be removed in sing-box 1.16.0.
2323

24-
#### Legacy `ip_accept_any` DNS rule item
25-
26-
Legacy `ip_accept_any` DNS rule item is deprecated,
27-
check [Migration](../migration/#migrate-address-filter-fields-to-response-matching).
28-
29-
Old fields will be removed in sing-box 1.16.0.
30-
3124
#### Legacy `rule_set_ip_cidr_accept_empty` DNS rule item
3225

3326
Legacy `rule_set_ip_cidr_accept_empty` DNS rule item is deprecated,

docs/deprecated.zh.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ TLS 中的内联 ACME 选项(`tls.acme`)已废弃,
2121

2222
旧字段将在 sing-box 1.16.0 中被移除。
2323

24-
#### 旧版 `ip_accept_any` DNS 规则项
25-
26-
旧版 `ip_accept_any` DNS 规则项已废弃,
27-
参阅[迁移指南](/zh/migration/#迁移地址筛选字段到响应匹配)
28-
29-
旧字段将在 sing-box 1.16.0 中被移除。
30-
3124
#### 旧版 `rule_set_ip_cidr_accept_empty` DNS 规则项
3225

3326
旧版 `rule_set_ip_cidr_accept_empty` DNS 规则项已废弃,

docs/migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Use `ip_version` or `query_type` rule items to control which query types a rule
129129
### Migrate address filter fields to response matching
130130

131131
Legacy Address Filter Fields (`ip_cidr`, `ip_is_private` without `match_response`) in DNS rules are deprecated,
132-
along with Legacy `ip_accept_any` and Legacy `rule_set_ip_cidr_accept_empty` DNS rule items.
132+
along with the Legacy `rule_set_ip_cidr_accept_empty` DNS rule item.
133133

134134
In sing-box 1.14.0, use the [`evaluate`](/configuration/dns/rule_action/#evaluate) action
135135
to fetch a DNS response, then match against it explicitly with `match_response`.

docs/migration.zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ sing-box 1.14.0 新增字段参阅 [ACME](/zh/configuration/shared/certificate-p
129129
### 迁移地址筛选字段到响应匹配
130130

131131
旧版地址筛选字段(不使用 `match_response``ip_cidr``ip_is_private`)已废弃,
132-
旧版 `ip_accept_any` 和旧版 `rule_set_ip_cidr_accept_empty` DNS 规则项也已废弃。
132+
旧版 `rule_set_ip_cidr_accept_empty` DNS 规则项也已废弃。
133133

134134
在 sing-box 1.14.0 中,请使用 [`evaluate`](/zh/configuration/dns/rule_action/#evaluate) 动作
135135
获取 DNS 响应,然后通过 `match_response` 显式匹配。

experimental/deprecated/constants.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,6 @@ var OptionInlineACME = Note{
9393
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-inline-acme-to-certificate-provider",
9494
}
9595

96-
var OptionIPAcceptAny = Note{
97-
Name: "dns-rule-ip-accept-any",
98-
Description: "Legacy `ip_accept_any` DNS rule item",
99-
DeprecatedVersion: "1.14.0",
100-
ScheduledVersion: "1.16.0",
101-
EnvName: "DNS_RULE_IP_ACCEPT_ANY",
102-
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-address-filter-fields-to-response-matching",
103-
}
104-
10596
var OptionRuleSetIPCIDRAcceptEmpty = Note{
10697
Name: "dns-rule-rule-set-ip-cidr-accept-empty",
10798
Description: "Legacy `rule_set_ip_cidr_accept_empty` DNS rule item",
@@ -134,7 +125,6 @@ var Options = []Note{
134125
OptionMissingDomainResolver,
135126
OptionLegacyDomainStrategyOptions,
136127
OptionInlineACME,
137-
OptionIPAcceptAny,
138128
OptionRuleSetIPCIDRAcceptEmpty,
139129
OptionLegacyDNSAddressFilter,
140130
OptionLegacyDNSRuleStrategy,

option/rule_dns.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ type RawDefaultDNSRule struct {
107107
MatchResponse bool `json:"match_response,omitempty"`
108108
IPCIDR badoption.Listable[string] `json:"ip_cidr,omitempty"`
109109
IPIsPrivate bool `json:"ip_is_private,omitempty"`
110+
IPAcceptAny bool `json:"ip_accept_any,omitempty"`
110111
ResponseRcode *DNSRCode `json:"response_rcode,omitempty"`
111112
ResponseAnswer badoption.Listable[DNSRecordOptions] `json:"response_answer,omitempty"`
112113
ResponseNs badoption.Listable[DNSRecordOptions] `json:"response_ns,omitempty"`
@@ -117,8 +118,6 @@ type RawDefaultDNSRule struct {
117118
Geosite badoption.Listable[string] `json:"geosite,omitempty"`
118119
SourceGeoIP badoption.Listable[string] `json:"source_geoip,omitempty"`
119120
GeoIP badoption.Listable[string] `json:"geoip,omitempty"`
120-
// Deprecated: use match_response with response items
121-
IPAcceptAny bool `json:"ip_accept_any,omitempty"`
122121
// Deprecated: removed in sing-box 1.11.0
123122
RuleSetIPCIDRAcceptEmpty bool `json:"rule_set_ip_cidr_accept_empty,omitempty"`
124123
// Deprecated: renamed to rule_set_ip_cidr_match_source

route/rule/rule_dns.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,7 @@ func NewDefaultDNSRule(ctx context.Context, logger log.ContextLogger, options op
177177
rule.destinationIPCIDRItems = append(rule.destinationIPCIDRItems, item)
178178
rule.allItems = append(rule.allItems, item)
179179
}
180-
if options.IPAcceptAny { //nolint:staticcheck
181-
if legacyDNSMode {
182-
deprecated.Report(ctx, deprecated.OptionIPAcceptAny)
183-
} else {
184-
return nil, E.New(deprecated.OptionIPAcceptAny.MessageWithLink())
185-
}
180+
if options.IPAcceptAny {
186181
item := NewIPAcceptAnyItem()
187182
rule.destinationIPCIDRItems = append(rule.destinationIPCIDRItems, item)
188183
rule.allItems = append(rule.allItems, item)

0 commit comments

Comments
 (0)