Compare commits

..

108 Commits

Author SHA1 Message Date
renovate[bot]
35df5635c5
[dependencies] Update golangci/golangci-lint-action action to v8 2025-06-20 05:23:27 +00:00
世界
8f4bbf9a7a
documentation: Bump version 2025-06-20 13:21:44 +08:00
世界
9e3b34ea50
Add API to dump AdGuard rules 2025-06-20 13:21:22 +08:00
Sukka
983421c1cb
Improve AdGuard rule-set parser 2025-06-20 13:21:05 +08:00
Restia-Ashbell
4861ceb6ee
Add ECH support for uTLS 2025-06-20 13:21:04 +08:00
世界
4f4e3eb8c3
Improve TLS fragments 2025-06-20 13:21:04 +08:00
世界
7b7feb794e
Add cache support for ssm-api 2025-06-20 13:21:04 +08:00
世界
b3b8d1fa29
Fix service will not be closed 2025-06-20 13:21:04 +08:00
世界
da924b51c8
Add loopback address support for tun 2025-06-20 13:21:04 +08:00
世界
fb3983ff6d
Fix tproxy listener 2025-06-20 13:21:04 +08:00
世界
07ec062876
Fix systemd package 2025-06-20 13:21:04 +08:00
世界
80f43fa51b
Fix missing home for derp service 2025-06-20 13:21:03 +08:00
Zero Clover
e0e9160290
documentation: Fix services 2025-06-20 13:21:03 +08:00
世界
5d1f13385b
Fix dns.client_subnet ignored 2025-06-20 13:21:03 +08:00
世界
9ef08196a4
documentation: Minor fixes 2025-06-20 13:21:03 +08:00
世界
cf26a7b6f6
Fix tailscale forward 2025-06-20 13:21:03 +08:00
世界
49efb2b8de
Minor fixes 2025-06-20 13:21:03 +08:00
世界
965bec8967
Add SSM API service 2025-06-20 13:21:03 +08:00
世界
cc34e8391d
Add resolved service and DNS server 2025-06-20 13:21:02 +08:00
世界
b89158efb9
Add DERP service 2025-06-20 13:20:54 +08:00
世界
a226bdca28
Add service component type 2025-06-20 13:20:53 +08:00
世界
360130af7b
Fix tproxy tcp control 2025-06-20 13:20:53 +08:00
愚者
f327ea7737
release: Fix build tags for android
Signed-off-by: 愚者 <11926619+FansChou@users.noreply.github.com>
2025-06-20 13:20:53 +08:00
世界
90d6de9220
prevent creation of bind and mark controls on unsupported platforms 2025-06-20 13:20:53 +08:00
PuerNya
6d71e440e0
documentation: Fix description of reject DNS action behavior 2025-06-20 13:20:52 +08:00
Restia-Ashbell
d249150a63
Fix TLS record fragment 2025-06-20 13:20:52 +08:00
世界
b3921910e4
Add missing accept_routes option for Tailscale 2025-06-20 13:20:52 +08:00
世界
b9163feb77
Add TLS record fragment support 2025-06-20 13:20:52 +08:00
世界
40d7e13103
Fix set edns0 client subnet 2025-06-20 13:20:52 +08:00
世界
7b56fb370f
Update minor dependencies 2025-06-20 13:20:52 +08:00
世界
6036174a37
Update certmagic and providers 2025-06-20 13:20:52 +08:00
世界
6ed4a3e25e
Update protobuf and grpc 2025-06-20 13:20:52 +08:00
世界
168809cfe2
Add control options for listeners 2025-06-20 13:20:51 +08:00
世界
b6ca331c7d
Update quic-go to v0.52.0 2025-06-20 13:20:51 +08:00
世界
d2a04c4e41
Update utls to v1.7.2 2025-06-20 13:20:51 +08:00
世界
027ff49390
Handle EDNS version downgrade 2025-06-20 13:20:43 +08:00
世界
8936f41e54
documentation: Fix anytls padding scheme description 2025-06-20 13:20:42 +08:00
安容
e8a6ae0ac7
Report invalid DNS address early 2025-06-20 13:20:42 +08:00
世界
df36013d7d
Fix wireguard listen_port 2025-06-20 13:20:42 +08:00
世界
a9cd830a9a
clash-api: Add more meta api 2025-06-20 13:20:42 +08:00
世界
306abab55d
Fix DNS lookup 2025-06-20 13:20:41 +08:00
世界
f7a92111c5
Fix fetch ECH configs 2025-06-20 13:20:41 +08:00
reletor
dfe82895ab
documentation: Minor fixes 2025-06-20 13:20:41 +08:00
caelansar
973ab97813
Fix callback deletion in UDP transport 2025-06-20 13:20:41 +08:00
世界
a78f3cb116
documentation: Try to make the play review happy 2025-06-20 13:20:41 +08:00
世界
13037a56d8
Fix missing handling of legacy domain_strategy options 2025-06-20 13:20:41 +08:00
世界
3dc3a0b6e3
Improve local DNS server 2025-06-20 13:20:40 +08:00
anytls
577c51a1f1
Update anytls
Co-authored-by: anytls <anytls>
2025-06-20 13:20:25 +08:00
世界
64db52f638
Fix DNS dialer 2025-06-20 13:20:25 +08:00
世界
1b6521f5f8
release: Skip override version for iOS 2025-06-20 13:20:25 +08:00
iikira
ec8821fc94
Fix UDP DNS server crash
Signed-off-by: iikira <i2@mail.iikira.com>
2025-06-20 13:20:25 +08:00
ReleTor
c90e0ad48d
Fix fetch ECH configs 2025-06-20 13:20:24 +08:00
世界
38676a2f06
Allow direct outbounds without domain_resolver 2025-06-20 13:20:24 +08:00
世界
8d2b641f92
Fix Tailscale dialer 2025-06-20 13:20:24 +08:00
dyhkwong
f0bf1f0ae8
Fix DNS over QUIC stream close 2025-06-20 13:20:24 +08:00
anytls
084071e882
Update anytls
Co-authored-by: anytls <anytls>
2025-06-20 13:20:24 +08:00
Rambling2076
90499e90de
Fix missing with_tailscale in Dockerfile
Signed-off-by: Rambling2076 <Rambling2076@proton.me>
2025-06-20 13:20:23 +08:00
世界
20055a362c
Fail when default DNS server not found 2025-06-20 13:20:23 +08:00
世界
376dd20254
Update gVisor to 20250319.0 2025-06-20 13:20:22 +08:00
世界
9a83c088b1
Explicitly reject detour to empty direct outbounds 2025-06-20 13:20:22 +08:00
世界
2b4c6f4ebb
Add netns support 2025-06-20 13:20:22 +08:00
世界
3ca6fee62f
Add wildcard name support for predefined records 2025-06-20 13:20:22 +08:00
世界
372ac544c8
Remove map usage in options 2025-06-20 13:20:22 +08:00
世界
138c1e4969
Fix unhandled DNS loop 2025-06-20 13:20:22 +08:00
世界
8a586db5f1
Add wildcard-sni support for shadow-tls inbound 2025-06-20 13:20:21 +08:00
k9982874
9959239b1a
Add ntp protocol sniffing 2025-06-20 13:20:13 +08:00
世界
4d96d78cd8
option: Fix marshal legacy DNS options 2025-06-20 13:20:13 +08:00
世界
d3d58b37e8
Make domain_resolver optional when only one DNS server is configured 2025-06-20 13:20:12 +08:00
世界
21e7bbdffc
Fix DNS lookup context pollution 2025-06-20 13:20:12 +08:00
世界
c0b6a876ff
Fix http3 DNS server connecting to wrong address 2025-06-20 13:20:12 +08:00
Restia-Ashbell
9b42c2efac
documentation: Fix typo 2025-06-20 13:20:12 +08:00
anytls
dc433869cd
Update sing-anytls
Co-authored-by: anytls <anytls>
2025-06-20 13:20:11 +08:00
k9982874
98db9aa3ec
Fix hosts DNS server 2025-06-20 13:20:11 +08:00
世界
46a7a2b457
Fix UDP DNS server crash 2025-06-20 13:20:11 +08:00
世界
279fa7379c
documentation: Fix missing ip_accept_any DNS rule option 2025-06-20 13:20:10 +08:00
世界
d896cbe623
Fix anytls dialer usage 2025-06-20 13:20:10 +08:00
世界
2b1d40c9b7
Move predefined DNS server to rule action 2025-06-20 13:20:10 +08:00
世界
ca304a9d6f
Fix domain resolver on direct outbound 2025-06-20 13:20:09 +08:00
Zephyruso
7bc733b5b1
Fix missing AnyTLS display name 2025-06-20 13:20:09 +08:00
anytls
a6a934a91b
Update sing-anytls
Co-authored-by: anytls <anytls>
2025-06-20 13:20:09 +08:00
Estel
cf5a34a318
documentation: Fix typo
Signed-off-by: Estel <callmebedrockdigger@gmail.com>
2025-06-20 13:20:08 +08:00
TargetLocked
9570568caa
Fix parsing legacy DNS options 2025-06-20 13:20:08 +08:00
世界
bf1962cfe4
Fix DNS fallback 2025-06-20 13:20:08 +08:00
世界
e6a07492d0
documentation: Fix missing hosts DNS server 2025-06-20 13:20:07 +08:00
anytls
36b12f4ab5
Add MinIdleSession option to AnyTLS outbound
Co-authored-by: anytls <anytls>
2025-06-20 13:20:07 +08:00
ReleTor
bc0cbef785
documentation: Minor fixes 2025-06-20 13:20:07 +08:00
libtry486
8dc7698c5f
documentation: Fix typo
fix typo

