Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
b3ea0bd
Bump version
nekohasekai Mar 18, 2025
2c648b7
refactor: DNS
nekohasekai Mar 16, 2025
e515c91
refactor: Outbound domain resolver
nekohasekai Jan 12, 2025
067ea0d
Add TLS fragment support
nekohasekai Jan 26, 2025
469faff
Add certificate store
nekohasekai Jan 8, 2025
a3c44f7
documentation: Refactor DNS
nekohasekai Jan 25, 2025
28f937e
documentation: Outbound domain resolver
nekohasekai Jan 29, 2025
dbe8239
documentation: TLS fragment
nekohasekai Jan 30, 2025
cf8889b
documentation: Certificate store
nekohasekai Jan 30, 2025
ce0ae1f
documentation: Remove outdated icons
nekohasekai Jan 30, 2025
8aaaa06
Build legacy binaries with latest Go
nekohasekai Feb 12, 2025
773cb3d
Add Tailscale endpoint
nekohasekai Feb 12, 2025
f495360
Remove single quotes of raw Moziila certs
xchacha20-poly1305 Feb 12, 2025
16c3c68
Update dependencies
nekohasekai Feb 14, 2025
a160309
Add back port hopping to hysteria 1
nekohasekai Feb 16, 2025
9559d7b
Fix toolchain version
nekohasekai Feb 18, 2025
6249f07
Improve resolve action
nekohasekai Feb 20, 2025
0c261c2
Get darwin local DNS server from libresolv
nekohasekai Feb 20, 2025
e4e0744
Add fallback local DNS server for iOS
nekohasekai Feb 20, 2025
4625876
Migrate to stdlib ECH support
nekohasekai Feb 22, 2025
7035d80
Add AnyTLS protocol
anytls Feb 20, 2025
3ef7cb1
documentation: Fix AnyTLS doc
nekohasekai Feb 22, 2025
ea77932
Fix Outbound deadlock
alireza0 Feb 23, 2025
f982c02
documentation: Fix typo
libtry486 Feb 23, 2025
3bbb0f4
documentation: Minor fixes
Feb 20, 2025
1a3c9ec
Add MinIdleSession option to AnyTLS outbound
anytls Feb 24, 2025
a2fc5a0
documentation: Fix missing hosts DNS server
nekohasekai Feb 24, 2025
d9dc7da
Fix DNS fallback
nekohasekai Feb 25, 2025
a1547b3
Fix parsing legacy DNS options
TargetLocked Feb 25, 2025
3488877
documentation: Fix typo
BedrockDigger Feb 25, 2025
652ea40
Update sing-anytls
anytls Feb 25, 2025
5c6fcc8
Fix missing AnyTLS display name
Zephyruso Feb 25, 2025
4975c3a
Fix domain resolver on direct outbound
nekohasekai Feb 26, 2025
6435808
Move predefined DNS server to rule action
nekohasekai Feb 26, 2025
d533f3e
Fix anytls dialer usage
nekohasekai Feb 27, 2025
19b388f
documentation: Fix missing `ip_accept_any` DNS rule option
nekohasekai Mar 6, 2025
f47803c
Fix UDP DNS server crash
nekohasekai Mar 6, 2025
7d6adf6
Fix hosts DNS server
k9982874 Mar 10, 2025
e9fb5fa
Update sing-anytls
anytls Mar 10, 2025
7a22d50
documentation: Fix typo
Restia-Ashbell Mar 10, 2025
af1db56
Fix http3 DNS server connecting to wrong address
nekohasekai Mar 13, 2025
d698e23
Fix DNS lookup context pollution
nekohasekai Mar 13, 2025
566b97d
Make `domain_resolver` optional when only one DNS server is configured
nekohasekai Mar 15, 2025
ece54e8
option: Fix marshal legacy DNS options
nekohasekai Mar 15, 2025
324073f
Add ntp protocol sniffing
k9982874 Mar 15, 2025
a36080c
Fix Tailscale DNS
nekohasekai Mar 15, 2025
6794db2
Add wildcard-sni support for shadow-tls inbound
nekohasekai Mar 16, 2025
079c491
Fix unhandled DNS loop
nekohasekai Mar 17, 2025
b0a36b9
Remove map usage in options
nekohasekai Mar 18, 2025
170d22c
Add wildcard name support for predefined records
nekohasekai Mar 18, 2025
e0e7a9e
Add netns support
nekohasekai Mar 18, 2025
e257b19
Ignore UDP offload error
nekohasekai Mar 19, 2025
ef92ed6
Explicitly reject detour to empty direct outbounds
nekohasekai Mar 20, 2025
5d8f43c
release: Do not build tailscale on iOS and tvOS
nekohasekai Mar 21, 2025
276584b
documentation: Bump version
nekohasekai Feb 23, 2025
a789e05
build: enable acme by default
merrkry Mar 23, 2025
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
22 changes: 22 additions & 0 deletions .github/setup_legacy_go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

