Compare commits

..
Author SHA1 Message Date
世界 8ff27cafb1 documentation: Bump version 2024-03-23 22:33:09 +08:00
世界 e505a94773 documentation: Update DNS manual 2024-03-23 22:33:09 +08:00
世界 16092b83c1 Add bypass_domain and search_domain platform HTTP proxy options 2024-03-23 22:33:09 +08:00
世界 77cb17baef Update gVisor to 20240212.0-65-g71212d503 2024-03-23 22:32:56 +08:00
世界 cfd65e6430 Update quic-go to v0.42.0 2024-03-23 21:43:23 +08:00
世界 fa8cb0a513 Fixed order for Clash modes 2024-03-23 21:43:23 +08:00
气息and世界 d8f8f0bb4d Fix DNS exchange index
Signed-off-by: 气息 <qdshizh@gmail.com>
2024-03-23 21:43:23 +08:00
PuerNyaand世界 86833c7a50 Always disable cache for fake-ip DNS transport if independent_cache disabled 2024-03-23 21:43:23 +08:00
世界 f6ced68f38 Fix missing rule_set_ipcidr_match_source item in DNS rules 2024-03-23 21:43:23 +08:00
世界 0843c22e83 Improve DNS truncate behavior 2024-03-23 21:43:23 +08:00
世界 adb800197f Fix DNS fallthrough incorrectly 2024-03-23 21:43:22 +08:00
世界 3ba856cf75 Add rejected DNS response cache support 2024-03-23 21:43:22 +08:00
世界 3908270235 Add support for client-subnet DNS options 2024-03-23 21:43:22 +08:00
世界 718de0a326 Add address filter support for DNS rules 2024-03-23 21:43:22 +08:00
世界 bb8bdf489f Fix timezone for Android and iOS 2024-03-23 21:43:22 +08:00
世界 945c0aec7e Handle Windows power events 2024-03-23 21:43:22 +08:00
世界 a189d90f55 Improve domain suffix match behavior
For historical reasons, sing-box's `domain_suffix` rule matches literal prefixes instead of the same as other projects.

This change modifies the behavior of `domain_suffix`: If the rule value is prefixed with `.`,
the behavior is unchanged, otherwise it matches `(domain|.+\.domain)` instead.
2024-03-23 21:43:22 +08:00
世界 e2b9d3cfd9 Remove PROCESS_NAME_NATIVE dwFlag in process query output
The `process_path` rule of sing-box is inherited from Clash,
the original code uses the local system's path format (e.g. `\Device\HarddiskVolume1\folder\program.exe`),
but when the device has multiple disks, the HarddiskVolume serial number is not stable.

