Compare commits

..

85 Commits

Author SHA1 Message Date
renovate[bot]
4d24b7198d
[dependencies] Update golangci/golangci-lint-action action to v7 2025-04-25 08:04:34 +00:00
世界
8c1b03df4f
documentation: Bump version 2025-04-25 12:58:50 +08:00
世界
465bb41ace
clash-api: Add more meta api 2025-04-25 12:58:50 +08:00
世界
284f10b296
Fix DNS Lookup 2025-04-25 11:58:56 +08:00
世界
7a109569f9
Fix tailscale sending unexpected stuff 2025-04-25 11:58:51 +08:00
世界
ea342f257a
Fix fetch ECH configs 2025-04-25 11:56:39 +08:00
reletor
8814994368
documentation: Minor fixes 2025-04-25 11:56:39 +08:00
caelansar
20d338a06b
Fix callback deletion in UDP transport 2025-04-25 11:56:39 +08:00
世界
7527134ef2
documentation: Try to make the play review happy 2025-04-25 11:56:39 +08:00
世界
43230a89ef
Fix missing handling of legacy domain_strategy options 2025-04-25 11:56:38 +08:00
世界
967d84825f
Improve local DNS server 2025-04-25 11:56:38 +08:00
anytls
c38000d94f
Update anytls
Co-authored-by: anytls <anytls>
2025-04-25 11:56:15 +08:00
世界
ff8e11dfe3
Fix DNS dialer 2025-04-25 11:56:15 +08:00
世界
eaaa70f118
release: Skip override version for iOS 2025-04-25 11:56:14 +08:00
iikira
13870fb4b5
Fix UDP DNS server crash
Signed-off-by: iikira <i2@mail.iikira.com>
2025-04-25 11:56:14 +08:00
ReleTor
961d586e47
Fix fetch ECH configs 2025-04-25 11:56:14 +08:00
世界
4f4b7def78
release: Update Go to 1.24.2 2025-04-25 11:56:13 +08:00
世界
4acb3065b8
Allow direct outbounds without domain_resolver 2025-04-25 11:56:13 +08:00
世界
0ab2ef8c44
Fix Tailscale dialer 2025-04-25 11:56:13 +08:00
dyhkwong
56c144fc2b
Fix DNS over QUIC stream close 2025-04-25 11:56:13 +08:00
anytls
7f0fec0bb3
Update anytls
Co-authored-by: anytls <anytls>
2025-04-25 11:56:12 +08:00
Rambling2076
448d534d25
Fix missing with_tailscale in Dockerfile
Signed-off-by: Rambling2076 <Rambling2076@proton.me>
2025-04-25 11:56:12 +08:00
世界
f9f60bb9ea
Fail when default DNS server not found 2025-04-25 11:56:12 +08:00
世界
9554908971
Update gVisor to 20250319.0 2025-04-25 11:56:11 +08:00
世界
74be568a93
release: Do not build tailscale on iOS and tvOS 2025-04-25 11:56:11 +08:00
世界
b37f4b68d5
Explicitly reject detour to empty direct outbounds 2025-04-25 11:56:11 +08:00
世界
bbe6ded13c
Add netns support 2025-04-25 11:56:11 +08:00
世界
9111cfa5d7
Add wildcard name support for predefined records 2025-04-25 11:56:11 +08:00
世界
546218c0f8
Remove map usage in options 2025-04-25 11:56:10 +08:00
世界
680f8dd008
Fix unhandled DNS loop 2025-04-25 11:56:10 +08:00
世界
13c251287b
Add wildcard-sni support for shadow-tls inbound 2025-04-25 11:56:09 +08:00
世界
8051bb4f3b
Fix Tailscale DNS 2025-04-25 11:56:09 +08:00
k9982874
24c7b040c5
Add ntp protocol sniffing 2025-04-25 11:56:08 +08:00
世界
ac74bbf5dd
option: Fix marshal legacy DNS options 2025-04-25 11:56:08 +08:00
世界
2d72940096
Make domain_resolver optional when only one DNS server is configured 2025-04-25 11:56:08 +08:00
世界
b2d6708f96
Fix DNS lookup context pollution 2025-04-25 11:56:08 +08:00
世界
5108103f3f
Fix http3 DNS server connecting to wrong address 2025-04-25 11:56:07 +08:00
Restia-Ashbell
e875eebf9c
documentation: Fix typo 2025-04-25 11:56:07 +08:00
anytls
445eae88ab
Update sing-anytls
Co-authored-by: anytls <anytls>
2025-04-25 11:56:07 +08:00
k9982874
3f4f804e3e
Fix hosts DNS server 2025-04-25 11:56:07 +08:00
世界
1347d92ebe
Fix UDP DNS server crash 2025-04-25 11:56:06 +08:00
世界
2819ec16f3
documentation: Fix missing ip_accept_any DNS rule option 2025-04-25 11:56:06 +08:00
世界
aa5e7822a4
Fix anytls dialer usage 2025-04-25 11:56:06 +08:00
世界
fa7d03542d
Move predefined DNS server to rule action 2025-04-25 11:56:06 +08:00
世界
dbbab063fe
Fix domain resolver on direct outbound 2025-04-25 11:56:05 +08:00
Zephyruso
ded7d45dee
Fix missing AnyTLS display name 2025-04-25 11:56:05 +08:00
anytls
96bf78ddc1
Update sing-anytls
Co-authored-by: anytls <anytls>
2025-04-25 11:56:05 +08:00
Estel
5af81fa969
documentation: Fix typo
Signed-off-by: Estel <callmebedrockdigger@gmail.com>
2025-04-25 11:56:04 +08:00
TargetLocked
a4ff6f2075
Fix parsing legacy DNS options 2025-04-25 11:56:04 +08:00
世界
3ea9468107
Fix DNS fallback 2025-04-25 11:56:04 +08:00
世界
a7c7703fd3
documentation: Fix missing hosts DNS server 2025-04-25 11:56:03 +08:00
anytls
db33a68eb2
Add MinIdleSession option to AnyTLS outbound
Co-authored-by: anytls <anytls>
2025-04-25 11:56:03 +08:00
ReleTor
c3e4bf6a4c
documentation: Minor fixes 2025-04-25 11:56:03 +08:00
libtry486
3e455902c9
documentation: Fix typo
fix typo

