mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-08-30 22:08:49 +08:00
Compare commits
106 Commits
ea149f2401
...
0e5f1814cc
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0e5f1814cc | ||
![]() |
d8e1cd0d51 | ||
![]() |
0a5f09f147 | ||
![]() |
e7ae3ddf31 | ||
![]() |
8b15576289 | ||
![]() |
c86f47bdf8 | ||
![]() |
ce013ceabb | ||
![]() |
d0824ea7f6 | ||
![]() |
7291d7e802 | ||
![]() |
3f38520f5e | ||
![]() |
de7e0364e8 | ||
![]() |
867c267bef | ||
![]() |
2dfe93c99c | ||
![]() |
656301bb9e | ||
![]() |
301549f453 | ||
![]() |
cd7229f39b | ||
![]() |
f0e42f8b8f | ||
![]() |
65a629cbb5 | ||
![]() |
7774f16552 | ||
![]() |
2ded81f1f7 | ||
![]() |
e68036ea62 | ||
![]() |
f5dd883fb5 | ||
![]() |
aa2a4ea2bb | ||
![]() |
aeb340170d | ||
![]() |
009b224de6 | ||
![]() |
f6898a7806 | ||
![]() |
44ada21eb2 | ||
![]() |
d276db1ccc | ||
![]() |
1016ba6cef | ||
![]() |
ecfd010ac9 | ||
![]() |
3c07a9dbf5 | ||
![]() |
115eb9e872 | ||
![]() |
26f0c5dd93 | ||
![]() |
0d9883b2c8 | ||
![]() |
b026e78f79 | ||
![]() |
2e20110f02 | ||
![]() |
9fc424498d | ||
![]() |
886ea0c893 | ||
![]() |
fbd79337e5 | ||
![]() |
de31c316a0 | ||
![]() |
ebaaee7b75 | ||
![]() |
1f35f25ada | ||
![]() |
5a1d726242 | ||
![]() |
2f3ebe6f68 | ||
![]() |
c2e962f9da | ||
![]() |
d0052e3803 | ||
![]() |
f2cb235305 | ||
![]() |
d6bd251e2d | ||
![]() |
1f07157ab5 | ||
![]() |
10afe58231 | ||
![]() |
23a99c2af1 | ||
![]() |
8337505d0d | ||
![]() |
9bd951264f | ||
![]() |
7ef938ed05 | ||
![]() |
45d20963c4 | ||
![]() |
e53428481f | ||
![]() |
9d3c47b612 | ||
![]() |
029783522c | ||
![]() |
b7f55e931e | ||
![]() |
e3405c656e | ||
![]() |
264c67f755 | ||
![]() |
b5f5e94fdb | ||
![]() |
3b53ca6e94 | ||
![]() |
6cb3030457 | ||
![]() |
47a717c6c1 | ||
![]() |
2167079ac6 | ||
![]() |
cf77712dc1 | ||
![]() |
883e9dac43 | ||
![]() |
d1ebc72b9d | ||
![]() |
27efb76ac0 | ||
![]() |
ada4633f49 | ||
![]() |
f4b6f828d6 | ||
![]() |
0ddef18bce | ||
![]() |
2e196ebba6 | ||
![]() |
15e41980f3 | ||
![]() |
6e8eff3296 | ||
![]() |
243a40ae1a | ||
![]() |
0d300cd5f8 | ||
![]() |
4879dd6992 | ||
![]() |
ad2ff84166 | ||
![]() |
753f036748 | ||
![]() |
27fa1a730d | ||
![]() |
afdf750da4 | ||
![]() |
75e0ce993f | ||
![]() |
88b4a8ae8e | ||
![]() |
92c639040c | ||
![]() |
f329e859dd | ||
![]() |
4918580820 | ||
![]() |
9dbd482971 | ||
![]() |
7cc6e1c0ae | ||
![]() |
2a03668d15 | ||
![]() |
095721e0e5 | ||
![]() |
7d0d59c9ee | ||
![]() |
18e9eaa244 | ||
![]() |
3439b75e41 | ||
![]() |
7b095b7719 | ||
![]() |
5dd1a09663 | ||
![]() |
750a9be4a9 | ||
![]() |
d21d724345 | ||
![]() |
74f1c3aa09 | ||
![]() |
aef0d477d2 | ||
![]() |
24cf4e9062 | ||
![]() |
dd89730ee7 | ||
![]() |
912bd00f1c | ||
![]() |
3ab6e6c0b0 | ||
![]() |
81ff3eef20 |
@ -5,7 +5,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/sagernet/sing-box/common/convertor/adguard"
|
||||
"github.com/sagernet/sing-box/cmd/sing-box/internal/convertor/adguard"
|
||||
"github.com/sagernet/sing-box/common/srs"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/log"
|
||||
@ -54,7 +54,7 @@ func convertRuleSet(sourcePath string) error {
|
||||
var rules []option.HeadlessRule
|
||||
switch flagRuleSetConvertType {
|
||||
case "adguard":
|
||||
rules, err = adguard.Convert(reader, log.StdLogger())
|
||||
rules, err = adguard.Convert(reader)
|
||||
case "":
|
||||
return E.New("source type is required")
|
||||
default:
|
||||
|
@ -9,10 +9,10 @@ import (
|
||||
"strings"
|
||||
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/log"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
"github.com/sagernet/sing/common"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/logger"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
)
|
||||
|
||||
@ -27,7 +27,7 @@ type agdguardRuleLine struct {
|
||||
isImportant bool
|
||||
}
|
||||
|
||||
func Convert(reader io.Reader, logger logger.Logger) ([]option.HeadlessRule, error) {
|
||||
func Convert(reader io.Reader) ([]option.HeadlessRule, error) {
|
||||
scanner := bufio.NewScanner(reader)
|
||||
var (
|
||||
ruleLines []agdguardRuleLine
|
||||
@ -36,45 +36,9 @@ func Convert(reader io.Reader, logger logger.Logger) ([]option.HeadlessRule, err
|
||||
parseLine:
|
||||
for scanner.Scan() {
|
||||
ruleLine := scanner.Text()
|
||||
|
||||
// Empty line
|
||||
if ruleLine == "" {
|
||||
if ruleLine == "" || ruleLine[0] == '!' || ruleLine[0] == '#' {
|
||||
continue
|
||||
}
|
||||
// Comment (both line comment and in-line comment)
|
||||
if strings.Contains(ruleLine, "!") {
|
||||
continue
|
||||
}
|
||||
// Either comment or cosmetic filter
|
||||
if strings.Contains(ruleLine, "#") {
|
||||
ignoredLines++
|
||||
logger.Debug("ignored unsupported cosmetic filter: ", ruleLine)
|
||||
continue
|
||||
}
|
||||
// We don't support URL query anyway
|
||||
if strings.Contains(ruleLine, "?") || strings.Contains(ruleLine, "&") {
|
||||
ignoredLines++
|
||||
logger.Debug("ignored unsupported rule with query: ", ruleLine)
|
||||
continue
|
||||
}
|
||||
// Commonly seen in CSS selectors of cosmetic filters
|
||||
if strings.Contains(ruleLine, "[") || strings.Contains(ruleLine, "]") {
|
||||
ignoredLines++
|
||||
logger.Debug("ignored unsupported cosmetic filter: ", ruleLine)
|
||||
continue
|
||||
}
|
||||
if strings.Contains(ruleLine, "(") || strings.Contains(ruleLine, ")") {
|
||||
ignoredLines++
|
||||
logger.Debug("ignored unsupported cosmetic filter: ", ruleLine)
|
||||
continue
|
||||
}
|
||||
// We don't support $domain modifier
|
||||
if strings.Contains(ruleLine, "~") {
|
||||
ignoredLines++
|
||||
logger.Debug("ignored unsupported rule modifier: ", ruleLine)
|
||||
continue
|
||||
}
|
||||
|
||||
originRuleLine := ruleLine
|
||||
if M.IsDomainName(ruleLine) {
|
||||
ruleLines = append(ruleLines, agdguardRuleLine{
|
||||
@ -128,7 +92,7 @@ parseLine:
|
||||
}
|
||||
if !ignored {
|
||||
ignoredLines++
|
||||
logger.Debug("ignored unsupported rule with modifier: ", paramParts[0], ": ", ruleLine)
|
||||
log.Debug("ignored unsupported rule with modifier: ", paramParts[0], ": ", ruleLine)
|
||||
continue parseLine
|
||||
}
|
||||
}
|
||||
@ -156,7 +120,7 @@ parseLine:
|
||||
ruleLine = ruleLine[1 : len(ruleLine)-1]
|
||||
if ignoreIPCIDRRegexp(ruleLine) {
|
||||
ignoredLines++
|
||||
logger.Debug("ignored unsupported rule with IPCIDR regexp: ", ruleLine)
|
||||
log.Debug("ignored unsupported rule with IPCIDR regexp: ", ruleLine)
|
||||
continue
|
||||
}
|
||||
isRegexp = true
|
||||
@ -166,7 +130,17 @@ parseLine:
|
||||
}
|
||||
if strings.Contains(ruleLine, "/") {
|
||||
ignoredLines++
|
||||
logger.Debug("ignored unsupported rule with path: ", ruleLine)
|
||||
log.Debug("ignored unsupported rule with path: ", ruleLine)
|
||||
continue
|
||||
}
|
||||
if strings.Contains(ruleLine, "##") {
|
||||
ignoredLines++
|
||||
log.Debug("ignored unsupported rule with element hiding: ", ruleLine)
|
||||
continue
|
||||
}
|
||||
if strings.Contains(ruleLine, "#$#") {
|
||||
ignoredLines++
|
||||
log.Debug("ignored unsupported rule with element hiding: ", ruleLine)
|
||||
continue
|
||||
}
|
||||
var domainCheck string
|
||||
@ -177,7 +151,7 @@ parseLine:
|
||||
}
|
||||
if ruleLine == "" {
|
||||
ignoredLines++
|
||||
logger.Debug("ignored unsupported rule with empty domain", originRuleLine)
|
||||
log.Debug("ignored unsupported rule with empty domain", originRuleLine)
|
||||
continue
|
||||
} else {
|
||||
domainCheck = strings.ReplaceAll(domainCheck, "*", "x")
|
||||
@ -185,13 +159,13 @@ parseLine:
|
||||
_, ipErr := parseADGuardIPCIDRLine(ruleLine)
|
||||
if ipErr == nil {
|
||||
ignoredLines++
|
||||
logger.Debug("ignored unsupported rule with IPCIDR: ", ruleLine)
|
||||
log.Debug("ignored unsupported rule with IPCIDR: ", ruleLine)
|
||||
continue
|
||||
}
|
||||
if M.ParseSocksaddr(domainCheck).Port != 0 {
|
||||
logger.Debug("ignored unsupported rule with port: ", ruleLine)
|
||||
log.Debug("ignored unsupported rule with port: ", ruleLine)
|
||||
} else {
|
||||
logger.Debug("ignored unsupported rule with invalid domain: ", ruleLine)
|
||||
log.Debug("ignored unsupported rule with invalid domain: ", ruleLine)
|
||||
}
|
||||
ignoredLines++
|
||||
continue
|
||||
@ -309,7 +283,7 @@ parseLine:
|
||||
},
|
||||
}
|
||||
}
|
||||
logger.Info("parsed rules: ", len(ruleLines), "/", len(ruleLines)+ignoredLines)
|
||||
log.Info("parsed rules: ", len(ruleLines), "/", len(ruleLines)+ignoredLines)
|
||||
return []option.HeadlessRule{currentRule}, nil
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/route/rule"
|
||||
"github.com/sagernet/sing/common/logger"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@ -25,7 +24,7 @@ example.arpa
|
||||
@@|sagernet.example.org|
|
||||
||sagernet.org^$important
|
||||
@@|sing-box.sagernet.org^$important
|
||||
`), logger.NOP())
|
||||
`))
|
||||
require.NoError(t, err)
|
||||
require.Len(t, rules, 1)
|
||||
rule, err := rule.NewHeadlessRule(context.Background(), rules[0])
|
||||
@ -84,7 +83,7 @@ func TestHosts(t *testing.T) {
|
||||
127.0.0.1 localhost
|
||||
::1 localhost #[IPv6]
|
||||
0.0.0.0 google.com
|
||||
`), logger.NOP())
|
||||
`))
|
||||
require.NoError(t, err)
|
||||
require.Len(t, rules, 1)
|
||||
rule, err := rule.NewHeadlessRule(context.Background(), rules[0])
|
||||
@ -114,7 +113,7 @@ func TestSimpleHosts(t *testing.T) {
|
||||
rules, err := Convert(strings.NewReader(`
|
||||
example.com
|
||||
www.example.org
|
||||
`), logger.NOP())
|
||||
`))
|
||||
require.NoError(t, err)
|
||||
require.Len(t, rules, 1)
|
||||
rule, err := rule.NewHeadlessRule(context.Background(), rules[0])
|
@ -2,10 +2,6 @@
|
||||
icon: material/alert-decagram
|
||||
---
|
||||
|
||||
#### 1.12.0-beta.25
|
||||
|
||||
* Fixes and improvements
|
||||
|
||||
#### 1.12.0-beta.24
|
||||
|
||||
* Allow `tls_fragment` and `tls_record_fragment` to be enabled together **1**
|
||||
|
2
go.mod
2
go.mod
@ -34,7 +34,7 @@ require (
|
||||
github.com/sagernet/sing-shadowsocks v0.2.8
|
||||
github.com/sagernet/sing-shadowsocks2 v0.2.1
|
||||
github.com/sagernet/sing-shadowtls v0.2.1-0.20250503051639-fcd445d33c11
|
||||
github.com/sagernet/sing-tun v0.6.8-0.20250615093440-d1f6001b58c2
|
||||
github.com/sagernet/sing-tun v0.6.6-0.20250610083027-da0a50057fb5
|
||||
github.com/sagernet/sing-vmess v0.2.4-0.20250605032146-38cc72672c88
|
||||
github.com/sagernet/smux v1.5.34-mod.2
|
||||
github.com/sagernet/tailscale v1.80.3-mod.5
|
||||
|
4
go.sum
4
go.sum
@ -180,8 +180,8 @@ github.com/sagernet/sing-shadowsocks2 v0.2.1 h1:dWV9OXCeFPuYGHb6IRqlSptVnSzOelnq
|
||||
github.com/sagernet/sing-shadowsocks2 v0.2.1/go.mod h1:RnXS0lExcDAovvDeniJ4IKa2IuChrdipolPYWBv9hWQ=
|
||||
github.com/sagernet/sing-shadowtls v0.2.1-0.20250503051639-fcd445d33c11 h1:tK+75l64tm9WvEFrYRE1t0YxoFdWQqw/h7Uhzj0vJ+w=
|
||||
github.com/sagernet/sing-shadowtls v0.2.1-0.20250503051639-fcd445d33c11/go.mod h1:sWqKnGlMipCHaGsw1sTTlimyUpgzP4WP3pjhCsYt9oA=
|
||||
github.com/sagernet/sing-tun v0.6.8-0.20250615093440-d1f6001b58c2 h1:leio5dGtYCKHQam+SyLszq4bbXGaxF4ElK5Aif/lUb8=
|
||||
github.com/sagernet/sing-tun v0.6.8-0.20250615093440-d1f6001b58c2/go.mod h1:fisFCbC4Vfb6HqQNcwPJi2CDK2bf0Xapyz3j3t4cnHE=
|
||||
github.com/sagernet/sing-tun v0.6.6-0.20250610083027-da0a50057fb5 h1:zlcioVa11g8VLz5L0yPG7PbvQrw7mrxkDDdlMPEgqDk=
|
||||
github.com/sagernet/sing-tun v0.6.6-0.20250610083027-da0a50057fb5/go.mod h1:fisFCbC4Vfb6HqQNcwPJi2CDK2bf0Xapyz3j3t4cnHE=
|
||||
github.com/sagernet/sing-vmess v0.2.4-0.20250605032146-38cc72672c88 h1:0pVm8sPOel+BoiCddW3pV3cKDKEaSioVTYDdTSKjyFI=
|
||||
github.com/sagernet/sing-vmess v0.2.4-0.20250605032146-38cc72672c88/go.mod h1:IL8Rr+EGwuqijszZkNrEFTQDKhilEpkqFqOlvdpS6/w=
|
||||
github.com/sagernet/smux v1.5.34-mod.2 h1:gkmBjIjlJ2zQKpLigOkFur5kBKdV6bNRoFu2WkltRQ4=
|
||||
|
Loading…
x
Reference in New Issue
Block a user