This change make QueryFullProcessImageNameW output a Win32 path (such as `C:\folder\program.exe`),
which will disrupt the existing `process_path` use cases in Windows.
2024-03-23 21:43:21 +08:00
世界 969770a0a3 badtls: Support uTLS and TLS ECH for read waiter 2024-03-23 21:43:07 +08:00
13 changed files with 29 additions and 131 deletions
+5 -1
View File
@@ -61,12 +61,16 @@ type InboundContext struct {
}
func (c *InboundContext) ResetRuleCache() {
c.ResetRuleCacheContext()
c.DidMatch = false
}
func (c *InboundContext) ResetRuleCacheContext() {
c.IPCIDRMatchSource = false
c.SourceAddressMatch = false
c.SourcePortMatch = false
c.DestinationAddressMatch = false
c.DestinationPortMatch = false
c.DidMatch = false
}
type inboundContextKey struct{}
+1 -1
View File
@@ -71,7 +71,6 @@ func RouterFromContext(ctx context.Context) Router {
type HeadlessRule interface {
Match(metadata *InboundContext) bool
String() string
}
type Rule interface {
@@ -80,6 +79,7 @@ type Rule interface {
Type() string
UpdateGeosite() error
Outbound() string
String() string
}
type DNSRule interface {
-86
View File
@@ -1,86 +0,0 @@
package main
import (
"bytes"
"io"
"os"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/common/srs"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-box/route"
E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/json"
"github.com/spf13/cobra"
)
var flagRuleSetMatchFormat string
var commandRuleSetMatch = &cobra.Command{
Use: "match <rule-set path> <domain>",
Short: "Check if a domain matches the rule set",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
err := ruleSetMatch(args[0], args[1])
if err != nil {
log.Fatal(err)
}
},
}
func init() {
commandRuleSetMatch.Flags().StringVarP(&flagRuleSetMatchFormat, "format", "f", "source", "rule-set format")
commandRuleSet.AddCommand(commandRuleSetMatch)
}
func ruleSetMatch(sourcePath string, domain string) error {
var (
reader io.Reader
err error
)
if sourcePath == "stdin" {
reader = os.Stdin
} else {
reader, err = os.Open(sourcePath)
if err != nil {
return E.Cause(err, "read rule-set")
}
}
content, err := io.ReadAll(reader)
if err != nil {
return E.Cause(err, "read rule-set")
}
var plainRuleSet option.PlainRuleSet
switch flagRuleSetMatchFormat {
case C.RuleSetFormatSource:
var compat option.PlainRuleSetCompat
compat, err = json.UnmarshalExtended[option.PlainRuleSetCompat](content)
if err != nil {
return err
}
plainRuleSet = compat.Upgrade()
case C.RuleSetFormatBinary:
plainRuleSet, err = srs.Read(bytes.NewReader(content), false)
if err != nil {
return err
}
default:
return E.New("unknown rule set format: ", flagRuleSetMatchFormat)
}
for i, ruleOptions := range plainRuleSet.Rules {
var currentRule adapter.HeadlessRule
currentRule, err = route.NewHeadlessRule(nil, ruleOptions)
if err != nil {
return E.Cause(err, "parse rule_set.rules.[", i, "]")
}
if currentRule.Match(&adapter.InboundContext{
Domain: domain,
}) {
println("match rules.[", i, "]: "+currentRule.String())
}
}
return nil
}
+1 -1
View File
@@ -2,7 +2,7 @@
icon: material/alert-decagram
---
#### 1.9.0-rc.2
#### 1.9.0-rc.1
* Fixes and improvements
+2 -4
View File
@@ -380,8 +380,7 @@ flowchart TB
"mode": "and",
"rules": [
{
"rule_set": "geosite-geolocation-!cn",
"invert": true
"rule_set": "geosite-geolocation-!cn"
},
{
"rule_set": "geoip-cn"
@@ -463,8 +462,7 @@ flowchart TB
"mode": "and",
"rules": [
{
"rule_set": "geosite-geolocation-!cn",
"invert": true
"rule_set": "geosite-geolocation-!cn"
},
{
"rule_set": "geoip-cn"
+1 -1
View File
@@ -26,7 +26,7 @@ require (
github.com/sagernet/gvisor v0.0.0-20240315080113-799fb6b6d311
github.com/sagernet/quic-go v0.42.0-beta.2
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691
github.com/sagernet/sing v0.4.0-beta.5
github.com/sagernet/sing v0.4.0-beta.3
github.com/sagernet/sing-dns v0.2.0-beta.16
github.com/sagernet/sing-mux v0.2.0
github.com/sagernet/sing-quic v0.1.9-beta.3
+2 -2
View File
@@ -109,8 +109,8 @@ github.com/sagernet/quic-go v0.42.0-beta.2/go.mod h1:lf8OYop+fMxIlrfM/ZHpENt/7ZD
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691 h1:5Th31OC6yj8byLGkEnIYp6grlXfo1QYUfiYFGjewIdc=
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691/go.mod h1:B8lp4WkQ1PwNnrVMM6KyuFR20pU8jYBD+A4EhJovEXU=
github.com/sagernet/sing v0.2.18/go.mod h1:OL6k2F0vHmEzXz2KW19qQzu172FDgSbUSODylighuVo=
github.com/sagernet/sing v0.4.0-beta.5 h1:2RXOU+Hrb5gEOFA+S6Ji+7egLoWj6QMAFpbO1SQ3XTM=
github.com/sagernet/sing v0.4.0-beta.5/go.mod h1:+60H3Cm91RnL9dpVGWDPHt0zTQImO9Vfqt9a4rSambI=
github.com/sagernet/sing v0.4.0-beta.3 h1:TYA4DJtxs0dWDG6ahjU/Fh+eg6vintiqGjXN4h9BbiA=
github.com/sagernet/sing v0.4.0-beta.3/go.mod h1:+60H3Cm91RnL9dpVGWDPHt0zTQImO9Vfqt9a4rSambI=
github.com/sagernet/sing-dns v0.2.0-beta.16 h1:bzd4B8eHD7/WO3HrYknvgE8A56/R3n5oXBjNF97iPzQ=
github.com/sagernet/sing-dns v0.2.0-beta.16/go.mod h1:XU6Vqr6aHcMz/34Fcv8jmXpRCEuShzW+B7Qg1Xe1nxY=
github.com/sagernet/sing-mux v0.2.0 h1:4C+vd8HztJCWNYfufvgL49xaOoOHXty2+EAjnzN3IYo=
+2 -2
View File
@@ -211,12 +211,12 @@ func (r *abstractLogicalRule) Close() error {
func (r *abstractLogicalRule) Match(metadata *adapter.InboundContext) bool {
if r.mode == C.LogicalTypeAnd {
return common.All(r.rules, func(it adapter.HeadlessRule) bool {
metadata.ResetRuleCache()
metadata.ResetRuleCacheContext()
return it.Match(metadata)
}) != r.invert
} else {
return common.Any(r.rules, func(it adapter.HeadlessRule) bool {
metadata.ResetRuleCache()
metadata.ResetRuleCacheContext()
return it.Match(metadata)
}) != r.invert
}
+4 -4
View File
@@ -334,12 +334,12 @@ func (r *LogicalDNSRule) WithAddressLimit() bool {
func (r *LogicalDNSRule) Match(metadata *adapter.InboundContext) bool {
if r.mode == C.LogicalTypeAnd {
return common.All(r.rules, func(it adapter.HeadlessRule) bool {
metadata.ResetRuleCache()
metadata.ResetRuleCacheContext()
return it.(adapter.DNSRule).Match(metadata)
}) != r.invert
} else {
return common.Any(r.rules, func(it adapter.HeadlessRule) bool {
metadata.ResetRuleCache()
metadata.ResetRuleCacheContext()
return it.(adapter.DNSRule).Match(metadata)
}) != r.invert
}
@@ -348,12 +348,12 @@ func (r *LogicalDNSRule) Match(metadata *adapter.InboundContext) bool {
func (r *LogicalDNSRule) MatchAddressLimit(metadata *adapter.InboundContext) bool {
if r.mode == C.LogicalTypeAnd {
return common.All(r.rules, func(it adapter.HeadlessRule) bool {
metadata.ResetRuleCache()
metadata.ResetRuleCacheContext()
return it.(adapter.DNSRule).MatchAddressLimit(metadata)
}) != r.invert
} else {
return common.Any(r.rules, func(it adapter.HeadlessRule) bool {
metadata.ResetRuleCache()
metadata.ResetRuleCacheContext()
return it.(adapter.DNSRule).MatchAddressLimit(metadata)
}) != r.invert
}
+6 -10
View File
@@ -129,18 +129,14 @@ func NewDefaultHeadlessRule(router adapter.Router, options option.DefaultHeadles
rule.allItems = append(rule.allItems, item)
}
if len(options.WIFISSID) > 0 {
if router != nil {
item := NewWIFISSIDItem(router, options.WIFISSID)
rule.items = append(rule.items, item)
rule.allItems = append(rule.allItems, item)
}
item := NewWIFISSIDItem(router, options.WIFISSID)
rule.items = append(rule.items, item)
rule.allItems = append(rule.allItems, item)
}
if len(options.WIFIBSSID) > 0 {
if router != nil {
item := NewWIFIBSSIDItem(router, options.WIFIBSSID)
rule.items = append(rule.items, item)
rule.allItems = append(rule.allItems, item)
}
item := NewWIFIBSSIDItem(router, options.WIFIBSSID)
rule.items = append(rule.items, item)
rule.allItems = append(rule.allItems, item)
}
return rule, nil
}
+5 -7
View File
@@ -24,14 +24,12 @@ func (r *IPIsPrivateItem) Match(metadata *adapter.InboundContext) bool {
} else {
destination = metadata.Destination.Addr
}
if destination.IsValid() {
return !N.IsPublicAddr(destination)
if destination.IsValid() && !N.IsPublicAddr(destination) {
return true
}
if !r.isSource {
for _, destinationAddress := range metadata.DestinationAddresses {
if !N.IsPublicAddr(destinationAddress) {
return true
}
for _, destinationAddress := range metadata.DestinationAddresses {
if !N.IsPublicAddr(destinationAddress) {
return true
}
}
return false
-6
View File
@@ -3,14 +3,12 @@ package route
import (
"context"
"os"
"strings"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/common/srs"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/option"
E "github.com/sagernet/sing/common/exceptions"
F "github.com/sagernet/sing/common/format"
"github.com/sagernet/sing/common/json"
)
@@ -70,10 +68,6 @@ func (s *LocalRuleSet) Match(metadata *adapter.InboundContext) bool {
return false
}
func (s *LocalRuleSet) String() string {
return strings.Join(F.MapToString(s.rules), " ")
}
func (s *LocalRuleSet) StartContext(ctx context.Context, startContext adapter.RuleSetStartContext) error {
return nil
}
-6
View File
@@ -7,7 +7,6 @@ import (
"net"
"net/http"
"runtime"
"strings"
"time"
"github.com/sagernet/sing-box/adapter"
@@ -15,7 +14,6 @@ import (
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/option"
E "github.com/sagernet/sing/common/exceptions"
F "github.com/sagernet/sing/common/format"
"github.com/sagernet/sing/common/json"
"github.com/sagernet/sing/common/logger"
M "github.com/sagernet/sing/common/metadata"
@@ -70,10 +68,6 @@ func (s *RemoteRuleSet) Match(metadata *adapter.InboundContext) bool {
return false
}
func (s *RemoteRuleSet) String() string {
return strings.Join(F.MapToString(s.rules), " ")
}
func (s *RemoteRuleSet) StartContext(ctx context.Context, startContext adapter.RuleSetStartContext) error {
var dialer N.Dialer
if s.options.RemoteOptions.DownloadDetour != "" {