Signed-off-by: libtry486 <89328481+libtry486@users.noreply.github.com>
2025-06-20 13:20:06 +08:00
Alireza Ahmadi
cc59cb27e9
Fix Outbound deadlock 2025-06-20 13:20:06 +08:00
世界
0e1c8a1134
documentation: Fix AnyTLS doc 2025-06-20 13:20:06 +08:00
anytls
418f6fff49
Add AnyTLS protocol 2025-06-20 13:20:06 +08:00
世界
e5f87fab4b
Migrate to stdlib ECH support 2025-06-20 13:20:05 +08:00
世界
61e9a9f674
Add fallback local DNS server for iOS 2025-06-20 13:20:05 +08:00
世界
19fd3e836e
Get darwin local DNS server from libresolv 2025-06-20 13:20:05 +08:00
世界
78515fd9c7
Improve resolve action 2025-06-20 13:20:04 +08:00
世界
7506b2711c
Add back port hopping to hysteria 1 2025-06-20 13:20:04 +08:00
xchacha20-poly1305
07817df680
Remove single quotes of raw Moziila certs 2025-06-20 13:20:03 +08:00
世界
dc9b7c880d
Add Tailscale endpoint 2025-06-20 13:20:03 +08:00
世界
b79f1b2540
Build legacy binaries with latest Go 2025-06-20 13:20:03 +08:00
世界
7487fa28be
documentation: Remove outdated icons 2025-06-20 13:20:03 +08:00
世界
10c7c67e3c
documentation: Certificate store 2025-06-20 13:20:02 +08:00
世界
ca2a10f9f6
documentation: TLS fragment 2025-06-20 13:20:02 +08:00
世界
ddc6cdc3fb
documentation: Outbound domain resolver 2025-06-20 13:20:01 +08:00
世界
2e96569fef
documentation: Refactor DNS 2025-06-20 13:20:01 +08:00
世界
fe5ee7d31d
Add certificate store 2025-06-20 13:20:01 +08:00
世界
06c2824df9
Add TLS fragment support 2025-06-20 13:20:01 +08:00
世界
b28d19cfa7
refactor: Outbound domain resolver 2025-06-20 13:20:01 +08:00
世界
1709ad7f7f
refactor: DNS 2025-06-20 13:19:42 +08:00
世界
842f209da0
Fix log for rejected connections 2025-06-20 13:12:49 +08:00
9 changed files with 61 additions and 50 deletions