Signed-off-by: libtry486 <89328481+libtry486@users.noreply.github.com>
2025-04-25 11:56:02 +08:00
Alireza Ahmadi
aaba387a8a
Fix Outbound deadlock 2025-04-25 11:56:02 +08:00
世界
4d1be802cb
documentation: Fix AnyTLS doc 2025-04-25 11:56:02 +08:00
anytls
83ccc72e2b
Add AnyTLS protocol 2025-04-25 11:56:02 +08:00
世界
f9e850867a
Migrate to stdlib ECH support 2025-04-25 11:56:01 +08:00
世界
342c2361f1
Add fallback local DNS server for iOS 2025-04-25 11:56:01 +08:00
世界
ac4e30b190
Get darwin local DNS server from libresolv 2025-04-25 11:56:00 +08:00
世界
cf008519fd
Improve resolve action 2025-04-25 11:56:00 +08:00
世界
91d9fc63b7
Fix toolchain version 2025-04-25 11:55:59 +08:00
世界
7d054da0b1
Add back port hopping to hysteria 1 2025-04-25 11:55:59 +08:00
世界
40d35829e1
Update dependencies 2025-04-25 11:55:59 +08:00
xchacha20-poly1305
41ad180be1
Remove single quotes of raw Moziila certs 2025-04-25 11:55:58 +08:00
世界
9cb07a2387
Add Tailscale endpoint 2025-04-25 11:55:58 +08:00
世界
086784baf3
Build legacy binaries with latest Go 2025-04-25 11:55:58 +08:00
世界
0e8cd7d3be
documentation: Remove outdated icons 2025-04-25 11:55:57 +08:00
世界
58f712d222
documentation: Certificate store 2025-04-25 11:55:57 +08:00
世界
dfb7569d11
documentation: TLS fragment 2025-04-25 11:55:56 +08:00
世界
638179fd7c
documentation: Outbound domain resolver 2025-04-25 11:55:56 +08:00
世界
69fff5591f
documentation: Refactor DNS 2025-04-25 11:55:56 +08:00
世界
7c3c3ddbeb
Add certificate store 2025-04-25 11:55:56 +08:00
世界
d88e87b9a4
Add TLS fragment support 2025-04-25 11:55:42 +08:00
世界
1f529be0f1
refactor: Outbound domain resolver 2025-04-25 11:54:18 +08:00
世界
f87808f8c3
refactor: DNS 2025-04-25 11:54:14 +08:00
世界
11e3634a63
Fix panic on some stupid input 2025-04-25 11:49:25 +08:00
世界
c46f70a4c8
Fix ssh outbound 2025-04-25 11:35:22 +08:00
世界
4ed2e1ee1b
Fix wireguard listening 2025-04-25 09:55:54 +08:00
世界
aa8a85b4bc
option: Fix listable again and again 2025-04-25 09:52:00 +08:00
世界
6103ecb771
option: Fix omitempty reject method 2025-04-25 09:47:45 +08:00
世界
3dbe90c535
release: Fix apt-get install 2025-04-25 09:07:41 +08:00
世界
0eac73a8fd
Fix set wireguard reserved on Linux 2025-04-25 09:02:20 +08:00
世界
f9cb268ee7
Fix vmess working with zero uuids 2025-04-25 08:55:26 +08:00
世界
d7085167e7
Fix hysteria1 server panic 2025-04-24 21:46:23 +08:00
12 changed files with 117 additions and 21 deletions

