Unique rule-set names

This commit is contained in:
世界 2024-06-26 00:45:10 +08:00
parent cd2edabba7
commit 42643c6489
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
15 changed files with 57 additions and 57 deletions

View file

@ -6,7 +6,7 @@ import (
var commandRuleSet = &cobra.Command{ var commandRuleSet = &cobra.Command{
Use: "rule-set", Use: "rule-set",
Short: "Manage rule sets", Short: "Manage rule-sets",
} }
func init() { func init() {

View file

@ -23,7 +23,7 @@ var flagRuleSetMatchFormat string
var commandRuleSetMatch = &cobra.Command{ var commandRuleSetMatch = &cobra.Command{
Use: "match <rule-set path> <IP address/domain>", Use: "match <rule-set path> <IP address/domain>",
Short: "Check if an IP address or a domain matches the rule set", Short: "Check if an IP address or a domain matches the rule-set",
Args: cobra.ExactArgs(2), Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
err := ruleSetMatch(args[0], args[1]) err := ruleSetMatch(args[0], args[1])
@ -70,7 +70,7 @@ func ruleSetMatch(sourcePath string, domain string) error {
return err return err
} }
default: default:
return E.New("unknown rule set format: ", flagRuleSetMatchFormat) return E.New("unknown rule-set format: ", flagRuleSetMatchFormat)
} }
ipAddress := M.ParseAddr(domain) ipAddress := M.ParseAddr(domain)
var metadata adapter.InboundContext var metadata adapter.InboundContext

View file

@ -46,7 +46,7 @@ func Read(reader io.Reader, recover bool) (ruleSet option.PlainRuleSet, err erro
return return
} }
if magicBytes != MagicBytes { if magicBytes != MagicBytes {
err = E.New("invalid sing-box rule set file") err = E.New("invalid sing-box rule-set file")
return return
} }
var version uint8 var version uint8

View file

@ -338,7 +338,7 @@ See [Address Filter Fields](/configuration/dns/rule#address-filter-fields).
Important changes since 1.7: Important changes since 1.7:
* Migrate cache file from Clash API to independent options **1** * Migrate cache file from Clash API to independent options **1**
* Introducing [Rule Set](/configuration/rule-set/) **2** * Introducing [rule-set](/configuration/rule-set/) **2**
* Add `sing-box geoip`, `sing-box geosite` and `sing-box rule-set` commands **3** * Add `sing-box geoip`, `sing-box geosite` and `sing-box rule-set` commands **3**
* Allow nested logical rules **4** * Allow nested logical rules **4**
* Independent `source_ip_is_private` and `ip_is_private` rules **5** * Independent `source_ip_is_private` and `ip_is_private` rules **5**
@ -358,7 +358,7 @@ See [Cache File](/configuration/experimental/cache-file/) and
**2**: **2**:
Rule set is independent collections of rules that can be compiled into binaries to improve performance. rule-set is independent collections of rules that can be compiled into binaries to improve performance.
Compared to legacy GeoIP and Geosite resources, Compared to legacy GeoIP and Geosite resources,
it can include more types of rules, load faster, it can include more types of rules, load faster,
use less memory, and update automatically. use less memory, and update automatically.
@ -366,16 +366,16 @@ use less memory, and update automatically.
See [Route#rule_set](/configuration/route/#rule_set), See [Route#rule_set](/configuration/route/#rule_set),
[Route Rule](/configuration/route/rule/), [Route Rule](/configuration/route/rule/),
[DNS Rule](/configuration/dns/rule/), [DNS Rule](/configuration/dns/rule/),
[Rule Set](/configuration/rule-set/), [rule-set](/configuration/rule-set/),
[Source Format](/configuration/rule-set/source-format/) and [Source Format](/configuration/rule-set/source-format/) and
[Headless Rule](/configuration/rule-set/headless-rule/). [Headless Rule](/configuration/rule-set/headless-rule/).
For GEO resources migration, see [Migrate GeoIP to rule sets](/migration/#migrate-geoip-to-rule-sets) and For GEO resources migration, see [Migrate GeoIP to rule-sets](/migration/#migrate-geoip-to-rule-sets) and
[Migrate Geosite to rule sets](/migration/#migrate-geosite-to-rule-sets). [Migrate Geosite to rule-sets](/migration/#migrate-geosite-to-rule-sets).
**3**: **3**:
New commands manage GeoIP, Geosite and rule set resources, and help you migrate GEO resources to rule sets. New commands manage GeoIP, Geosite and rule-set resources, and help you migrate GEO resources to rule-sets.
**4**: **4**:
@ -572,7 +572,7 @@ This change is intended to break incorrect usage and essentially requires no act
**1**: **1**:
Now the rules in the `rule_set` rule item can be logically considered to be merged into the rule using rule sets, Now the rules in the `rule_set` rule item can be logically considered to be merged into the rule using rule-sets,
rather than completely following the AND logic. rather than completely following the AND logic.
#### 1.8.0-alpha.5 #### 1.8.0-alpha.5
@ -588,7 +588,7 @@ Since GeoIP was deprecated, we made this rule independent, see [Migration](/migr
#### 1.8.0-alpha.1 #### 1.8.0-alpha.1
* Migrate cache file from Clash API to independent options **1** * Migrate cache file from Clash API to independent options **1**
* Introducing [Rule Set](/configuration/rule-set/) **2** * Introducing [rule-set](/configuration/rule-set/) **2**
* Add `sing-box geoip`, `sing-box geosite` and `sing-box rule-set` commands **3** * Add `sing-box geoip`, `sing-box geosite` and `sing-box rule-set` commands **3**
* Allow nested logical rules **4** * Allow nested logical rules **4**
@ -599,7 +599,7 @@ See [Cache File](/configuration/experimental/cache-file/) and
**2**: **2**:
Rule set is independent collections of rules that can be compiled into binaries to improve performance. rule-set is independent collections of rules that can be compiled into binaries to improve performance.
Compared to legacy GeoIP and Geosite resources, Compared to legacy GeoIP and Geosite resources,
it can include more types of rules, load faster, it can include more types of rules, load faster,
use less memory, and update automatically. use less memory, and update automatically.
@ -607,16 +607,16 @@ use less memory, and update automatically.
See [Route#rule_set](/configuration/route/#rule_set), See [Route#rule_set](/configuration/route/#rule_set),
[Route Rule](/configuration/route/rule/), [Route Rule](/configuration/route/rule/),
[DNS Rule](/configuration/dns/rule/), [DNS Rule](/configuration/dns/rule/),
[Rule Set](/configuration/rule-set/), [rule-set](/configuration/rule-set/),
[Source Format](/configuration/rule-set/source-format/) and [Source Format](/configuration/rule-set/source-format/) and
[Headless Rule](/configuration/rule-set/headless-rule/). [Headless Rule](/configuration/rule-set/headless-rule/).
For GEO resources migration, see [Migrate GeoIP to rule sets](/migration/#migrate-geoip-to-rule-sets) and For GEO resources migration, see [Migrate GeoIP to rule-sets](/migration/#migrate-geoip-to-rule-sets) and
[Migrate Geosite to rule sets](/migration/#migrate-geosite-to-rule-sets). [Migrate Geosite to rule-sets](/migration/#migrate-geosite-to-rule-sets).
**3**: **3**:
New commands manage GeoIP, Geosite and rule set resources, and help you migrate GEO resources to rule sets. New commands manage GeoIP, Geosite and rule-set resources, and help you migrate GEO resources to rule-sets.
**4**: **4**:

View file

@ -166,7 +166,7 @@ icon: material/new-box
(`source_port` || `source_port_range`) && (`source_port` || `source_port_range`) &&
`other fields` `other fields`
Additionally, included rule sets can be considered merged rather than as a single rule sub-item. Additionally, included rule-sets can be considered merged rather than as a single rule sub-item.
#### inbound #### inbound
@ -312,7 +312,7 @@ Match WiFi BSSID.
!!! question "Since sing-box 1.8.0" !!! question "Since sing-box 1.8.0"
Match [Rule Set](/configuration/route/#rule_set). Match [rule-set](/configuration/route/#rule_set).
#### rule_set_ipcidr_match_source #### rule_set_ipcidr_match_source
@ -322,13 +322,13 @@ Match [Rule Set](/configuration/route/#rule_set).
`rule_set_ipcidr_match_source` is renamed to `rule_set_ip_cidr_match_source` and will be remove in sing-box 1.11.0. `rule_set_ipcidr_match_source` is renamed to `rule_set_ip_cidr_match_source` and will be remove in sing-box 1.11.0.
Make `ip_cidr` rule items in rule sets match the source IP. Make `ip_cidr` rule items in rule-sets match the source IP.
#### rule_set_ip_cidr_match_source #### rule_set_ip_cidr_match_source
!!! question "Since sing-box 1.10.0" !!! question "Since sing-box 1.10.0"
Make `ip_cidr` rule items in rule sets match the source IP. Make `ip_cidr` rule items in rule-sets match the source IP.
#### invert #### invert
@ -370,7 +370,7 @@ Only takes effect for address requests (A/AAAA/HTTPS). When the query results do
!!! info "" !!! info ""
`ip_cidr` items in included rule sets also takes effect as an address filtering field. `ip_cidr` items in included rule-sets also takes effect as an address filtering field.
!!! note "" !!! note ""
@ -398,7 +398,7 @@ Match private IP with query response.
!!! question "Since sing-box 1.10.0" !!! question "Since sing-box 1.10.0"
Make `ip_cidr` rules in rule sets accept empty query response. Make `ip_cidr` rules in rule-sets accept empty query response.
### Logical Fields ### Logical Fields

View file

@ -39,7 +39,7 @@ List of [Route Rule](./rule/)
!!! question "Since sing-box 1.8.0" !!! question "Since sing-box 1.8.0"
List of [Rule Set](/configuration/rule-set/) List of [rule-set](/configuration/rule-set/)
#### final #### final

View file

@ -148,7 +148,7 @@ icon: material/alert-decagram
(`source_port` || `source_port_range`) && (`source_port` || `source_port_range`) &&
`other fields` `other fields`
Additionally, included rule sets can be considered merged rather than as a single rule sub-item. Additionally, included rule-sets can be considered merged rather than as a single rule sub-item.
#### inbound #### inbound
@ -308,7 +308,7 @@ Match WiFi BSSID.
!!! question "Since sing-box 1.8.0" !!! question "Since sing-box 1.8.0"
Match [Rule Set](/configuration/route/#rule_set). Match [rule-set](/configuration/route/#rule_set).
#### rule_set_ipcidr_match_source #### rule_set_ipcidr_match_source
@ -318,13 +318,13 @@ Match [Rule Set](/configuration/route/#rule_set).
`rule_set_ipcidr_match_source` is renamed to `rule_set_ip_cidr_match_source` and will be remove in sing-box 1.11.0. `rule_set_ipcidr_match_source` is renamed to `rule_set_ip_cidr_match_source` and will be remove in sing-box 1.11.0.
Make `ip_cidr` in rule sets match the source IP. Make `ip_cidr` in rule-sets match the source IP.
#### rule_set_ip_cidr_match_source #### rule_set_ip_cidr_match_source
!!! question "Since sing-box 1.10.0" !!! question "Since sing-box 1.10.0"
Make `ip_cidr` in rule sets match the source IP. Make `ip_cidr` in rule-sets match the source IP.
#### invert #### invert

View file

@ -1,4 +1,4 @@
# Rule Set # rule-set
!!! question "Since sing-box 1.8.0" !!! question "Since sing-box 1.8.0"
@ -50,19 +50,19 @@
==Required== ==Required==
Type of Rule Set, `local` or `remote`. Type of rule-set, `local` or `remote`.
#### tag #### tag
==Required== ==Required==
Tag of Rule Set. Tag of rule-set.
#### format #### format
==Required== ==Required==
Format of Rule Set, `source` or `binary`. Format of rule-set, `source` or `binary`.
### Local Fields ### Local Fields
@ -70,7 +70,7 @@ Format of Rule Set, `source` or `binary`.
==Required== ==Required==
File path of Rule Set. File path of rule-set.
### Remote Fields ### Remote Fields
@ -78,7 +78,7 @@ File path of Rule Set.
==Required== ==Required==
Download URL of Rule Set. Download URL of rule-set.
#### download_detour #### download_detour
@ -88,6 +88,6 @@ Default outbound will be used if empty.
#### update_interval #### update_interval
Update interval of Rule Set. Update interval of rule-set.
`1d` will be used if empty. `1d` will be used if empty.

View file

@ -33,7 +33,7 @@ The maxmind GeoIP National Database, as an IP classification database,
is not entirely suitable for traffic bypassing, is not entirely suitable for traffic bypassing,
and all existing implementations suffer from high memory usage and difficult management. and all existing implementations suffer from high memory usage and difficult management.
sing-box 1.8.0 introduces [Rule Set](/configuration/rule-set/), which can completely replace GeoIP, sing-box 1.8.0 introduces [rule-set](/configuration/rule-set/), which can completely replace GeoIP,
check [Migration](/migration/#migrate-geoip-to-rule-sets). check [Migration](/migration/#migrate-geoip-to-rule-sets).
#### Geosite #### Geosite
@ -43,7 +43,7 @@ Geosite is deprecated and may be removed in the future.
Geosite, the `domain-list-community` project maintained by V2Ray as an early traffic bypassing solution, Geosite, the `domain-list-community` project maintained by V2Ray as an early traffic bypassing solution,
suffers from a number of problems, including lack of maintenance, inaccurate rules, and difficult management. suffers from a number of problems, including lack of maintenance, inaccurate rules, and difficult management.
sing-box 1.8.0 introduces [Rule Set](/configuration/rule-set/), which can completely replace Geosite, sing-box 1.8.0 introduces [rule-set](/configuration/rule-set/), which can completely replace Geosite,
check [Migration](/migration/#migrate-geosite-to-rule-sets). check [Migration](/migration/#migrate-geosite-to-rule-sets).
## 1.6.0 ## 1.6.0

View file

@ -128,7 +128,7 @@ which will disrupt the existing `process_path` use cases in Windows.
} }
``` ```
### :material-checkbox-intermediate: Migrate GeoIP to rule sets ### :material-checkbox-intermediate: Migrate GeoIP to rule-sets
!!! info "References" !!! info "References"
@ -136,11 +136,11 @@ which will disrupt the existing `process_path` use cases in Windows.
[Route](/configuration/route/) / [Route](/configuration/route/) /
[Route Rule](/configuration/route/rule/) / [Route Rule](/configuration/route/rule/) /
[DNS Rule](/configuration/dns/rule/) / [DNS Rule](/configuration/dns/rule/) /
[Rule Set](/configuration/rule-set/) [rule-set](/configuration/rule-set/)
!!! tip !!! tip
`sing-box geoip` commands can help you convert custom GeoIP into rule sets. `sing-box geoip` commands can help you convert custom GeoIP into rule-sets.
=== ":material-card-remove: Deprecated" === ":material-card-remove: Deprecated"
@ -207,13 +207,13 @@ which will disrupt the existing `process_path` use cases in Windows.
}, },
"experimental": { "experimental": {
"cache_file": { "cache_file": {
"enabled": true // required to save Rule Set cache "enabled": true // required to save rule-set cache
} }
} }
} }
``` ```
### :material-checkbox-intermediate: Migrate Geosite to rule sets ### :material-checkbox-intermediate: Migrate Geosite to rule-sets
!!! info "References" !!! info "References"
@ -221,11 +221,11 @@ which will disrupt the existing `process_path` use cases in Windows.
[Route](/configuration/route/) / [Route](/configuration/route/) /
[Route Rule](/configuration/route/rule/) / [Route Rule](/configuration/route/rule/) /
[DNS Rule](/configuration/dns/rule/) / [DNS Rule](/configuration/dns/rule/) /
[Rule Set](/configuration/rule-set/) [rule-set](/configuration/rule-set/)
!!! tip !!! tip
`sing-box geosite` commands can help you convert custom Geosite into rule sets. `sing-box geosite` commands can help you convert custom Geosite into rule-sets.
=== ":material-card-remove: Deprecated" === ":material-card-remove: Deprecated"
@ -268,7 +268,7 @@ which will disrupt the existing `process_path` use cases in Windows.
}, },
"experimental": { "experimental": {
"cache_file": { "cache_file": {
"enabled": true // required to save Rule Set cache "enabled": true // required to save rule-set cache
} }
} }
} }

View file

@ -206,7 +206,7 @@ sing-box 1.9.0 使 QueryFullProcessImageNameW 输出 Win32 路径(如 `C:\fold
}, },
"experimental": { "experimental": {
"cache_file": { "cache_file": {
"enabled": true // required to save Rule Set cache "enabled": true // required to save rule-set cache
} }
} }
} }
@ -267,7 +267,7 @@ sing-box 1.9.0 使 QueryFullProcessImageNameW 输出 Win32 路径(如 `C:\fold
}, },
"experimental": { "experimental": {
"cache_file": { "cache_file": {
"enabled": true // required to save Rule Set cache "enabled": true // required to save rule-set cache
} }
} }
} }

View file

@ -31,7 +31,7 @@ func (r RuleSet) MarshalJSON() ([]byte, error) {
case C.RuleSetTypeRemote: case C.RuleSetTypeRemote:
v = r.RemoteOptions v = r.RemoteOptions
default: default:
return nil, E.New("unknown rule set type: " + r.Type) return nil, E.New("unknown rule-set type: " + r.Type)
} }
return MarshallObjects((_RuleSet)(r), v) return MarshallObjects((_RuleSet)(r), v)
} }
@ -49,7 +49,7 @@ func (r *RuleSet) UnmarshalJSON(bytes []byte) error {
return E.New("missing format") return E.New("missing format")
case C.RuleSetFormatSource, C.RuleSetFormatBinary: case C.RuleSetFormatSource, C.RuleSetFormatBinary:
default: default:
return E.New("unknown rule set format: " + r.Format) return E.New("unknown rule-set format: " + r.Format)
} }
var v any var v any
switch r.Type { switch r.Type {
@ -60,7 +60,7 @@ func (r *RuleSet) UnmarshalJSON(bytes []byte) error {
case "": case "":
return E.New("missing type") return E.New("missing type")
default: default:
return E.New("unknown rule set type: " + r.Type) return E.New("unknown rule-set type: " + r.Type)
} }
err = UnmarshallExcluded(bytes, (*_RuleSet)(r), v) err = UnmarshallExcluded(bytes, (*_RuleSet)(r), v)
if err != nil { if err != nil {
@ -188,7 +188,7 @@ func (r PlainRuleSetCompat) MarshalJSON() ([]byte, error) {
case C.RuleSetVersion1, C.RuleSetVersion2: case C.RuleSetVersion1, C.RuleSetVersion2:
v = r.Options v = r.Options
default: default:
return nil, E.New("unknown rule set version: ", r.Version) return nil, E.New("unknown rule-set version: ", r.Version)
} }
return MarshallObjects((_PlainRuleSetCompat)(r), v) return MarshallObjects((_PlainRuleSetCompat)(r), v)
} }
@ -203,9 +203,9 @@ func (r *PlainRuleSetCompat) UnmarshalJSON(bytes []byte) error {
case C.RuleSetVersion1, C.RuleSetVersion2: case C.RuleSetVersion1, C.RuleSetVersion2:
v = &r.Options v = &r.Options
case 0: case 0:
return E.New("missing rule set version") return E.New("missing rule-set version")
default: default:
return E.New("unknown rule set version: ", r.Version) return E.New("unknown rule-set version: ", r.Version)
} }
err = UnmarshallExcluded(bytes, (*_PlainRuleSetCompat)(r), v) err = UnmarshallExcluded(bytes, (*_PlainRuleSetCompat)(r), v)
if err != nil { if err != nil {
@ -220,7 +220,7 @@ func (r PlainRuleSetCompat) Upgrade() PlainRuleSet {
case C.RuleSetVersion1, C.RuleSetVersion2: case C.RuleSetVersion1, C.RuleSetVersion2:
result = r.Options result = r.Options
default: default:
panic("unknown rule set version: " + F.ToString(r.Version)) panic("unknown rule-set version: " + F.ToString(r.Version))
} }
return result return result
} }