View File

@ -46,7 +46,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ^1.24.4
go-version: ^1.24
- name: Check input version
if: github.event_name == 'workflow_dispatch'
run: |-
@ -109,7 +109,7 @@ jobs:
if: ${{ ! matrix.legacy_go }}
uses: actions/setup-go@v5
with:
go-version: ^1.24.4
go-version: ^1.24
- name: Cache Legacy Go
if: matrix.require_legacy_go
id: cache-legacy-go
@ -294,7 +294,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ^1.24.4
go-version: ^1.24
- name: Setup Android NDK
id: setup-ndk
uses: nttld/setup-ndk@v1
@ -374,7 +374,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ^1.24.4
go-version: ^1.24
- name: Setup Android NDK
id: setup-ndk
uses: nttld/setup-ndk@v1
@ -472,7 +472,7 @@ jobs:
if: matrix.if
uses: actions/setup-go@v5
with:
go-version: ^1.24.4
go-version: ^1.24
- name: Setup Xcode stable
if: matrix.if && github.ref == 'refs/heads/main-next'
run: |-

View File

@ -28,7 +28,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ^1.24.4
go-version: ^1.24
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:

View File

@ -25,7 +25,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ^1.24.4
go-version: ^1.24
- name: Check input version
if: github.event_name == 'workflow_dispatch'
run: |-
@ -66,7 +66,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ^1.24.4
go-version: ^1.24
- name: Setup Android NDK
if: matrix.os == 'android'
uses: nttld/setup-ndk@v1

