Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect path in findNDK #1777

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8eee98f
Improve domain suffix match behavior
nekohasekai Jan 5, 2024
a8e480a
Handle Windows power events
nekohasekai Feb 22, 2024
5ce4384
Migrate ntp service to library
nekohasekai Mar 26, 2024
fd36b07
Set the default TCP keep alive period
nekohasekai Apr 8, 2024
e596213
Remove unused fakeip packet conn
nekohasekai Apr 10, 2024
fd38020
Improve loopback detector
nekohasekai Apr 12, 2024
6ebec97
Fix timezone for Android and iOS
nekohasekai Jan 16, 2024
53c3445
Add address filter support for DNS rules
nekohasekai Feb 3, 2024
7763c78
Add support for `client-subnet` DNS options
nekohasekai Feb 9, 2024
f287856
Add rejected DNS response cache support
nekohasekai Feb 14, 2024
38eaf15
Fix DNS fallthrough incorrectly
nekohasekai Mar 15, 2024
8fc13e4
Improve DNS truncate behavior
nekohasekai Feb 14, 2024
926e436
Fix missing `rule_set_ipcidr_match_source` item in DNS rules
nekohasekai Feb 21, 2024
041a499
Always disable cache for fake-ip DNS transport if `independent_cache`…
PuerNya Feb 4, 2024
3efaf83
Always disable cache for fake-ip servers
dyhkwong Apr 28, 2024
1fa7de0
Fix DNS exchange index
szouc Mar 19, 2024
3f6f879
Add custom prefix support in EDNS0 client subnet options
nekohasekai May 12, 2024
dcf68fe
Fixed order for Clash modes
nekohasekai Feb 6, 2024
d2e2345
Update quic-go to v0.43.1
nekohasekai Feb 14, 2024
1c87693
Update gVisor to 20240422.0
nekohasekai Feb 14, 2024
44e0579
Handle `includeAllNetworks`
nekohasekai May 7, 2024
423430c
Add `bypass_domain` and `search_domain` platform HTTP proxy options
nekohasekai Feb 18, 2024
bf1d4d0
Add `rule-set match` command
nekohasekai Mar 24, 2024
0141a47
dialer: Allow nil router
nekohasekai Apr 25, 2024
9bd961b
documentation: Update DNS manual
nekohasekai Mar 15, 2024
100911f
documentation: Add manuel for mitigating tunnelvision attacks
nekohasekai May 7, 2024
2e24f6a
documentation: Bump version
nekohasekai Apr 26, 2024
1133988
Fix incorrect path in findNDK
iKirby May 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions adapter/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/sagernet/sing-box/common/urltest"
"github.com/sagernet/sing-dns"
N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/rw"
)
Expand All @@ -30,6 +31,9 @@ type CacheFile interface {
StoreFakeIP() bool
FakeIPStorage

StoreRDRC() bool
dns.RDRCStore

LoadMode() string
StoreMode(mode string) error
LoadSelected(group string) string
Expand Down
13 changes: 8 additions & 5 deletions adapter/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ type InboundContext struct {

// rule cache

IPCIDRMatchSource bool
SourceAddressMatch bool
SourcePortMatch bool
DestinationAddressMatch bool
DestinationPortMatch bool
IPCIDRMatchSource bool
SourceAddressMatch bool
SourcePortMatch bool
DestinationAddressMatch bool
DestinationPortMatch bool
DidMatch bool
IgnoreDestinationIPCIDRMatch bool
}

func (c *InboundContext) ResetRuleCache() {
Expand All @@ -64,6 +66,7 @@ func (c *InboundContext) ResetRuleCache() {
c.SourcePortMatch = false
c.DestinationAddressMatch = false
c.DestinationPortMatch = false
c.DidMatch = false
}

type inboundContextKey struct{}
Expand Down
6 changes: 5 additions & 1 deletion adapter/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func RouterFromContext(ctx context.Context) Router {

type HeadlessRule interface {
Match(metadata *InboundContext) bool
String() string
}

type Rule interface {
Expand All @@ -79,13 +80,15 @@ type Rule interface {
Type() string
UpdateGeosite() error
Outbound() string
String() string
}

type DNSRule interface {
Rule
DisableCache() bool
RewriteTTL() *uint32
ClientSubnet() *netip.Prefix
WithAddressLimit() bool
MatchAddressLimit(metadata *InboundContext) bool
}

type RuleSet interface {
Expand All @@ -99,6 +102,7 @@ type RuleSet interface {
type RuleSetMetadata struct {
ContainsProcessRule bool
ContainsWIFIRule bool
ContainsIPCIDRRule bool
}

type RuleSetStartContext interface {
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/build_shared/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func findNDK() bool {
})
for _, versionName := range versionNames {
currentNDKPath := filepath.Join(androidSDKPath, "ndk", versionName)
if rw.FileExists(filepath.Join(androidSDKPath, versionFile)) {
if rw.FileExists(filepath.Join(currentNDKPath, versionFile)) {
androidNDKPath = currentNDKPath
log.Warn("reproducibility warning: using NDK version " + versionName + " instead of " + fixedVersion)
return true
Expand Down
86 changes: 86 additions & 0 deletions cmd/sing-box/cmd_rule_set_match.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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
}
17 changes: 13 additions & 4 deletions common/dialer/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,28 @@ func NewDefault(router adapter.Router, options option.DialerOptions) (*DefaultDi
var dialer net.Dialer
var listener net.ListenConfig
if options.BindInterface != "" {
bindFunc := control.BindToInterface(router.InterfaceFinder(), options.BindInterface, -1)
var interfaceFinder control.InterfaceFinder
if router != nil {
interfaceFinder = router.InterfaceFinder()
} else {
interfaceFinder = control.NewDefaultInterfaceFinder()
}
bindFunc := control.BindToInterface(interfaceFinder, options.BindInterface, -1)
dialer.Control = control.Append(dialer.Control, bindFunc)
listener.Control = control.Append(listener.Control, bindFunc)
} else if router.AutoDetectInterface() {
} else if router != nil && router.AutoDetectInterface() {
bindFunc := router.AutoDetectInterfaceFunc()
dialer.Control = control.Append(dialer.Control, bindFunc)
listener.Control = control.Append(listener.Control, bindFunc)
} else if router.DefaultInterface() != "" {
} else if router != nil && router.DefaultInterface() != "" {
bindFunc := control.BindToInterface(router.InterfaceFinder(), router.DefaultInterface(), -1)
dialer.Control = control.Append(dialer.Control, bindFunc)
listener.Control = control.Append(listener.Control, bindFunc)
}
if options.RoutingMark != 0 {
dialer.Control = control.Append(dialer.Control, control.RoutingMark(options.RoutingMark))
listener.Control = control.Append(listener.Control, control.RoutingMark(options.RoutingMark))
} else if router.DefaultMark() != 0 {
} else if router != nil && router.DefaultMark() != 0 {
dialer.Control = control.Append(dialer.Control, control.RoutingMark(router.DefaultMark()))
listener.Control = control.Append(listener.Control, control.RoutingMark(router.DefaultMark()))
}
Expand All @@ -63,6 +69,9 @@ func NewDefault(router adapter.Router, options option.DialerOptions) (*DefaultDi
} else {
dialer.Timeout = C.TCPTimeout
}
// TODO: Add an option to customize the keep alive period
dialer.KeepAlive = C.TCPKeepAliveInitial
dialer.Control = control.Append(dialer.Control, control.SetKeepAlivePeriod(C.TCPKeepAliveInitial, C.TCPKeepAliveInterval))
var udpFragment bool
if options.UDPFragment != nil {
udpFragment = *options.UDPFragment
Expand Down
3 changes: 3 additions & 0 deletions common/dialer/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ func New(router adapter.Router, options option.DialerOptions) (N.Dialer, error)
if options.IsWireGuardListener {
return NewDefault(router, options)
}
if router == nil {
return NewDefault(nil, options)
}
var (
dialer N.Dialer
err error
Expand Down
5 changes: 2 additions & 3 deletions common/tls/ech_quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ func (c *echClientConfig) DialEarly(ctx context.Context, conn net.PacketConn, ad
return quic.DialEarly(ctx, conn, addr, c.config, config)
}

func (c *echClientConfig) CreateTransport(conn net.PacketConn, quicConnPtr *quic.EarlyConnection, serverAddr M.Socksaddr, quicConfig *quic.Config, enableDatagrams bool) http.RoundTripper {
func (c *echClientConfig) CreateTransport(conn net.PacketConn, quicConnPtr *quic.EarlyConnection, serverAddr M.Socksaddr, quicConfig *quic.Config) http.RoundTripper {
return &http3.RoundTripper{
TLSClientConfig: c.config,
QuicConfig: quicConfig,
EnableDatagrams: enableDatagrams,
QUICConfig: quicConfig,
Dial: func(ctx context.Context, addr string, tlsCfg *tls.Config, cfg *quic.Config) (quic.EarlyConnection, error) {
quicConn, err := quic.DialEarly(ctx, conn, serverAddr.UDPAddr(), tlsCfg, cfg)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions constant/quic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build with_quic

package constant

const WithQUIC = true
5 changes: 5 additions & 0 deletions constant/quic_stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build !with_quic

package constant

const WithQUIC = false
2 changes: 2 additions & 0 deletions constant/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package constant
import "time"

const (
TCPKeepAliveInitial = 10 * time.Minute
TCPKeepAliveInterval = 75 * time.Second
TCPTimeout = 5 * time.Second
ReadPayloadTimeout = 300 * time.Millisecond
DNSTimeout = 10 * time.Second
Expand Down
Loading
Loading