View File

@ -196,6 +196,7 @@ jobs:
run: | run: |
set -xeuo pipefail set -xeuo pipefail
sudo gem install fpm sudo gem install fpm
sudo apt-get update
sudo apt-get install -y debsigs sudo apt-get install -y debsigs
cp .fpm_systemd .fpm cp .fpm_systemd .fpm
fpm -t deb \ fpm -t deb \
@ -234,6 +235,7 @@ jobs:
run: |- run: |-
set -xeuo pipefail set -xeuo pipefail
sudo gem install fpm sudo gem install fpm
sudo apt-get update
sudo apt-get install -y libarchive-tools sudo apt-get install -y libarchive-tools
cp .fpm_systemd .fpm cp .fpm_systemd .fpm
fpm -t pacman \ fpm -t pacman \

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"net" "net"
"net/http" "net/http"
"runtime/debug"
"time" "time"
"github.com/sagernet/sing-box/experimental/clashapi/trafficontrol" "github.com/sagernet/sing-box/experimental/clashapi/trafficontrol"
@ -12,14 +13,23 @@ import (
"github.com/sagernet/ws/wsutil" "github.com/sagernet/ws/wsutil"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/render" "github.com/go-chi/render"
) )
// API created by Clash.Meta // API created by Clash.Meta
func (s *Server) setupMetaAPI(r chi.Router) { func (s *Server) setupMetaAPI(r chi.Router) {
if s.logDebug {
r := chi.NewRouter()
r.Put("/gc", func(w http.ResponseWriter, r *http.Request) {
debug.FreeOSMemory()
})
r.Mount("/", middleware.Profiler())
}
r.Get("/memory", memory(s.trafficManager)) r.Get("/memory", memory(s.trafficManager))
r.Mount("/group", groupRouter(s)) r.Mount("/group", groupRouter(s))
r.Mount("/upgrade", upgradeRouter(s))
} }
type Memory struct { type Memory struct {

View File

@ -0,0 +1,36 @@
package clashapi
import (
"net/http"
E "github.com/sagernet/sing/common/exceptions"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
)
func upgradeRouter(server *Server) http.Handler {
r := chi.NewRouter()
r.Post("/ui", updateExternalUI(server))
return r
}
func updateExternalUI(server *Server) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if server.externalUI == "" {
render.Status(r, http.StatusNotFound)
render.JSON(w, r, newError("external UI not enabled"))
return
}
server.logger.Info("upgrading external UI")
err := server.downloadExternalUI()
if err != nil {
server.logger.Error(E.Cause(err, "upgrade external ui"))
render.Status(r, http.StatusInternalServerError)
render.JSON(w, r, newError(err.Error()))
return
}
server.logger.Info("updated external UI")
render.JSON(w, r, render.M{"status": "ok"})
}
}