View File

@ -40,12 +40,7 @@ parseLine:
if ruleLine == "" {
continue
}
if strings.Contains(ruleLine, "!") {
continue
}
if strings.Contains(ruleLine, "#") {
ignoredLines++
logger.Debug("ignored unsupported cosmetic filter: ", ruleLine)
if strings.HasPrefix(ruleLine, "!") || strings.HasPrefix(ruleLine, "#") {
continue
}
originRuleLine := ruleLine
@ -147,12 +142,9 @@ parseLine:
logger.Debug("ignored unsupported rule with query: ", ruleLine)
continue
}
if strings.Contains(ruleLine, "[") || strings.Contains(ruleLine, "]") {
ignoredLines++
logger.Debug("ignored unsupported cosmetic filter: ", ruleLine)
continue
}
if strings.Contains(ruleLine, "(") || strings.Contains(ruleLine, ")") {
if strings.Contains(ruleLine, "[") || strings.Contains(ruleLine, "]") ||
strings.Contains(ruleLine, "(") || strings.Contains(ruleLine, ")") ||
strings.Contains(ruleLine, "!") || strings.Contains(ruleLine, "#") {
ignoredLines++
logger.Debug("ignored unsupported cosmetic filter: ", ruleLine)
continue
@ -302,7 +294,9 @@ parseLine:
},
}
}
logger.Info("parsed rules: ", len(ruleLines), "/", len(ruleLines)+ignoredLines)
if ignoredLines > 0 {
logger.Info("parsed rules: ", len(ruleLines), "/", len(ruleLines)+ignoredLines)
}
return []option.HeadlessRule{currentRule}, nil
}

2
go.mod
View File

@ -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.9-0.20250617062442-df4458520f26
github.com/sagernet/sing-tun v0.6.10-0.20250620051458-5e343c4b66b2
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
View File

@ -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.9-0.20250617062442-df4458520f26 h1:N9yAoqtQlawlJzLONjdQvIO3GJLEg9tZBfyKToSi0cM=
github.com/sagernet/sing-tun v0.6.9-0.20250617062442-df4458520f26/go.mod h1:fisFCbC4Vfb6HqQNcwPJi2CDK2bf0Xapyz3j3t4cnHE=
github.com/sagernet/sing-tun v0.6.10-0.20250620051458-5e343c4b66b2 h1:ykbqGFHDNVvp0jhgLime/XBAtQpcOcFpT8Rs5Hcc5n4=
github.com/sagernet/sing-tun v0.6.10-0.20250620051458-5e343c4b66b2/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=

View File