VERSION="1.23.6"
wget "https://dl.google.com/go/go${VERSION}.linux-amd64.tar.gz"
tar -xzf "go${VERSION}.linux-amd64.tar.gz"
mv go $HOME/go/go_legacy
cd $HOME/go/go_legacy

# modify from https://github.com/restic/restic/issues/4636#issuecomment-1896455557
# this patch file only works on golang1.23.x
# that means after golang1.24 release it must be changed
# see: https://github.com/MetaCubeX/go/commits/release-branch.go1.23/
# revert:
# 693def151adff1af707d82d28f55dba81ceb08e1: "crypto/rand,runtime: switch RtlGenRandom for ProcessPrng"
# 7c1157f9544922e96945196b47b95664b1e39108: "net: remove sysSocket fallback for Windows 7"
# 48042aa09c2f878c4faa576948b07fe625c4707a: "syscall: remove Windows 7 console handle workaround"
# a17d959debdb04cd550016a3501dd09d50cd62e7: "runtime: always use LoadLibraryEx to load system libraries"

curl https://github.com/MetaCubeX/go/commit/9ac42137ef6730e8b7daca016ece831297a1d75b.diff | patch --verbose -p 1
curl https://github.com/MetaCubeX/go/commit/21290de8a4c91408de7c2b5b68757b1e90af49dd.diff | patch --verbose -p 1
curl https://github.com/MetaCubeX/go/commit/6a31d3fa8e47ddabc10bd97bff10d9a85f4cfb76.diff | patch --verbose -p 1
curl https://github.com/MetaCubeX/go/commit/69e2eed6dd0f6d815ebf15797761c13f31213dd6.diff | patch --verbose -p 1
10 changes: 3 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ jobs:
- name: darwin_amd64
goos: darwin
goarch: amd64
require_legacy_go: true
- name: android_arm64
goos: android
goarch: arm64
Expand Down Expand Up @@ -141,14 +140,11 @@ jobs:
uses: actions/cache@v4
with:
path: |
~/go/go1.20.14
key: go120
~/go/go_legacy
key: go_legacy_1236
- name: Setup legacy Go
if: matrix.require_legacy_go && steps.cache-legacy-go.outputs.cache-hit != 'true'
run: |-
wget https://dl.google.com/go/go1.20.14.linux-amd64.tar.gz
tar -xzf go1.20.14.linux-amd64.tar.gz
mv go $HOME/go/go1.20.14
run: bash .github/setup_legacy_go.sh
- name: Setup Android NDK
if: matrix.goos == 'android'
uses: nttld/setup-ndk@v1
Expand Down
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ linters-settings:
- -SA1003