View File

@ -9,6 +9,7 @@ import (
"os" "os"
"runtime" "runtime"
"strings" "strings"
"sync"
"syscall" "syscall"
"time" "time"
@ -49,6 +50,9 @@ type Server struct {
httpServer *http.Server httpServer *http.Server
trafficManager *trafficontrol.Manager trafficManager *trafficontrol.Manager
urlTestHistory adapter.URLTestHistoryStorage urlTestHistory adapter.URLTestHistoryStorage
uiUpdateAccess sync.Mutex
logDebug bool
mode string mode string
modeList []string modeList []string
modeUpdateHook chan<- struct{} modeUpdateHook chan<- struct{}
@ -74,6 +78,7 @@ func NewServer(ctx context.Context, logFactory log.ObservableFactory, options op
Handler: chiRouter, Handler: chiRouter,
}, },
trafficManager: trafficManager, trafficManager: trafficManager,
logDebug: logFactory.Level() >= log.LevelDebug,
modeList: options.ModeList, modeList: options.ModeList,
externalController: options.ExternalController != "", externalController: options.ExternalController != "",
externalUIDownloadURL: options.ExternalUIDownloadURL, externalUIDownloadURL: options.ExternalUIDownloadURL,

View File

@ -37,6 +37,8 @@ func (s *Server) checkAndDownloadExternalUI() {
} }
func (s *Server) downloadExternalUI() error { func (s *Server) downloadExternalUI() error {
s.uiUpdateAccess.Lock()
defer s.uiUpdateAccess.Unlock()
var downloadURL string var downloadURL string
if s.externalUIDownloadURL != "" { if s.externalUIDownloadURL != "" {
downloadURL = s.externalUIDownloadURL downloadURL = s.externalUIDownloadURL

10
go.mod
View File

@ -26,18 +26,18 @@ require (
github.com/sagernet/gvisor v0.0.0-20250325023245-7a9c0f5725fb github.com/sagernet/gvisor v0.0.0-20250325023245-7a9c0f5725fb
github.com/sagernet/quic-go v0.49.0-beta.1 github.com/sagernet/quic-go v0.49.0-beta.1
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691 github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691
github.com/sagernet/sing v0.6.7-0.20250409030945-77e2a1bb577c github.com/sagernet/sing v0.6.8-0.20250425035333-84184da91a3a
github.com/sagernet/sing-mux v0.3.1 github.com/sagernet/sing-mux v0.3.1
github.com/sagernet/sing-quic v0.4.1 github.com/sagernet/sing-quic v0.4.1-0.20250423030647-0eb05f373a76
github.com/sagernet/sing-shadowsocks v0.2.7 github.com/sagernet/sing-shadowsocks v0.2.7
github.com/sagernet/sing-shadowsocks2 v0.2.0 github.com/sagernet/sing-shadowsocks2 v0.2.0
github.com/sagernet/sing-shadowtls v0.2.1-0.20250316154757-6f9e732e5056 github.com/sagernet/sing-shadowtls v0.2.1-0.20250316154757-6f9e732e5056
github.com/sagernet/sing-tun v0.6.5-0.20250412112220-15069fc1c20a github.com/sagernet/sing-tun v0.6.5-0.20250412112220-15069fc1c20a
github.com/sagernet/sing-vmess v0.2.0 github.com/sagernet/sing-vmess v0.2.1
github.com/sagernet/smux v0.0.0-20231208180855-7041f6ea79e7 github.com/sagernet/smux v0.0.0-20231208180855-7041f6ea79e7
github.com/sagernet/tailscale v1.80.3-mod.2.0.20250422104142-2421001a70ff github.com/sagernet/tailscale v1.80.3-mod.4
github.com/sagernet/utls v1.6.7 github.com/sagernet/utls v1.6.7
github.com/sagernet/wireguard-go v0.0.1-beta.5 github.com/sagernet/wireguard-go v0.0.1-beta.7
github.com/sagernet/ws v0.0.0-20231204124109-acfe8907c854 github.com/sagernet/ws v0.0.0-20231204124109-acfe8907c854
github.com/spf13/cobra v1.8.1 github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.10.0 github.com/stretchr/testify v1.10.0

20
go.sum
View File

@ -178,12 +178,12 @@ github.com/sagernet/quic-go v0.49.0-beta.1/go.mod h1:uesWD1Ihrldq1M3XtjuEvIUqi8W
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691 h1:5Th31OC6yj8byLGkEnIYp6grlXfo1QYUfiYFGjewIdc= 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/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.2.18/go.mod h1:OL6k2F0vHmEzXz2KW19qQzu172FDgSbUSODylighuVo=
github.com/sagernet/sing v0.6.7-0.20250409030945-77e2a1bb577c h1:Zi+WR7f9SQ96yNHmyxj42BtaVb3kTouQ8bQLBHReTSI= github.com/sagernet/sing v0.6.8-0.20250425035333-84184da91a3a h1:oE67hmp5rzLlE6clE7FpK4Hg6yLXsa1Zu3A01vcazb0=
github.com/sagernet/sing v0.6.7-0.20250409030945-77e2a1bb577c/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak= github.com/sagernet/sing v0.6.8-0.20250425035333-84184da91a3a/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak=
github.com/sagernet/sing-mux v0.3.1 h1:kvCc8HyGAskDHDQ0yQvoTi/7J4cZPB/VJMsAM3MmdQI= github.com/sagernet/sing-mux v0.3.1 h1:kvCc8HyGAskDHDQ0yQvoTi/7J4cZPB/VJMsAM3MmdQI=
github.com/sagernet/sing-mux v0.3.1/go.mod h1:Mkdz8LnDstthz0HWuA/5foncnDIdcNN5KZ6AdJX+x78= github.com/sagernet/sing-mux v0.3.1/go.mod h1:Mkdz8LnDstthz0HWuA/5foncnDIdcNN5KZ6AdJX+x78=
github.com/sagernet/sing-quic v0.4.1 h1:pxlMa4efZu/M07RgGagNNDDyl6ZUwpmNUjRTpgHOWK4= github.com/sagernet/sing-quic v0.4.1-0.20250423030647-0eb05f373a76 h1:iwpCX6H3nZEOGUGwx0q5azcgYOA9f6v9YssihXoRKHk=
github.com/sagernet/sing-quic v0.4.1/go.mod h1:tqPa0/Wqa19MkkSlKVZZX5sHxtiDR9BROcn4ufcbVdY= github.com/sagernet/sing-quic v0.4.1-0.20250423030647-0eb05f373a76/go.mod h1:tqPa0/Wqa19MkkSlKVZZX5sHxtiDR9BROcn4ufcbVdY=
github.com/sagernet/sing-shadowsocks v0.2.7 h1:zaopR1tbHEw5Nk6FAkM05wCslV6ahVegEZaKMv9ipx8= github.com/sagernet/sing-shadowsocks v0.2.7 h1:zaopR1tbHEw5Nk6FAkM05wCslV6ahVegEZaKMv9ipx8=
github.com/sagernet/sing-shadowsocks v0.2.7/go.mod h1:0rIKJZBR65Qi0zwdKezt4s57y/Tl1ofkaq6NlkzVuyE= github.com/sagernet/sing-shadowsocks v0.2.7/go.mod h1:0rIKJZBR65Qi0zwdKezt4s57y/Tl1ofkaq6NlkzVuyE=
github.com/sagernet/sing-shadowsocks2 v0.2.0 h1:wpZNs6wKnR7mh1wV9OHwOyUr21VkS3wKFHi+8XwgADg= github.com/sagernet/sing-shadowsocks2 v0.2.0 h1:wpZNs6wKnR7mh1wV9OHwOyUr21VkS3wKFHi+8XwgADg=
@ -192,16 +192,16 @@ github.com/sagernet/sing-shadowtls v0.2.1-0.20250316154757-6f9e732e5056 h1:GFNJQ
github.com/sagernet/sing-shadowtls v0.2.1-0.20250316154757-6f9e732e5056/go.mod h1:HyacBPIFiKihJQR8LQp56FM4hBtd/7MZXnRxxQIOPsc= github.com/sagernet/sing-shadowtls v0.2.1-0.20250316154757-6f9e732e5056/go.mod h1:HyacBPIFiKihJQR8LQp56FM4hBtd/7MZXnRxxQIOPsc=
github.com/sagernet/sing-tun v0.6.5-0.20250412112220-15069fc1c20a h1:2aLxZFD2HPCLrnFGpH+KBuPqMOk0cuaDE2dgEvANuMk= github.com/sagernet/sing-tun v0.6.5-0.20250412112220-15069fc1c20a h1:2aLxZFD2HPCLrnFGpH+KBuPqMOk0cuaDE2dgEvANuMk=
github.com/sagernet/sing-tun v0.6.5-0.20250412112220-15069fc1c20a/go.mod h1:fisFCbC4Vfb6HqQNcwPJi2CDK2bf0Xapyz3j3t4cnHE= github.com/sagernet/sing-tun v0.6.5-0.20250412112220-15069fc1c20a/go.mod h1:fisFCbC4Vfb6HqQNcwPJi2CDK2bf0Xapyz3j3t4cnHE=
github.com/sagernet/sing-vmess v0.2.0 h1:pCMGUXN2k7RpikQV65/rtXtDHzb190foTfF9IGTMZrI= github.com/sagernet/sing-vmess v0.2.1 h1:6izHC2+B68aQCxTagki6eZZc+g5eh4dYwxOV5a2Lhug=
github.com/sagernet/sing-vmess v0.2.0/go.mod h1:jDAZ0A0St1zVRkyvhAPRySOFfhC+4SQtO5VYyeFotgA= github.com/sagernet/sing-vmess v0.2.1/go.mod h1:jDAZ0A0St1zVRkyvhAPRySOFfhC+4SQtO5VYyeFotgA=
github.com/sagernet/smux v0.0.0-20231208180855-7041f6ea79e7 h1:DImB4lELfQhplLTxeq2z31Fpv8CQqqrUwTbrIRumZqQ= github.com/sagernet/smux v0.0.0-20231208180855-7041f6ea79e7 h1:DImB4lELfQhplLTxeq2z31Fpv8CQqqrUwTbrIRumZqQ=
github.com/sagernet/smux v0.0.0-20231208180855-7041f6ea79e7/go.mod h1:FP9X2xjT/Az1EsG/orYYoC+5MojWnuI7hrffz8fGwwo= github.com/sagernet/smux v0.0.0-20231208180855-7041f6ea79e7/go.mod h1:FP9X2xjT/Az1EsG/orYYoC+5MojWnuI7hrffz8fGwwo=
github.com/sagernet/tailscale v1.80.3-mod.2.0.20250422104142-2421001a70ff h1:PK4zmYqcMpW1a416jKR/y7XTqeyANTcbvux8cAA0Vw8= github.com/sagernet/tailscale v1.80.3-mod.4 h1:9UgYq8m9mwX5dbTbueVxbRh+bq7AayxemJGM2PkJQnE=
github.com/sagernet/tailscale v1.80.3-mod.2.0.20250422104142-2421001a70ff/go.mod h1:EBxXsWu4OH2ELbQLq32WoBeIubG8KgDrg4/Oaxjs6lI= github.com/sagernet/tailscale v1.80.3-mod.4/go.mod h1:EBxXsWu4OH2ELbQLq32WoBeIubG8KgDrg4/Oaxjs6lI=
github.com/sagernet/utls v1.6.7 h1:Ep3+aJ8FUGGta+II2IEVNUc3EDhaRCZINWkj/LloIA8= github.com/sagernet/utls v1.6.7 h1:Ep3+aJ8FUGGta+II2IEVNUc3EDhaRCZINWkj/LloIA8=
github.com/sagernet/utls v1.6.7/go.mod h1:Uua1TKO/FFuAhLr9rkaVnnrTmmiItzDjv1BUb2+ERwM= github.com/sagernet/utls v1.6.7/go.mod h1:Uua1TKO/FFuAhLr9rkaVnnrTmmiItzDjv1BUb2+ERwM=
github.com/sagernet/wireguard-go v0.0.1-beta.5 h1:aBEsxJUMEONwOZqKPIkuAcv4zJV5p6XlzEN04CF0FXc= github.com/sagernet/wireguard-go v0.0.1-beta.7 h1:ltgBwYHfr+9Wz1eG59NiWnHrYEkDKHG7otNZvu85DXI=
github.com/sagernet/wireguard-go v0.0.1-beta.5/go.mod h1:jGXij2Gn2wbrWuYNUmmNhf1dwcZtvyAvQoe8Xd8MbUo= github.com/sagernet/wireguard-go v0.0.1-beta.7/go.mod h1:jGXij2Gn2wbrWuYNUmmNhf1dwcZtvyAvQoe8Xd8MbUo=
github.com/sagernet/ws v0.0.0-20231204124109-acfe8907c854 h1:6uUiZcDRnZSAegryaUGwPC/Fj13JSHwiTftrXhMmYOc= github.com/sagernet/ws v0.0.0-20231204124109-acfe8907c854 h1:6uUiZcDRnZSAegryaUGwPC/Fj13JSHwiTftrXhMmYOc=
github.com/sagernet/ws v0.0.0-20231204124109-acfe8907c854/go.mod h1:LtfoSK3+NG57tvnVEHgcuBW9ujgE8enPSgzgwStwCAA= github.com/sagernet/ws v0.0.0-20231204124109-acfe8907c854/go.mod h1:LtfoSK3+NG57tvnVEHgcuBW9ujgE8enPSgzgwStwCAA=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=

View File

@ -10,6 +10,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"time"
"github.com/sagernet/sing-box/adapter" "github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/adapter/outbound" "github.com/sagernet/sing-box/adapter/outbound"
@ -191,9 +192,29 @@ func (s *Outbound) DialContext(ctx context.Context, network string, destination
if err != nil { if err != nil {
return nil, err return nil, err
} }
return client.Dial(network, destination.String()) conn, err := client.Dial(network, destination.String())
if err != nil {
return nil, err
}
return &chanConnWrapper{Conn: conn}, nil
} }
func (s *Outbound) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) { func (s *Outbound) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
return nil, os.ErrInvalid return nil, os.ErrInvalid
} }
type chanConnWrapper struct {
net.Conn
}
func (c *chanConnWrapper) SetDeadline(t time.Time) error {
return os.ErrInvalid
}
func (c *chanConnWrapper) SetReadDeadline(t time.Time) error {
return os.ErrInvalid
}
func (c *chanConnWrapper) SetWriteDeadline(t time.Time) error {
return os.ErrInvalid
}

View File

@ -102,7 +102,10 @@ func NewDefaultRule(ctx context.Context, logger log.ContextLogger, options optio
rule.allItems = append(rule.allItems, item) rule.allItems = append(rule.allItems, item)
} }
if len(options.Domain) > 0 || len(options.DomainSuffix) > 0 { if len(options.Domain) > 0 || len(options.DomainSuffix) > 0 {
item := NewDomainItem(options.Domain, options.DomainSuffix) item, err := NewDomainItem(options.Domain, options.DomainSuffix)
if err != nil {
return nil, err
}
rule.destinationAddressItems = append(rule.destinationAddressItems, item) rule.destinationAddressItems = append(rule.destinationAddressItems, item)
rule.allItems = append(rule.allItems, item) rule.allItems = append(rule.allItems, item)
} }

View File

@ -93,7 +93,10 @@ func NewDefaultDNSRule(ctx context.Context, logger log.ContextLogger, options op
rule.allItems = append(rule.allItems, item) rule.allItems = append(rule.allItems, item)
} }
if len(options.Domain) > 0 || len(options.DomainSuffix) > 0 { if len(options.Domain) > 0 || len(options.DomainSuffix) > 0 {
item := NewDomainItem(options.Domain, options.DomainSuffix) item, err := NewDomainItem(options.Domain, options.DomainSuffix)
if err != nil {
return nil, err
}
rule.destinationAddressItems = append(rule.destinationAddressItems, item) rule.destinationAddressItems = append(rule.destinationAddressItems, item)
rule.allItems = append(rule.allItems, item) rule.allItems = append(rule.allItems, item)
} }