View file

@ -25,7 +25,7 @@ func NewRuleSet(ctx context.Context, router adapter.Router, logger logger.Contex
case C.RuleSetTypeRemote: case C.RuleSetTypeRemote:
return NewRemoteRuleSet(ctx, router, logger, options), nil return NewRemoteRuleSet(ctx, router, logger, options), nil
default: default:
return nil, E.New("unknown rule set type: ", options.Type) return nil, E.New("unknown rule-set type: ", options.Type)
} }
} }

View file

@ -51,7 +51,7 @@ func NewLocalRuleSet(router adapter.Router, options option.RuleSet) (*LocalRuleS
return nil, err return nil, err
} }
default: default:
return nil, E.New("unknown rule set format: ", options.Format) return nil, E.New("unknown rule-set format: ", options.Format)
} }
rules := make([]adapter.HeadlessRule, len(plainRuleSet.Rules)) rules := make([]adapter.HeadlessRule, len(plainRuleSet.Rules))
var err error var err error

View file

@ -175,7 +175,7 @@ func (s *RemoteRuleSet) loadBytes(content []byte) error {
return err return err
} }
default: default:
return E.New("unknown rule set format: ", s.options.Format) return E.New("unknown rule-set format: ", s.options.Format)
} }
rules := make([]adapter.HeadlessRule, len(plainRuleSet.Rules)) rules := make([]adapter.HeadlessRule, len(plainRuleSet.Rules))
for i, ruleOptions := range plainRuleSet.Rules { for i, ruleOptions := range plainRuleSet.Rules {