Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
7372d23
refactor: DNS
nekohasekai Dec 2, 2024
fe0ce58
refactor: Outbound domain resolver
nekohasekai Jan 12, 2025
6c59874
Add TLS fragment support
nekohasekai Jan 26, 2025
6c38fec
Add certificate store
nekohasekai Jan 8, 2025
5ac18ce
documentation: Refactor DNS
nekohasekai Jan 25, 2025
23a0d12
documentation: Outbound domain resolver
nekohasekai Jan 29, 2025
ef82c51
documentation: TLS fragment
nekohasekai Jan 30, 2025
7a7cf62
documentation: Certificate store
nekohasekai Jan 30, 2025
10faff7
documentation: Remove outdated icons
nekohasekai Jan 30, 2025
2377898
Build legacy binaries with latest Go
nekohasekai Feb 12, 2025
32ac8fe
Add Tailscale endpoint
nekohasekai Feb 12, 2025
1645cd3
Remove single quotes of raw Moziila certs
xchacha20-poly1305 Feb 12, 2025
764d4b1
Update dependencies
nekohasekai Feb 14, 2025
8b1fcf7
Add back port hopping to hysteria 1
nekohasekai Feb 16, 2025
b43c4e0
Fix toolchain version
nekohasekai Feb 18, 2025
53344f7
Improve resolve action
nekohasekai Feb 20, 2025
b7311fd
Get darwin local DNS server from libresolv
nekohasekai Feb 20, 2025
fd16af0
Add fallback local DNS server for iOS
nekohasekai Feb 20, 2025
bb7989e
Migrate to stdlib ECH support
nekohasekai Feb 22, 2025
bc72bcc
Add AnyTLS protocol
anytls Feb 20, 2025
c3da006
documentation: Fix AnyTLS doc
nekohasekai Feb 22, 2025
ca09454
Fix Outbound deadlock
alireza0 Feb 23, 2025
a120f8a
documentation: Fix typo
libtry486 Feb 23, 2025
84f1307
documentation: Minor fixes
Feb 20, 2025
21feafa
Add MinIdleSession option to AnyTLS outbound
anytls Feb 24, 2025
609918d
documentation: Fix missing hosts DNS server
nekohasekai Feb 24, 2025
4bec17c
Fix DNS fallback
nekohasekai Feb 25, 2025
d1c4fa4
Fix parsing legacy DNS options
TargetLocked Feb 25, 2025
94cb87e
documentation: Fix typo
BedrockDigger Feb 25, 2025
02d3e7e
Update sing-anytls
anytls Feb 25, 2025
9a521c7
Fix missing AnyTLS display name
Zephyruso Feb 25, 2025
400dbb4
Fix domain resolver on direct outbound
nekohasekai Feb 26, 2025
86a68e8
Move predefined DNS server to rule action
nekohasekai Feb 26, 2025
4c7fc47
Fix anytls dialer usage
nekohasekai Feb 27, 2025
5c628f3
documentation: Fix missing `ip_accept_any` DNS rule option
nekohasekai Mar 6, 2025
1a8994b
Fix UDP DNS server crash
nekohasekai Mar 6, 2025
6358fd6
Fix hosts DNS server
k9982874 Mar 10, 2025
8bd0d97
Update sing-anytls
anytls Mar 10, 2025
ca37772
documentation: Fix typo
Restia-Ashbell Mar 10, 2025
75f526c
documentation: Bump version
nekohasekai Feb 23, 2025
34f6e10
Add dialer options for remote ruleset
k9982874 Mar 12, 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
16 changes: 11 additions & 5 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_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
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 {
Type() string
Tag() string
Dependencies() []string
Reset()
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 @@ -71,14 +71,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