@ -2,7 +2,6 @@ package route
import (
"context"
"errors"
"net"
"time"
@ -10,7 +9,7 @@ import (
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/dns"
dnsOutbound "github.com/sagernet/sing-box/protocol/dns"
"github.com/sagernet/sing-tun"
R "github.com/sagernet/sing-box/route/rule"
"github.com/sagernet/sing/common/buf"
E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/logger"
@ -65,7 +64,7 @@ func (r *Router) hijackDNSPacket(ctx context.Context, conn N.PacketConn, packetB
func ExchangeDNSPacket(ctx context.Context, router adapter.DNSRouter, logger logger.ContextLogger, conn N.PacketConn, buffer *buf.Buffer, metadata adapter.InboundContext, destination M.Socksaddr) {
err := exchangeDNSPacket(ctx, router, conn, buffer, metadata, destination)
if err != nil && !errors.Is(err, tun.ErrDrop) && !E.IsClosedOrCanceled(err) {
if err != nil && !R.IsRejected(err) && !E.IsClosedOrCanceled(err) {
logger.ErrorContext(ctx, E.Cause(err, "process DNS packet"))
}
}

View File

@ -15,7 +15,7 @@ import (
"github.com/sagernet/sing-box/common/sniff"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-box/route/rule"
R "github.com/sagernet/sing-box/route/rule"
"github.com/sagernet/sing-mux"
"github.com/sagernet/sing-vmess"
"github.com/sagernet/sing/common"
@ -49,7 +49,7 @@ func (r *Router) RouteConnectionEx(ctx context.Context, conn net.Conn, metadata
err := r.routeConnection(ctx, conn, metadata, onClose)
if err != nil {
N.CloseOnHandshakeFailure(conn, onClose, err)
if E.IsClosedOrCanceled(err) {
if E.IsClosedOrCanceled(err) || R.IsRejected(err) {
r.logger.DebugContext(ctx, "connection closed: ", err)
} else {
r.logger.ErrorContext(ctx, err)
@ -99,7 +99,7 @@ func (r *Router) routeConnection(ctx context.Context, conn net.Conn, metadata ad
var selectedOutbound adapter.Outbound
if selectedRule != nil {
switch action := selectedRule.Action().(type) {
case *rule.RuleActionRoute:
case *R.RuleActionRoute:
var loaded bool
selectedOutbound, loaded = r.outbound.Outbound(action.Outbound)
if !loaded {
@ -110,10 +110,10 @@ func (r *Router) routeConnection(ctx context.Context, conn net.Conn, metadata ad
buf.ReleaseMulti(buffers)
return E.New("TCP is not supported by outbound: ", selectedOutbound.Tag())
}
case *rule.RuleActionReject:
case *R.RuleActionReject:
buf.ReleaseMulti(buffers)
return action.Error(ctx)
case *rule.RuleActionHijackDNS:
case *R.RuleActionHijackDNS:
for _, buffer := range buffers {
conn = bufio.NewCachedConn(conn, buffer)
}
@ -151,7 +151,7 @@ func (r *Router) RoutePacketConnection(ctx context.Context, conn N.PacketConn, m
}))
if err != nil {
conn.Close()
if E.IsClosedOrCanceled(err) {
if E.IsClosedOrCanceled(err) || R.IsRejected(err) {
r.logger.DebugContext(ctx, "connection closed: ", err)
} else {
r.logger.ErrorContext(ctx, err)
@ -168,7 +168,7 @@ func (r *Router) RoutePacketConnectionEx(ctx context.Context, conn N.PacketConn,
err := r.routePacketConnection(ctx, conn, metadata, onClose)
if err != nil {
N.CloseOnHandshakeFailure(conn, onClose, err)
if E.IsClosedOrCanceled(err) {
if E.IsClosedOrCanceled(err) || R.IsRejected(err) {
r.logger.DebugContext(ctx, "connection closed: ", err)
} else {
r.logger.ErrorContext(ctx, err)
@ -214,7 +214,7 @@ func (r *Router) routePacketConnection(ctx context.Context, conn N.PacketConn, m
var selectReturn bool
if selectedRule != nil {
switch action := selectedRule.Action().(type) {
case *rule.RuleActionRoute:
case *R.RuleActionRoute:
var loaded bool
selectedOutbound, loaded = r.outbound.Outbound(action.Outbound)
if !loaded {
@ -225,10 +225,10 @@ func (r *Router) routePacketConnection(ctx context.Context, conn N.PacketConn, m
N.ReleaseMultiPacketBuffer(packetBuffers)
return E.New("UDP is not supported by outbound: ", selectedOutbound.Tag())
}
case *rule.RuleActionReject:
case *R.RuleActionReject:
N.ReleaseMultiPacketBuffer(packetBuffers)
return action.Error(ctx)
case *rule.RuleActionHijackDNS:
case *R.RuleActionHijackDNS:
return r.hijackDNSPacket(ctx, conn, packetBuffers, metadata, onClose)
}
}
@ -266,7 +266,7 @@ func (r *Router) PreMatch(metadata adapter.InboundContext) error {
if selectedRule == nil {
return nil
}
rejectAction, isReject := selectedRule.Action().(*rule.RuleActionReject)
rejectAction, isReject := selectedRule.Action().(*R.RuleActionReject)
if !isReject {
return nil
}
@ -342,7 +342,7 @@ func (r *Router) matchRule(
//nolint:staticcheck
if metadata.InboundOptions != common.DefaultValue[option.InboundOptions]() {
if !preMatch && metadata.InboundOptions.SniffEnabled {
newBuffer, newPackerBuffers, newErr := r.actionSniff(ctx, metadata, &rule.RuleActionSniff{
newBuffer, newPackerBuffers, newErr := r.actionSniff(ctx, metadata, &R.RuleActionSniff{
OverrideDestination: metadata.InboundOptions.SniffOverrideDestination,
Timeout: time.Duration(metadata.InboundOptions.SniffTimeout),
}, inputConn, inputPacketConn, nil)
@ -357,7 +357,7 @@ func (r *Router) matchRule(
}
}
if C.DomainStrategy(metadata.InboundOptions.DomainStrategy) != C.DomainStrategyAsIS {
fatalErr = r.actionResolve(ctx, metadata, &rule.RuleActionResolve{
fatalErr = r.actionResolve(ctx, metadata, &R.RuleActionResolve{
Strategy: C.DomainStrategy(metadata.InboundOptions.DomainStrategy),
})
if fatalErr != nil {
@ -394,11 +394,11 @@ match:
}
}
}
var routeOptions *rule.RuleActionRouteOptions
var routeOptions *R.RuleActionRouteOptions
switch action := currentRule.Action().(type) {
case *rule.RuleActionRoute:
case *R.RuleActionRoute:
routeOptions = &action.RuleActionRouteOptions
case *rule.RuleActionRouteOptions:
case *R.RuleActionRouteOptions:
routeOptions = action
}
if routeOptions != nil {
@ -451,7 +451,7 @@ match:
}
}
switch action := currentRule.Action().(type) {
case *rule.RuleActionSniff:
case *R.RuleActionSniff:
if !preMatch {
newBuffer, newPacketBuffers, newErr := r.actionSniff(ctx, metadata, action, inputConn, inputPacketConn, buffers)
if newErr != nil {
@ -468,7 +468,7 @@ match:
selectedRuleIndex = currentRuleIndex
break match
}
case *rule.RuleActionResolve:
case *R.RuleActionResolve:
fatalErr = r.actionResolve(ctx, metadata, action)
if fatalErr != nil {
return
@ -488,7 +488,7 @@ match:
}
func (r *Router) actionSniff(
ctx context.Context, metadata *adapter.InboundContext, action *rule.RuleActionSniff,
ctx context.Context, metadata *adapter.InboundContext, action *R.RuleActionSniff,
inputConn net.Conn, inputPacketConn N.PacketConn, inputBuffers []*buf.Buffer,
) (buffer *buf.Buffer, packetBuffers []*N.PacketBuffer, fatalErr error) {
if sniff.Skip(metadata) {
@ -649,7 +649,7 @@ func (r *Router) actionSniff(
return
}
func (r *Router) actionResolve(ctx context.Context, metadata *adapter.InboundContext, action *rule.RuleActionResolve) error {
func (r *Router) actionResolve(ctx context.Context, metadata *adapter.InboundContext, action *R.RuleActionResolve) error {
if metadata.Destination.IsFqdn() {
var transport adapter.DNSTransport
if action.Server != "" {

View File

@ -2,6 +2,7 @@ package rule
import (
"context"
"errors"
"net/netip"
"strings"
"sync"
@ -284,6 +285,23 @@ func (r *RuleActionDirect) String() string {
return "direct" + r.description
}
type RejectedError struct {
Cause error
}
func (r *RejectedError) Error() string {
return "rejected"
}
func (r *RejectedError) Unwrap() error {
return r.Cause
}
func IsRejected(err error) bool {
var rejected *RejectedError
return errors.As(err, &rejected)
}
type RuleActionReject struct {
Method string
NoDrop bool
@ -307,9 +325,9 @@ func (r *RuleActionReject) Error(ctx context.Context) error {
var returnErr error
switch r.Method {
case C.RuleActionRejectMethodDefault:
returnErr = syscall.ECONNREFUSED
returnErr = &RejectedError{syscall.ECONNREFUSED}
case C.RuleActionRejectMethodDrop:
return tun.ErrDrop
return &RejectedError{tun.ErrDrop}
default:
panic(F.ToString("unknown reject method: ", r.Method))
}
@ -327,7 +345,7 @@ func (r *RuleActionReject) Error(ctx context.Context) error {
if ctx != nil {
r.logger.DebugContext(ctx, "dropped due to flooding")
}
return tun.ErrDrop
return &RejectedError{tun.ErrDrop}
}
return returnErr
}