View File

@ -47,7 +47,10 @@ func NewDefaultHeadlessRule(ctx context.Context, options option.DefaultHeadlessR
rule.allItems = append(rule.allItems, item) rule.allItems = append(rule.allItems, item)
} }
if len(options.Domain) > 0 || len(options.DomainSuffix) > 0 { if len(options.Domain) > 0 || len(options.DomainSuffix) > 0 {
item := NewDomainItem(options.Domain, options.DomainSuffix) item, err := NewDomainItem(options.Domain, options.DomainSuffix)
if err != nil {
return nil, err
}
rule.destinationAddressItems = append(rule.destinationAddressItems, item) rule.destinationAddressItems = append(rule.destinationAddressItems, item)
rule.allItems = append(rule.allItems, item) rule.allItems = append(rule.allItems, item)
} else if options.DomainMatcher != nil { } else if options.DomainMatcher != nil {

View File

@ -5,6 +5,7 @@ import (
"github.com/sagernet/sing-box/adapter" "github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing/common/domain" "github.com/sagernet/sing/common/domain"
E "github.com/sagernet/sing/common/exceptions"
) )
var _ RuleItem = (*DomainItem)(nil) var _ RuleItem = (*DomainItem)(nil)
@ -14,7 +15,17 @@ type DomainItem struct {
description string description string
} }
func NewDomainItem(domains []string, domainSuffixes []string) *DomainItem { func NewDomainItem(domains []string, domainSuffixes []string) (*DomainItem, error) {
for _, domainItem := range domains {
if domainItem == "" {
return nil, E.New("domain: empty item is not allowed")
}
}
for _, domainSuffixItem := range domainSuffixes {
if domainSuffixItem == "" {
return nil, E.New("domain_suffix: empty item is not allowed")
}
}
var description string var description string
if dLen := len(domains); dLen > 0 { if dLen := len(domains); dLen > 0 {
if dLen == 1 { if dLen == 1 {
@ -40,7 +51,7 @@ func NewDomainItem(domains []string, domainSuffixes []string) *DomainItem {
return &DomainItem{ return &DomainItem{
domain.NewMatcher(domains, domainSuffixes, false), domain.NewMatcher(domains, domainSuffixes, false),
description, description,
} }, nil
} }
func NewRawDomainItem(matcher *domain.Matcher) *DomainItem { func NewRawDomainItem(matcher *domain.Matcher) *DomainItem {