run:
go: "1.23"
go: "1.24"
build-tags:
- with_gvisor
- with_quic
- with_dhcp
- with_wireguard
- with_ech
- with_utls
- with_reality_server
- with_acme
Expand Down
6 changes: 4 additions & 2 deletions .goreleaser.fury.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ builds:
- -v
- -trimpath
ldflags:
- -X github.com/sagernet/sing-box/constant.Version={{ .Version }} -s -w -buildid=
- -X github.com/sagernet/sing-box/constant.Version={{ .Version }}
- -s
- -buildid=
tags:
- with_gvisor
- with_quic
- with_dhcp
- with_wireguard
- with_ech
- with_utls
- with_reality_server
- with_acme
- with_clash_api
- with_tailscale
env:
- CGO_ENABLED=0
targets:
Expand Down
14 changes: 8 additions & 6 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ builds:
- with_quic
- with_dhcp
- with_wireguard
- with_ech
- with_utls
- with_reality_server
- with_acme
- with_clash_api
- with_tailscale
env:
- CGO_ENABLED=0
- GOTOOLCHAIN=local
targets:
- linux_386
- linux_amd64_v1
Expand All @@ -49,18 +50,19 @@ builds:
- with_reality_server
- with_acme
- with_clash_api
- with_tailscale
env:
- CGO_ENABLED=0
- GOROOT={{ .Env.GOPATH }}/go1.20.14
tool: "{{ .Env.GOPATH }}/go1.20.14/bin/go"
- GOROOT={{ .Env.GOPATH }}/go_legacy
tool: "{{ .Env.GOPATH }}/go_legacy/bin/go"
targets:
- windows_amd64_v1
- windows_386
- darwin_amd64_v1
- id: android
<<: *template
env:
- CGO_ENABLED=1
- GOTOOLCHAIN=local
overrides:
- goos: android
goarch: arm
Expand Down Expand Up @@ -124,8 +126,8 @@ nfpms:
- deb
- rpm
- archlinux
# - apk
# - ipk
# - apk
# - ipk
priority: extra
contents:
- src: release/config/config.json
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN set -ex \
&& export COMMIT=$(git rev-parse --short HEAD) \
&& export VERSION=$(go run ./cmd/internal/read_tag) \
&& go build -v -trimpath -tags \
"with_gvisor,with_quic,with_dhcp,with_wireguard,with_ech,with_utls,with_reality_server,with_acme,with_clash_api" \
"with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_reality_server,with_acme,with_clash_api" \
-o /go/bin/sing-box \
-ldflags "-X \"github.com/sagernet/sing-box/constant.Version=$VERSION\" -s -w -buildid=" \
./cmd/sing-box
Expand Down
24 changes: 15 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
NAME = sing-box
COMMIT = $(shell git rev-parse --short HEAD)
TAGS_GO120 = with_gvisor,with_dhcp,with_wireguard,with_reality_server,with_clash_api,with_quic,with_utls
TAGS_GO121 = with_ech
TAGS ?= $(TAGS_GO118),$(TAGS_GO120),$(TAGS_GO121)
TAGS_TEST ?= with_gvisor,with_quic,with_wireguard,with_grpc,with_ech,with_utls,with_reality_server
TAGS_GO120 = with_gvisor,with_dhcp,with_wireguard,with_reality_server,with_clash_api,with_quic,with_utls,with_acme
TAGS_GO123 = with_tailscale
TAGS ?= $(TAGS_GO120),$(TAGS_GO123)
TAGS_TEST ?= with_gvisor,with_quic,with_wireguard,with_grpc,with_utls,with_reality_server

GOHOSTOS = $(shell go env GOHOSTOS)
GOHOSTARCH = $(shell go env GOHOSTARCH)
Expand All @@ -17,14 +17,17 @@ PREFIX ?= $(shell go env GOPATH)
.PHONY: test release docs build

build:
export GOTOOLCHAIN=local && \
go build $(MAIN_PARAMS) $(MAIN)

ci_build_go120:
go build $(PARAMS) $(MAIN)
export GOTOOLCHAIN=local && \
go build $(PARAMS) $(MAIN) && \
go build $(PARAMS) -tags "$(TAGS_GO120)" $(MAIN)

ci_build:
go build $(PARAMS) $(MAIN)
export GOTOOLCHAIN=local && \
go build $(PARAMS) $(MAIN) && \
go build $(MAIN_PARAMS) $(MAIN)

generate_completions:
Expand Down Expand Up @@ -61,6 +64,9 @@ proto_install:
go install -v google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install -v google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

update_certificates:
go run ./cmd/internal/update_certificates

release:
go run ./cmd/internal/build goreleaser release --clean --skip publish
mkdir dist/release
Expand Down Expand Up @@ -227,8 +233,8 @@ lib:
go run ./cmd/internal/build_libbox -target ios

lib_install:
go install -v github.com/sagernet/gomobile/cmd/[email protected].4
go install -v github.com/sagernet/gomobile/cmd/[email protected].4
go install -v github.com/sagernet/gomobile/cmd/[email protected].5
go install -v github.com/sagernet/gomobile/cmd/[email protected].5

docs:
venv/bin/mkdocs serve
Expand All @@ -247,4 +253,4 @@ clean:
update:
git fetch
git reset FETCH_HEAD --hard
git clean -fdx
git clean -fdx
21 changes: 21 additions & 0 deletions adapter/certificate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package adapter

import (
"context"
"crypto/x509"

"github.com/sagernet/sing/service"
)

type CertificateStore interface {
LifecycleService
Pool() *x509.CertPool
}

func RootPoolFromContext(ctx context.Context) *x509.CertPool {
store := service.FromContext[CertificateStore](ctx)
if store == nil {
return nil
}
return store.Pool()
}
73 changes: 73 additions & 0 deletions adapter/dns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package adapter

import (
"context"
"net/netip"

C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing/common/logger"

"github.com/miekg/dns"
)

type DNSRouter interface {
Lifecycle
Exchange(ctx context.Context, message *dns.Msg, options DNSQueryOptions) (*dns.Msg, error)
Lookup(ctx context.Context, domain string, options DNSQueryOptions) ([]netip.Addr, error)
ClearCache()
LookupReverseMapping(ip netip.Addr) (string, bool)
ResetNetwork()
}

type DNSClient interface {
Start()
Exchange(ctx context.Context, transport DNSTransport, message *dns.Msg, options DNSQueryOptions, responseChecker func(responseAddrs []netip.Addr) bool) (*dns.Msg, error)
Lookup(ctx context.Context, transport DNSTransport, domain string, options DNSQueryOptions, responseChecker func(responseAddrs []netip.Addr) bool) ([]netip.Addr, error)
LookupCache(domain string, strategy C.DomainStrategy) ([]netip.Addr, bool)
ExchangeCache(ctx context.Context, message *dns.Msg) (*dns.Msg, bool)
ClearCache()
}

type DNSQueryOptions struct {
Transport DNSTransport
Strategy C.DomainStrategy
DisableCache bool
RewriteTTL *uint32
ClientSubnet netip.Prefix
}

type RDRCStore interface {
LoadRDRC(transportName string, qName string, qType uint16) (rejected bool)
SaveRDRC(transportName string, qName string, qType uint16) error
SaveRDRCAsync(transportName string, qName string, qType uint16, logger logger.Logger)
}

type DNSTransport interface {
Lifecycle
Type() string
Tag() string
Dependencies() []string
Exchange(ctx context.Context, message *dns.Msg) (*dns.Msg, error)
}

type LegacyDNSTransport interface {
LegacyStrategy() C.DomainStrategy
LegacyClientSubnet() netip.Prefix
}

type DNSTransportRegistry interface {
option.DNSTransportOptionsRegistry
CreateDNSTransport(ctx context.Context, logger log.ContextLogger, tag string, transportType string, options any) (DNSTransport, error)
}

type DNSTransportManager interface {
Lifecycle
Transports() []DNSTransport
Transport(tag string) (DNSTransport, bool)
Default() DNSTransport
FakeIP() FakeIPTransport
Remove(tag string) error
Create(ctx context.Context, logger log.ContextLogger, tag string, outboundType string, options any) error
}
19 changes: 15 additions & 4 deletions adapter/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"encoding/binary"
"time"

"github.com/sagernet/sing-box/common/urltest"
"github.com/sagernet/sing-dns"
"github.com/sagernet/sing/common/varbin"
)

Expand All @@ -16,7 +14,20 @@ type ClashServer interface {
ConnectionTracker
Mode() string
ModeList() []string
HistoryStorage() *urltest.HistoryStorage
HistoryStorage() URLTestHistoryStorage
}

type URLTestHistory struct {
Time time.Time `json:"time"`
Delay uint16 `json:"delay"`
}

type URLTestHistoryStorage interface {
SetHook(hook chan<- struct{})
LoadURLTestHistory(tag string) *URLTestHistory
DeleteURLTestHistory(tag string)
StoreURLTestHistory(tag string, history *URLTestHistory)
Close() error
}

type V2RayServer interface {
Expand All @@ -31,7 +42,7 @@ type CacheFile interface {
FakeIPStorage

StoreRDRC() bool
dns.RDRCStore
RDRCStore

LoadMode() string
StoreMode(mode string) error
Expand Down
3 changes: 1 addition & 2 deletions adapter/fakeip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package adapter
import (
"net/netip"

"github.com/sagernet/sing-dns"
"github.com/sagernet/sing/common/logger"
)

Expand All @@ -27,6 +26,6 @@ type FakeIPStorage interface {
}

type FakeIPTransport interface {
dns.Transport
DNSTransport
Store() FakeIPStore
}
4 changes: 2 additions & 2 deletions adapter/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ type InboundContext struct {
UDPDisableDomainUnmapping bool
UDPConnect bool
UDPTimeout time.Duration
TLSFragment bool
TLSFragmentFallbackDelay time.Duration

NetworkStrategy *C.NetworkStrategy
NetworkType []C.InterfaceType
FallbackNetworkType []C.InterfaceType
FallbackDelay time.Duration

DNSServer string

DestinationAddresses []netip.Addr
SourceGeoIPCode string
GeoIPCode string
Expand Down
14 changes: 8 additions & 6 deletions adapter/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ type NetworkManager interface {
}

type NetworkOptions struct {
NetworkStrategy *C.NetworkStrategy
NetworkType []C.InterfaceType
FallbackNetworkType []C.InterfaceType
FallbackDelay time.Duration
BindInterface string
RoutingMark uint32
BindInterface string
RoutingMark uint32
DomainResolver string
DomainResolveOptions DNSQueryOptions
NetworkStrategy *C.NetworkStrategy
NetworkType []C.InterfaceType
FallbackNetworkType []C.InterfaceType
FallbackDelay time.Duration
}

type InterfaceUpdateListener interface {
Expand Down
Loading