mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-12-01 14:18:36 +00:00
merge: Merge upstream v1.14.6
This commit is contained in:
@@ -1 +1 @@
|
||||
0d28acc44093df24b2526dea3d6ffefd6b0a54f0
|
||||
ccefd17767e7b91299e0d54a6b1bb0468cf9173f
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
--- a/src/internal/cpu/cpu_arm64_other.go
|
||||
+++ b/src/internal/cpu/cpu_arm64_other.go
|
||||
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
-//go:build arm64 && !linux && !freebsd && !android && (!darwin || ios) && !openbsd
|
||||
+//go:build arm64 && !linux && !freebsd && !android && (!darwin || ios) && !openbsd && !windows
|
||||
|
||||
package cpu
|
||||
|
||||
--- a/src/internal/cpu/cpu_arm64_windows.go
|
||||
+++ b/src/internal/cpu/cpu_arm64_windows.go
|
||||
@@ -0,0 +1,26 @@
|
||||
+// Copyright 2026 The Go Authors. All rights reserved.
|
||||
+// Use of this source code is governed by a BSD-style
|
||||
+// license that can be found in the LICENSE file.
|
||||
+
|
||||
+//go:build arm64
|
||||
+
|
||||
+package cpu
|
||||
+
|
||||
+func osInit() {
|
||||
+ // TODO(brainman): we don't know how to retrieve those bits form user space - leaving them as false for now
|
||||
+ // https://github.com/golang/go/issues/76791#issuecomment-3877873959
|
||||
+ ARM64.HasCPUID = false
|
||||
+ ARM64.HasDIT = false
|
||||
+ ARM64.IsNeoverse = false
|
||||
+
|
||||
+ if isProcessorFeaturePresent(_PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) {
|
||||
+ ARM64.HasAES = true
|
||||
+ ARM64.HasPMULL = true
|
||||
+ ARM64.HasSHA1 = true
|
||||
+ ARM64.HasSHA2 = true
|
||||
+ }
|
||||
+ ARM64.HasSHA3 = isProcessorFeaturePresent(_PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE)
|
||||
+ ARM64.HasCRC32 = isProcessorFeaturePresent(_PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE)
|
||||
+ ARM64.HasSHA512 = isProcessorFeaturePresent(_PF_ARM_SHA512_INSTRUCTIONS_AVAILABLE)
|
||||
+ ARM64.HasATOMICS = isProcessorFeaturePresent(_PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE)
|
||||
+}
|
||||
--- a/src/internal/cpu/cpu_windows.go
|
||||
+++ b/src/internal/cpu/cpu_windows.go
|
||||
@@ -0,0 +1,20 @@
|
||||
+// Copyright 2026 The Go Authors. All rights reserved.
|
||||
+// Use of this source code is governed by a BSD-style
|
||||
+// license that can be found in the LICENSE file.
|
||||
+
|
||||
+package cpu
|
||||
+
|
||||
+import _ "unsafe" // for linkname
|
||||
+
|
||||
+const (
|
||||
+ _PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE = 30
|
||||
+ _PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE = 31
|
||||
+ _PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE = 34
|
||||
+ _PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE = 64
|
||||
+ _PF_ARM_SHA512_INSTRUCTIONS_AVAILABLE = 65
|
||||
+)
|
||||
+
|
||||
+// isProcessorFeaturePresent calls windows IsProcessorFeaturePresent API.
|
||||
+//
|
||||
+//go:linkname isProcessorFeaturePresent
|
||||
+func isProcessorFeaturePresent(processorFeature uint32) bool // Implemented in runtime package.
|
||||
--- a/src/runtime/os_windows.go
|
||||
+++ b/src/runtime/os_windows.go
|
||||
@@ -39,6 +39,7 @@ const (
|
||||
//go:cgo_import_dynamic runtime._GetSystemDirectoryA GetSystemDirectoryA%2 "kernel32.dll"
|
||||
//go:cgo_import_dynamic runtime._GetSystemInfo GetSystemInfo%1 "kernel32.dll"
|
||||
//go:cgo_import_dynamic runtime._GetThreadContext GetThreadContext%2 "kernel32.dll"
|
||||
+//go:cgo_import_dynamic runtime._IsProcessorFeaturePresent IsProcessorFeaturePresent%1 "kernel32.dll"
|
||||
//go:cgo_import_dynamic runtime._SetThreadContext SetThreadContext%2 "kernel32.dll"
|
||||
//go:cgo_import_dynamic runtime._LoadLibraryExW LoadLibraryExW%3 "kernel32.dll"
|
||||
//go:cgo_import_dynamic runtime._PostQueuedCompletionStatus PostQueuedCompletionStatus%4 "kernel32.dll"
|
||||
@@ -96,6 +97,7 @@ var (
|
||||
_GetSystemDirectoryA,
|
||||
_GetSystemInfo,
|
||||
_GetThreadContext,
|
||||
+ _IsProcessorFeaturePresent,
|
||||
_SetThreadContext,
|
||||
_LoadLibraryExW,
|
||||
_PostQueuedCompletionStatus,
|
||||
@@ -261,6 +263,12 @@ func windows_QueryPerformanceFrequency() int64 {
|
||||
return frequency
|
||||
}
|
||||
|
||||
+//go:linkname cpu_isProcessorFeaturePresent internal/cpu.isProcessorFeaturePresent
|
||||
+func cpu_isProcessorFeaturePresent(processorFeature uint32) bool {
|
||||
+ ret := stdcall(_IsProcessorFeaturePresent, uintptr(processorFeature))
|
||||
+ return ret != 0
|
||||
+}
|
||||
+
|
||||
func loadOptionalSyscalls() {
|
||||
bcryptPrimitives := windowsLoadSystemLib(bcryptprimitivesdll[:])
|
||||
if bcryptPrimitives == 0 {
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Go's internal/cpu never detects ARM64 features on windows/arm64 before Go 1.27,
|
||||
# so crypto/aes, AES-GCM and crypto/sha256 use their generic implementations.
|
||||
# Backport of https://go.dev/cl/745560 (golang/go#76791).
|
||||
#
|
||||
# Remove once the Go release used by the Windows builds includes the fix.
|
||||
|
||||
export GOTOOLCHAIN=local
|
||||
|
||||
GOROOT="$(go env GOROOT)"
|
||||
PATCH_FILE="$(cd "$(dirname "$0")" && pwd)/go_windows_arm64_cpu_features.patch"
|
||||
|
||||
cd "$GOROOT"
|
||||
if [[ -f src/internal/cpu/cpu_arm64_windows.go ]]; then
|
||||
echo "already patched"
|
||||
else
|
||||
patch --verbose -p1 < "$PATCH_FILE"
|
||||
fi
|
||||
|
||||
CPU_FILES="$(GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go list -f '{{.GoFiles}}' internal/cpu)"
|
||||
echo "internal/cpu files for windows/arm64: $CPU_FILES"
|
||||
case "$CPU_FILES" in
|
||||
*cpu_arm64_windows.go*) ;;
|
||||
*)
|
||||
echo "patch is not effective" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
VERSION="1.26.8"
|
||||
VERSION="1.26.11"
|
||||
PATCH_COMMITS=(
|
||||
"f080b0c6346eb690c0dc82497b35925f385b35ac"
|
||||
"2d9c12887c342fb9051d231aa5388743cb7e9cb6"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
VERSION="1.26.8"
|
||||
VERSION="1.26.11"
|
||||
PATCH_COMMITS=(
|
||||
"a4ae550aa148b04c9d4890e98bee63aede5c4b53"
|
||||
"95b851f661584711faa8115b3234a461044f4510"
|
||||
|
||||
+45
-18
@@ -54,7 +54,7 @@ jobs:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.26.8
|
||||
go-version: 1.26.11
|
||||
cache: false
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache/restore@v4
|
||||
@@ -145,7 +145,7 @@ jobs:
|
||||
if: ${{ ! matrix.legacy_win7 }}
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.26.8
|
||||
go-version: 1.26.11
|
||||
cache: false
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache/restore@v4
|
||||
@@ -160,7 +160,7 @@ jobs:
|
||||
with:
|
||||
path: |
|
||||
~/go/go_win7
|
||||
key: go_win7_1268
|
||||
key: go_win7_12611
|
||||
- name: Setup Go for Windows 7
|
||||
if: matrix.legacy_win7 && steps.cache-go-for-windows7.outputs.cache-hit != 'true'
|
||||
env:
|
||||
@@ -224,6 +224,8 @@ jobs:
|
||||
set -xeuo pipefail
|
||||
if [[ "${{ matrix.naive }}" == "true" ]]; then
|
||||
TAGS=$(cat release/DEFAULT_BUILD_TAGS)
|
||||
elif [[ "${{ matrix.legacy_win7 }}" == "true" ]]; then
|
||||
TAGS=$(sed 's/,with_usbip//' release/DEFAULT_BUILD_TAGS_OTHERS)
|
||||
else
|
||||
TAGS=$(cat release/DEFAULT_BUILD_TAGS_OTHERS)
|
||||
fi
|
||||
@@ -488,7 +490,7 @@ jobs:
|
||||
if: ${{ ! matrix.legacy_osx }}
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.26.8
|
||||
go-version: 1.26.11
|
||||
cache: false
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache/restore@v4
|
||||
@@ -503,7 +505,7 @@ jobs:
|
||||
with:
|
||||
path: |
|
||||
~/go/go_osx
|
||||
key: go_osx_1268
|
||||
key: go_osx_12611
|
||||
- name: Setup Go for macOS 10.13
|
||||
if: matrix.legacy_osx && steps.cache-go-for-macos1013.outputs.cache-hit != 'true'
|
||||
env:
|
||||
@@ -587,8 +589,12 @@ jobs:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.26.8
|
||||
go-version: 1.26.11
|
||||
cache: false
|
||||
- name: Patch Go for Windows ARM64
|
||||
if: matrix.arch == 'arm64'
|
||||
shell: bash
|
||||
run: .github/patch_go_for_windows_arm64.sh
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
@@ -690,7 +696,7 @@ jobs:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.26.8
|
||||
go-version: 1.26.11
|
||||
cache: false
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache@v4
|
||||
@@ -754,7 +760,7 @@ jobs:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.26.8
|
||||
go-version: 1.26.11
|
||||
cache: false
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache/restore@v4
|
||||
@@ -862,7 +868,7 @@ jobs:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.26.8
|
||||
go-version: 1.26.11
|
||||
cache: false
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache/restore@v4
|
||||
@@ -975,8 +981,12 @@ jobs:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.26.8
|
||||
go-version: 1.26.11
|
||||
cache: false
|
||||
- name: Patch Go for Windows ARM64
|
||||
if: matrix.desktop_arch == 'arm64'
|
||||
shell: bash
|
||||
run: .github/patch_go_for_windows_arm64.sh
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
@@ -1066,9 +1076,9 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- { desktop_arch: x64, go_arch: amd64 }
|
||||
- { desktop_arch: arm64, go_arch: arm64 }
|
||||
- { desktop_arch: armv7l, go_arch: arm, go_arm: "7" }
|
||||
- { desktop_arch: x64, go_arch: amd64, rust_target: x86_64-unknown-linux-gnu }
|
||||
- { desktop_arch: arm64, go_arch: arm64, rust_target: aarch64-unknown-linux-gnu }
|
||||
- { desktop_arch: armv7l, go_arch: arm, go_arm: "7", rust_target: armv7-unknown-linux-gnueabihf }
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
||||
@@ -1087,7 +1097,7 @@ jobs:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.26.8
|
||||
go-version: 1.26.11
|
||||
cache: false
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache@v4
|
||||
@@ -1095,6 +1105,23 @@ jobs:
|
||||
path: ~/go/pkg/mod
|
||||
key: go-mod-desktop-linux-${{ hashFiles('go.sum') }}
|
||||
restore-keys: go-mod-desktop-linux-
|
||||
- name: Setup Rust
|
||||
uses: dtolnay/rust-toolchain@1.88.0
|
||||
with:
|
||||
targets: ${{ matrix.rust_target }}
|
||||
- name: Setup Zig
|
||||
uses: mlugg/setup-zig@v2
|
||||
with:
|
||||
version: 0.16.0
|
||||
- name: Cache Wayland menu module
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/git
|
||||
~/.cargo/registry
|
||||
clients/desktop/bin/wayland-menu-toolchain
|
||||
key: wayland-menu-${{ matrix.rust_target }}-${{ hashFiles('clients/desktop/native/wayland-menu/Cargo.lock') }}
|
||||
restore-keys: wayland-menu-${{ matrix.rust_target }}-
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
with:
|
||||
@@ -1244,7 +1271,7 @@ jobs:
|
||||
if: matrix.build
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.26.8
|
||||
go-version: 1.26.11
|
||||
cache: false
|
||||
- name: Patch Go for iOS
|
||||
if: matrix.build && (matrix.platform == 'ios/arm64' || matrix.platform == 'tvos/arm64')
|
||||
@@ -1261,8 +1288,8 @@ jobs:
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/Library/Caches/go-build
|
||||
key: libbox-go-build-${{ matrix.artifact }}-1.26.8-${{ hashFiles('go.sum') }}
|
||||
restore-keys: libbox-go-build-${{ matrix.artifact }}-1.26.8-
|
||||
key: libbox-go-build-${{ matrix.artifact }}-1.26.11-${{ hashFiles('go.sum') }}
|
||||
restore-keys: libbox-go-build-${{ matrix.artifact }}-1.26.11-
|
||||
- name: Set tag
|
||||
if: matrix.build
|
||||
run: git tag v${{ needs.calculate_version.outputs.version }} -f
|
||||
@@ -1331,7 +1358,7 @@ jobs:
|
||||
if: matrix.if
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.26.8
|
||||
go-version: 1.26.11
|
||||
cache: false
|
||||
- name: Cache Go modules
|
||||
if: matrix.if
|
||||
|
||||
@@ -55,7 +55,7 @@ jobs:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.26.8
|
||||
go-version: 1.26.11
|
||||
- name: Clone cronet-go
|
||||
if: matrix.naive
|
||||
run: |
|
||||
|
||||
@@ -29,7 +29,7 @@ jobs:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.26.8
|
||||
go-version: 1.26.11
|
||||
- name: Check input version
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
run: |-
|
||||
@@ -72,7 +72,7 @@ jobs:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.26.8
|
||||
go-version: 1.26.11
|
||||
- name: Clone cronet-go
|
||||
if: matrix.naive
|
||||
run: |
|
||||
|
||||
@@ -33,7 +33,6 @@ jobs:
|
||||
- windows-latest
|
||||
- macos-latest
|
||||
go:
|
||||
- ~1.25
|
||||
- ~1.26
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
|
||||
@@ -11,8 +11,6 @@ PARAMS = -v -trimpath -ldflags "-X 'github.com/sagernet/sing-box/constant.Versio
|
||||
MAIN_PARAMS = $(PARAMS) -tags "$(TAGS)"
|
||||
MAIN = ./cmd/sing-box
|
||||
PREFIX ?= $(shell go env GOPATH)
|
||||
SING_FFI ?= sing-ffi
|
||||
LIBBOX_FFI_CONFIG ?= ./experimental/libbox/ffi.json
|
||||
|
||||
ADMIN_PANEL_DIR = service/admin_panel
|
||||
ADMIN_PANEL_WEB = $(ADMIN_PANEL_DIR)/web
|
||||
@@ -55,7 +53,7 @@ ci_build:
|
||||
go build $(MAIN_PARAMS) $(MAIN)
|
||||
|
||||
generate_completions:
|
||||
go run -v --tags "$(TAGS),generate,generate_completions" $(MAIN)
|
||||
go run -v -ldflags "$(LDFLAGS_SHARED)" --tags "$(TAGS),generate_completions" $(MAIN)
|
||||
|
||||
schema:
|
||||
go run -ldflags "$(LDFLAGS_SHARED)" --tags "$(TAGS)" $(MAIN) schema -o docs/schema.json
|
||||
@@ -309,15 +307,6 @@ lib_android:
|
||||
lib_apple:
|
||||
go run ./cmd/internal/build_libbox -target apple
|
||||
|
||||
lib_windows:
|
||||
$(SING_FFI) generate --config $(LIBBOX_FFI_CONFIG) --platform-type csharp
|
||||
|
||||
lib_android_new:
|
||||
$(SING_FFI) generate --config $(LIBBOX_FFI_CONFIG) --platform-type android
|
||||
|
||||
lib_apple_new:
|
||||
$(SING_FFI) generate --config $(LIBBOX_FFI_CONFIG) --platform-type apple
|
||||
|
||||
lib_install:
|
||||
go install -v github.com/sagernet/gomobile/cmd/gomobile@v0.1.13
|
||||
go install -v github.com/sagernet/gomobile/cmd/gobind@v0.1.13
|
||||
|
||||
@@ -20,6 +20,7 @@ type DNSRouter interface {
|
||||
Lookup(ctx context.Context, domain string, options DNSQueryOptions) ([]netip.Addr, error)
|
||||
ClearCache()
|
||||
LookupReverseMapping(ip netip.Addr) (string, bool)
|
||||
LookupECHPublicName(domain string) string
|
||||
ResetNetwork()
|
||||
}
|
||||
|
||||
@@ -41,6 +42,7 @@ type DNSQueryOptions struct {
|
||||
Timeout time.Duration
|
||||
ClientSubnet netip.Prefix
|
||||
RemoveClientSubnet bool
|
||||
DisableReverseMapping bool
|
||||
}
|
||||
|
||||
type RDRCStore interface {
|
||||
|
||||
@@ -12,6 +12,7 @@ type Endpoint interface {
|
||||
Type() string
|
||||
Tag() string
|
||||
Outbound
|
||||
IsEndpoint()
|
||||
}
|
||||
|
||||
type EndpointRegistry interface {
|
||||
|
||||
@@ -41,3 +41,6 @@ func (a *Adapter) Network() []string {
|
||||
func (a *Adapter) Dependencies() []string {
|
||||
return a.dependencies
|
||||
}
|
||||
|
||||
func (a *Adapter) IsEndpoint() {
|
||||
}
|
||||
|
||||
@@ -160,8 +160,9 @@ func (s *SavedBinary) UnmarshalBinary(data []byte) error {
|
||||
|
||||
type OutboundGroup interface {
|
||||
Outbound
|
||||
Now() string
|
||||
All() []string
|
||||
Selected(network string) Outbound
|
||||
AttachConnection(closer io.Closer) (detach func())
|
||||
}
|
||||
|
||||
type URLTestGroup interface {
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ type FakeIPStore interface {
|
||||
type FakeIPStorage interface {
|
||||
FakeIPMetadata() *FakeIPMetadata
|
||||
FakeIPSaveMetadata(metadata *FakeIPMetadata) error
|
||||
FakeIPSaveMetadataAsync(metadata *FakeIPMetadata)
|
||||
FakeIPReserve(metadata *FakeIPMetadata, current netip.Addr, reservedEnd netip.Addr) error
|
||||
FakeIPStore(address netip.Addr, domain string) error
|
||||
FakeIPStoreAsync(address netip.Addr, domain string, logger logger.Logger)
|
||||
FakeIPLoad(address netip.Addr) (string, bool)
|
||||
|
||||
+42
-33
@@ -6,6 +6,7 @@ import (
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing-box/common/interrupt"
|
||||
"github.com/sagernet/sing-box/common/tlsspoof"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/log"
|
||||
@@ -59,15 +60,17 @@ type InboundContext struct {
|
||||
|
||||
RouteRule string
|
||||
RouteOutbound string
|
||||
OutboundChain []Outbound
|
||||
|
||||
// sniffer
|
||||
|
||||
Protocol string
|
||||
Domain string
|
||||
Client string
|
||||
SniffContext any
|
||||
SnifferNames []string
|
||||
SniffError error
|
||||
Protocol string
|
||||
Domain string
|
||||
ECHPublicName string
|
||||
Client string
|
||||
SniffContext any
|
||||
SnifferNames []string
|
||||
SniffError error
|
||||
|
||||
// cache
|
||||
|
||||
@@ -141,34 +144,39 @@ func DNSResponseAddresses(response *dns.Msg) []netip.Addr {
|
||||
return nil
|
||||
}
|
||||
addresses := make([]netip.Addr, 0, len(response.Answer))
|
||||
for _, rawRecord := range response.Answer {
|
||||
switch record := rawRecord.(type) {
|
||||
case *dns.A:
|
||||
addr := M.AddrFromIP(record.A)
|
||||
if addr.IsValid() {
|
||||
addresses = append(addresses, addr)
|
||||
}
|
||||
case *dns.AAAA:
|
||||
addr := M.AddrFromIP(record.AAAA)
|
||||
if addr.IsValid() {
|
||||
addresses = append(addresses, addr)
|
||||
}
|
||||
case *dns.HTTPS:
|
||||
for _, value := range record.SVCB.Value {
|
||||
switch hint := value.(type) {
|
||||
case *dns.SVCBIPv4Hint:
|
||||
for _, ip := range hint.Hint {
|
||||
addr := M.AddrFromIP(ip).Unmap()
|
||||
if addr.IsValid() {
|
||||
addresses = append(addresses, addr)
|
||||
}
|
||||
for _, record := range response.Answer {
|
||||
addresses = AppendDNSRecordAddresses(addresses, record)
|
||||
}
|
||||
return addresses
|
||||
}
|
||||
|
||||
func AppendDNSRecordAddresses(addresses []netip.Addr, rawRecord dns.RR) []netip.Addr {
|
||||
switch record := rawRecord.(type) {
|
||||
case *dns.A:
|
||||
addr := M.AddrFromIP(record.A)
|
||||
if addr.IsValid() {
|
||||
addresses = append(addresses, addr)
|
||||
}
|
||||
case *dns.AAAA:
|
||||
addr := M.AddrFromIP(record.AAAA)
|
||||
if addr.IsValid() {
|
||||
addresses = append(addresses, addr)
|
||||
}
|
||||
case *dns.HTTPS:
|
||||
for _, value := range record.SVCB.Value {
|
||||
switch hint := value.(type) {
|
||||
case *dns.SVCBIPv4Hint:
|
||||
for _, ip := range hint.Hint {
|
||||
addr := M.AddrFromIP(ip).Unmap()
|
||||
if addr.IsValid() {
|
||||
addresses = append(addresses, addr)
|
||||
}
|
||||
case *dns.SVCBIPv6Hint:
|
||||
for _, ip := range hint.Hint {
|
||||
addr := M.AddrFromIP(ip)
|
||||
if addr.IsValid() {
|
||||
addresses = append(addresses, addr)
|
||||
}
|
||||
}
|
||||
case *dns.SVCBIPv6Hint:
|
||||
for _, ip := range hint.Hint {
|
||||
addr := M.AddrFromIP(ip)
|
||||
if addr.IsValid() {
|
||||
addresses = append(addresses, addr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,6 +205,7 @@ func ContextForMultiplexSession(ctx context.Context) context.Context {
|
||||
sessionContext.Outbound = metadata.Outbound
|
||||
}
|
||||
ctx = ContextWithDNSTransportTag(ctx, "")
|
||||
ctx = interrupt.ContextWithIsExternalConnection(ctx, false)
|
||||
return WithContext(ctx, &sessionContext)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/sagernet/sing-box/common/taskmonitor"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/log"
|
||||
"github.com/sagernet/sing/common"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
F "github.com/sagernet/sing/common/format"
|
||||
"github.com/sagernet/sing/common/x/list"
|
||||
@@ -153,11 +154,13 @@ func (s *Scope) Close() error {
|
||||
s.cleanups.Init()
|
||||
s.children = nil
|
||||
s.access.Unlock()
|
||||
var err error
|
||||
var cleanupErrors []error
|
||||
for _, cleanup := range cleanups {
|
||||
err = E.Errors(err, cleanup())
|
||||
cleanupErrors = append(cleanupErrors, E.Expand(cleanup())...)
|
||||
}
|
||||
return err
|
||||
return E.Errors(common.Filter(cleanupErrors, func(it error) bool {
|
||||
return !E.IsClosed(it) && !E.IsCanceled(it)
|
||||
})...)
|
||||
}
|
||||
|
||||
func LogElapsed(logger log.ContextLogger, description ...any) func() {
|
||||
|
||||
@@ -35,6 +35,7 @@ type NetworkManager interface {
|
||||
WIFIState() WIFIState
|
||||
UpdateWIFIState(ctx context.Context)
|
||||
ResetNetwork(ctx context.Context)
|
||||
FlushSystemDNSCache()
|
||||
}
|
||||
|
||||
type NetworkOptions struct {
|
||||
@@ -52,6 +53,10 @@ type InterfaceUpdateListener interface {
|
||||
InterfaceUpdated(ctx context.Context)
|
||||
}
|
||||
|
||||
type SystemDNSCacheFlusher interface {
|
||||
FlushSystemDNSCache()
|
||||
}
|
||||
|
||||
type WIFIState struct {
|
||||
SSID string
|
||||
BSSID string
|
||||
|
||||
+1
-1
@@ -58,5 +58,5 @@ type IdleConnectionKeeper interface {
|
||||
}
|
||||
|
||||
type Referrer interface {
|
||||
References() []string
|
||||
References() (outbounds []string, dnsServers []string)
|
||||
}
|
||||
|
||||
+108
-104
@@ -3,6 +3,7 @@ package outbound
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -15,18 +16,17 @@ import (
|
||||
var _ adapter.OutboundManager = (*Manager)(nil)
|
||||
|
||||
type Manager struct {
|
||||
registry adapter.OutboundRegistry
|
||||
endpoint adapter.EndpointManager
|
||||
defaultTag string
|
||||
access sync.RWMutex
|
||||
startAccess sync.Mutex
|
||||
scope *adapter.Scope
|
||||
stage adapter.StartStage
|
||||
outbounds []adapter.Outbound
|
||||
outboundByTag map[string]adapter.Outbound
|
||||
dependByTag map[string][]string
|
||||
defaultOutbound adapter.Outbound
|
||||
defaultOutboundFallback func() (adapter.Outbound, error)
|
||||
registry adapter.OutboundRegistry
|
||||
endpoint adapter.EndpointManager
|
||||
defaultTag string
|
||||
access sync.RWMutex
|
||||
startAccess sync.Mutex
|
||||
scope *adapter.Scope
|
||||
stage adapter.StartStage
|
||||
outbounds []adapter.Outbound
|
||||
outboundByTag map[string]adapter.Outbound
|
||||
dependByTag map[string][]string
|
||||
defaultOutbound adapter.Outbound
|
||||
}
|
||||
|
||||
func NewManager(registry adapter.OutboundRegistry, endpoint adapter.EndpointManager, defaultTag string) *Manager {
|
||||
@@ -39,42 +39,52 @@ func NewManager(registry adapter.OutboundRegistry, endpoint adapter.EndpointMana
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) Initialize(defaultOutboundFallback func() (adapter.Outbound, error)) {
|
||||
m.defaultOutboundFallback = defaultOutboundFallback
|
||||
func (m *Manager) Initialize(defaultOutboundFallback func() (adapter.Outbound, error)) error {
|
||||
m.access.Lock()
|
||||
defer m.access.Unlock()
|
||||
if m.defaultTag != "" && m.defaultOutbound == nil {
|
||||
defaultEndpoint, loaded := m.endpoint.Get(m.defaultTag)
|
||||
if !loaded {
|
||||
return E.New("default outbound not found: ", m.defaultTag)
|
||||
}
|
||||
m.defaultOutbound = defaultEndpoint
|
||||
}
|
||||
if m.defaultOutbound == nil {
|
||||
directOutbound, err := defaultOutboundFallback()
|
||||
if err != nil {
|
||||
return E.Cause(err, "create direct outbound for fallback")
|
||||
}
|
||||
m.outbounds = append(m.outbounds, directOutbound)
|
||||
m.outboundByTag[directOutbound.Tag()] = directOutbound
|
||||
m.defaultOutbound = directOutbound
|
||||
}
|
||||
_, err := sortOutbounds(slices.Concat(m.outbounds, common.Map(m.endpoint.Endpoints(), func(it adapter.Endpoint) adapter.Outbound { return it })))
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Manager) Start(stage adapter.StartStage, scope *adapter.Scope) error {
|
||||
m.startAccess.Lock()
|
||||
defer m.startAccess.Unlock()
|
||||
m.access.Lock()
|
||||
outbounds := slices.Concat(m.outbounds, common.Map(m.endpoint.Endpoints(), func(endpoint adapter.Endpoint) adapter.Outbound { return endpoint }))
|
||||
sortedOutbounds, err := sortOutbounds(outbounds)
|
||||
if err != nil {
|
||||
m.access.Unlock()
|
||||
return err
|
||||
}
|
||||
m.scope = scope
|
||||
m.stage = stage
|
||||
if stage == adapter.StartStateInitialize {
|
||||
if m.defaultTag != "" && m.defaultOutbound == nil {
|
||||
defaultEndpoint, loaded := m.endpoint.Get(m.defaultTag)
|
||||
if !loaded {
|
||||
m.access.Unlock()
|
||||
return E.New("default outbound not found: ", m.defaultTag)
|
||||
}
|
||||
m.defaultOutbound = defaultEndpoint
|
||||
}
|
||||
if m.defaultOutbound == nil {
|
||||
directOutbound, err := m.defaultOutboundFallback()
|
||||
if err != nil {
|
||||
m.access.Unlock()
|
||||
return E.Cause(err, "create direct outbound for fallback")
|
||||
}
|
||||
m.outbounds = append(m.outbounds, directOutbound)
|
||||
m.outboundByTag[directOutbound.Tag()] = directOutbound
|
||||
m.defaultOutbound = directOutbound
|
||||
}
|
||||
}
|
||||
outbounds := m.outbounds
|
||||
m.access.Unlock()
|
||||
if stage == adapter.StartStateStart {
|
||||
return m.startOutbounds(scope, append(outbounds, common.Map(m.endpoint.Endpoints(), func(it adapter.Endpoint) adapter.Outbound { return it })...))
|
||||
}
|
||||
for _, outbound := range outbounds {
|
||||
for _, outbound := range sortedOutbounds {
|
||||
if endpoint, isEndpoint := outbound.(adapter.Endpoint); isEndpoint {
|
||||
if stage == adapter.StartStateStart {
|
||||
err := m.endpoint.StartEndpoint(endpoint)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
lifecycle, isLifecycle := outbound.(adapter.Lifecycle)
|
||||
if !isLifecycle {
|
||||
continue
|
||||
@@ -88,71 +98,6 @@ func (m *Manager) Start(stage adapter.StartStage, scope *adapter.Scope) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Manager) startOutbounds(scope *adapter.Scope, outbounds []adapter.Outbound) error {
|
||||
started := make(map[string]bool)
|
||||
for {
|
||||
canContinue := false
|
||||
startOne:
|
||||
for _, outboundToStart := range outbounds {
|
||||
outboundTag := outboundToStart.Tag()
|
||||
if started[outboundTag] {
|
||||
continue
|
||||
}
|
||||
dependencies := outboundToStart.Dependencies()
|
||||
for _, dependency := range dependencies {
|
||||
if !started[dependency] {
|
||||
continue startOne
|
||||
}
|
||||
}
|
||||
started[outboundTag] = true
|
||||
canContinue = true
|
||||
if endpoint, isEndpoint := outboundToStart.(adapter.Endpoint); isEndpoint {
|
||||
err := m.endpoint.StartEndpoint(endpoint)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
lifecycle, isLifecycle := outboundToStart.(adapter.Lifecycle)
|
||||
if !isLifecycle {
|
||||
continue
|
||||
}
|
||||
name := "outbound/" + outboundToStart.Type() + "[" + outboundTag + "]"
|
||||
err := scope.Start(name, lifecycle, adapter.StartStateStart)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(started) == len(outbounds) {
|
||||
break
|
||||
}
|
||||
if canContinue {
|
||||
continue
|
||||
}
|
||||
currentOutbound := common.Find(outbounds, func(it adapter.Outbound) bool {
|
||||
return !started[it.Tag()]
|
||||
})
|
||||
var lintOutbound func(oTree []string, oCurrent adapter.Outbound) error
|
||||
lintOutbound = func(oTree []string, oCurrent adapter.Outbound) error {
|
||||
problemOutboundTag := common.Find(oCurrent.Dependencies(), func(it string) bool {
|
||||
return !started[it]
|
||||
})
|
||||
if common.Contains(oTree, problemOutboundTag) {
|
||||
return E.New("circular outbound dependency: ", strings.Join(oTree, " -> "), " -> ", problemOutboundTag)
|
||||
}
|
||||
problemOutbound := common.Find(outbounds, func(it adapter.Outbound) bool {
|
||||
return it.Tag() == problemOutboundTag
|
||||
})
|
||||
if problemOutbound == nil {
|
||||
return E.New("dependency[", problemOutboundTag, "] not found for outbound[", oCurrent.Tag(), "]")
|
||||
}
|
||||
return lintOutbound(append(oTree, problemOutboundTag), problemOutbound)
|
||||
}
|
||||
return lintOutbound([]string{currentOutbound.Tag()}, currentOutbound)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Manager) Outbounds() []adapter.Outbound {
|
||||
m.access.RLock()
|
||||
defer m.access.RUnlock()
|
||||
@@ -265,6 +210,65 @@ func (m *Manager) Create(ctx context.Context, router adapter.Router, logger log.
|
||||
return nil
|
||||
}
|
||||
|
||||
func sortOutbounds(outbounds []adapter.Outbound) ([]adapter.Outbound, error) {
|
||||
tags := make(map[string]bool, len(outbounds))
|
||||
for _, outbound := range outbounds {
|
||||
tag := outbound.Tag()
|
||||
if tags[tag] {
|
||||
return nil, E.New("duplicate outbound tag: ", tag)
|
||||
}
|
||||
tags[tag] = true
|
||||
}
|
||||
sortedOutbounds := make([]adapter.Outbound, 0, len(outbounds))
|
||||
sorted := make(map[string]bool)
|
||||
for {
|
||||
canContinue := false
|
||||
sortOne:
|
||||
for _, outboundToSort := range outbounds {
|
||||
outboundTag := outboundToSort.Tag()
|
||||
if sorted[outboundTag] {
|
||||
continue
|
||||
}
|
||||
dependencies := outboundToSort.Dependencies()
|
||||
for _, dependency := range dependencies {
|
||||
if !sorted[dependency] {
|
||||
continue sortOne
|
||||
}
|
||||
}
|
||||
sorted[outboundTag] = true
|
||||
canContinue = true
|
||||
sortedOutbounds = append(sortedOutbounds, outboundToSort)
|
||||
}
|
||||
if len(sorted) == len(outbounds) {
|
||||
break
|
||||
}
|
||||
if canContinue {
|
||||
continue
|
||||
}
|
||||
currentOutbound := common.Find(outbounds, func(it adapter.Outbound) bool {
|
||||
return !sorted[it.Tag()]
|
||||
})
|
||||
var lintOutbound func(dependencyPath []string, current adapter.Outbound) error
|
||||
lintOutbound = func(dependencyPath []string, current adapter.Outbound) error {
|
||||
problemOutboundTag := common.Find(current.Dependencies(), func(it string) bool {
|
||||
return !sorted[it]
|
||||
})
|
||||
if common.Contains(dependencyPath, problemOutboundTag) {
|
||||
return E.New("circular outbound dependency: ", strings.Join(dependencyPath, " -> "), " -> ", problemOutboundTag)
|
||||
}
|
||||
problemOutbound := common.Find(outbounds, func(it adapter.Outbound) bool {
|
||||
return it.Tag() == problemOutboundTag
|
||||
})
|
||||
if problemOutbound == nil {
|
||||
return E.New("dependency[", problemOutboundTag, "] not found for outbound[", current.Tag(), "]")
|
||||
}
|
||||
return lintOutbound(append(dependencyPath, problemOutboundTag), problemOutbound)
|
||||
}
|
||||
return nil, lintOutbound([]string{currentOutbound.Tag()}, currentOutbound)
|
||||
}
|
||||
return sortedOutbounds, nil
|
||||
}
|
||||
|
||||
func (m *Manager) removeDependencies(outbound adapter.Outbound) {
|
||||
tag := outbound.Tag()
|
||||
for _, dependency := range outbound.Dependencies() {
|
||||
|
||||
@@ -240,7 +240,7 @@ func New(options Options) (*Box, error) {
|
||||
}
|
||||
service.MustRegister[adapter.DNSRouter](ctx, dnsRouter)
|
||||
service.MustRegister[adapter.DNSRuleSetUpdateValidator](ctx, dnsRouter)
|
||||
connectionManager := route.NewConnectionManager(logFactory.NewLogger("connection"))
|
||||
connectionManager := route.NewConnectionManager(ctx, logFactory.NewLogger("connection"))
|
||||
service.MustRegister[adapter.ConnectionManager](ctx, connectionManager)
|
||||
networkManager, err := route.NewNetworkManager(ctx, logFactory.NewLogger("network"), routeOptions, dnsOptions)
|
||||
if err != nil {
|
||||
@@ -258,7 +258,7 @@ func New(options Options) (*Box, error) {
|
||||
return nil, E.Cause(err, "initialize router")
|
||||
}
|
||||
if needClashAPI || needAPIService || options.PlatformLogWriter != nil {
|
||||
trafficManager := trafficcontrol.NewManager(outboundManager)
|
||||
trafficManager := trafficcontrol.NewManager()
|
||||
service.MustRegisterPtr(ctx, trafficManager)
|
||||
router.AppendTracker(trafficManager)
|
||||
internalServices = append(internalServices, trafficManager)
|
||||
@@ -296,10 +296,6 @@ func New(options Options) (*Box, error) {
|
||||
return nil, E.Cause(err, "initialize DNS server[", i, "]")
|
||||
}
|
||||
}
|
||||
err = dnsRouter.Initialize(dnsOptions.Rules)
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "initialize dns router")
|
||||
}
|
||||
for i, endpointOptions := range options.Endpoints {
|
||||
var tag string
|
||||
if endpointOptions.Tag != "" {
|
||||
@@ -430,24 +426,6 @@ func New(options Options) (*Box, error) {
|
||||
return nil, E.Cause(err, "initialize certificate provider[", i, "]")
|
||||
}
|
||||
}
|
||||
outboundManager.Initialize(func() (adapter.Outbound, error) {
|
||||
return direct.NewOutbound(
|
||||
ctx,
|
||||
router,
|
||||
logFactory.NewLogger("outbound/direct"),
|
||||
"direct",
|
||||
option.DirectOutboundOptions{},
|
||||
)
|
||||
})
|
||||
dnsTransportManager.Initialize(func() (adapter.DNSTransport, error) {
|
||||
return dnsTransportRegistry.CreateDNSTransport(
|
||||
ctx,
|
||||
logFactory.NewLogger("dns/local"),
|
||||
"local",
|
||||
C.DNSTypeLocal,
|
||||
&option.LocalDNSServerOptions{},
|
||||
)
|
||||
})
|
||||
httpClientManager.Initialize(func() (*httpclient.ManagedTransport, error) {
|
||||
deprecated.Report(ctx, deprecated.OptionImplicitDefaultHTTPClient)
|
||||
var httpClientOptions option.HTTPClientOptions
|
||||
@@ -505,6 +483,38 @@ func New(options Options) (*Box, error) {
|
||||
})
|
||||
timeService.TimeService = ntpService
|
||||
}
|
||||
err = outboundManager.Initialize(func() (adapter.Outbound, error) {
|
||||
return direct.NewOutbound(
|
||||
ctx,
|
||||
router,
|
||||
logFactory.NewLogger("outbound/direct"),
|
||||
"direct",
|
||||
option.DirectOutboundOptions{},
|
||||
)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = dnsTransportManager.Initialize(func() (adapter.DNSTransport, error) {
|
||||
return dnsTransportRegistry.CreateDNSTransport(
|
||||
ctx,
|
||||
logFactory.NewLogger("dns/local"),
|
||||
"local",
|
||||
C.DNSTypeLocal,
|
||||
&option.LocalDNSServerOptions{},
|
||||
)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = dnsRouter.Initialize(dnsOptions.Rules)
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "initialize dns router")
|
||||
}
|
||||
err = router.ValidateRuleActions()
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "initialize router")
|
||||
}
|
||||
return &Box{
|
||||
network: networkManager,
|
||||
endpoint: endpointManager,
|
||||
|
||||
+1
-1
Submodule clients/desktop updated: 50f5038491...9fea2530e2
@@ -55,7 +55,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
var standaloneVersionUpdated bool
|
||||
newContent, standaloneVersionUpdated = findAndReplace(objectsMap, newContent, []string{"io.nekohasekai.sfamt.standalone", "io.nekohasekai.sfamt.system"}, newVersion.String())
|
||||
newContent, standaloneVersionUpdated = findAndReplace(objectsMap, newContent, []string{"io.nekohasekai.sfamt.standalone", "io.nekohasekai.sfamt.system", "io.nekohasekai.sfamt.helper"}, newVersion.String())
|
||||
if standaloneVersionUpdated {
|
||||
marketingVersionUpdated = true
|
||||
log.Info("updated version to ", newVersion.String())
|
||||
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var initialDir, _ = os.Getwd()
|
||||
|
||||
func runInUserNamespaceIfNeeded(options option.Options, optionsList []*OptionsEntry) error {
|
||||
if !common.Any(options.NetworkNamespaces, func(namespace option.NetworkNamespace) bool {
|
||||
return namespace.Type == C.NetNsTypeUnshare
|
||||
@@ -31,8 +33,12 @@ func runInUserNamespaceIfNeeded(options option.Options, optionsList []*OptionsEn
|
||||
if data[0].Effective&(1<<unix.CAP_SYS_ADMIN) != 0 {
|
||||
return nil
|
||||
}
|
||||
if data[0].Effective != 0 || data[1].Effective != 0 {
|
||||
return E.New("unshare network namespace requires CAP_SYS_ADMIN when running with other capabilities, as the rootless user namespace drops them")
|
||||
}
|
||||
command := exec.Command("/proc/self/exe", os.Args[1:]...)
|
||||
command.Args = os.Args
|
||||
command.Dir = initialDir
|
||||
command.Stdin = os.Stdin
|
||||
for _, entry := range optionsList {
|
||||
if entry.path == "stdin" {
|
||||
@@ -50,7 +56,7 @@ func runInUserNamespaceIfNeeded(options option.Options, optionsList []*OptionsEn
|
||||
{ContainerID: os.Getegid(), HostID: os.Getegid(), Size: 1},
|
||||
},
|
||||
GidMappingsEnableSetgroups: false,
|
||||
AmbientCaps: []uintptr{unix.CAP_SYS_ADMIN, unix.CAP_NET_ADMIN, unix.CAP_NET_RAW},
|
||||
AmbientCaps: []uintptr{unix.CAP_SYS_ADMIN, unix.CAP_NET_ADMIN, unix.CAP_NET_RAW, unix.CAP_NET_BIND_SERVICE},
|
||||
Setpgid: true,
|
||||
Pdeathsig: syscall.SIGKILL,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build generate && generate_completions
|
||||
//go:build generate_completions
|
||||
|
||||
package main
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !generate
|
||||
//go:build !generate_completions
|
||||
|
||||
package main
|
||||
|
||||
|
||||
@@ -171,6 +171,6 @@ func (c *RawConn) HandlePostHandshakeMessage() error {
|
||||
return c.methods.handlePostHandshakeMessage(c.pointer)
|
||||
}
|
||||
|
||||
func (c *RawConn) WriteRecordLocked(typ uint16, data []byte) (int, error) {
|
||||
func (c *RawConn) WriteRecordLocked(typ uint8, data []byte) (int, error) {
|
||||
return c.methods.writeRecordLocked(c.pointer, typ, data)
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func (c *ReadWaitConn) WaitReadBuffer() (buffer *buf.Buffer, err error) {
|
||||
}
|
||||
buffer.Truncate(n)
|
||||
|
||||
if n != 0 && c.rawConn.Input.Len() == 0 && c.rawConn.Input.Len() > 0 &&
|
||||
if n != 0 && c.rawConn.Input.Len() == 0 && c.rawConn.RawInput.Len() > 0 &&
|
||||
// recordType(c.RawInput.Bytes()[0]) == recordTypeAlert {
|
||||
c.rawConn.RawInput.Bytes()[0] == 21 {
|
||||
_ = c.rawConn.ReadRecord()
|
||||
|
||||
@@ -17,7 +17,7 @@ var _ *tls.Conn
|
||||
type Methods struct {
|
||||
readRecord func(c unsafe.Pointer) error
|
||||
handlePostHandshakeMessage func(c unsafe.Pointer) error
|
||||
writeRecordLocked func(c unsafe.Pointer, typ uint16, data []byte) (int, error)
|
||||
writeRecordLocked func(c unsafe.Pointer, typ uint8, data []byte) (int, error)
|
||||
|
||||
setErrorLocked func(hc unsafe.Pointer, err error) error
|
||||
decrypt func(hc unsafe.Pointer, record []byte) ([]byte, uint8, error)
|
||||
@@ -53,7 +53,7 @@ func stdTLSReadRecord(c unsafe.Pointer) error
|
||||
func stdTLSHandlePostHandshakeMessage(c unsafe.Pointer) error
|
||||
|
||||
//go:linkname stdWriteRecordLocked crypto/tls.(*Conn).writeRecordLocked
|
||||
func stdWriteRecordLocked(c unsafe.Pointer, typ uint16, data []byte) (int, error)
|
||||
func stdWriteRecordLocked(c unsafe.Pointer, typ uint8, data []byte) (int, error)
|
||||
|
||||
//go:linkname stdSetErrorLocked crypto/tls.(*halfConn).setErrorLocked
|
||||
func stdSetErrorLocked(hc unsafe.Pointer, err error) error
|
||||
|
||||
@@ -41,7 +41,7 @@ func utlsReadRecord(c unsafe.Pointer) error
|
||||
func utlsHandlePostHandshakeMessage(c unsafe.Pointer) error
|
||||
|
||||
//go:linkname utlsWriteRecordLocked github.com/metacubex/utls.(*Conn).writeRecordLocked
|
||||
func utlsWriteRecordLocked(hc unsafe.Pointer, typ uint16, data []byte) (int, error)
|
||||
func utlsWriteRecordLocked(hc unsafe.Pointer, typ uint8, data []byte) (int, error)
|
||||
|
||||
//go:linkname utlsSetErrorLocked github.com/metacubex/utls.(*halfConn).setErrorLocked
|
||||
func utlsSetErrorLocked(hc unsafe.Pointer, err error) error
|
||||
|
||||
+752
-859
File diff suppressed because it is too large
Load Diff
+342
-265
@@ -317,6 +317,128 @@ qJZ9ZPskWkoDbGs4xugDQ5r3V7mzKWmTOPQD8rv7gmsHINFSH5pkAnuYZttcTVoP
|
||||
E2Efv4WstK2tBZQIgx51F9NxO5NQI1mg7TyRVJ12AMXDuDjb
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Atos TrustedRoot 2011
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDdzCCAl+gAwIBAgIIXDPLYixfszIwDQYJKoZIhvcNAQELBQAwPDEeMBwGA1UE
|
||||
AwwVQXRvcyBUcnVzdGVkUm9vdCAyMDExMQ0wCwYDVQQKDARBdG9zMQswCQYDVQQG
|
||||
EwJERTAeFw0xMTA3MDcxNDU4MzBaFw0zMDEyMzEyMzU5NTlaMDwxHjAcBgNVBAMM
|
||||
FUF0b3MgVHJ1c3RlZFJvb3QgMjAxMTENMAsGA1UECgwEQXRvczELMAkGA1UEBhMC
|
||||
REUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCVhTuXbyo7LjvPpvMp
|
||||
Nb7PGKw+qtn4TaA+Gke5vJrf8v7MPkfoepbCJI419KkM/IL9bcFyYie96mvr54rM
|
||||
VD6QUM+A1JX76LWC1BTFtqlVJVfbsVD2sGBkWXppzwO3bw2+yj5vdHLqqjAqc2K+
|
||||
SZFhyBH+DgMq92og3AIVDV4VavzjgsG1xZ1kCWyjWZgHJ8cblithdHFsQ/H3NYkQ
|
||||
4J7sVaE3IqKHBAUsR320HLliKWYoyrfhk/WklAOZuXCFteZI6o1Q/NnezG8HDt0L
|
||||
cp2AMBYHlT8oDv3FdU9T1nSatCQujgKRz3bFmx5VdJx4IbHwLfELn8LVlhgf8FQi
|
||||
eowHAgMBAAGjfTB7MB0GA1UdDgQWBBSnpQaxLKYJYO7Rl+lwrrw7GWzbITAPBgNV
|
||||
HRMBAf8EBTADAQH/MB8GA1UdIwQYMBaAFKelBrEspglg7tGX6XCuvDsZbNshMBgG
|
||||
A1UdIAQRMA8wDQYLKwYBBAGwLQMEAQEwDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3
|
||||
DQEBCwUAA4IBAQAmdzTblEiGKkGdLD4GkGDEjKwLVLgfuXvTBznk+j57sj1O7Z8j
|
||||
vZfza1zv7v1Apt+hk6EKhqzvINB5Ab149xnYJDE0BAGmuhWawyfc2E8PzBhj/5kP
|
||||
DpFrdRbhIfzYJsdHt6bPWHJxfrrhTZVHO8mvbaG0weyJ9rQPOLXiZNwlz6bb65pc
|
||||
maHFCN795trV1lpFDMS3wrUU77QR/w4VtfX128a961qn8FYiqTxlVMYVqL2Gns2D
|
||||
lmh6cYGJ4Qvh6hEbaAjMaZ7snkGeRDImeuKHCnE96+RapNLbxc3G3mB/ufNPRJLv
|
||||
KrcYPqcZ2Qt9sTdBQrC6YB3y/gkRsPCHe6ed
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Atos TrustedRoot Root CA ECC G2 2020
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICMTCCAbagAwIBAgIMC3MoERh0MBzvbwiEMAoGCCqGSM49BAMDMEsxCzAJBgNV
|
||||
BAYTAkRFMQ0wCwYDVQQKDARBdG9zMS0wKwYDVQQDDCRBdG9zIFRydXN0ZWRSb290
|
||||
IFJvb3QgQ0EgRUNDIEcyIDIwMjAwHhcNMjAxMjE1MDgzOTEwWhcNNDAxMjEwMDgz
|
||||
OTA5WjBLMQswCQYDVQQGEwJERTENMAsGA1UECgwEQXRvczEtMCsGA1UEAwwkQXRv
|
||||
cyBUcnVzdGVkUm9vdCBSb290IENBIEVDQyBHMiAyMDIwMHYwEAYHKoZIzj0CAQYF
|
||||
K4EEACIDYgAEyFyAyk7CKB9XvzjmYSP80KlblhYWwwxeFaWQCf84KLR6HgrWUyrB
|
||||
u5BAdDfpgeiNL2gBNXxSLtj0WLMRHFvZhxiTkS3sndpsnm2ESPzCiQXrmBMCAWxT
|
||||
Hg5JY1hHsa/Co2MwYTAPBgNVHRMBAf8EBTADAQH/MB8GA1UdIwQYMBaAFFsfxHFs
|
||||
shufvlwfjP2ztvuzDgmHMB0GA1UdDgQWBBRbH8RxbLIbn75cH4z9s7b7sw4JhzAO
|
||||
BgNVHQ8BAf8EBAMCAYYwCgYIKoZIzj0EAwMDaQAwZgIxAOzgmf3d5FTByx/oPijX
|
||||
FVlKgspTMOzrNqW5yM6TR1bIYabhbZJTlY/241VT8N165wIxALCH1RuzYPyRjYDK
|
||||
ohtRSzhUy6oee9flRJUWLzxEeC4luuqQ5OxS7lfsA4TzXtsWDQ==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Atos TrustedRoot Root CA ECC TLS 2021
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICFTCCAZugAwIBAgIQPZg7pmY9kGP3fiZXOATvADAKBggqhkjOPQQDAzBMMS4w
|
||||
LAYDVQQDDCVBdG9zIFRydXN0ZWRSb290IFJvb3QgQ0EgRUNDIFRMUyAyMDIxMQ0w
|
||||
CwYDVQQKDARBdG9zMQswCQYDVQQGEwJERTAeFw0yMTA0MjIwOTI2MjNaFw00MTA0
|
||||
MTcwOTI2MjJaMEwxLjAsBgNVBAMMJUF0b3MgVHJ1c3RlZFJvb3QgUm9vdCBDQSBF
|
||||
Q0MgVExTIDIwMjExDTALBgNVBAoMBEF0b3MxCzAJBgNVBAYTAkRFMHYwEAYHKoZI
|
||||
zj0CAQYFK4EEACIDYgAEloZYKDcKZ9Cg3iQZGeHkBQcfl+3oZIK59sRxUM6KDP/X
|
||||
tXa7oWyTbIOiaG6l2b4siJVBzV3dscqDY4PMwL502eCdpO5KTlbgmClBk1IQ1SQ4
|
||||
AjJn8ZQSb+/Xxd4u/RmAo0IwQDAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBR2
|
||||
KCXWfeBmmnoJsmo7jjPXNtNPojAOBgNVHQ8BAf8EBAMCAYYwCgYIKoZIzj0EAwMD
|
||||
aAAwZQIwW5kp85wxtolrbNa9d+F851F+uDrNozZffPc8dz7kUK2o59JZDCaOMDtu
|
||||
CCrCp1rIAjEAmeMM56PDr9NJLkaCI2ZdyQAUEv049OGYa3cpetskz2VAv9LcjBHo
|
||||
9H1/IISpQuQo
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Atos TrustedRoot Root CA RSA G2 2020
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFfzCCA2egAwIBAgIMR7opRlU+FpKXsKtAMA0GCSqGSIb3DQEBDAUAMEsxCzAJ
|
||||
BgNVBAYTAkRFMQ0wCwYDVQQKDARBdG9zMS0wKwYDVQQDDCRBdG9zIFRydXN0ZWRS
|
||||
b290IFJvb3QgQ0EgUlNBIEcyIDIwMjAwHhcNMjAxMjE1MDg0MTIzWhcNNDAxMjEw
|
||||
MDg0MTIyWjBLMQswCQYDVQQGEwJERTENMAsGA1UECgwEQXRvczEtMCsGA1UEAwwk
|
||||
QXRvcyBUcnVzdGVkUm9vdCBSb290IENBIFJTQSBHMiAyMDIwMIICIjANBgkqhkiG
|
||||
9w0BAQEFAAOCAg8AMIICCgKCAgEAljGFSqoPMv554UOHnPsjt45/DVS9x2KTd+Qc
|
||||
NQR2owOLIu7EhN2lk25uso4JA+tRFjEXqmkVGA5ndCNe6pp9tTk+PYKpa+H+qRyw
|
||||
rVpNTHiDQYvP8h1impgEnGPpq2X+SB0kZQdHPrmRLumdm38aNak0sLflcDPvSnJR
|
||||
tge/YD8qn51U3/PXlElRA1pAqWjdEVlc+HamvFBSEO2s7JXg1INrSdoKT5mD3jKD
|
||||
SINnlbJ+54GFPc2C98oC7W2IXQiNuDW/KmkwmbtL0UHbRaCTmVGBkDYIqoq26I+z
|
||||
y+7lRg1ydfVJbOGify+87YSmN+7ewk85Tvae8MnRmzCdSW3h2v8SEIzW5Zl7BbZ9
|
||||
sAnHpPiyHDmVOTP0Nc4lYnuwXyDzy234bFIUZESP08ipdgflr3GZLS0EJUh2r8Pn
|
||||
zEPyB7xKJCQ33fpulAlvTF4BtP5U7COWpV7dhv/pRirx6NzspT2vb6oOD7R1+j4I
|
||||
uSZFT2aGTLwZuOHVNe6ChMjTqxLnzXMzYnf0F8u9NHYqBc6V5Xh5S56wjfk8WDiR
|
||||
6l6HOMC3Qv2qTIcjrQQgsX52Qtq7tha6V8iOE/p11QhMrziRqu+P+p9JLlR8Clax
|
||||
evrETi/Uo/oWitCV5Zem/8P8fA5HWPN/B3sS3Fc/LeOhTVtSTDOHmagJe2x+DvLP
|
||||
VkKe6wUCAwEAAaNjMGEwDwYDVR0TAQH/BAUwAwEB/zAfBgNVHSMEGDAWgBQgJfMH
|
||||
/adv8ZbukRBpzJrvfchoeDAdBgNVHQ4EFgQUICXzB/2nb/GW7pEQacya733IaHgw
|
||||
DgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3DQEBDAUAA4ICAQAkK06Y8h0X7dl2JrYw
|
||||
M+hpRaFRS1LYejowtuQS6r+fTOAEpPY1xv6hMPdThZKtVAVXX5LlKt42J557E0fJ
|
||||
anWv/PM35wz1PQFztWlR+L1Z0boL+Lq6ZCdDs3yDlYrnnhOW129KlkFJiw4grRbG
|
||||
96aHW4gSiYuJyhLSVq8iASFG6auYP6eI3uTLKpp1Gfo5XgkF1wMyGrgXUQjHAEB9
|
||||
9L74DFn0aXZu06RYW14mc+RCVQZeeEAP0zif7yZRcHSR8XdiAejZy+uh3zkyHbtr
|
||||
/XH+68+l5hT9AIATxpoASLCZBemugEj7CT9RFLW552BNTcovgSHuUgxletz1iUlM
|
||||
MJI0WIAyWbEN/yRhD+cKQtB7vPiOJ0c/cJ0n2bYGPaW7y16Prg5Tx5xqbztMD6NA
|
||||
cKiaB87UblsHotLiVLa9bzNyY61RmOGPdvFqBzgl/vZizl/bY8Jume8G3LneGRro
|
||||
VD190nZ12V4+MkinjPKecgz4uFi4FyOlFId1WHoAgQciOWpMlKC1otunLMGw8aOb
|
||||
wEz3bXDqMZ/xrn0+cyjZod/6k/CbsPDizSUgde/ifTIFyZt27su9MR75lJhLJFhW
|
||||
SMDeBky9pjRd7RZhY3P7GeL6W9iXddRtnmA5XpSLAizrmc5gKm4bjKdLvP025pgf
|
||||
ZfJ/8eOPTIBGNli2oWXLzhxEdQ==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Atos TrustedRoot Root CA RSA TLS 2021
|
||||
-----BEGIN CERTIFICATE-----
|
||||
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
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Autoridad de Certificacion Firmaprofesional CIF A62634068
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIGFDCCA/ygAwIBAgIIG3Dp0v+ubHEwDQYJKoZIhvcNAQELBQAwUTELMAkGA1UE
|
||||
@@ -599,41 +721,6 @@ PuXaTH4MNMn5X7azKFGnpyuqSfqNZSlO42sTp5SjLVFteAxEy9/eCG/Oo2Sr05WE
|
||||
QRBdJ3NghVdJIgc=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// ePKI Root Certification Authority
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFsDCCA5igAwIBAgIQFci9ZUdcr7iXAF7kBtK8nTANBgkqhkiG9w0BAQUFADBe
|
||||
MQswCQYDVQQGEwJUVzEjMCEGA1UECgwaQ2h1bmdod2EgVGVsZWNvbSBDby4sIEx0
|
||||
ZC4xKjAoBgNVBAsMIWVQS0kgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAe
|
||||
Fw0wNDEyMjAwMjMxMjdaFw0zNDEyMjAwMjMxMjdaMF4xCzAJBgNVBAYTAlRXMSMw
|
||||
IQYDVQQKDBpDaHVuZ2h3YSBUZWxlY29tIENvLiwgTHRkLjEqMCgGA1UECwwhZVBL
|
||||
SSBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIICIjANBgkqhkiG9w0BAQEF
|
||||
AAOCAg8AMIICCgKCAgEA4SUP7o3biDN1Z82tH306Tm2d0y8U82N0ywEhajfqhFAH
|
||||
SyZbCUNsIZ5qyNUD9WBpj8zwIuQf5/dqIjG3LBXy4P4AakP/h2XGtRrBp0xtInAh
|
||||
ijHyl3SJCRImHJ7K2RKilTza6We/CKBk49ZCt0Xvl/T29de1ShUCWH2YWEtgvM3X
|
||||
DZoTM1PRYfl61dd4s5oz9wCGzh1NlDivqOx4UXCKXBCDUSH3ET00hl7lSM2XgYI1
|
||||
TBnsZfZrxQWh7kcT1rMhJ5QQCtkkO7q+RBNGMD+XPNjX12ruOzjjK9SXDrkb5wdJ
|
||||
fzcq+Xd4z1TtW0ado4AOkUPB1ltfFLqfpo0kR0BZv3I4sjZsN/+Z0V0OWQqraffA
|
||||
sgRFelQArr5T9rXn4fg8ozHSqf4hUmTFpmfwdQcGlBSBVcYn5AGPF8Fqcde+S/uU
|
||||
WH1+ETOxQvdibBjWzwloPn9s9h6PYq2lY9sJpx8iQkEeb5mKPtf5P0B6ebClAZLS
|
||||
nT0IFaUQAS2zMnaolQ2zepr7BxB4EW/hj8e6DyUadCrlHJhBmd8hh+iVBmoKs2pH
|
||||
dmX2Os+PYhcZewoozRrSgx4hxyy/vv9haLdnG7t4TY3OZ+XkwY63I2binZB1NJip
|
||||
NiuKmpS5nezMirH4JYlcWrYvjB9teSSnUmjDhDXiZo1jDiVN1Rmy5nk3pyKdVDEC
|
||||
AwEAAaNqMGgwHQYDVR0OBBYEFB4M97Zn8uGSJglFwFU5Lnc/QkqiMAwGA1UdEwQF
|
||||
MAMBAf8wOQYEZyoHAAQxMC8wLQIBADAJBgUrDgMCGgUAMAcGBWcqAwAABBRFsMLH
|
||||
ClZ87lt4DJX5GFPBphzYEDANBgkqhkiG9w0BAQUFAAOCAgEACbODU1kBPpVJufGB
|
||||
uvl2ICO1J2B01GqZNF5sAFPZn/KmsSQHRGoqxqWOeBLoR9lYGxMqXnmbnwoqZ6Yl
|
||||
PwZpVnPDimZI+ymBV3QGypzqKOg4ZyYr8dW1P2WT+DZdjo2NQCCHGervJ8A9tDkP
|
||||
JXtoUHRVnAxZfVo9QZQlUgjgRywVMRnVvwdVxrsStZf0X4OFunHB2WyBEXYKCrC/
|
||||
gpf36j36+uwtqSiUO1bd0lEursC9CBWMd1I0ltabrNMdjmEPNXubrjlpC2JgQCA2
|
||||
j6/7Nu4tCEoduL+bXPjqpRugc6bY+G7gMwRfaKonh+3ZwZCc7b3jajWvY9+rGNm6
|
||||
5ulK6lCKD2GTHuItGeIwlDWSXQ62B68ZgI9HkFFLLk3dheLSClIKF5r8GrBQAuUB
|
||||
o2M3IUxExJtRmREOc5wGj1QupyheRDmHVi03vYVElOEMSyycw5KFNGHLD7ibSkNS
|
||||
/jQ6fbjpKdx2qcgw+BRxgMYeNkh0IkFch4LoGHGLQYlE535YW6i4jRPpp2zDR+2z
|
||||
Gp1iro2C6pSe3VkQw63d4k3jMdXH7OjysP6SHhYKGvzZ8/gntsm+HbRsZJB/9OTE
|
||||
W9c3rkIO3aQab3yIVMUWbuF6aC74Or8NpDyJO3inTmODBCEIZ43ygknQW/2xzQ+D
|
||||
hNQ+IIX3Sj0rnP0qCglN6oH4EZw=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// HiPKI Root CA - G1
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFajCCA1KgAwIBAgIQLd2szmKXlKFD6LDNdmpeYDANBgkqhkiG9w0BAQsFADBP
|
||||
@@ -667,29 +754,6 @@ vhV4nYWBSipX3tUZQ9rbyltHhoMLP7YNdnhzeSJesYAfz77RP1YQmCuVh6EfnWQU
|
||||
YDksswBVLuT1sw5XxJFBAJw/6KXf6vb/yPCtbVKoF6ubYfwSUTXkJf2vqmqGOQ==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// SecureSign Root CA12
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDcjCCAlqgAwIBAgIUZvnHwa/swlG07VOX5uaCwysckBYwDQYJKoZIhvcNAQEL
|
||||
BQAwUTELMAkGA1UEBhMCSlAxIzAhBgNVBAoTGkN5YmVydHJ1c3QgSmFwYW4gQ28u
|
||||
LCBMdGQuMR0wGwYDVQQDExRTZWN1cmVTaWduIFJvb3QgQ0ExMjAeFw0yMDA0MDgw
|
||||
NTM2NDZaFw00MDA0MDgwNTM2NDZaMFExCzAJBgNVBAYTAkpQMSMwIQYDVQQKExpD
|
||||
eWJlcnRydXN0IEphcGFuIENvLiwgTHRkLjEdMBsGA1UEAxMUU2VjdXJlU2lnbiBS
|
||||
b290IENBMTIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC6OcE3emhF
|
||||
KxS06+QT61d1I02PJC0W6K6OyX2kVzsqdiUzg2zqMoqUm048luT9Ub+ZyZN+v/mt
|
||||
p7JIKwccJ/VMvHASd6SFVLX9kHrko+RRWAPNEHl57muTH2SOa2SroxPjcf59q5zd
|
||||
J1M3s6oYwlkm7Fsf0uZlfO+TvdhYXAvA42VvPMfKWeP+bl+sg779XSVOKik71gur
|
||||
FzJ4pOE+lEa+Ym6b3kaosRbnhW70CEBFEaCeVESE99g2zvVQR9wsMJvuwPWW0v4J
|
||||
hscGWa5Pro4RmHvzC1KqYiaqId+OJTN5lxZJjfU+1UefNzFJM3IFTQy2VYzxV4+K
|
||||
h9GtxRESOaCtAgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQD
|
||||
AgEGMB0GA1UdDgQWBBRXNPN0zwRL1SXm8UC2LEzZLemgrTANBgkqhkiG9w0BAQsF
|
||||
AAOCAQEAPrvbFxbS8hQBICw4g0utvsqFepq2m2um4fylOqyttCg6r9cBg0krY6Ld
|
||||
mmQOmFxv3Y67ilQiLUoT865AQ9tPkbeGGuwAtEGBpE/6aouIs3YIcipJQMPTw4WJ
|
||||
mBClnW8Zt7vPemVV2zfrPIpyMpcemik+rY3moxtt9XUa5rBouVui7mlHJzWhhpmA
|
||||
8zNL4WukJsPvdFlseqJkth5Ew1DgDzk9qTPxpfPSvWKErI4cqc1avTc7bgoitPQV
|
||||
55FYxTpE05Uo2cBl6XLK0A+9H7MV2anjpEcJnuDLN/v9vZfVvhgaaaI5gdka9at/
|
||||
yOPiZwud9AzqVN/Ssq+xIvEg37xEHA==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// SecureSign Root CA14
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFcjCCA1qgAwIBAgIUZNtaDCBO6Ncpd8hQJ6JaJ90t8sswDQYJKoZIhvcNAQEM
|
||||
@@ -740,6 +804,40 @@ Af8wDgYDVR0PAQH/BAQDAgEGMB0GA1UdDgQWBBTrQciu/NWeUUj1vYv0hyCTQSvT
|
||||
bkU6iYAZezKYVWOr62Nuk22rGwlgMU4=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// SecureSign Root CA16
|
||||
-----BEGIN CERTIFICATE-----
|
||||
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
|
||||
jUVvQawB
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// D-TRUST BR Root CA 1 2020
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIC2zCCAmCgAwIBAgIQfMmPK4TX3+oPyWWa00tNljAKBggqhkjOPQQDAzBIMQsw
|
||||
@@ -1682,62 +1780,6 @@ zMOl6W8KjptlwlCFtaOgUxLMVYdh84GuEEZhvUQhuMI9dM9+JDX6HAcOmz0iyu8x
|
||||
L4ysEr3vQCj8KWefshNPZiTEUxnpHikV7+ZtsH8tZ/3zbBt1RqPlShfppNcL
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// emSign ECC Root CA - C3
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICKzCCAbGgAwIBAgIKe3G2gla4EnycqDAKBggqhkjOPQQDAzBaMQswCQYDVQQG
|
||||
EwJVUzETMBEGA1UECxMKZW1TaWduIFBLSTEUMBIGA1UEChMLZU11ZGhyYSBJbmMx
|
||||
IDAeBgNVBAMTF2VtU2lnbiBFQ0MgUm9vdCBDQSAtIEMzMB4XDTE4MDIxODE4MzAw
|
||||
MFoXDTQzMDIxODE4MzAwMFowWjELMAkGA1UEBhMCVVMxEzARBgNVBAsTCmVtU2ln
|
||||
biBQS0kxFDASBgNVBAoTC2VNdWRocmEgSW5jMSAwHgYDVQQDExdlbVNpZ24gRUND
|
||||
IFJvb3QgQ0EgLSBDMzB2MBAGByqGSM49AgEGBSuBBAAiA2IABP2lYa57JhAd6bci
|
||||
MK4G9IGzsUJxlTm801Ljr6/58pc1kjZGDoeVjbk5Wum739D+yAdBPLtVb4Ojavti
|
||||
sIGJAnB9SMVK4+kiVCJNk7tCDK93nCOmfddhEc5lx/h//vXyqaNCMEAwHQYDVR0O
|
||||
BBYEFPtaSNCAIEDyqOkAB2kZd6fmw/TPMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB
|
||||
Af8EBTADAQH/MAoGCCqGSM49BAMDA2gAMGUCMQC02C8Cif22TGK6Q04ThHK1rt0c
|
||||
3ta13FaPWEBaLd4gTCKDypOofu4SQMfWh0/434UCMBwUZOR8loMRnLDRWmFLpg9J
|
||||
0wD8ofzkpf9/rdcw0Md3f76BB1UwUCAU9Vc4CqgxUQ==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// emSign ECC Root CA - G3
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICTjCCAdOgAwIBAgIKPPYHqWhwDtqLhDAKBggqhkjOPQQDAzBrMQswCQYDVQQG
|
||||
EwJJTjETMBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhyYSBUZWNo
|
||||
bm9sb2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290IENBIC0g
|
||||
RzMwHhcNMTgwMjE4MTgzMDAwWhcNNDMwMjE4MTgzMDAwWjBrMQswCQYDVQQGEwJJ
|
||||
TjETMBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhyYSBUZWNobm9s
|
||||
b2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290IENBIC0gRzMw
|
||||
djAQBgcqhkjOPQIBBgUrgQQAIgNiAAQjpQy4LRL1KPOxst3iAhKAnjlfSU2fySU0
|
||||
WXTsuwYc58Byr+iuL+FBVIcUqEqy6HyC5ltqtdyzdc6LBtCGI79G1Y4PPwT01xyS
|
||||
fvalY8L1X44uT6EYGQIrMgqCZH0Wk9GjQjBAMB0GA1UdDgQWBBR8XQKEE9TMipuB
|
||||
zhccLikenEhjQjAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAKBggq
|
||||
hkjOPQQDAwNpADBmAjEAvvNhzwIQHWSVB7gYboiFBS+DCBeQyh+KTOgNG3qxrdWB
|
||||
CUfvO6wIBHxcmbHtRwfSAjEAnbpV/KlK6O3t5nYBQnvI+GDZjVGLVTv7jHvrZQnD
|
||||
+JbNR6iC8hZVdyR+EhCVBCyj
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// emSign Root CA - C1
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDczCCAlugAwIBAgILAK7PALrEzzL4Q7IwDQYJKoZIhvcNAQELBQAwVjELMAkG
|
||||
A1UEBhMCVVMxEzARBgNVBAsTCmVtU2lnbiBQS0kxFDASBgNVBAoTC2VNdWRocmEg
|
||||
SW5jMRwwGgYDVQQDExNlbVNpZ24gUm9vdCBDQSAtIEMxMB4XDTE4MDIxODE4MzAw
|
||||
MFoXDTQzMDIxODE4MzAwMFowVjELMAkGA1UEBhMCVVMxEzARBgNVBAsTCmVtU2ln
|
||||
biBQS0kxFDASBgNVBAoTC2VNdWRocmEgSW5jMRwwGgYDVQQDExNlbVNpZ24gUm9v
|
||||
dCBDQSAtIEMxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz+upufGZ
|
||||
BczYKCFK83M0UYRWEPWgTywS4/oTmifQz/l5GnRfHXk5/Fv4cI7gklL35CX5VIPZ
|
||||
HdPIWoU/Xse2B+4+wM6ar6xWQio5JXDWv7V7Nq2s9nPczdcdioOl+yuQFTdrHCZH
|
||||
3DspVpNqs8FqOp099cGXOFgFixwR4+S0uF2FHYP+eF8LRWgYSKVGczQ7/g/IdrvH
|
||||
GPMF0Ybzhe3nudkyrVWIzqa2kbBPrH4VI5b2P/AgNBbeCsbEBEV5f6f9vtKppa+c
|
||||
xSMq9zwhbL2vj07FOrLzNBL834AaSaTUqZX3noleoomslMuoaJuvimUnzYnu3Yy1
|
||||
aylwQ6BpC+S5DwIDAQABo0IwQDAdBgNVHQ4EFgQU/qHgcB4qAzlSWkK+XJGFehiq
|
||||
TbUwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEL
|
||||
BQADggEBAMJKVvoVIXsoounlHfv4LcQ5lkFMOycsxGwYFYDGrK9HWS8mC+M2sO87
|
||||
/kOXSTKZEhVb3xEp/6tT+LvBeA+snFOvV71ojD1pM/CjoCNjO2RnIkSt1XHLVip4
|
||||
kqNPEjE2NuLe/gDEo2APJ62gsIq1NnpSob0n9CAnYuhNlCQT5AoE6TyrLshDCUrG
|
||||
YQTlSTR+08TI9Q/Aqum6VF7zYytPT1DU/rl7mYw9wC68AivTxEDkigcxHpvOJpkT
|
||||
+xHqmiIMERnHXhuBUDDIlhJu58tBf5E7oke3VIAb3ADMmpDqw8NQBmIMMMAVSKeo
|
||||
WXzhriKi4gp6D/piq1JM4fHfyr6DDUI=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// emSign Root CA - G1
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDlDCCAnygAwIBAgIKMfXkYgxsWO3W2DANBgkqhkiG9w0BAQsFADBnMQswCQYD
|
||||
@@ -1762,128 +1804,6 @@ RQuQ+q7hv53yrlc8pa6yVvSLZUDp/TGBLPQ5Cdjua6e0ph0VpZj3AYHYhX3zUVxx
|
||||
iN66zB+Afko=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Atos TrustedRoot 2011
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDdzCCAl+gAwIBAgIIXDPLYixfszIwDQYJKoZIhvcNAQELBQAwPDEeMBwGA1UE
|
||||
AwwVQXRvcyBUcnVzdGVkUm9vdCAyMDExMQ0wCwYDVQQKDARBdG9zMQswCQYDVQQG
|
||||
EwJERTAeFw0xMTA3MDcxNDU4MzBaFw0zMDEyMzEyMzU5NTlaMDwxHjAcBgNVBAMM
|
||||
FUF0b3MgVHJ1c3RlZFJvb3QgMjAxMTENMAsGA1UECgwEQXRvczELMAkGA1UEBhMC
|
||||
REUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCVhTuXbyo7LjvPpvMp
|
||||
Nb7PGKw+qtn4TaA+Gke5vJrf8v7MPkfoepbCJI419KkM/IL9bcFyYie96mvr54rM
|
||||
VD6QUM+A1JX76LWC1BTFtqlVJVfbsVD2sGBkWXppzwO3bw2+yj5vdHLqqjAqc2K+
|
||||
SZFhyBH+DgMq92og3AIVDV4VavzjgsG1xZ1kCWyjWZgHJ8cblithdHFsQ/H3NYkQ
|
||||
4J7sVaE3IqKHBAUsR320HLliKWYoyrfhk/WklAOZuXCFteZI6o1Q/NnezG8HDt0L
|
||||
cp2AMBYHlT8oDv3FdU9T1nSatCQujgKRz3bFmx5VdJx4IbHwLfELn8LVlhgf8FQi
|
||||
eowHAgMBAAGjfTB7MB0GA1UdDgQWBBSnpQaxLKYJYO7Rl+lwrrw7GWzbITAPBgNV
|
||||
HRMBAf8EBTADAQH/MB8GA1UdIwQYMBaAFKelBrEspglg7tGX6XCuvDsZbNshMBgG
|
||||
A1UdIAQRMA8wDQYLKwYBBAGwLQMEAQEwDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3
|
||||
DQEBCwUAA4IBAQAmdzTblEiGKkGdLD4GkGDEjKwLVLgfuXvTBznk+j57sj1O7Z8j
|
||||
vZfza1zv7v1Apt+hk6EKhqzvINB5Ab149xnYJDE0BAGmuhWawyfc2E8PzBhj/5kP
|
||||
DpFrdRbhIfzYJsdHt6bPWHJxfrrhTZVHO8mvbaG0weyJ9rQPOLXiZNwlz6bb65pc
|
||||
maHFCN795trV1lpFDMS3wrUU77QR/w4VtfX128a961qn8FYiqTxlVMYVqL2Gns2D
|
||||
lmh6cYGJ4Qvh6hEbaAjMaZ7snkGeRDImeuKHCnE96+RapNLbxc3G3mB/ufNPRJLv
|
||||
KrcYPqcZ2Qt9sTdBQrC6YB3y/gkRsPCHe6ed
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Atos TrustedRoot Root CA ECC G2 2020
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICMTCCAbagAwIBAgIMC3MoERh0MBzvbwiEMAoGCCqGSM49BAMDMEsxCzAJBgNV
|
||||
BAYTAkRFMQ0wCwYDVQQKDARBdG9zMS0wKwYDVQQDDCRBdG9zIFRydXN0ZWRSb290
|
||||
IFJvb3QgQ0EgRUNDIEcyIDIwMjAwHhcNMjAxMjE1MDgzOTEwWhcNNDAxMjEwMDgz
|
||||
OTA5WjBLMQswCQYDVQQGEwJERTENMAsGA1UECgwEQXRvczEtMCsGA1UEAwwkQXRv
|
||||
cyBUcnVzdGVkUm9vdCBSb290IENBIEVDQyBHMiAyMDIwMHYwEAYHKoZIzj0CAQYF
|
||||
K4EEACIDYgAEyFyAyk7CKB9XvzjmYSP80KlblhYWwwxeFaWQCf84KLR6HgrWUyrB
|
||||
u5BAdDfpgeiNL2gBNXxSLtj0WLMRHFvZhxiTkS3sndpsnm2ESPzCiQXrmBMCAWxT
|
||||
Hg5JY1hHsa/Co2MwYTAPBgNVHRMBAf8EBTADAQH/MB8GA1UdIwQYMBaAFFsfxHFs
|
||||
shufvlwfjP2ztvuzDgmHMB0GA1UdDgQWBBRbH8RxbLIbn75cH4z9s7b7sw4JhzAO
|
||||
BgNVHQ8BAf8EBAMCAYYwCgYIKoZIzj0EAwMDaQAwZgIxAOzgmf3d5FTByx/oPijX
|
||||
FVlKgspTMOzrNqW5yM6TR1bIYabhbZJTlY/241VT8N165wIxALCH1RuzYPyRjYDK
|
||||
ohtRSzhUy6oee9flRJUWLzxEeC4luuqQ5OxS7lfsA4TzXtsWDQ==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Atos TrustedRoot Root CA ECC TLS 2021
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICFTCCAZugAwIBAgIQPZg7pmY9kGP3fiZXOATvADAKBggqhkjOPQQDAzBMMS4w
|
||||
LAYDVQQDDCVBdG9zIFRydXN0ZWRSb290IFJvb3QgQ0EgRUNDIFRMUyAyMDIxMQ0w
|
||||
CwYDVQQKDARBdG9zMQswCQYDVQQGEwJERTAeFw0yMTA0MjIwOTI2MjNaFw00MTA0
|
||||
MTcwOTI2MjJaMEwxLjAsBgNVBAMMJUF0b3MgVHJ1c3RlZFJvb3QgUm9vdCBDQSBF
|
||||
Q0MgVExTIDIwMjExDTALBgNVBAoMBEF0b3MxCzAJBgNVBAYTAkRFMHYwEAYHKoZI
|
||||
zj0CAQYFK4EEACIDYgAEloZYKDcKZ9Cg3iQZGeHkBQcfl+3oZIK59sRxUM6KDP/X
|
||||
tXa7oWyTbIOiaG6l2b4siJVBzV3dscqDY4PMwL502eCdpO5KTlbgmClBk1IQ1SQ4
|
||||
AjJn8ZQSb+/Xxd4u/RmAo0IwQDAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBR2
|
||||
KCXWfeBmmnoJsmo7jjPXNtNPojAOBgNVHQ8BAf8EBAMCAYYwCgYIKoZIzj0EAwMD
|
||||
aAAwZQIwW5kp85wxtolrbNa9d+F851F+uDrNozZffPc8dz7kUK2o59JZDCaOMDtu
|
||||
CCrCp1rIAjEAmeMM56PDr9NJLkaCI2ZdyQAUEv049OGYa3cpetskz2VAv9LcjBHo
|
||||
9H1/IISpQuQo
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Atos TrustedRoot Root CA RSA G2 2020
|
||||
-----BEGIN CERTIFICATE-----
|
||||
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
|
||||
ZfJ/8eOPTIBGNli2oWXLzhxEdQ==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Atos TrustedRoot Root CA RSA TLS 2021
|
||||
-----BEGIN CERTIFICATE-----
|
||||
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
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// GlobalSign
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFgzCCA2ugAwIBAgIORea7A4Mzw4VlSOb/RVEwDQYJKoZIhvcNAQEMBQAwTDEg
|
||||
@@ -3197,6 +3117,92 @@ rYy0UGYwEAYJKwYBBAGCNxUBBAMCAQAwCgYIKoZIzj0EAwMDaAAwZQIwJsdpW9zV
|
||||
Mgj/mkkCtojeFK9dbJlxjRo/i9fgojaGHAeCOnZT/cKi7e97sIBPWA9LUzm9
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// SECOM SMIME RSA Root CA 2024
|
||||
-----BEGIN CERTIFICATE-----
|
||||
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
|
||||
JKQ=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// SECOM TLS ECC Root CA 2024
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICTDCCAdGgAwIBAgIJAIF6LO+PI3pEMAoGCCqGSM49BAMDMFoxCzAJBgNVBAYT
|
||||
AkpQMSYwJAYDVQQKEx1TRUNPTSBUcnVzdCBTeXN0ZW1zIENvLiwgTHRkLjEjMCEG
|
||||
A1UEAxMaU0VDT00gVExTIEVDQyBSb290IENBIDIwMjQwHhcNMjQwMTMxMDU1MjM0
|
||||
WhcNNDkwMTE0MDU1MjM0WjBaMQswCQYDVQQGEwJKUDEmMCQGA1UEChMdU0VDT00g
|
||||
VHJ1c3QgU3lzdGVtcyBDby4sIEx0ZC4xIzAhBgNVBAMTGlNFQ09NIFRMUyBFQ0Mg
|
||||
Um9vdCBDQSAyMDI0MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE7NzFMtu9dzQXSNC1
|
||||
2fabk0+GlC5finB3R7XaZonRUd20aFiWObtuNBCLUZSfk6QXAE55BjEXsXQ/NG8y
|
||||
UqicXjsu9ksDK3JZBgCwLOVh6+nwJXTvso/dEj/GUYH5mBdoo2MwYTAdBgNVHQ4E
|
||||
FgQUO3YReyl04k4GTFaCQNAhL3qzydUwHwYDVR0jBBgwFoAUO3YReyl04k4GTFaC
|
||||
QNAhL3qzydUwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wCgYIKoZI
|
||||
zj0EAwMDaQAwZgIxAN3ib8fi1pMYtAPjMilB5e5/H+t5CL0xPL+cZ5oTTZuSCjpA
|
||||
n1v7F/VAr8bFxQXAowIxAKsBVO1ACFp7skwzPvdv1EUY5a897WGLT4lb+bjxFAWy
|
||||
l8wDcZJdwGZ/pAHxt1AJ1g==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// SECOM TLS RSA Root CA 2024
|
||||
-----BEGIN CERTIFICATE-----
|
||||
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
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Security Communication ECC RootCA1
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICODCCAb6gAwIBAgIJANZdm7N4gS7rMAoGCCqGSM49BAMDMGExCzAJBgNVBAYT
|
||||
@@ -3344,35 +3350,6 @@ QOhTsiedSrnAdyGN/4fy3ryM7xfft0kL0fJuMAsaDk527RH89elWsn2/x20Kk4yl
|
||||
NVOFBkpdn627G190
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Entrust Root Certification Authority
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEkTCCA3mgAwIBAgIERWtQVDANBgkqhkiG9w0BAQUFADCBsDELMAkGA1UEBhMC
|
||||
VVMxFjAUBgNVBAoTDUVudHJ1c3QsIEluYy4xOTA3BgNVBAsTMHd3dy5lbnRydXN0
|
||||
Lm5ldC9DUFMgaXMgaW5jb3Jwb3JhdGVkIGJ5IHJlZmVyZW5jZTEfMB0GA1UECxMW
|
||||
KGMpIDIwMDYgRW50cnVzdCwgSW5jLjEtMCsGA1UEAxMkRW50cnVzdCBSb290IENl
|
||||
cnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTA2MTEyNzIwMjM0MloXDTI2MTEyNzIw
|
||||
NTM0MlowgbAxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1FbnRydXN0LCBJbmMuMTkw
|
||||
NwYDVQQLEzB3d3cuZW50cnVzdC5uZXQvQ1BTIGlzIGluY29ycG9yYXRlZCBieSBy
|
||||
ZWZlcmVuY2UxHzAdBgNVBAsTFihjKSAyMDA2IEVudHJ1c3QsIEluYy4xLTArBgNV
|
||||
BAMTJEVudHJ1c3QgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTCCASIwDQYJ
|
||||
KoZIhvcNAQEBBQADggEPADCCAQoCggEBALaVtkNC+sZtKm9I35RMOVcF7sN5EUFo
|
||||
Nu3s/poBj6E4KPz3EEZmLk0eGrEaTsbRwJWIsMn/MYszA9u3g3s+IIRe7bJWKKf4
|
||||
4LlAcTfFy0cOlypowCKVYhXbR9n10Cv/gkvJrT7eTNuQgFA/CYqEAOwwCj0Yzfv9
|
||||
KlmaI5UXLEWeH25DeW0MXJj+SKfFI0dcXv1u5x609mhF0YaDW6KKjbHjKYD+JXGI
|
||||
rb68j6xSlkuqUY3kEzEZ6E5Nn9uss2rVvDlUccp6en+Q3X0dgNmBu1kmwhH+5pPi
|
||||
94DkZfs0Nw4pgHBNrziGLp5/V6+eF67rHMsoIV+2HNjnogQi+dPa2MsCAwEAAaOB
|
||||
sDCBrTAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zArBgNVHRAEJDAi
|
||||
gA8yMDA2MTEyNzIwMjM0MlqBDzIwMjYxMTI3MjA1MzQyWjAfBgNVHSMEGDAWgBRo
|
||||
kORnpKZTgMeGZqTx90tD+4S9bTAdBgNVHQ4EFgQUaJDkZ6SmU4DHhmak8fdLQ/uE
|
||||
vW0wHQYJKoZIhvZ9B0EABBAwDhsIVjcuMTo0LjADAgSQMA0GCSqGSIb3DQEBBQUA
|
||||
A4IBAQCT1DCw1wMgKtD5Y+iRDAUgqV8ZyntyTtSx29CW+1RaGSwMCPeyvIWonX9t
|
||||
O1KzKtvn1ISMY/YPyyYBkVBs9F8U4pN0wBOeMDpQ47RgxRzwIkSNcUesyBrJ6Zua
|
||||
AGAT/3B+XxFNSRuzFVJ7yVTav52Vr2ua2J7p8eRDjeIRRDq/r72DQnNSi6q7pynP
|
||||
9WQcCk3RvKqsnyrQ/39/2n3qse0wJcGE2jTSW3iDVuycNsMm4hH2Z0kdkquM++v/
|
||||
eu6FSqdQgPCnXEqULl8FmTxSQeDNtGPPAUO6nIPcj2A781q0tHuu2guQOHXvgR1m
|
||||
0vdXcDazv/wor3ElhVsT/h5/WrQ8
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Entrust Root Certification Authority - EC1
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIC+TCCAoCgAwIBAgINAKaLeSkAAAAAUNCR+TAKBggqhkjOPQQDAzCBvzELMAkG
|
||||
@@ -4075,6 +4052,38 @@ aspHYcN6+NOSBB+4IIThNlQWx0DeO4pz3N/GCUzf7Nr/1FNCocnyYh0igzyXxfkZ
|
||||
YiesZSLX0zzG5Y6yU8xJzrww/nsOM5D77dIUkR8Hrw==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Telia EC Email Root CA v3
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICNTCCAbugAwIBAgIPAYvS4Qwe2A2UA4cFEQCmMAoGCCqGSM49BAMDMEwxCzAJ
|
||||
BgNVBAYTAlNFMRkwFwYDVQQKDBBUZWxpYSBDb21wYW55IEFCMSIwIAYDVQQDDBlU
|
||||
ZWxpYSBFQyBFbWFpbCBSb290IENBIHYzMB4XDTIzMTExNTEyMTQxNFoXDTQ4MDUy
|
||||
MzExMDAwMFowTDELMAkGA1UEBhMCU0UxGTAXBgNVBAoMEFRlbGlhIENvbXBhbnkg
|
||||
QUIxIjAgBgNVBAMMGVRlbGlhIEVDIEVtYWlsIFJvb3QgQ0EgdjMwdjAQBgcqhkjO
|
||||
PQIBBgUrgQQAIgNiAASUAOZjnxYvpPi6RSXNRytXnFkuh8Je8yNFmcWUrltqwjYz
|
||||
3my30si8EILpRqcOq2QNTC6lBefNuzRiWKnHutxBYCpHGbavHvuRkbC1nOWaV3wY
|
||||
mB+Sa0iysgwJX53hgRijYzBhMB8GA1UdIwQYMBaAFC7R0R9PqSatpq0hmEX7ExxT
|
||||
Aq/mMB0GA1UdDgQWBBQu0dEfT6kmraatIZhF+xMcUwKv5jAOBgNVHQ8BAf8EBAMC
|
||||
AQYwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAwNoADBlAjEA66pq9QyvgQMO
|
||||
qpI/7ysbC7O01JjY95WkHaq8tr/mUpgLeFwPD6PGo2nCvVDWb3p/AjA8Hex69YmD
|
||||
PyHpsNV4+ttQ83QHzHmnJfL2jDiH2bZsQvRySUzWu11Mrh72+pFaKks=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Telia EC TLS Root CA v3
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICMjCCAbegAwIBAgIPAYvSIlRjTQSLbOVHH9K1MAoGCCqGSM49BAMDMEoxCzAJ
|
||||
BgNVBAYTAlNFMRkwFwYDVQQKDBBUZWxpYSBDb21wYW55IEFCMSAwHgYDVQQDDBdU
|
||||
ZWxpYSBFQyBUTFMgUm9vdCBDQSB2MzAeFw0yMzExMTUwODU1MjZaFw00ODA1MjMx
|
||||
MTAwMDBaMEoxCzAJBgNVBAYTAlNFMRkwFwYDVQQKDBBUZWxpYSBDb21wYW55IEFC
|
||||
MSAwHgYDVQQDDBdUZWxpYSBFQyBUTFMgUm9vdCBDQSB2MzB2MBAGByqGSM49AgEG
|
||||
BSuBBAAiA2IABMHIlhVDLbmFKUpW0iK4dpryT6emYOeS31JPwWnWPmkWRrAkTbPX
|
||||
40sQfHI9mpR7Rbktu3ngg6W+BBSXSechtMCnBmWXj/EaVlmV5cY1jD2HoTfhBQ3A
|
||||
acpCNMLJK4NpZaNjMGEwHwYDVR0jBBgwFoAU1GToQ4g6cy/QGnGCNgtehd7H3kMw
|
||||
HQYDVR0OBBYEFNRk6EOIOnMv0BpxgjYLXoXex95DMA4GA1UdDwEB/wQEAwIBBjAP
|
||||
BgNVHRMBAf8EBTADAQH/MAoGCCqGSM49BAMDA2kAMGYCMQCXAUdS/9bbJ8A1JYaG
|
||||
f/bWt/s7Ta0ot5Ulno8OjSNYRWQIlS4tVWldvTAVA7heOFgCMQCvKr8+Z2Rn+OBr
|
||||
5UHzlgBObpad1LuwNTRcdNgUJxIWadcki+UBLEi1/AURKV5md2M=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Telia Root CA v2
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFdDCCA1ygAwIBAgIPAWdfJ9b+euPkrL4JWwWeMA0GCSqGSIb3DQEBCwUAMEQx
|
||||
@@ -4109,6 +4118,74 @@ ysUsWNc8e89ihmpQfTU2Zqf7N+cox9jQraVplI/owd8k+BsHMYeB2F326CjYSlKA
|
||||
rBPuUBQemMc=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Telia RSA Email Root CA v3
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFhjCCA26gAwIBAgIPAYvSzvTBFXgpYk15snVbMA0GCSqGSIb3DQEBDAUAME0x
|
||||
CzAJBgNVBAYTAlNFMRkwFwYDVQQKDBBUZWxpYSBDb21wYW55IEFCMSMwIQYDVQQD
|
||||
DBpUZWxpYSBSU0EgRW1haWwgUm9vdCBDQSB2MzAeFw0yMzExMTUxMTU1MDJaFw00
|
||||
ODA1MjMxMTAwMDBaME0xCzAJBgNVBAYTAlNFMRkwFwYDVQQKDBBUZWxpYSBDb21w
|
||||
YW55IEFCMSMwIQYDVQQDDBpUZWxpYSBSU0EgRW1haWwgUm9vdCBDQSB2MzCCAiIw
|
||||
DQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBALlJOy9bUhjJz2SsqNv2ep4+rdeB
|
||||
o+y66oEu9b2vldFLXojulGIKy4YnCagn0cMyowrq7hdlDDwTFvrfBNNrz2CKNlv3
|
||||
J5Yx3Nv3x24VEbpjKbvQiXBs40iiNJnI+kqSj7B+ki7spnT50Sqcc8JyK1SPCXh7
|
||||
7yYMPvJ8OhFdIQfVz75eI4igKwXCjL8pv1hFPPFqyKv0/jn+sm4VWg+nSz5pxLs7
|
||||
0ZKg2F8ogcK9SpaloUZx+A2xEWNqpgFfxXN62ElKLsE0vj9l3sJqxo8g2L4mArrH
|
||||
ciIWmJmX5mRtSTiQytRxBrSEIrSeMzRWyh12qZpI3cz1jy6JScZ6BgOPr47sgHIV
|
||||
8dkJgFhSqcIcrT5fNzFmlxCh2HO03S7CM6V+p1ibgRFriNX8S7Utun78Ua3nPk2u
|
||||
885RnuVTi68eqELkZbny5ipD50889dvR3Lug3xfY4b5SWWc+IRQ6g1l+b4PZlWsx
|
||||
eWOOyV3UNI345NourtkI69uzHOndlRiuYps1gEXv0pSg1gvgoskgQDO1S3uYNmQ0
|
||||
l9SLA7d6iptnKpWTY7Py8h8ULBGo0WYM2kbmDN5VukcjxuoPskNdjv4PV9Sv58o4
|
||||
y9bbmbtKWLZoodSKJXKqmw1AOqahox63Wi2h56A5j8ZE1KB2X4g8/+UlUIzuPH4S
|
||||
Nj2yXiVHNmmZFCFfAgMBAAGjYzBhMB8GA1UdIwQYMBaAFIe5Bj9GxSkUzRRexZ4j
|
||||
kLYkrmaZMB0GA1UdDgQWBBSHuQY/RsUpFM0UXsWeI5C2JK5mmTAOBgNVHQ8BAf8E
|
||||
BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQwFAAOCAgEAjVNZ2f87
|
||||
Mo/XMT7tdp0Nho3iMFBwuJ3ZnxI5y52vta7Dh+FrxO2DELxFeraZ8LR5fG01o5OQ
|
||||
LDCGsf+F14xlV1iSB0jsR5i353bGd2D/R+x3QK0cLerfUsySfqXbK0f1G6dHQF1x
|
||||
c0jE0/2nsCNAsSO769qBQMUyB9kpyRMGthiWV1mLYAGv7wyYSkumFqKhI0OsVWlM
|
||||
MV/7Ybwrs8UCMbVUP3UZq108PmTF4+vwf7KKui8EMjvyA94qu8IJ4qMl800uhnhW
|
||||
2DxHLWSt+gF5sNiITuuywVrlS7o2xBlC65suDA2k+LvaJB4AnO5KI9GhtKLPXSeq
|
||||
QlODIoQUlyhcl3mmYLyHNpn4wxdo4rpl8w7KNtfTJDzBCYnu+xO5Q6gpFMW7QUe0
|
||||
9kq920ciz/ej2jBWxn2YZSVpUGBq9fq1v4x4G3etuV3O15dpbu4J5t+Wd7sGk6pT
|
||||
oZzZK7veO5kiBKm8FPY9A6LzNZQ8Th9ivvCy51i50xcpxasO1UtlRhlbJDpiSSQF
|
||||
isB49xSU0a8LHzdsNAXOZ/F2wPesZEjWV5oo8xdPmvcDtCARYp//GqppM2Eofj32
|
||||
xGgXzDM5w85S4fayu1VcZm2f4Tyupg4VTUbx1gQNhZazXygUT87Wm+H6DXNsb6f9
|
||||
uekqpLdATHAOOE8brMd1KHipdzaaaHSg17c=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// Telia RSA TLS Root CA v3
|
||||
-----BEGIN CERTIFICATE-----
|
||||
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
|
||||
50LqFQ+A1/Hq6xHHDNx7CI83d23Erw==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
// TrustAsia Global Root CA G3
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFpTCCA42gAwIBAgIUZPYOZXdhaqs7tOqFhLuxibhxkw8wDQYJKoZIhvcNAQEM
|
||||
|
||||
@@ -49,7 +49,10 @@ func newAppleAnchors(pemBytes []byte) (*appleAnchors, error) {
|
||||
}
|
||||
pointerSize := C.size_t(unsafe.Sizeof((*C.uint8_t)(nil)))
|
||||
lenSize := C.size_t(unsafe.Sizeof(C.size_t(0)))
|
||||
pointersC := (**C.uint8_t)(C.malloc(pointerSize * C.size_t(len(derBlocks))))
|
||||
pointersC := (**C.uint8_t)(C.calloc(C.size_t(len(derBlocks)), pointerSize))
|
||||
if pointersC == nil {
|
||||
return nil, E.New("allocate certificate pointers")
|
||||
}
|
||||
defer C.free(unsafe.Pointer(pointersC))
|
||||
lensC := (*C.size_t)(C.malloc(lenSize * C.size_t(len(derBlocks))))
|
||||
defer C.free(unsafe.Pointer(lensC))
|
||||
|
||||
+111
-68
@@ -6,6 +6,8 @@ import (
|
||||
"net"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
@@ -26,8 +28,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_ ParallelInterfaceDialer = (*DefaultDialer)(nil)
|
||||
_ UDPListener = (*DefaultDialer)(nil)
|
||||
_ ParallelNetworkDialer = (*DefaultDialer)(nil)
|
||||
_ UDPListener = (*DefaultDialer)(nil)
|
||||
)
|
||||
|
||||
type DefaultDialer struct {
|
||||
@@ -39,6 +41,8 @@ type DefaultDialer struct {
|
||||
udpAddr4 string
|
||||
udpAddr6 string
|
||||
netns string
|
||||
tcpFastOpen bool
|
||||
bindInterface string
|
||||
autoDetectBindFunc control.Func
|
||||
connectionManager adapter.ConnectionManager
|
||||
networkManager adapter.NetworkManager
|
||||
@@ -46,6 +50,7 @@ type DefaultDialer struct {
|
||||
outboundManager adapter.OutboundManager
|
||||
dnsTransportManager adapter.DNSTransportManager
|
||||
networkStrategy *C.NetworkStrategy
|
||||
canUseNetworkStrategy atomic.Bool
|
||||
defaultNetworkStrategy bool
|
||||
networkType []C.InterfaceType
|
||||
fallbackNetworkType []C.InterfaceType
|
||||
@@ -62,6 +67,7 @@ func NewDefault(ctx context.Context, options option.DialerOptions) (*DefaultDial
|
||||
dialer net.Dialer
|
||||
listener net.ListenConfig
|
||||
interfaceFinder control.InterfaceFinder
|
||||
bindInterface string
|
||||
networkStrategy *C.NetworkStrategy
|
||||
defaultNetworkStrategy bool
|
||||
networkType []C.InterfaceType
|
||||
@@ -78,20 +84,24 @@ func NewDefault(ctx context.Context, options option.DialerOptions) (*DefaultDial
|
||||
if !(C.IsLinux || C.IsDarwin || C.IsWindows) {
|
||||
return nil, E.New("`bind_interface` is only supported on Linux, macOS and Windows")
|
||||
}
|
||||
if platformInterface != nil && platformInterface.UsePlatformAutoDetectInterfaceControl() {
|
||||
interfaceName := options.BindInterface
|
||||
bindFunc := func(network, address string, conn syscall.RawConn) error {
|
||||
return control.Raw(conn, func(fd uintptr) error {
|
||||
return platformInterface.BindInterfaceControl(int(fd), interfaceName)
|
||||
var bindInterfaceControl control.Func
|
||||
switch {
|
||||
case options.NetNs != "":
|
||||
bindInterfaceControl = func(network, address string, connection syscall.RawConn) error {
|
||||
return control.BindToInterface0(nil, connection, network, address, options.BindInterface, -1, true)
|
||||
}
|
||||
case platformInterface != nil && platformInterface.UsePlatformAutoDetectInterfaceControl():
|
||||
bindInterfaceControl = func(network, address string, connection syscall.RawConn) error {
|
||||
return control.Raw(connection, func(descriptor uintptr) error {
|
||||
return platformInterface.BindInterfaceControl(int(descriptor), options.BindInterface)
|
||||
})
|
||||
}
|
||||
dialer.Control = control.Append(dialer.Control, bindFunc)
|
||||
listener.Control = control.Append(listener.Control, bindFunc)
|
||||
} else {
|
||||
bindFunc := control.BindToInterface(interfaceFinder, options.BindInterface, -1)
|
||||
dialer.Control = control.Append(dialer.Control, bindFunc)
|
||||
listener.Control = control.Append(listener.Control, bindFunc)
|
||||
default:
|
||||
bindInterfaceControl = control.BindToInterface(interfaceFinder, options.BindInterface, -1)
|
||||
}
|
||||
dialer.Control = control.Append(dialer.Control, bindInterfaceControl)
|
||||
listener.Control = control.Append(listener.Control, bindInterfaceControl)
|
||||
bindInterface = options.BindInterface
|
||||
}
|
||||
if options.RoutingMark > 0 {
|
||||
if !C.IsLinux {
|
||||
@@ -109,11 +119,12 @@ func NewDefault(ctx context.Context, options option.DialerOptions) (*DefaultDial
|
||||
|
||||
if networkManager != nil {
|
||||
defaultOptions := networkManager.DefaultOptions()
|
||||
if defaultOptions.BindInterface != "" && !disableDefaultBind {
|
||||
if defaultOptions.BindInterface != "" && !disableDefaultBind && options.NetNs == "" {
|
||||
bindFunc := control.BindToInterface(networkManager.InterfaceFinder(), defaultOptions.BindInterface, -1)
|
||||
dialer.Control = control.Append(dialer.Control, bindFunc)
|
||||
listener.Control = control.Append(listener.Control, bindFunc)
|
||||
} else if networkManager.AutoDetectInterface() && !disableDefaultBind {
|
||||
bindInterface = defaultOptions.BindInterface
|
||||
} else if networkManager.AutoDetectInterface() && !disableDefaultBind && options.NetNs == "" {
|
||||
if platformInterface != nil && platformInterface.UsePlatformNetworkInterfaces() {
|
||||
networkStrategy = (*C.NetworkStrategy)(options.NetworkStrategy)
|
||||
networkType = common.Map(options.NetworkType, option.InterfaceType.Build)
|
||||
@@ -239,7 +250,7 @@ func NewDefault(ctx context.Context, options option.DialerOptions) (*DefaultDial
|
||||
}
|
||||
tcpDialer4 := tfo.Dialer{Dialer: dialer4, DisableTFO: !options.TCPFastOpen}
|
||||
tcpDialer6 := tfo.Dialer{Dialer: dialer6, DisableTFO: !options.TCPFastOpen}
|
||||
return &DefaultDialer{
|
||||
defaultDialer := &DefaultDialer{
|
||||
dialer4: tcpDialer4,
|
||||
dialer6: tcpDialer6,
|
||||
udpDialer4: udpDialer4,
|
||||
@@ -248,6 +259,8 @@ func NewDefault(ctx context.Context, options option.DialerOptions) (*DefaultDial
|
||||
udpAddr4: udpAddr4,
|
||||
udpAddr6: udpAddr6,
|
||||
netns: options.NetNs,
|
||||
tcpFastOpen: options.TCPFastOpen,
|
||||
bindInterface: bindInterface,
|
||||
autoDetectBindFunc: autoDetectBindFunc,
|
||||
connectionManager: connectionManager,
|
||||
networkManager: networkManager,
|
||||
@@ -259,7 +272,9 @@ func NewDefault(ctx context.Context, options option.DialerOptions) (*DefaultDial
|
||||
networkType: networkType,
|
||||
fallbackNetworkType: fallbackNetworkType,
|
||||
networkFallbackDelay: networkFallbackDelay,
|
||||
}, nil
|
||||
}
|
||||
defaultDialer.canUseNetworkStrategy.Store(true)
|
||||
return defaultDialer, nil
|
||||
}
|
||||
|
||||
func setMarkWrapper(networkManager adapter.NetworkManager, mark uint32, isDefault bool) control.Func {
|
||||
@@ -284,7 +299,20 @@ func (d *DefaultDialer) DialContext(ctx context.Context, network string, address
|
||||
} else if address.IsDomain() {
|
||||
return nil, E.New("domain not resolved")
|
||||
}
|
||||
if d.networkStrategy == nil {
|
||||
if d.networkStrategy == nil || !d.canUseNetworkStrategy.Load() {
|
||||
if d.netns == "" && address.Addr.Zone() == "" && isLinkScoped(address.Addr) {
|
||||
if d.bindInterface != "" {
|
||||
address.Addr = address.Addr.WithZone(d.bindInterface)
|
||||
} else if d.autoDetectBindFunc != nil || d.defaultNetworkStrategy {
|
||||
iif, err := d.networkManager.InterfaceFinder().ByAddr(address.Addr)
|
||||
if err != nil {
|
||||
iif = d.networkManager.InterfaceMonitor().DefaultInterface()
|
||||
}
|
||||
if iif != nil {
|
||||
address.Addr = address.Addr.WithZone(strconv.Itoa(iif.Index))
|
||||
}
|
||||
}
|
||||
}
|
||||
conn, err := listener.ListenNetworkNamespace[net.Conn](ctx, d.netns, func() (net.Conn, error) {
|
||||
switch N.NetworkName(network) {
|
||||
case N.NetworkUDP:
|
||||
@@ -295,23 +323,38 @@ func (d *DefaultDialer) DialContext(ctx context.Context, network string, address
|
||||
}
|
||||
}
|
||||
if !address.IsIPv6() {
|
||||
return DialSlowContext(&d.dialer4, ctx, network, address)
|
||||
return DialSlowContext(&d.dialer4, ctx, d.netns, network, address)
|
||||
} else {
|
||||
return DialSlowContext(&d.dialer6, ctx, network, address)
|
||||
return DialSlowContext(&d.dialer6, ctx, d.netns, network, address)
|
||||
}
|
||||
})
|
||||
return d.trackConn(ctx, address, conn, err)
|
||||
} else {
|
||||
return d.DialParallelInterface(ctx, network, address, d.networkStrategy, d.networkType, d.fallbackNetworkType, d.networkFallbackDelay)
|
||||
return d.DialParallelNetwork(ctx, network, address, nil, nil, nil, nil, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *DefaultDialer) DialParallelInterface(ctx context.Context, network string, address M.Socksaddr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.Conn, error) {
|
||||
if strategy == nil {
|
||||
func isLinkScoped(addr netip.Addr) bool {
|
||||
return addr.Is6() && (addr.IsLinkLocalUnicast() || addr.IsLinkLocalMulticast() || addr.IsInterfaceLocalMulticast())
|
||||
}
|
||||
|
||||
func (d *DefaultDialer) DialParallelNetwork(ctx context.Context, network string, destination M.Socksaddr, destinationAddresses []netip.Addr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.Conn, error) {
|
||||
if len(destinationAddresses) == 0 {
|
||||
destinationAddresses = []netip.Addr{destination.Addr}
|
||||
}
|
||||
if d.networkStrategy == nil || !d.canUseNetworkStrategy.Load() {
|
||||
strategy = nil
|
||||
} else if strategy == nil {
|
||||
strategy = d.networkStrategy
|
||||
}
|
||||
if fallbackDelay == 0 {
|
||||
fallbackDelay = d.networkFallbackDelay
|
||||
}
|
||||
if strategy == nil {
|
||||
return d.DialContext(ctx, network, address)
|
||||
if d.tcpFastOpen {
|
||||
return N.DialSerial(ctx, d, network, destination, destinationAddresses)
|
||||
}
|
||||
return N.DialParallel(ctx, d, network, destination, destinationAddresses, destinationAddresses[0].Is6(), fallbackDelay)
|
||||
}
|
||||
if len(interfaceType) == 0 {
|
||||
interfaceType = d.networkType
|
||||
@@ -319,9 +362,6 @@ func (d *DefaultDialer) DialParallelInterface(ctx context.Context, network strin
|
||||
if len(fallbackInterfaceType) == 0 {
|
||||
fallbackInterfaceType = d.fallbackNetworkType
|
||||
}
|
||||
if fallbackDelay == 0 {
|
||||
fallbackDelay = d.networkFallbackDelay
|
||||
}
|
||||
var dialer net.Dialer
|
||||
if N.NetworkName(network) == N.NetworkTCP {
|
||||
dialer = d.dialer4.Dialer
|
||||
@@ -335,15 +375,15 @@ func (d *DefaultDialer) DialParallelInterface(ctx context.Context, network strin
|
||||
err error
|
||||
)
|
||||
if !fastFallback {
|
||||
conn, isPrimary, err = d.dialParallelInterface(ctx, dialer, network, address.String(), *strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
conn, isPrimary, err = d.dialParallelInterface(ctx, dialer, network, destination, destinationAddresses, *strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
} else {
|
||||
conn, isPrimary, err = d.dialParallelInterfaceFastFallback(ctx, dialer, network, address.String(), *strategy, interfaceType, fallbackInterfaceType, fallbackDelay, d.networkLastFallback.Store)
|
||||
conn, isPrimary, err = d.dialParallelInterfaceFastFallback(ctx, dialer, network, destination, destinationAddresses, *strategy, interfaceType, fallbackInterfaceType, fallbackDelay, d.networkLastFallback.Store)
|
||||
}
|
||||
if err != nil {
|
||||
// bind interface failed on legacy xiaomi systems
|
||||
if d.defaultNetworkStrategy && errors.Is(err, syscall.EPERM) {
|
||||
d.networkStrategy = nil
|
||||
return d.DialContext(ctx, network, address)
|
||||
d.canUseNetworkStrategy.Store(false)
|
||||
return d.DialParallelNetwork(ctx, network, destination, destinationAddresses, nil, nil, nil, fallbackDelay)
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
@@ -351,11 +391,11 @@ func (d *DefaultDialer) DialParallelInterface(ctx context.Context, network strin
|
||||
if !fastFallback && !isPrimary {
|
||||
d.networkLastFallback.Store(time.Now())
|
||||
}
|
||||
return d.trackConn(ctx, address, conn, nil)
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func (d *DefaultDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
|
||||
if d.networkStrategy == nil {
|
||||
if d.networkStrategy == nil || !d.canUseNetworkStrategy.Load() {
|
||||
packetConn, err := listener.ListenNetworkNamespace[net.PacketConn](ctx, d.netns, func() (net.PacketConn, error) {
|
||||
listenConfig := d.udpListener
|
||||
if d.autoDetectBindFunc != nil {
|
||||
@@ -376,20 +416,44 @@ func (d *DefaultDialer) ListenPacket(ctx context.Context, destination M.Socksadd
|
||||
})
|
||||
return d.trackPacketConn(ctx, destination, packetConn, err)
|
||||
} else {
|
||||
return d.ListenSerialInterfacePacket(ctx, destination, d.networkStrategy, d.networkType, d.fallbackNetworkType, d.networkFallbackDelay)
|
||||
return d.listenSerialInterfacePacket(ctx, destination, nil, nil, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *DefaultDialer) DialerForICMPDestination(destination netip.Addr) net.Dialer {
|
||||
if !destination.Is6() {
|
||||
return d.dialer4.Dialer
|
||||
} else {
|
||||
return d.dialer6.Dialer
|
||||
func (d *DefaultDialer) ICMPControl() control.Func {
|
||||
if d.networkStrategy == nil || d.defaultNetworkStrategy && len(d.networkType) == 0 {
|
||||
return d.dialer4.Control
|
||||
}
|
||||
interfaceControl := d.serialInterfaceControl(*d.networkStrategy, d.networkType, d.fallbackNetworkType)
|
||||
return control.Append(d.dialer4.Control, func(network, address string, conn syscall.RawConn) error {
|
||||
err := interfaceControl(network, address, conn)
|
||||
// bind interface failed on legacy xiaomi systems
|
||||
if d.defaultNetworkStrategy && errors.Is(err, syscall.EPERM) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (d *DefaultDialer) ListenSerialInterfacePacket(ctx context.Context, destination M.Socksaddr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.PacketConn, error) {
|
||||
if strategy == nil {
|
||||
func (d *DefaultDialer) ListenSerialNetworkPacket(ctx context.Context, destination M.Socksaddr, destinationAddresses []netip.Addr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.PacketConn, netip.Addr, error) {
|
||||
if len(destinationAddresses) == 0 {
|
||||
destinationAddresses = []netip.Addr{destination.Addr}
|
||||
}
|
||||
var errors []error
|
||||
for _, address := range destinationAddresses {
|
||||
packetConn, err := d.listenSerialInterfacePacket(ctx, M.SocksaddrFrom(address, destination.Port), strategy, interfaceType, fallbackInterfaceType)
|
||||
if err == nil {
|
||||
return packetConn, address, nil
|
||||
}
|
||||
errors = append(errors, err)
|
||||
}
|
||||
return nil, netip.Addr{}, E.Errors(errors...)
|
||||
}
|
||||
|
||||
func (d *DefaultDialer) listenSerialInterfacePacket(ctx context.Context, destination M.Socksaddr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType) (net.PacketConn, error) {
|
||||
if d.networkStrategy == nil || !d.canUseNetworkStrategy.Load() {
|
||||
strategy = nil
|
||||
} else if strategy == nil {
|
||||
strategy = d.networkStrategy
|
||||
}
|
||||
if strategy == nil {
|
||||
@@ -401,18 +465,17 @@ func (d *DefaultDialer) ListenSerialInterfacePacket(ctx context.Context, destina
|
||||
if len(fallbackInterfaceType) == 0 {
|
||||
fallbackInterfaceType = d.fallbackNetworkType
|
||||
}
|
||||
if fallbackDelay == 0 {
|
||||
fallbackDelay = d.networkFallbackDelay
|
||||
}
|
||||
network := N.NetworkUDP
|
||||
if destination.IsIPv4() && !destination.Addr.IsUnspecified() {
|
||||
network += "4"
|
||||
}
|
||||
packetConn, err := d.listenSerialInterfacePacket(ctx, d.udpListener, network, "", *strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
listenConfig := d.udpListener
|
||||
listenConfig.Control = control.Append(listenConfig.Control, d.serialInterfaceControl(*strategy, interfaceType, fallbackInterfaceType))
|
||||
packetConn, err := listenConfig.ListenPacket(ctx, network, "")
|
||||
if err != nil {
|
||||
// bind interface failed on legacy xiaomi systems
|
||||
if d.defaultNetworkStrategy && errors.Is(err, syscall.EPERM) {
|
||||
d.networkStrategy = nil
|
||||
d.canUseNetworkStrategy.Store(false)
|
||||
return d.ListenPacket(ctx, destination)
|
||||
} else {
|
||||
return nil, err
|
||||
@@ -536,6 +599,8 @@ func (d *DefaultDialer) dialAttribution(ctx context.Context, destination M.Socks
|
||||
}
|
||||
attribution.Rule = metadata.RouteRule
|
||||
attribution.Outbound = metadata.Outbound
|
||||
attribution.Chain = common.Map(metadata.OutboundChain, adapter.Outbound.Tag)
|
||||
slices.Reverse(attribution.Chain)
|
||||
if d.outboundManager != nil {
|
||||
if metadata.Outbound != "" {
|
||||
outbound, loaded := d.outboundManager.Outbound(metadata.Outbound)
|
||||
@@ -543,9 +608,6 @@ func (d *DefaultDialer) dialAttribution(ctx context.Context, destination M.Socks
|
||||
attribution.OutboundType = outbound.Type()
|
||||
}
|
||||
}
|
||||
if metadata.RouteOutbound != "" {
|
||||
attribution.Chain = d.outboundChain(metadata.RouteOutbound)
|
||||
}
|
||||
}
|
||||
if metadata.Destination.IsValid() {
|
||||
attribution.Destination = metadata.Destination.String()
|
||||
@@ -557,22 +619,3 @@ func (d *DefaultDialer) dialAttribution(ctx context.Context, destination M.Socks
|
||||
}
|
||||
return attribution
|
||||
}
|
||||
|
||||
func (d *DefaultDialer) outboundChain(head string) []string {
|
||||
var chain []string
|
||||
next := head
|
||||
for {
|
||||
detour, loaded := d.outboundManager.Outbound(next)
|
||||
if !loaded {
|
||||
break
|
||||
}
|
||||
chain = append(chain, next)
|
||||
outboundGroup, isGroup := detour.(adapter.OutboundGroup)
|
||||
if !isGroup {
|
||||
break
|
||||
}
|
||||
next = outboundGroup.Now()
|
||||
}
|
||||
slices.Reverse(chain)
|
||||
return chain
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@ package dialer
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
@@ -10,10 +14,11 @@ import (
|
||||
"github.com/sagernet/sing/common"
|
||||
"github.com/sagernet/sing/common/control"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
)
|
||||
|
||||
func (d *DefaultDialer) dialParallelInterface(ctx context.Context, dialer net.Dialer, network string, addr string, strategy C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.Conn, bool, error) {
|
||||
func (d *DefaultDialer) dialParallelInterface(ctx context.Context, dialer net.Dialer, network string, destination M.Socksaddr, destinationAddresses []netip.Addr, strategy C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.Conn, bool, error) {
|
||||
primaryInterfaces, fallbackInterfaces := selectInterfaces(d.networkManager, strategy, interfaceType, fallbackInterfaceType)
|
||||
if len(primaryInterfaces)+len(fallbackInterfaces) == 0 {
|
||||
return nil, false, E.New("no available network interface")
|
||||
@@ -30,13 +35,9 @@ func (d *DefaultDialer) dialParallelInterface(ctx context.Context, dialer net.Di
|
||||
} else {
|
||||
iif = fallbackInterfaces[0]
|
||||
}
|
||||
perNetDialer := dialer
|
||||
if defaultInterface == nil || iif.Index != defaultInterface.Index {
|
||||
perNetDialer.Control = control.Append(perNetDialer.Control, control.BindToInterface(nil, iif.Name, iif.Index))
|
||||
}
|
||||
conn, err := perNetDialer.DialContext(ctx, network, addr)
|
||||
conn, err := d.dialInterface(ctx, dialer, network, destination, destinationAddresses, iif, defaultInterface, fallbackDelay)
|
||||
if err != nil {
|
||||
return nil, false, E.Cause(err, "dial ", iif.Name, " (", iif.Index, ")")
|
||||
return nil, false, err
|
||||
}
|
||||
return conn, primary, nil
|
||||
}
|
||||
@@ -52,14 +53,10 @@ func (d *DefaultDialer) dialParallelInterface(ctx context.Context, dialer net.Di
|
||||
}
|
||||
results := make(chan dialResult) // unbuffered
|
||||
startRacer := func(ctx context.Context, primary bool, iif adapter.NetworkInterface) {
|
||||
perNetDialer := dialer
|
||||
if defaultInterface == nil || iif.Index != defaultInterface.Index {
|
||||
perNetDialer.Control = control.Append(perNetDialer.Control, control.BindToInterface(nil, iif.Name, iif.Index))
|
||||
}
|
||||
conn, err := perNetDialer.DialContext(ctx, network, addr)
|
||||
conn, err := d.dialInterface(ctx, dialer, network, destination, destinationAddresses, iif, defaultInterface, fallbackDelay)
|
||||
if err != nil {
|
||||
select {
|
||||
case results <- dialResult{error: E.Cause(err, "dial ", iif.Name, " (", iif.Index, ")"), primary: primary}:
|
||||
case results <- dialResult{error: err, primary: primary}:
|
||||
case <-returned:
|
||||
}
|
||||
} else {
|
||||
@@ -108,7 +105,7 @@ func (d *DefaultDialer) dialParallelInterface(ctx context.Context, dialer net.Di
|
||||
}
|
||||
}
|
||||
|
||||
func (d *DefaultDialer) dialParallelInterfaceFastFallback(ctx context.Context, dialer net.Dialer, network string, addr string, strategy C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration, resetFastFallback func(time.Time)) (net.Conn, bool, error) {
|
||||
func (d *DefaultDialer) dialParallelInterfaceFastFallback(ctx context.Context, dialer net.Dialer, network string, destination M.Socksaddr, destinationAddresses []netip.Addr, strategy C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration, resetFastFallback func(time.Time)) (net.Conn, bool, error) {
|
||||
primaryInterfaces, fallbackInterfaces := selectInterfaces(d.networkManager, strategy, interfaceType, fallbackInterfaceType)
|
||||
if len(primaryInterfaces)+len(fallbackInterfaces) == 0 {
|
||||
return nil, false, E.New("no available network interface")
|
||||
@@ -125,13 +122,9 @@ func (d *DefaultDialer) dialParallelInterfaceFastFallback(ctx context.Context, d
|
||||
} else {
|
||||
iif = fallbackInterfaces[0]
|
||||
}
|
||||
perNetDialer := dialer
|
||||
if defaultInterface == nil || iif.Index != defaultInterface.Index {
|
||||
perNetDialer.Control = control.Append(perNetDialer.Control, control.BindToInterface(nil, iif.Name, iif.Index))
|
||||
}
|
||||
conn, err := perNetDialer.DialContext(ctx, network, addr)
|
||||
conn, err := d.dialInterface(ctx, dialer, network, destination, destinationAddresses, iif, defaultInterface, fallbackDelay)
|
||||
if err != nil {
|
||||
return nil, false, E.Cause(err, "dial ", iif.Name, " (", iif.Index, ")")
|
||||
return nil, false, err
|
||||
}
|
||||
return conn, primary, nil
|
||||
}
|
||||
@@ -148,21 +141,17 @@ func (d *DefaultDialer) dialParallelInterfaceFastFallback(ctx context.Context, d
|
||||
startAt := time.Now()
|
||||
results := make(chan dialResult) // unbuffered
|
||||
startRacer := func(ctx context.Context, primary bool, iif adapter.NetworkInterface) {
|
||||
perNetDialer := dialer
|
||||
if defaultInterface == nil || iif.Index != defaultInterface.Index {
|
||||
perNetDialer.Control = control.Append(perNetDialer.Control, control.BindToInterface(nil, iif.Name, iif.Index))
|
||||
}
|
||||
conn, err := perNetDialer.DialContext(ctx, network, addr)
|
||||
conn, err := d.dialInterface(ctx, dialer, network, destination, destinationAddresses, iif, defaultInterface, fallbackDelay)
|
||||
if err != nil {
|
||||
select {
|
||||
case results <- dialResult{error: E.Cause(err, "dial ", iif.Name, " (", iif.Index, ")"), primary: primary}:
|
||||
case results <- dialResult{error: err, primary: primary}:
|
||||
case <-returned:
|
||||
}
|
||||
} else {
|
||||
select {
|
||||
case results <- dialResult{Conn: conn, primary: primary}:
|
||||
case <-returned:
|
||||
if primary && time.Since(startAt) <= fallbackDelay {
|
||||
if primary && N.NetworkName(network) == N.NetworkTCP && time.Since(startAt) <= fallbackDelay {
|
||||
resetFastFallback(time.Time{})
|
||||
}
|
||||
conn.Close()
|
||||
@@ -190,36 +179,70 @@ func (d *DefaultDialer) dialParallelInterfaceFastFallback(ctx context.Context, d
|
||||
return nil, false, E.Errors(errors...)
|
||||
}
|
||||
|
||||
func (d *DefaultDialer) listenSerialInterfacePacket(ctx context.Context, listener net.ListenConfig, network string, addr string, strategy C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.PacketConn, error) {
|
||||
primaryInterfaces, fallbackInterfaces := selectInterfaces(d.networkManager, strategy, interfaceType, fallbackInterfaceType)
|
||||
if len(primaryInterfaces)+len(fallbackInterfaces) == 0 {
|
||||
return nil, E.New("no available network interface")
|
||||
func (d *DefaultDialer) dialInterface(ctx context.Context, dialer net.Dialer, network string, destination M.Socksaddr, destinationAddresses []netip.Addr, iif adapter.NetworkInterface, defaultInterface *control.Interface, fallbackDelay time.Duration) (net.Conn, error) {
|
||||
if defaultInterface == nil || iif.Index != defaultInterface.Index {
|
||||
dialer.Control = control.Append(dialer.Control, control.BindToInterface(nil, iif.Name, iif.Index))
|
||||
}
|
||||
defaultInterface := d.networkManager.InterfaceMonitor().DefaultInterface()
|
||||
var errors []error
|
||||
for _, primaryInterface := range primaryInterfaces {
|
||||
perNetListener := listener
|
||||
if defaultInterface == nil || primaryInterface.Index != defaultInterface.Index {
|
||||
perNetListener.Control = control.Append(perNetListener.Control, control.BindToInterface(nil, primaryInterface.Name, primaryInterface.Index))
|
||||
}
|
||||
conn, err := perNetListener.ListenPacket(ctx, network, addr)
|
||||
if err == nil {
|
||||
return conn, nil
|
||||
}
|
||||
errors = append(errors, E.Cause(err, "listen ", primaryInterface.Name, " (", primaryInterface.Index, ")"))
|
||||
boundDialer := &interfaceDialer{
|
||||
parent: d,
|
||||
dialer: dialer,
|
||||
interfaceIndex: iif.Index,
|
||||
}
|
||||
for _, fallbackInterface := range fallbackInterfaces {
|
||||
perNetListener := listener
|
||||
if defaultInterface == nil || fallbackInterface.Index != defaultInterface.Index {
|
||||
perNetListener.Control = control.Append(perNetListener.Control, control.BindToInterface(nil, fallbackInterface.Name, fallbackInterface.Index))
|
||||
}
|
||||
conn, err := perNetListener.ListenPacket(ctx, network, addr)
|
||||
if err == nil {
|
||||
return conn, nil
|
||||
}
|
||||
errors = append(errors, E.Cause(err, "listen ", fallbackInterface.Name, " (", fallbackInterface.Index, ")"))
|
||||
var (
|
||||
conn net.Conn
|
||||
err error
|
||||
)
|
||||
if d.tcpFastOpen {
|
||||
conn, err = N.DialSerial(ctx, boundDialer, network, destination, destinationAddresses)
|
||||
} else {
|
||||
conn, err = N.DialParallel(ctx, boundDialer, network, destination, destinationAddresses, destinationAddresses[0].Is6(), fallbackDelay)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "dial ", iif.Name, " (", iif.Index, ")")
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
type interfaceDialer struct {
|
||||
parent *DefaultDialer
|
||||
dialer net.Dialer
|
||||
interfaceIndex int
|
||||
}
|
||||
|
||||
func (d *interfaceDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
|
||||
if destination.Addr.Zone() == "" && isLinkScoped(destination.Addr) {
|
||||
destination.Addr = destination.Addr.WithZone(strconv.Itoa(d.interfaceIndex))
|
||||
}
|
||||
conn, err := d.dialer.DialContext(ctx, network, destination.String())
|
||||
return d.parent.trackConn(ctx, destination, conn, err)
|
||||
}
|
||||
|
||||
func (d *interfaceDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
|
||||
return nil, os.ErrInvalid
|
||||
}
|
||||
|
||||
func (d *DefaultDialer) serialInterfaceControl(strategy C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType) control.Func {
|
||||
return func(network, address string, conn syscall.RawConn) error {
|
||||
primaryInterfaces, fallbackInterfaces := selectInterfaces(d.networkManager, strategy, interfaceType, fallbackInterfaceType)
|
||||
if len(primaryInterfaces)+len(fallbackInterfaces) == 0 {
|
||||
return E.New("no available network interface")
|
||||
}
|
||||
defaultInterface := d.networkManager.InterfaceMonitor().DefaultInterface()
|
||||
var errors []error
|
||||
for _, networkInterfaces := range [][]adapter.NetworkInterface{primaryInterfaces, fallbackInterfaces} {
|
||||
for _, networkInterface := range networkInterfaces {
|
||||
if defaultInterface != nil && networkInterface.Index == defaultInterface.Index {
|
||||
return nil
|
||||
}
|
||||
err := control.BindToInterface0(nil, conn, network, address, networkInterface.Name, networkInterface.Index, false)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
errors = append(errors, E.Cause(err, "bind ", networkInterface.Name, " (", networkInterface.Index, ")"))
|
||||
}
|
||||
}
|
||||
return E.Errors(errors...)
|
||||
}
|
||||
return nil, E.Errors(errors...)
|
||||
}
|
||||
|
||||
func selectInterfaces(networkManager adapter.NetworkManager, strategy C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType) (primaryInterfaces []adapter.NetworkInterface, fallbackInterfaces []adapter.NetworkInterface) {
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
package dialer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing/common"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
)
|
||||
|
||||
func DialSerialNetwork(ctx context.Context, dialer N.Dialer, network string, destination M.Socksaddr, destinationAddresses []netip.Addr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.Conn, error) {
|
||||
if len(destinationAddresses) == 0 {
|
||||
if !destination.IsIP() {
|
||||
panic("invalid usage")
|
||||
}
|
||||
destinationAddresses = []netip.Addr{destination.Addr}
|
||||
}
|
||||
if parallelDialer, isParallel := dialer.(ParallelNetworkDialer); isParallel {
|
||||
return parallelDialer.DialParallelNetwork(ctx, network, destination, destinationAddresses, strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
}
|
||||
var errors []error
|
||||
if parallelDialer, isParallel := dialer.(ParallelInterfaceDialer); isParallel {
|
||||
for _, address := range destinationAddresses {
|
||||
conn, err := parallelDialer.DialParallelInterface(ctx, network, M.SocksaddrFrom(address, destination.Port), strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
if err == nil {
|
||||
return conn, nil
|
||||
}
|
||||
errors = append(errors, err)
|
||||
}
|
||||
} else {
|
||||
for _, address := range destinationAddresses {
|
||||
conn, err := dialer.DialContext(ctx, network, M.SocksaddrFrom(address, destination.Port))
|
||||
if err == nil {
|
||||
return conn, nil
|
||||
}
|
||||
errors = append(errors, err)
|
||||
}
|
||||
}
|
||||
return nil, E.Errors(errors...)
|
||||
}
|
||||
|
||||
func DialParallelNetwork(ctx context.Context, dialer ParallelInterfaceDialer, network string, destination M.Socksaddr, destinationAddresses []netip.Addr, preferIPv6 bool, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.Conn, error) {
|
||||
if len(destinationAddresses) == 0 {
|
||||
if !destination.IsIP() {
|
||||
panic("invalid usage")
|
||||
}
|
||||
destinationAddresses = []netip.Addr{destination.Addr}
|
||||
}
|
||||
|
||||
if fallbackDelay == 0 {
|
||||
fallbackDelay = N.DefaultFallbackDelay
|
||||
}
|
||||
|
||||
returned := make(chan struct{})
|
||||
defer close(returned)
|
||||
|
||||
addresses4 := common.Filter(destinationAddresses, func(address netip.Addr) bool {
|
||||
return address.Is4() || address.Is4In6()
|
||||
})
|
||||
addresses6 := common.Filter(destinationAddresses, func(address netip.Addr) bool {
|
||||
return address.Is6() && !address.Is4In6()
|
||||
})
|
||||
if len(addresses4) == 0 || len(addresses6) == 0 {
|
||||
return DialSerialNetwork(ctx, dialer, network, destination, destinationAddresses, strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
}
|
||||
var primaries, fallbacks []netip.Addr
|
||||
if preferIPv6 {
|
||||
primaries = addresses6
|
||||
fallbacks = addresses4
|
||||
} else {
|
||||
primaries = addresses4
|
||||
fallbacks = addresses6
|
||||
}
|
||||
type dialResult struct {
|
||||
net.Conn
|
||||
error
|
||||
primary bool
|
||||
done bool
|
||||
}
|
||||
results := make(chan dialResult) // unbuffered
|
||||
startRacer := func(ctx context.Context, primary bool) {
|
||||
ras := primaries
|
||||
if !primary {
|
||||
ras = fallbacks
|
||||
}
|
||||
c, err := DialSerialNetwork(ctx, dialer, network, destination, ras, strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
select {
|
||||
case results <- dialResult{Conn: c, error: err, primary: primary, done: true}:
|
||||
case <-returned:
|
||||
if c != nil {
|
||||
c.Close()
|
||||
}
|
||||
}
|
||||
}
|
||||
var primary, fallback dialResult
|
||||
primaryCtx, primaryCancel := context.WithCancel(ctx)
|
||||
defer primaryCancel()
|
||||
go startRacer(primaryCtx, true)
|
||||
fallbackTimer := time.NewTimer(fallbackDelay)
|
||||
defer fallbackTimer.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-fallbackTimer.C:
|
||||
fallbackCtx, fallbackCancel := context.WithCancel(ctx)
|
||||
defer fallbackCancel()
|
||||
go startRacer(fallbackCtx, false)
|
||||
|
||||
case res := <-results:
|
||||
if res.error == nil {
|
||||
return res.Conn, nil
|
||||
}
|
||||
if res.primary {
|
||||
primary = res
|
||||
} else {
|
||||
fallback = res
|
||||
}
|
||||
if primary.done && fallback.done {
|
||||
return nil, primary.error
|
||||
}
|
||||
if res.primary && fallbackTimer.Stop() {
|
||||
fallbackTimer.Reset(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ListenSerialNetworkPacket(ctx context.Context, dialer N.Dialer, destination M.Socksaddr, destinationAddresses []netip.Addr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.PacketConn, netip.Addr, error) {
|
||||
if len(destinationAddresses) == 0 {
|
||||
if !destination.IsIP() {
|
||||
panic("invalid usage")
|
||||
}
|
||||
destinationAddresses = []netip.Addr{destination.Addr}
|
||||
}
|
||||
if parallelDialer, isParallel := dialer.(ParallelNetworkDialer); isParallel {
|
||||
return parallelDialer.ListenSerialNetworkPacket(ctx, destination, destinationAddresses, strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
}
|
||||
var errors []error
|
||||
if parallelDialer, isParallel := dialer.(ParallelInterfaceDialer); isParallel {
|
||||
for _, address := range destinationAddresses {
|
||||
conn, err := parallelDialer.ListenSerialInterfacePacket(ctx, M.SocksaddrFrom(address, destination.Port), strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
if err == nil {
|
||||
return conn, address, nil
|
||||
}
|
||||
errors = append(errors, err)
|
||||
}
|
||||
} else {
|
||||
for _, address := range destinationAddresses {
|
||||
conn, err := dialer.ListenPacket(ctx, M.SocksaddrFrom(address, destination.Port))
|
||||
if err == nil {
|
||||
return conn, address, nil
|
||||
}
|
||||
errors = append(errors, err)
|
||||
}
|
||||
}
|
||||
return nil, netip.Addr{}, E.Errors(errors...)
|
||||
}
|
||||
@@ -120,16 +120,17 @@ func NewDNSQueryOptions(ctx context.Context, domainResolver *option.DomainResolv
|
||||
}
|
||||
dnsQueryOptions := defaultOptions.DomainResolveOptions
|
||||
dnsQueryOptions.Transport = transport
|
||||
dnsQueryOptions.DisableReverseMapping = true
|
||||
return dnsQueryOptions, nil
|
||||
}
|
||||
if len(dnsTransport.Transports()) < 2 {
|
||||
return adapter.DNSQueryOptions{Transport: dnsTransport.Default()}, nil
|
||||
return adapter.DNSQueryOptions{Transport: dnsTransport.Default(), DisableReverseMapping: true}, nil
|
||||
}
|
||||
if newDialer {
|
||||
return adapter.DNSQueryOptions{}, E.New("missing domain resolver for domain server address")
|
||||
}
|
||||
deprecated.Report(ctx, deprecated.OptionMissingDomainResolver)
|
||||
return adapter.DNSQueryOptions{}, nil
|
||||
return adapter.DNSQueryOptions{DisableReverseMapping: true}, nil
|
||||
}
|
||||
|
||||
func domainResolveQueryOptions(domainResolver *option.DomainResolveOptions) adapter.DNSQueryOptions {
|
||||
@@ -140,16 +141,12 @@ func domainResolveQueryOptions(domainResolver *option.DomainResolveOptions) adap
|
||||
DisableOptimisticCache: domainResolver.DisableOptimisticCache,
|
||||
RewriteTTL: domainResolver.RewriteTTL,
|
||||
ClientSubnet: domainResolver.ClientSubnet.Build(netip.Prefix{}),
|
||||
DisableReverseMapping: true,
|
||||
}
|
||||
}
|
||||
|
||||
type ParallelInterfaceDialer interface {
|
||||
N.Dialer
|
||||
DialParallelInterface(ctx context.Context, network string, destination M.Socksaddr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.Conn, error)
|
||||
ListenSerialInterfacePacket(ctx context.Context, destination M.Socksaddr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.PacketConn, error)
|
||||
}
|
||||
|
||||
type ParallelNetworkDialer interface {
|
||||
N.Dialer
|
||||
DialParallelNetwork(ctx context.Context, network string, destination M.Socksaddr, destinationAddresses []netip.Addr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.Conn, error)
|
||||
ListenSerialNetworkPacket(ctx context.Context, destination M.Socksaddr, destinationAddresses []netip.Addr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.PacketConn, netip.Addr, error)
|
||||
}
|
||||
|
||||
+63
-53
@@ -3,6 +3,7 @@ package dialer
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/netip"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -17,8 +18,10 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_ N.Dialer = (*resolveDialer)(nil)
|
||||
_ ParallelInterfaceDialer = (*resolveParallelNetworkDialer)(nil)
|
||||
_ ResolveDialer = (*resolveDialer)(nil)
|
||||
_ ResolveDialer = (*resolveParallelNetworkDialer)(nil)
|
||||
_ ParallelNetworkDialer = (*resolveParallelNetworkDialer)(nil)
|
||||
_ PacketDialerWithDestination = (*resolveParallelNetworkDialer)(nil)
|
||||
)
|
||||
|
||||
type ResolveDialer interface {
|
||||
@@ -26,11 +29,6 @@ type ResolveDialer interface {
|
||||
QueryOptions() adapter.DNSQueryOptions
|
||||
}
|
||||
|
||||
type ParallelInterfaceResolveDialer interface {
|
||||
ParallelInterfaceDialer
|
||||
QueryOptions() adapter.DNSQueryOptions
|
||||
}
|
||||
|
||||
type resolveDialer struct {
|
||||
transport adapter.DNSTransportManager
|
||||
router adapter.DNSRouter
|
||||
@@ -44,7 +42,7 @@ type resolveDialer struct {
|
||||
}
|
||||
|
||||
func NewResolveDialer(ctx context.Context, dialer N.Dialer, parallel bool, server string, queryOptions adapter.DNSQueryOptions, fallbackDelay time.Duration) ResolveDialer {
|
||||
if parallelDialer, isParallel := dialer.(ParallelInterfaceDialer); isParallel {
|
||||
if parallelDialer, isParallel := dialer.(ParallelNetworkDialer); isParallel {
|
||||
return &resolveParallelNetworkDialer{
|
||||
resolveDialer{
|
||||
transport: service.FromContext[adapter.DNSTransportManager](ctx),
|
||||
@@ -71,7 +69,7 @@ func NewResolveDialer(ctx context.Context, dialer N.Dialer, parallel bool, serve
|
||||
|
||||
type resolveParallelNetworkDialer struct {
|
||||
resolveDialer
|
||||
dialer ParallelInterfaceDialer
|
||||
dialer ParallelNetworkDialer
|
||||
}
|
||||
|
||||
func (d *resolveDialer) initialize() error {
|
||||
@@ -105,30 +103,38 @@ func (d *resolveDialer) DialContext(ctx context.Context, network string, destina
|
||||
return nil, err
|
||||
}
|
||||
if d.parallel {
|
||||
return N.DialParallel(ctx, d.dialer, network, destination, addresses, d.queryOptions.Strategy == C.DomainStrategyPreferIPv6, d.fallbackDelay)
|
||||
return N.DialParallel(ctx, d.dialer, network, destination, addresses, addresses[0].Is6(), d.fallbackDelay)
|
||||
} else {
|
||||
return N.DialSerial(ctx, d.dialer, network, destination, addresses)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *resolveDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
|
||||
err := d.initialize()
|
||||
conn, destinationAddress, err := d.ListenPacketWithDestination(ctx, destination)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !destinationAddress.IsValid() {
|
||||
return conn, nil
|
||||
}
|
||||
return bufio.NewNATPacketConn(bufio.NewPacketConn(conn), M.SocksaddrFrom(destinationAddress, destination.Port), destination), nil
|
||||
}
|
||||
|
||||
func (d *resolveDialer) ListenPacketWithDestination(ctx context.Context, destination M.Socksaddr) (net.PacketConn, netip.Addr, error) {
|
||||
err := d.initialize()
|
||||
if err != nil {
|
||||
return nil, netip.Addr{}, err
|
||||
}
|
||||
if !destination.IsDomain() {
|
||||
return d.dialer.ListenPacket(ctx, destination)
|
||||
conn, err := d.dialer.ListenPacket(ctx, destination)
|
||||
return conn, netip.Addr{}, err
|
||||
}
|
||||
ctx = log.ContextWithOverrideLevel(ctx, log.LevelDebug)
|
||||
addresses, err := d.router.Lookup(ctx, destination.Fqdn, d.queryOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, netip.Addr{}, err
|
||||
}
|
||||
conn, destinationAddress, err := N.ListenSerial(ctx, d.dialer, destination, addresses)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bufio.NewNATPacketConn(bufio.NewPacketConn(conn), M.SocksaddrFrom(destinationAddress, destination.Port), destination), nil
|
||||
return N.ListenSerial(ctx, d.dialer, destination, addresses)
|
||||
}
|
||||
|
||||
func (d *resolveDialer) QueryOptions() adapter.DNSQueryOptions {
|
||||
@@ -139,56 +145,60 @@ func (d *resolveDialer) Upstream() any {
|
||||
return d.dialer
|
||||
}
|
||||
|
||||
func (d *resolveParallelNetworkDialer) DialParallelInterface(ctx context.Context, network string, destination M.Socksaddr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.Conn, error) {
|
||||
func (d *resolveParallelNetworkDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
|
||||
if destination.IsDomain() {
|
||||
return d.DialParallelNetwork(ctx, network, destination, nil, nil, nil, nil, 0)
|
||||
}
|
||||
err := d.initialize()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !destination.IsDomain() {
|
||||
return d.dialer.DialContext(ctx, network, destination)
|
||||
}
|
||||
ctx = log.ContextWithOverrideLevel(ctx, log.LevelDebug)
|
||||
addresses, err := d.router.Lookup(ctx, destination.Fqdn, d.queryOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if fallbackDelay == 0 {
|
||||
fallbackDelay = d.fallbackDelay
|
||||
}
|
||||
if d.parallel {
|
||||
return DialParallelNetwork(ctx, d.dialer, network, destination, addresses, d.queryOptions.Strategy == C.DomainStrategyPreferIPv6, strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
} else {
|
||||
return DialSerialNetwork(ctx, d.dialer, network, destination, addresses, strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
}
|
||||
return d.dialer.DialContext(ctx, network, destination)
|
||||
}
|
||||
|
||||
func (d *resolveParallelNetworkDialer) ListenSerialInterfacePacket(ctx context.Context, destination M.Socksaddr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.PacketConn, error) {
|
||||
func (d *resolveParallelNetworkDialer) DialParallelNetwork(ctx context.Context, network string, destination M.Socksaddr, destinationAddresses []netip.Addr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.Conn, error) {
|
||||
err := d.initialize()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !destination.IsDomain() {
|
||||
return d.dialer.ListenPacket(ctx, destination)
|
||||
}
|
||||
ctx = log.ContextWithOverrideLevel(ctx, log.LevelDebug)
|
||||
addresses, err := d.router.Lookup(ctx, destination.Fqdn, d.queryOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if len(destinationAddresses) == 0 && destination.IsDomain() {
|
||||
ctx = log.ContextWithOverrideLevel(ctx, log.LevelDebug)
|
||||
destinationAddresses, err = d.router.Lookup(ctx, destination.Fqdn, d.queryOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if fallbackDelay == 0 {
|
||||
fallbackDelay = d.fallbackDelay
|
||||
}
|
||||
conn, destinationAddress, err := ListenSerialNetworkPacket(ctx, d.dialer, destination, addresses, strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if d.parallel || len(destinationAddresses) <= 1 {
|
||||
return d.dialer.DialParallelNetwork(ctx, network, destination, destinationAddresses, strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
}
|
||||
return bufio.NewNATPacketConn(bufio.NewPacketConn(conn), M.SocksaddrFrom(destinationAddress, destination.Port), destination), nil
|
||||
var errors []error
|
||||
for _, address := range destinationAddresses {
|
||||
conn, err := d.dialer.DialParallelNetwork(ctx, network, destination, []netip.Addr{address}, strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
if err == nil {
|
||||
return conn, nil
|
||||
}
|
||||
errors = append(errors, err)
|
||||
}
|
||||
return nil, E.Errors(errors...)
|
||||
}
|
||||
|
||||
func (d *resolveParallelNetworkDialer) QueryOptions() adapter.DNSQueryOptions {
|
||||
return d.queryOptions
|
||||
}
|
||||
|
||||
func (d *resolveParallelNetworkDialer) Upstream() any {
|
||||
return d.dialer
|
||||
func (d *resolveParallelNetworkDialer) ListenSerialNetworkPacket(ctx context.Context, destination M.Socksaddr, destinationAddresses []netip.Addr, strategy *C.NetworkStrategy, interfaceType []C.InterfaceType, fallbackInterfaceType []C.InterfaceType, fallbackDelay time.Duration) (net.PacketConn, netip.Addr, error) {
|
||||
err := d.initialize()
|
||||
if err != nil {
|
||||
return nil, netip.Addr{}, err
|
||||
}
|
||||
if len(destinationAddresses) == 0 && destination.IsDomain() {
|
||||
ctx = log.ContextWithOverrideLevel(ctx, log.LevelDebug)
|
||||
destinationAddresses, err = d.router.Lookup(ctx, destination.Fqdn, d.queryOptions)
|
||||
if err != nil {
|
||||
return nil, netip.Addr{}, err
|
||||
}
|
||||
}
|
||||
if fallbackDelay == 0 {
|
||||
fallbackDelay = d.fallbackDelay
|
||||
}
|
||||
return d.dialer.ListenSerialNetworkPacket(ctx, destination, destinationAddresses, strategy, interfaceType, fallbackInterfaceType, fallbackDelay)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing-box/common/listener"
|
||||
"github.com/sagernet/sing/common"
|
||||
"github.com/sagernet/sing/common/bufio"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
@@ -21,6 +22,7 @@ type slowOpenConn struct {
|
||||
dialer *tfo.Dialer
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
netns string
|
||||
network string
|
||||
destination M.Socksaddr
|
||||
conn atomic.Pointer[net.TCPConn]
|
||||
@@ -31,7 +33,7 @@ type slowOpenConn struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func DialSlowContext(dialer *tfo.Dialer, ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
|
||||
func DialSlowContext(dialer *tfo.Dialer, ctx context.Context, netns string, network string, destination M.Socksaddr) (net.Conn, error) {
|
||||
if dialer.DisableTFO || N.NetworkName(network) != N.NetworkTCP {
|
||||
switch N.NetworkName(network) {
|
||||
case N.NetworkTCP, N.NetworkUDP:
|
||||
@@ -45,6 +47,7 @@ func DialSlowContext(dialer *tfo.Dialer, ctx context.Context, network string, de
|
||||
dialer: dialer,
|
||||
ctx: dialCtx,
|
||||
cancel: cancel,
|
||||
netns: netns,
|
||||
network: network,
|
||||
destination: destination,
|
||||
create: make(chan struct{}),
|
||||
@@ -85,7 +88,9 @@ func (c *slowOpenConn) Write(b []byte) (n int, err error) {
|
||||
return 0, os.ErrClosed
|
||||
default:
|
||||
}
|
||||
conn, err := c.dialer.DialContext(c.ctx, c.network, c.destination.String(), b)
|
||||
conn, err := listener.ListenNetworkNamespace[net.Conn](c.ctx, c.netns, func() (net.Conn, error) {
|
||||
return c.dialer.DialContext(c.ctx, c.network, c.destination.String(), b)
|
||||
})
|
||||
if err != nil {
|
||||
c.err = err
|
||||
} else {
|
||||
|
||||
@@ -40,7 +40,7 @@ type internalTransport struct {
|
||||
|
||||
// net/http/internal/http2.clientConnPool
|
||||
type clientConnPool struct {
|
||||
t *internalTransport
|
||||
_ *internalTransport
|
||||
mu sync.Mutex
|
||||
conns map[string][]unsafe.Pointer // key is host:port, value is []*ClientConn
|
||||
}
|
||||
|
||||
@@ -812,7 +812,7 @@ func newAppleHTTPTestTransport(t *testing.T, server *appleHTTPTestServer, option
|
||||
func newAppleHTTPTestContext() context.Context {
|
||||
return service.ContextWith[adapter.ConnectionManager](
|
||||
context.Background(),
|
||||
route.NewConnectionManager(log.NewNOPFactory().NewLogger("connection")),
|
||||
route.NewConnectionManager(context.Background(), log.NewNOPFactory().NewLogger("connection")),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,10 @@ func NewTransport(ctx context.Context, logger logger.ContextLogger, tag string,
|
||||
headers := options.Headers.Build()
|
||||
host := headers.Get("Host")
|
||||
headers.Del("Host")
|
||||
var domainResolver string
|
||||
if options.DomainResolver != nil {
|
||||
domainResolver = options.DomainResolver.Server
|
||||
}
|
||||
|
||||
var cheapRebuild bool
|
||||
switch options.Engine {
|
||||
@@ -45,6 +49,7 @@ func NewTransport(ctx context.Context, logger logger.ContextLogger, tag string,
|
||||
host: host,
|
||||
tag: tag,
|
||||
detour: options.Detour,
|
||||
domainResolver: domainResolver,
|
||||
defaultOutbound: options.DefaultOutbound,
|
||||
factory: func() (innerTransport, error) {
|
||||
return newAppleTransport(ctx, logger, rawDialer, options)
|
||||
@@ -62,6 +67,8 @@ func NewTransport(ctx context.Context, logger logger.ContextLogger, tag string,
|
||||
Logger: logger,
|
||||
Options: tlsOptions,
|
||||
AllowEmptyServerName: true,
|
||||
DomainResolver: options.DomainResolver,
|
||||
DirectResolver: options.DirectResolver,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -77,6 +84,7 @@ func NewTransport(ctx context.Context, logger logger.ContextLogger, tag string,
|
||||
host: host,
|
||||
tag: tag,
|
||||
detour: options.Detour,
|
||||
domainResolver: domainResolver,
|
||||
defaultOutbound: options.DefaultOutbound,
|
||||
factory: func() (innerTransport, error) {
|
||||
return newTransport(rawDialer, baseTLSConfig, options)
|
||||
|
||||
@@ -2,7 +2,6 @@ package httpclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
stdTLS "crypto/tls"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -20,20 +19,10 @@ func dialTLS(ctx context.Context, rawDialer N.Dialer, baseTLSConfig tls.Config,
|
||||
if baseTLSConfig == nil {
|
||||
return nil, E.New("TLS transport unavailable")
|
||||
}
|
||||
tlsConfig := baseTLSConfig.Clone()
|
||||
if tlsConfig.ServerName() == "" && destination.IsValid() {
|
||||
tlsConfig.SetServerName(destination.AddrString())
|
||||
}
|
||||
tlsConfig.SetNextProtos(nextProtos)
|
||||
conn, err := rawDialer.DialContext(ctx, N.NetworkTCP, destination)
|
||||
tlsConn, err := tls.NewDialer(rawDialer, prepareTLSConfig(baseTLSConfig, destination, nextProtos)).DialTLSContext(ctx, destination)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tlsConn, err := tls.ClientHandshake(ctx, conn, tlsConfig)
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, err
|
||||
}
|
||||
if expectProto != "" && tlsConn.ConnectionState().NegotiatedProtocol != expectProto {
|
||||
tlsConn.Close()
|
||||
return nil, errHTTP2Fallback
|
||||
@@ -103,14 +92,11 @@ func requestAuthority(request *http.Request) string {
|
||||
return net.JoinHostPort(host, port)
|
||||
}
|
||||
|
||||
func buildSTDTLSConfig(baseTLSConfig tls.Config, destination M.Socksaddr, nextProtos []string) (*stdTLS.Config, error) {
|
||||
if baseTLSConfig == nil {
|
||||
return nil, nil
|
||||
}
|
||||
func prepareTLSConfig(baseTLSConfig tls.Config, destination M.Socksaddr, nextProtos []string) tls.Config {
|
||||
tlsConfig := baseTLSConfig.Clone()
|
||||
if tlsConfig.ServerName() == "" && destination.IsValid() {
|
||||
tlsConfig.SetServerName(destination.AddrString())
|
||||
}
|
||||
tlsConfig.SetNextProtos(nextProtos)
|
||||
return tlsConfig.STDConfig()
|
||||
return tlsConfig
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/sagernet/quic-go/http3"
|
||||
"github.com/sagernet/sing-box/common/tls"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
qtls "github.com/sagernet/sing-quic"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
@@ -72,21 +73,19 @@ func newHTTP3RoundTripper(
|
||||
quicConfig = quicConfig.Clone()
|
||||
quicConfig.HandshakeIdleTimeout = handshakeTimeout
|
||||
}
|
||||
if baseTLSConfig != nil {
|
||||
var err error
|
||||
tlsConfig, err = buildSTDTLSConfig(baseTLSConfig, M.ParseSocksaddr(addr), []string{http3.NextProtoH3})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
tlsConfig = tlsConfig.Clone()
|
||||
tlsConfig.NextProtos = []string{http3.NextProtoH3}
|
||||
}
|
||||
conn, err := rawDialer.DialContext(ctx, N.NetworkUDP, M.ParseSocksaddr(addr))
|
||||
destination := M.ParseSocksaddr(addr)
|
||||
conn, err := rawDialer.DialContext(ctx, N.NetworkUDP, destination)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
quicConn, err := quic.DialEarlyConn(ctx, conn, tlsConfig, quicConfig)
|
||||
var quicConn *quic.Conn
|
||||
if baseTLSConfig != nil {
|
||||
quicConn, err = qtls.DialEarly(ctx, conn, prepareTLSConfig(baseTLSConfig, destination, []string{http3.NextProtoH3}), quicConfig)
|
||||
} else {
|
||||
tlsConfig = tlsConfig.Clone()
|
||||
tlsConfig.NextProtos = []string{http3.NextProtoH3}
|
||||
quicConn, err = quic.DialEarlyConn(ctx, conn, tlsConfig, quicConfig)
|
||||
}
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, err
|
||||
|
||||
@@ -30,6 +30,7 @@ type ManagedTransport struct {
|
||||
host string
|
||||
tag string
|
||||
detour string
|
||||
domainResolver string
|
||||
defaultOutbound bool
|
||||
}
|
||||
|
||||
|
||||
@@ -178,17 +178,23 @@ func (m *Manager) close() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Manager) References() []string {
|
||||
func (m *Manager) References() ([]string, []string) {
|
||||
m.access.Lock()
|
||||
defer m.access.Unlock()
|
||||
var references []string
|
||||
var needDefault bool
|
||||
var (
|
||||
references []string
|
||||
dnsReferences []string
|
||||
needDefault bool
|
||||
)
|
||||
for _, transport := range m.managedTransports {
|
||||
if transport.detour != "" {
|
||||
references = append(references, transport.detour)
|
||||
} else if transport.defaultOutbound {
|
||||
needDefault = true
|
||||
}
|
||||
if transport.domainResolver != "" {
|
||||
dnsReferences = append(dnsReferences, transport.domainResolver)
|
||||
}
|
||||
}
|
||||
if needDefault {
|
||||
outboundManager := service.FromContext[adapter.OutboundManager](m.ctx)
|
||||
@@ -199,5 +205,5 @@ func (m *Manager) References() []string {
|
||||
}
|
||||
}
|
||||
}
|
||||
return references
|
||||
return references, dnsReferences
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@ import "context"
|
||||
|
||||
type contextKeyIsExternalConnection struct{}
|
||||
|
||||
func ContextWithIsExternalConnection(ctx context.Context) context.Context {
|
||||
return context.WithValue(ctx, contextKeyIsExternalConnection{}, true)
|
||||
func ContextWithIsExternalConnection(ctx context.Context, isExternal bool) context.Context {
|
||||
return context.WithValue(ctx, contextKeyIsExternalConnection{}, isExternal)
|
||||
}
|
||||
|
||||
func IsExternalConnectionFromContext(ctx context.Context) bool {
|
||||
return ctx.Value(contextKeyIsExternalConnection{}) != nil
|
||||
isExternal, _ := ctx.Value(contextKeyIsExternalConnection{}).(bool)
|
||||
return isExternal
|
||||
}
|
||||
|
||||
type contextKeyIsProviderConnection struct{}
|
||||
|
||||
@@ -24,6 +24,17 @@ func NewGroup() *Group {
|
||||
return &Group{}
|
||||
}
|
||||
|
||||
func (g *Group) Add(closer io.Closer, isExternal bool) (remove func()) {
|
||||
g.access.Lock()
|
||||
defer g.access.Unlock()
|
||||
element := g.connections.PushBack(&groupConnItem{conn: closer, isExternal: isExternal})
|
||||
return func() {
|
||||
g.access.Lock()
|
||||
defer g.access.Unlock()
|
||||
g.connections.Remove(element)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Group) NewConn(conn net.Conn, isExternal bool, isProvider bool) net.Conn {
|
||||
g.access.Lock()
|
||||
defer g.access.Unlock()
|
||||
|
||||
@@ -109,6 +109,12 @@ func (c *Conn) HandleSyscallReadError(inputErr error) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "ktls: handle non-application-data record")
|
||||
}
|
||||
for c.rawConn.Hand.Len() > 0 {
|
||||
err = c.handlePostHandshakeMessage()
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "ktls: handle post-handshake messages")
|
||||
}
|
||||
}
|
||||
var input bytes.Buffer
|
||||
if c.rawConn.Input.Len() > 0 {
|
||||
_, err = c.rawConn.Input.WriteTo(&input)
|
||||
|
||||
@@ -287,7 +287,7 @@ func (c *Conn) readKernelRecord() (uint8, []byte, error) {
|
||||
return recordTypeApplicationData, data[:n], nil
|
||||
}
|
||||
|
||||
func (c *Conn) writeKernelRecord(typ uint16, data []byte) (int, error) {
|
||||
func (c *Conn) writeKernelRecord(typ uint8, data []byte) (int, error) {
|
||||
if typ == recordTypeApplicationData {
|
||||
return c.conn.Write(data)
|
||||
}
|
||||
@@ -296,7 +296,7 @@ func (c *Conn) writeKernelRecord(typ uint16, data []byte) (int, error) {
|
||||
buffer := make([]byte, unix.CmsgSpace(1))
|
||||
cmsg := (*unix.Cmsghdr)(unsafe.Pointer(&buffer[0]))
|
||||
cmsg.SetLen(unix.CmsgLen(1))
|
||||
buffer[unix.CmsgLen(0)] = byte(typ)
|
||||
buffer[unix.CmsgLen(0)] = typ
|
||||
cmsg.Level = unix.SOL_TLS
|
||||
cmsg.Type = TLS_SET_RECORD_TYPE
|
||||
|
||||
|
||||
@@ -24,6 +24,12 @@ func (c *Conn) WaitReadBuffer() (buffer *buf.Buffer, err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for c.rawConn.Hand.Len() > 0 {
|
||||
err = c.handlePostHandshakeMessage()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
buffer = c.readWaitOptions.NewBuffer()
|
||||
n, err := c.rawConn.Input.Read(buffer.FreeBytes())
|
||||
@@ -32,7 +38,7 @@ func (c *Conn) WaitReadBuffer() (buffer *buf.Buffer, err error) {
|
||||
return
|
||||
}
|
||||
buffer.Truncate(n)
|
||||
if n != 0 && c.rawConn.Input.Len() == 0 && c.rawConn.Input.Len() > 0 &&
|
||||
if n != 0 && c.rawConn.Input.Len() == 0 && c.rawConn.RawInput.Len() > 0 && !c.kernelRx &&
|
||||
c.rawConn.RawInput.Bytes()[0] == recordTypeAlert {
|
||||
_ = c.rawConn.ReadRecord()
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func (c *Conn) Write(b []byte) (int, error) {
|
||||
return n + m, c.rawConn.Out.SetErrorLocked(err)
|
||||
}
|
||||
|
||||
func (c *Conn) writeRecordLocked(typ uint16, data []byte) (n int, err error) {
|
||||
func (c *Conn) writeRecordLocked(typ uint8, data []byte) (n int, err error) {
|
||||
if !c.kernelTx {
|
||||
return c.rawConn.WriteRecordLocked(typ, data)
|
||||
}
|
||||
|
||||
@@ -6,16 +6,20 @@ import (
|
||||
"net/netip"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/common/settings"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
"github.com/sagernet/sing/common"
|
||||
"github.com/sagernet/sing/common/control"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/logger"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
"github.com/sagernet/sing/common/x/list"
|
||||
"github.com/sagernet/sing/service"
|
||||
|
||||
"github.com/vishvananda/netns"
|
||||
@@ -42,6 +46,8 @@ type Listener struct {
|
||||
packetOutbound chan *N.PacketBuffer
|
||||
packetOutboundClosed chan struct{}
|
||||
shutdown atomic.Bool
|
||||
interfaceAccess sync.Mutex
|
||||
interfaceCallbacks []*list.Element[control.InterfaceUpdateCallback]
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
@@ -122,6 +128,14 @@ func (l *Listener) Start() error {
|
||||
|
||||
func (l *Listener) Close() error {
|
||||
l.shutdown.Store(true)
|
||||
l.interfaceAccess.Lock()
|
||||
if len(l.interfaceCallbacks) > 0 {
|
||||
interfaceFinder := service.FromContext[adapter.NetworkManager](l.ctx).InterfaceFinder()
|
||||
for _, element := range l.interfaceCallbacks {
|
||||
interfaceFinder.UnregisterInterfaceUpdateCallback(element)
|
||||
}
|
||||
}
|
||||
l.interfaceAccess.Unlock()
|
||||
var err error
|
||||
if l.systemProxy != nil {
|
||||
if l.systemProxy.IsEnabled() {
|
||||
@@ -135,6 +149,71 @@ func (l *Listener) Close() error {
|
||||
))
|
||||
}
|
||||
|
||||
func (l *Listener) bindInterfaceFunc() control.Func {
|
||||
if l.listenOptions.NetNs != "" {
|
||||
return func(network, address string, conn syscall.RawConn) error {
|
||||
return control.BindToInterface0(nil, conn, network, address, l.listenOptions.BindInterface, -1, true)
|
||||
}
|
||||
}
|
||||
return control.BindToInterface(service.FromContext[adapter.NetworkManager](l.ctx).InterfaceFinder(), l.listenOptions.BindInterface, -1)
|
||||
}
|
||||
|
||||
func (l *Listener) followBindInterface() (control.Func, func(conn syscall.Conn)) {
|
||||
if l.listenOptions.NetNs != "" {
|
||||
return l.bindInterfaceFunc(), nil
|
||||
}
|
||||
interfaceName := l.listenOptions.BindInterface
|
||||
interfaceFinder := service.FromContext[adapter.NetworkManager](l.ctx).InterfaceFinder()
|
||||
var (
|
||||
access sync.Mutex
|
||||
bindNetwork string
|
||||
bindAddress string
|
||||
interfaceIndex int
|
||||
)
|
||||
bindFunc := func(network, address string, conn syscall.RawConn) error {
|
||||
iif, err := interfaceFinder.ByName(interfaceName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
access.Lock()
|
||||
defer access.Unlock()
|
||||
bindNetwork, bindAddress, interfaceIndex = network, address, iif.Index
|
||||
return control.BindToInterface0(interfaceFinder, conn, network, address, interfaceName, iif.Index, false)
|
||||
}
|
||||
followFunc := func(conn syscall.Conn) {
|
||||
rawConn, _ := conn.SyscallConn()
|
||||
rebind := func(index int) {
|
||||
access.Lock()
|
||||
defer access.Unlock()
|
||||
if index == 0 || index == interfaceIndex {
|
||||
return
|
||||
}
|
||||
err := control.BindToInterface0(interfaceFinder, rawConn, bindNetwork, bindAddress, interfaceName, index, false)
|
||||
if err != nil {
|
||||
if !E.IsClosed(err) {
|
||||
l.logger.Error(E.Cause(err, "rebind ", N.NetworkName(bindNetwork), " server to interface ", interfaceName))
|
||||
}
|
||||
return
|
||||
}
|
||||
interfaceIndex = index
|
||||
l.logger.Info(N.NetworkName(bindNetwork), " server rebound to interface ", interfaceName)
|
||||
}
|
||||
element := interfaceFinder.RegisterInterfaceUpdateCallback(func(interfaces []control.Interface) {
|
||||
rebind(common.Find(interfaces, func(it control.Interface) bool {
|
||||
return it.Name == interfaceName
|
||||
}).Index)
|
||||
})
|
||||
l.interfaceAccess.Lock()
|
||||
l.interfaceCallbacks = append(l.interfaceCallbacks, element)
|
||||
l.interfaceAccess.Unlock()
|
||||
iif, err := interfaceFinder.ByName(interfaceName)
|
||||
if err == nil {
|
||||
rebind(iif.Index)
|
||||
}
|
||||
}
|
||||
return bindFunc, followFunc
|
||||
}
|
||||
|
||||
func (l *Listener) TCPListener() net.Listener {
|
||||
return l.tcpListener
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
"github.com/sagernet/sing/service"
|
||||
|
||||
"github.com/database64128/tfo-go/v2"
|
||||
)
|
||||
@@ -27,9 +26,14 @@ func (l *Listener) ListenTCP() (net.Listener, error) {
|
||||
}
|
||||
var err error
|
||||
bindAddr := M.SocksaddrFrom(l.listenOptions.Listen.Build(netip.AddrFrom4([4]byte{127, 0, 0, 1})), l.listenOptions.ListenPort)
|
||||
var listenConfig net.ListenConfig
|
||||
var (
|
||||
listenConfig net.ListenConfig
|
||||
followInterface func(conn syscall.Conn)
|
||||
)
|
||||
if l.listenOptions.BindInterface != "" {
|
||||
listenConfig.Control = control.Append(listenConfig.Control, control.BindToInterface(service.FromContext[adapter.NetworkManager](l.ctx).InterfaceFinder(), l.listenOptions.BindInterface, -1))
|
||||
var bindFunc control.Func
|
||||
bindFunc, followInterface = l.followBindInterface()
|
||||
listenConfig.Control = control.Append(listenConfig.Control, bindFunc)
|
||||
}
|
||||
if l.listenOptions.RoutingMark != 0 {
|
||||
listenConfig.Control = control.Append(listenConfig.Control, control.RoutingMark(uint32(l.listenOptions.RoutingMark)))
|
||||
@@ -77,6 +81,9 @@ func (l *Listener) ListenTCP() (net.Listener, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if followInterface != nil {
|
||||
followInterface(tcpListener.(syscall.Conn))
|
||||
}
|
||||
l.logger.Notice("tcp server started at ", tcpListener.Addr())
|
||||
l.tcpListener = tcpListener
|
||||
return tcpListener, err
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
"github.com/sagernet/sing/service"
|
||||
)
|
||||
|
||||
const udpOutputBatchSize = 128
|
||||
@@ -27,8 +26,11 @@ func (l *Listener) ListenUDP() (net.PacketConn, error) {
|
||||
|
||||
func (l *Listener) ListenUDPWithConfig(listenConfig net.ListenConfig) (net.PacketConn, error) {
|
||||
bindAddr := M.SocksaddrFrom(l.listenOptions.Listen.Build(netip.AddrFrom4([4]byte{127, 0, 0, 1})), l.listenOptions.ListenPort)
|
||||
var followInterface func(conn syscall.Conn)
|
||||
if l.listenOptions.BindInterface != "" {
|
||||
listenConfig.Control = control.Append(listenConfig.Control, control.BindToInterface(service.FromContext[adapter.NetworkManager](l.ctx).InterfaceFinder(), l.listenOptions.BindInterface, -1))
|
||||
var bindFunc control.Func
|
||||
bindFunc, followInterface = l.followBindInterface()
|
||||
listenConfig.Control = control.Append(listenConfig.Control, bindFunc)
|
||||
}
|
||||
if l.listenOptions.RoutingMark != 0 {
|
||||
listenConfig.Control = control.Append(listenConfig.Control, control.RoutingMark(uint32(l.listenOptions.RoutingMark)))
|
||||
@@ -62,6 +64,9 @@ func (l *Listener) ListenUDPWithConfig(listenConfig net.ListenConfig) (net.Packe
|
||||
}
|
||||
l.udpConn = udpConn.(*net.UDPConn)
|
||||
l.udpAddr = bindAddr
|
||||
if followInterface != nil {
|
||||
followInterface(l.udpConn)
|
||||
}
|
||||
l.logger.Notice("udp server started at ", udpConn.LocalAddr())
|
||||
return udpConn, err
|
||||
}
|
||||
@@ -69,7 +74,7 @@ func (l *Listener) ListenUDPWithConfig(listenConfig net.ListenConfig) (net.Packe
|
||||
func (l *Listener) DialContext(dialer net.Dialer, ctx context.Context, network string, address string) (net.Conn, error) {
|
||||
return ListenNetworkNamespace[net.Conn](l.ctx, l.listenOptions.NetNs, func() (net.Conn, error) {
|
||||
if l.listenOptions.BindInterface != "" {
|
||||
dialer.Control = control.Append(dialer.Control, control.BindToInterface(service.FromContext[adapter.NetworkManager](l.ctx).InterfaceFinder(), l.listenOptions.BindInterface, -1))
|
||||
dialer.Control = control.Append(dialer.Control, l.bindInterfaceFunc())
|
||||
}
|
||||
if l.listenOptions.RoutingMark != 0 {
|
||||
dialer.Control = control.Append(dialer.Control, control.RoutingMark(uint32(l.listenOptions.RoutingMark)))
|
||||
@@ -84,7 +89,7 @@ func (l *Listener) DialContext(dialer net.Dialer, ctx context.Context, network s
|
||||
func (l *Listener) ListenPacket(listenConfig net.ListenConfig, ctx context.Context, network string, address string) (net.PacketConn, error) {
|
||||
return ListenNetworkNamespace[net.PacketConn](l.ctx, l.listenOptions.NetNs, func() (net.PacketConn, error) {
|
||||
if l.listenOptions.BindInterface != "" {
|
||||
listenConfig.Control = control.Append(listenConfig.Control, control.BindToInterface(service.FromContext[adapter.NetworkManager](l.ctx).InterfaceFinder(), l.listenOptions.BindInterface, -1))
|
||||
listenConfig.Control = control.Append(listenConfig.Control, l.bindInterfaceFunc())
|
||||
}
|
||||
if l.listenOptions.RoutingMark != 0 {
|
||||
listenConfig.Control = control.Append(listenConfig.Control, control.RoutingMark(uint32(l.listenOptions.RoutingMark)))
|
||||
@@ -224,7 +229,7 @@ func (l *Listener) loopUDPOut() {
|
||||
packets = packets[:0]
|
||||
buffers = buffers[:0]
|
||||
destinations = destinations[:0]
|
||||
if err != nil {
|
||||
if err != nil && !N.IsPacketTooBig(err) {
|
||||
if l.shutdown.Load() && E.IsClosed(err) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/sagernet/sing/common/logger"
|
||||
|
||||
vnetns "github.com/vishvananda/netns"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
@@ -112,14 +113,31 @@ func (m *Manager) startNamespace(namespace option.NetworkNamespace, scope *adapt
|
||||
}
|
||||
m.paths[namespace.Tag] = netnsPath(pid)
|
||||
m.logger.Info("created network namespace[", namespace.Tag, "], holder pid: ", pid)
|
||||
if os.Geteuid() == 0 {
|
||||
m.logger.Info("enter network namespace[", namespace.Tag, "] with: nsenter -n -t ", pid)
|
||||
} else {
|
||||
if ownsUserNamespace() {
|
||||
m.logger.Info("enter network namespace[", namespace.Tag, "] with: nsenter -U --preserve-credentials -n -t ", pid)
|
||||
} else {
|
||||
m.logger.Info("enter network namespace[", namespace.Tag, "] with: nsenter -n -t ", pid)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ownsUserNamespace() bool {
|
||||
effectiveUID := os.Geteuid()
|
||||
if effectiveUID == 0 {
|
||||
return false
|
||||
}
|
||||
userNamespace, err := os.Open("/proc/self/ns/user")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer userNamespace.Close()
|
||||
ownerUID, err := unix.IoctlGetUint32(int(userNamespace.Fd()), unix.NS_GET_OWNER_UID)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return int(ownerUID) == effectiveUID
|
||||
}
|
||||
|
||||
func (m *Manager) ResolvePath(nameOrPath string) string {
|
||||
path, loaded := m.paths[nameOrPath]
|
||||
if loaded && path != "" {
|
||||
|
||||
@@ -2,6 +2,8 @@ package netns
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
)
|
||||
@@ -9,6 +11,7 @@ import (
|
||||
var _ adapter.NetworkNamespaceManager = (*Manager)(nil)
|
||||
|
||||
func Hold() {
|
||||
signal.Ignore(os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
|
||||
buffer := make([]byte, 1)
|
||||
for {
|
||||
_, err := os.Stdin.Read(buffer)
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"unicode"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/log"
|
||||
"github.com/sagernet/sing-tun"
|
||||
"github.com/sagernet/sing/common"
|
||||
@@ -87,7 +88,7 @@ func (s *linuxSearcher) FindProcessInfo(ctx context.Context, network string, sou
|
||||
processPath, err := s.findProcessPath(inode, uid)
|
||||
if err != nil {
|
||||
s.logger.DebugContext(ctx, "find process path: ", err)
|
||||
} else {
|
||||
} else if !C.IsAndroid || !strings.HasPrefix(processPath, "/system/bin/app_process") {
|
||||
processInfo.ProcessPath = processPath
|
||||
}
|
||||
if s.packageManager != nil {
|
||||
@@ -129,9 +130,14 @@ func (s *linuxSearcher) resolveSocketByNetlink(network string, source netip.Addr
|
||||
|
||||
// The socket keeps the uid it was created with, while /proc reflects the
|
||||
// current uid of the process, so a socket created before a privilege drop
|
||||
// only appears under a scan of all users.
|
||||
// only appears under a scan of all users. On Android, netd chowns the DNS
|
||||
// sockets it opens on behalf of an app to the app's uid.
|
||||
func (s *linuxSearcher) findProcessPath(targetInode, uid uint32) (string, error) {
|
||||
for _, scanUID := range []uint32{uid, processPathsAllUsers} {
|
||||
scanUIDs := []uint32{uid}
|
||||
if !C.IsAndroid {
|
||||
scanUIDs = append(scanUIDs, processPathsAllUsers)
|
||||
}
|
||||
for _, scanUID := range scanUIDs {
|
||||
if cached, ok := s.processPathCache.Get(scanUID); ok {
|
||||
if processPath, found := cached.entries[targetInode]; found {
|
||||
return processPath, nil
|
||||
@@ -180,6 +186,7 @@ func buildProcessPaths(uid uint32) (map[uint32]string, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
exePath = strings.TrimSuffix(exePath, " (deleted)")
|
||||
fds, err := os.ReadDir(fdPath)
|
||||
if err != nil {
|
||||
continue
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
package redir
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/netip"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
PF_OUT = 0x2
|
||||
DIOCNATLOOK = 0xc0544417
|
||||
)
|
||||
|
||||
func GetOriginalDestination(conn net.Conn) (destination netip.AddrPort, err error) {
|
||||
fd, err := syscall.Open("/dev/pf", 0, syscall.O_RDONLY)
|
||||
if err != nil {
|
||||
return netip.AddrPort{}, err
|
||||
}
|
||||
defer syscall.Close(fd)
|
||||
nl := struct {
|
||||
saddr, daddr, rsaddr, rdaddr [16]byte
|
||||
sxport, dxport, rsxport, rdxport [4]byte
|
||||
af, proto, protoVariant, direction uint8
|
||||
}{
|
||||
af: syscall.AF_INET,
|
||||
proto: syscall.IPPROTO_TCP,
|
||||
direction: PF_OUT,
|
||||
}
|
||||
la := conn.LocalAddr().(*net.TCPAddr)
|
||||
ra := conn.RemoteAddr().(*net.TCPAddr)
|
||||
raIP, laIP := ra.IP, la.IP
|
||||
raPort, laPort := ra.Port, la.Port
|
||||
switch {
|
||||
case raIP.To4() != nil:
|
||||
copy(nl.saddr[:net.IPv4len], raIP.To4())
|
||||
copy(nl.daddr[:net.IPv4len], laIP.To4())
|
||||
nl.af = syscall.AF_INET
|
||||
default:
|
||||
copy(nl.saddr[:], raIP.To16())
|
||||
copy(nl.daddr[:], laIP.To16())
|
||||
nl.af = syscall.AF_INET6
|
||||
}
|
||||
nl.sxport[0], nl.sxport[1] = byte(raPort>>8), byte(raPort)
|
||||
nl.dxport[0], nl.dxport[1] = byte(laPort>>8), byte(laPort)
|
||||
if _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), DIOCNATLOOK, uintptr(unsafe.Pointer(&nl))); errno != 0 {
|
||||
return netip.AddrPort{}, errno
|
||||
}
|
||||
|
||||
var ip net.IP
|
||||
switch nl.af {
|
||||
case syscall.AF_INET:
|
||||
ip = make(net.IP, net.IPv4len)
|
||||
copy(ip, nl.rdaddr[:net.IPv4len])
|
||||
case syscall.AF_INET6:
|
||||
ip = make(net.IP, net.IPv6len)
|
||||
copy(ip, nl.rdaddr[:])
|
||||
}
|
||||
port := uint16(nl.rdxport[0])<<8 | uint16(nl.rdxport[1])
|
||||
destination = netip.AddrPortFrom(M.AddrFromIP(ip), port)
|
||||
return
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package redir
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
"github.com/sagernet/sing/common"
|
||||
"github.com/sagernet/sing/common/control"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
)
|
||||
|
||||
func GetOriginalDestination(conn net.Conn) (destination netip.AddrPort, err error) {
|
||||
syscallConn, ok := common.Cast[syscall.Conn](conn)
|
||||
if !ok {
|
||||
return netip.AddrPort{}, os.ErrInvalid
|
||||
}
|
||||
err = control.Conn(syscallConn, func(fd uintptr) error {
|
||||
const SO_ORIGINAL_DST = 80
|
||||
if conn.RemoteAddr().(*net.TCPAddr).IP.To4() != nil {
|
||||
raw, err := syscall.GetsockoptIPv6Mreq(int(fd), syscall.IPPROTO_IP, SO_ORIGINAL_DST)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
destination = netip.AddrPortFrom(M.AddrFromIP(raw.Multiaddr[4:8]), uint16(raw.Multiaddr[2])<<8+uint16(raw.Multiaddr[3]))
|
||||
} else {
|
||||
raw, err := syscall.GetsockoptIPv6MTUInfo(int(fd), syscall.IPPROTO_IPV6, SO_ORIGINAL_DST)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var port [2]byte
|
||||
binary.BigEndian.PutUint16(port[:], raw.Addr.Port)
|
||||
destination = netip.AddrPortFrom(M.AddrFromIP(raw.Addr.Addr[:]), binary.LittleEndian.Uint16(port[:]))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
//go:build !linux && !darwin
|
||||
|
||||
package redir
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
)
|
||||
|
||||
func GetOriginalDestination(conn net.Conn) (destination netip.AddrPort, err error) {
|
||||
return netip.AddrPort{}, os.ErrInvalid
|
||||
}
|
||||
@@ -23,6 +23,8 @@ func HTTPHost(_ context.Context, metadata *adapter.InboundContext, reader io.Rea
|
||||
}
|
||||
}
|
||||
metadata.Protocol = C.ProtocolHTTP
|
||||
metadata.Domain = M.ParseSocksaddr(request.Host).Fqdn
|
||||
if domain := M.ParseSocksaddr(request.Host).Fqdn; domain != "" {
|
||||
metadata.Domain = domain
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"os"
|
||||
"slices"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/common/ja3"
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing/common/buf"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
|
||||
"golang.org/x/crypto/hkdf"
|
||||
)
|
||||
@@ -309,7 +311,9 @@ find:
|
||||
metadata.SniffContext = fragments
|
||||
return E.Cause1(ErrNeedMoreData, err)
|
||||
}
|
||||
metadata.Domain = fingerprint.ServerName
|
||||
if domain := M.ParseSocksaddrHostPort(fingerprint.ServerName, 0).Fqdn; domain != "" && (domain != metadata.ECHPublicName || !slices.Contains(fingerprint.Extensions, extensionEncryptedClientHello)) {
|
||||
metadata.Domain = domain
|
||||
}
|
||||
for metadata.Client == "" {
|
||||
if len(frameTypeList) == 1 {
|
||||
metadata.Client = C.ClientFirefox
|
||||
|
||||
+7
-1
@@ -5,13 +5,17 @@ import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"io"
|
||||
"slices"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing/common/bufio"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
)
|
||||
|
||||
const extensionEncryptedClientHello = 0xfe0d
|
||||
|
||||
func TLSClientHello(ctx context.Context, metadata *adapter.InboundContext, reader io.Reader) error {
|
||||
var clientHello *tls.ClientHelloInfo
|
||||
err := tls.Server(bufio.NewReadOnlyConn(reader), &tls.Config{
|
||||
@@ -22,7 +26,9 @@ func TLSClientHello(ctx context.Context, metadata *adapter.InboundContext, reade
|
||||
}).HandshakeContext(ctx)
|
||||
if clientHello != nil {
|
||||
metadata.Protocol = C.ProtocolTLS
|
||||
metadata.Domain = clientHello.ServerName
|
||||
if domain := M.ParseSocksaddrHostPort(clientHello.ServerName, 0).Fqdn; domain != "" && (domain != metadata.ECHPublicName || !slices.Contains(clientHello.Extensions, extensionEncryptedClientHello)) {
|
||||
metadata.Domain = domain
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if errors.Is(err, io.ErrUnexpectedEOF) {
|
||||
|
||||
+13
-11
@@ -333,8 +333,14 @@ func parseMappedAddress(data []byte) (netip.AddrPort, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func roundTrip(conn net.PacketConn, addr net.Addr, txID TransactionID, attrs []stunAttribute, rto time.Duration) (*parsedResponse, time.Duration, error) {
|
||||
func roundTrip(conn net.PacketConn, destination M.Socksaddr, txID TransactionID, attrs []stunAttribute, rto time.Duration) (*parsedResponse, time.Duration, error) {
|
||||
request := buildBindingRequest(txID, attrs...)
|
||||
var addr net.Addr
|
||||
if destination.IsIP() {
|
||||
addr = destination.UDPAddr()
|
||||
} else {
|
||||
addr = destination
|
||||
}
|
||||
currentRTO := rto
|
||||
retransmitCount := 0
|
||||
|
||||
@@ -409,7 +415,6 @@ func Run(options Options) (*Result, error) {
|
||||
|
||||
var (
|
||||
packetConn net.PacketConn
|
||||
serverAddr net.Addr
|
||||
err error
|
||||
)
|
||||
|
||||
@@ -418,17 +423,16 @@ func Run(options Options) (*Result, error) {
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "create UDP socket")
|
||||
}
|
||||
serverAddr = serverSocksaddr
|
||||
} else {
|
||||
serverUDPAddr, resolveErr := net.ResolveUDPAddr("udp", serverSocksaddr.String())
|
||||
if resolveErr != nil {
|
||||
return nil, E.Cause(resolveErr, "resolve STUN server")
|
||||
}
|
||||
serverSocksaddr = M.SocksaddrFromNet(serverUDPAddr).Unwrap()
|
||||
packetConn, err = net.ListenPacket("udp", "")
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "create UDP socket")
|
||||
}
|
||||
serverAddr = serverUDPAddr
|
||||
}
|
||||
defer func() {
|
||||
_ = packetConn.Close()
|
||||
@@ -449,7 +453,7 @@ func Run(options Options) (*Result, error) {
|
||||
reportProgress(Progress{Phase: PhaseBinding})
|
||||
|
||||
txID := newTransactionID()
|
||||
resp, latency, err := roundTrip(packetConn, serverAddr, txID, nil, rto)
|
||||
resp, latency, err := roundTrip(packetConn, serverSocksaddr, txID, nil, rto)
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "binding request")
|
||||
}
|
||||
@@ -522,7 +526,7 @@ func Run(options Options) (*Result, error) {
|
||||
NATMapping: result.NATMapping,
|
||||
})
|
||||
|
||||
result.NATFiltering = detectNATFiltering(packetConn, serverAddr, rto)
|
||||
result.NATFiltering = detectNATFiltering(packetConn, serverSocksaddr, rto)
|
||||
|
||||
reportProgress(Progress{
|
||||
Phase: PhaseDone,
|
||||
@@ -543,9 +547,7 @@ func detectNATMapping(
|
||||
rto time.Duration,
|
||||
) NATMapping {
|
||||
// Mapping Test II: Send to other_ip:server_port
|
||||
testIIAddr := net.UDPAddrFromAddrPort(
|
||||
netip.AddrPortFrom(otherAddr.Addr(), serverPort),
|
||||
)
|
||||
testIIAddr := M.SocksaddrFrom(otherAddr.Addr(), serverPort)
|
||||
txID2 := newTransactionID()
|
||||
resp2, _, err := roundTrip(conn, testIIAddr, txID2, nil, rto)
|
||||
if err != nil {
|
||||
@@ -562,7 +564,7 @@ func detectNATMapping(
|
||||
}
|
||||
|
||||
// Mapping Test III: Send to other_ip:other_port
|
||||
testIIIAddr := net.UDPAddrFromAddrPort(otherAddr)
|
||||
testIIIAddr := M.SocksaddrFromNetIP(otherAddr)
|
||||
txID3 := newTransactionID()
|
||||
resp3, _, err := roundTrip(conn, testIIIAddr, txID3, nil, rto)
|
||||
if err != nil {
|
||||
@@ -582,7 +584,7 @@ func detectNATMapping(
|
||||
|
||||
func detectNATFiltering(
|
||||
conn net.PacketConn,
|
||||
serverAddr net.Addr,
|
||||
serverAddr M.Socksaddr,
|
||||
rto time.Duration,
|
||||
) NATFiltering {
|
||||
// Filtering Test II: Request response from different IP and port
|
||||
|
||||
+15
-18
@@ -9,7 +9,6 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
@@ -32,6 +31,7 @@ type acmeWrapper struct {
|
||||
zapLogger *zap.Logger
|
||||
dataDirectory string
|
||||
domain []string
|
||||
nextProtos []string
|
||||
}
|
||||
|
||||
func (w *acmeWrapper) Start() error {
|
||||
@@ -70,7 +70,11 @@ func (w *acmeWrapper) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certifica
|
||||
return w.cfg.GetCertificate(hello)
|
||||
}
|
||||
|
||||
func startACME(ctx context.Context, logger logger.Logger, options option.InboundACMEOptions) (*tls.Config, adapter.SimpleLifecycle, error) {
|
||||
func (w *acmeWrapper) GetACMENextProtos() []string {
|
||||
return w.nextProtos
|
||||
}
|
||||
|
||||
func startACME(ctx context.Context, logger logger.Logger, options option.InboundACMEOptions) (managedCertificateProvider, error) {
|
||||
var acmeServer string
|
||||
switch options.Provider {
|
||||
case "", "letsencrypt":
|
||||
@@ -79,7 +83,7 @@ func startACME(ctx context.Context, logger logger.Logger, options option.Inbound
|
||||
acmeServer = certmagic.ZeroSSLProductionCA
|
||||
default:
|
||||
if !strings.HasPrefix(options.Provider, "https://") {
|
||||
return nil, nil, E.New("unsupported acme provider: " + options.Provider)
|
||||
return nil, E.New("unsupported acme provider: " + options.Provider)
|
||||
}
|
||||
acmeServer = options.Provider
|
||||
}
|
||||
@@ -146,7 +150,7 @@ func startACME(ctx context.Context, logger logger.Logger, options option.Inbound
|
||||
ServerURL: dnsOptions.ACMEDNSOptions.ServerURL,
|
||||
}
|
||||
default:
|
||||
return nil, nil, E.New("unsupported ACME DNS01 provider type: " + dnsOptions.Provider)
|
||||
return nil, E.New("unsupported ACME DNS01 provider type: " + dnsOptions.Provider)
|
||||
}
|
||||
acmeConfig.DNS01Solver = &solver
|
||||
}
|
||||
@@ -154,23 +158,16 @@ func startACME(ctx context.Context, logger logger.Logger, options option.Inbound
|
||||
acmeConfig.ExternalAccount = (*acme.EAB)(options.ExternalAccount)
|
||||
}
|
||||
config.Issuers = []certmagic.Issuer{certmagic.NewACMEIssuer(config, acmeConfig)}
|
||||
wrapper := &acmeWrapper{
|
||||
var nextProtos []string
|
||||
if !acmeConfig.DisableTLSALPNChallenge && acmeConfig.DNS01Solver == nil {
|
||||
nextProtos = []string{C.ACMETLS1Protocol}
|
||||
}
|
||||
return &acmeWrapper{
|
||||
ctx: ctx,
|
||||
cfg: config,
|
||||
zapLogger: zapLogger,
|
||||
dataDirectory: dataDirectory,
|
||||
domain: options.Domain,
|
||||
}
|
||||
var tlsConfig *tls.Config
|
||||
if acmeConfig.DisableTLSALPNChallenge || acmeConfig.DNS01Solver != nil {
|
||||
tlsConfig = &tls.Config{
|
||||
GetCertificate: wrapper.GetCertificate,
|
||||
}
|
||||
} else {
|
||||
tlsConfig = &tls.Config{
|
||||
GetCertificate: wrapper.GetCertificate,
|
||||
NextProtos: []string{C.ACMETLS1Protocol},
|
||||
}
|
||||
}
|
||||
return tlsConfig, wrapper, nil
|
||||
nextProtos: nextProtos,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -4,14 +4,12 @@ package tls
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/logger"
|
||||
)
|
||||
|
||||
func startACME(ctx context.Context, logger logger.Logger, options option.InboundACMEOptions) (*tls.Config, adapter.SimpleLifecycle, error) {
|
||||
return nil, nil, E.New(`ACME is not included in this build, rebuild with -tags with_acme`)
|
||||
func startACME(ctx context.Context, logger logger.Logger, options option.InboundACMEOptions) (managedCertificateProvider, error) {
|
||||
return nil, E.New(`ACME is not included in this build, rebuild with -tags with_acme`)
|
||||
}
|
||||
|
||||
@@ -43,17 +43,6 @@ func (c *appleClientConfig) ClientHandshake(ctx context.Context, conn net.Conn)
|
||||
return nil, E.Cause(err, "access raw connection")
|
||||
}
|
||||
|
||||
var dupFD int
|
||||
controlErr := syscallConn.Control(func(fd uintptr) {
|
||||
dupFD, err = unix.Dup(int(fd))
|
||||
})
|
||||
if controlErr != nil {
|
||||
return nil, E.Cause(controlErr, "access raw connection")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "duplicate raw connection")
|
||||
}
|
||||
|
||||
serverName := c.serverName
|
||||
serverNamePtr := cStringOrNil(serverName)
|
||||
defer cFree(serverNamePtr)
|
||||
@@ -68,6 +57,7 @@ func (c *appleClientConfig) ClientHandshake(ctx context.Context, conn net.Conn)
|
||||
}
|
||||
var anchorsRef unsafe.Pointer
|
||||
if anchors != nil {
|
||||
defer anchors.Release()
|
||||
anchorsRef = anchors.Ref()
|
||||
}
|
||||
|
||||
@@ -80,6 +70,17 @@ func (c *appleClientConfig) ClientHandshake(ctx context.Context, conn net.Conn)
|
||||
verifyTimeUnixMilli = c.timeFunc().UnixMilli()
|
||||
}
|
||||
|
||||
var dupFD int
|
||||
controlErr := syscallConn.Control(func(fd uintptr) {
|
||||
dupFD, err = unix.FcntlInt(fd, unix.F_DUPFD_CLOEXEC, 0)
|
||||
})
|
||||
if controlErr != nil {
|
||||
return nil, E.Cause(controlErr, "access raw connection")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "duplicate raw connection")
|
||||
}
|
||||
|
||||
var errorPtr *C.char
|
||||
client := C.box_apple_tls_client_create(
|
||||
C.int(dupFD),
|
||||
@@ -95,9 +96,6 @@ func (c *appleClientConfig) ClientHandshake(ctx context.Context, conn net.Conn)
|
||||
C.int64_t(verifyTimeUnixMilli),
|
||||
&errorPtr,
|
||||
)
|
||||
if anchors != nil {
|
||||
anchors.Release()
|
||||
}
|
||||
if client == nil {
|
||||
if errorPtr != nil {
|
||||
defer C.free(unsafe.Pointer(errorPtr))
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#import <string.h>
|
||||
#import <unistd.h>
|
||||
|
||||
typedef nw_connection_t _Nullable (*box_nw_connection_create_with_connected_socket_and_parameters_f)(int connected_socket, nw_parameters_t parameters);
|
||||
typedef nw_connection_t _Nullable (*box_nw_connection_create_with_connected_socket_and_parameters_f)(int connected_socket, nw_parameters_t parameters) NW_RETURNS_RETAINED;
|
||||
typedef const char * _Nullable (*box_sec_protocol_metadata_string_accessor_f)(sec_protocol_metadata_t metadata);
|
||||
|
||||
typedef struct box_apple_tls_client {
|
||||
@@ -367,104 +367,106 @@ box_apple_tls_client_t *box_apple_tls_client_create(
|
||||
int64_t verify_time_unix_millis,
|
||||
char **error_out
|
||||
) {
|
||||
box_apple_tls_client_t *client = calloc(1, sizeof(box_apple_tls_client_t));
|
||||
if (client == NULL) {
|
||||
close(connected_socket);
|
||||
box_set_error_message(error_out, "apple TLS: out of memory");
|
||||
return NULL;
|
||||
}
|
||||
client->queue = (__bridge_retained void *)dispatch_queue_create("sing-box.apple-private-tls", DISPATCH_QUEUE_SERIAL);
|
||||
client->ready_semaphore = (__bridge_retained void *)dispatch_semaphore_create(0);
|
||||
atomic_init(&client->ref_count, 1);
|
||||
atomic_init(&client->ready, false);
|
||||
atomic_init(&client->ready_done, false);
|
||||
if (anchors_cf != NULL) {
|
||||
client->anchors = (void *)CFRetain(anchors_cf);
|
||||
}
|
||||
@autoreleasepool {
|
||||
box_apple_tls_client_t *client = calloc(1, sizeof(box_apple_tls_client_t));
|
||||
if (client == NULL) {
|
||||
close(connected_socket);
|
||||
box_set_error_message(error_out, "apple TLS: out of memory");
|
||||
return NULL;
|
||||
}
|
||||
client->queue = (__bridge_retained void *)dispatch_queue_create("sing-box.apple-private-tls", DISPATCH_QUEUE_SERIAL);
|
||||
client->ready_semaphore = (__bridge_retained void *)dispatch_semaphore_create(0);
|
||||
atomic_init(&client->ref_count, 1);
|
||||
atomic_init(&client->ready, false);
|
||||
atomic_init(&client->ready_done, false);
|
||||
if (anchors_cf != NULL) {
|
||||
client->anchors = (void *)CFRetain(anchors_cf);
|
||||
}
|
||||
|
||||
NSArray<NSString *> *alpnList = box_split_lines(alpn, alpn_len);
|
||||
NSDate *verifyDate = nil;
|
||||
if (has_verify_time) {
|
||||
verifyDate = [NSDate dateWithTimeIntervalSince1970:(NSTimeInterval)verify_time_unix_millis / 1000.0];
|
||||
}
|
||||
nw_parameters_t parameters = nw_parameters_create_secure_tcp(^(nw_protocol_options_t tls_options) {
|
||||
sec_protocol_options_t sec_options = nw_tls_copy_sec_protocol_options(tls_options);
|
||||
if (min_version != 0) {
|
||||
sec_protocol_options_set_min_tls_protocol_version(sec_options, (tls_protocol_version_t)min_version);
|
||||
NSArray<NSString *> *alpnList = box_split_lines(alpn, alpn_len);
|
||||
NSDate *verifyDate = nil;
|
||||
if (has_verify_time) {
|
||||
verifyDate = [NSDate dateWithTimeIntervalSince1970:(NSTimeInterval)verify_time_unix_millis / 1000.0];
|
||||
}
|
||||
if (max_version != 0) {
|
||||
sec_protocol_options_set_max_tls_protocol_version(sec_options, (tls_protocol_version_t)max_version);
|
||||
}
|
||||
if (server_name != NULL && server_name[0] != '\0') {
|
||||
sec_protocol_options_set_tls_server_name(sec_options, server_name);
|
||||
}
|
||||
for (NSString *protocol in alpnList) {
|
||||
sec_protocol_options_add_tls_application_protocol(sec_options, protocol.UTF8String);
|
||||
}
|
||||
sec_protocol_options_set_peer_authentication_required(sec_options, !insecure);
|
||||
sec_protocol_options_set_verify_block(sec_options, ^(sec_protocol_metadata_t metadata, sec_trust_t trust, sec_protocol_verify_complete_t complete) {
|
||||
if (client->state.version == 0) {
|
||||
box_apple_tls_state_load(metadata, &client->state);
|
||||
nw_parameters_t parameters = nw_parameters_create_secure_tcp(^(nw_protocol_options_t tls_options) {
|
||||
sec_protocol_options_t sec_options = nw_tls_copy_sec_protocol_options(tls_options);
|
||||
if (min_version != 0) {
|
||||
sec_protocol_options_set_min_tls_protocol_version(sec_options, (tls_protocol_version_t)min_version);
|
||||
}
|
||||
complete(insecure || box_evaluate_trust(trust, box_apple_tls_client_anchors(client), anchor_only, verifyDate));
|
||||
}, box_apple_tls_client_queue(client));
|
||||
}, NW_PARAMETERS_DEFAULT_CONFIGURATION);
|
||||
|
||||
nw_connection_t connection = box_apple_tls_create_connection(connected_socket, parameters);
|
||||
if (connection == NULL) {
|
||||
close(connected_socket);
|
||||
if (client->anchors != NULL) {
|
||||
CFRelease((CFTypeRef)client->anchors);
|
||||
}
|
||||
if (client->ready_semaphore != NULL) {
|
||||
CFBridgingRelease(client->ready_semaphore);
|
||||
}
|
||||
if (client->queue != NULL) {
|
||||
CFBridgingRelease(client->queue);
|
||||
}
|
||||
free(client);
|
||||
box_set_error_message(error_out, "apple TLS: failed to create connection");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
client->connection = (__bridge_retained void *)connection;
|
||||
atomic_fetch_add(&client->ref_count, 1);
|
||||
|
||||
nw_connection_set_state_changed_handler(connection, ^(nw_connection_state_t state, nw_error_t error) {
|
||||
switch (state) {
|
||||
case nw_connection_state_ready:
|
||||
if (!atomic_load(&client->ready_done)) {
|
||||
if (max_version != 0) {
|
||||
sec_protocol_options_set_max_tls_protocol_version(sec_options, (tls_protocol_version_t)max_version);
|
||||
}
|
||||
if (server_name != NULL && server_name[0] != '\0') {
|
||||
sec_protocol_options_set_tls_server_name(sec_options, server_name);
|
||||
}
|
||||
for (NSString *protocol in alpnList) {
|
||||
sec_protocol_options_add_tls_application_protocol(sec_options, protocol.UTF8String);
|
||||
}
|
||||
sec_protocol_options_set_peer_authentication_required(sec_options, !insecure);
|
||||
sec_protocol_options_set_verify_block(sec_options, ^(sec_protocol_metadata_t metadata, sec_trust_t trust, sec_protocol_verify_complete_t complete) {
|
||||
if (client->state.version == 0) {
|
||||
box_set_error_message(&client->ready_error, "apple TLS: metadata unavailable");
|
||||
} else {
|
||||
atomic_store(&client->ready, true);
|
||||
box_apple_tls_state_load(metadata, &client->state);
|
||||
}
|
||||
atomic_store(&client->ready_done, true);
|
||||
dispatch_semaphore_signal(box_apple_tls_ready_semaphore(client));
|
||||
complete(insecure || box_evaluate_trust(trust, box_apple_tls_client_anchors(client), anchor_only, verifyDate));
|
||||
}, box_apple_tls_client_queue(client));
|
||||
}, NW_PARAMETERS_DEFAULT_CONFIGURATION);
|
||||
|
||||
nw_connection_t connection = box_apple_tls_create_connection(connected_socket, parameters);
|
||||
if (connection == NULL) {
|
||||
close(connected_socket);
|
||||
if (client->anchors != NULL) {
|
||||
CFRelease((CFTypeRef)client->anchors);
|
||||
}
|
||||
break;
|
||||
case nw_connection_state_failed:
|
||||
if (!atomic_load(&client->ready_done)) {
|
||||
box_set_error_from_nw_error(&client->ready_error, error);
|
||||
atomic_store(&client->ready_done, true);
|
||||
dispatch_semaphore_signal(box_apple_tls_ready_semaphore(client));
|
||||
if (client->ready_semaphore != NULL) {
|
||||
CFBridgingRelease(client->ready_semaphore);
|
||||
}
|
||||
break;
|
||||
case nw_connection_state_cancelled:
|
||||
if (!atomic_load(&client->ready_done)) {
|
||||
box_set_error_from_nw_error(&client->ready_error, error);
|
||||
atomic_store(&client->ready_done, true);
|
||||
dispatch_semaphore_signal(box_apple_tls_ready_semaphore(client));
|
||||
if (client->queue != NULL) {
|
||||
CFBridgingRelease(client->queue);
|
||||
}
|
||||
box_apple_tls_client_release(client);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
free(client);
|
||||
box_set_error_message(error_out, "apple TLS: failed to create connection");
|
||||
return NULL;
|
||||
}
|
||||
});
|
||||
nw_connection_set_queue(connection, box_apple_tls_client_queue(client));
|
||||
nw_connection_start(connection);
|
||||
return client;
|
||||
|
||||
client->connection = (__bridge_retained void *)connection;
|
||||
atomic_fetch_add(&client->ref_count, 1);
|
||||
|
||||
nw_connection_set_state_changed_handler(connection, ^(nw_connection_state_t state, nw_error_t error) {
|
||||
switch (state) {
|
||||
case nw_connection_state_ready:
|
||||
if (!atomic_load(&client->ready_done)) {
|
||||
if (client->state.version == 0) {
|
||||
box_set_error_message(&client->ready_error, "apple TLS: metadata unavailable");
|
||||
} else {
|
||||
atomic_store(&client->ready, true);
|
||||
}
|
||||
atomic_store(&client->ready_done, true);
|
||||
dispatch_semaphore_signal(box_apple_tls_ready_semaphore(client));
|
||||
}
|
||||
break;
|
||||
case nw_connection_state_failed:
|
||||
if (!atomic_load(&client->ready_done)) {
|
||||
box_set_error_from_nw_error(&client->ready_error, error);
|
||||
atomic_store(&client->ready_done, true);
|
||||
dispatch_semaphore_signal(box_apple_tls_ready_semaphore(client));
|
||||
}
|
||||
break;
|
||||
case nw_connection_state_cancelled:
|
||||
if (!atomic_load(&client->ready_done)) {
|
||||
box_set_error_from_nw_error(&client->ready_error, error);
|
||||
atomic_store(&client->ready_done, true);
|
||||
dispatch_semaphore_signal(box_apple_tls_ready_semaphore(client));
|
||||
}
|
||||
box_apple_tls_client_release(client);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
nw_connection_set_queue(connection, box_apple_tls_client_queue(client));
|
||||
nw_connection_start(connection);
|
||||
return client;
|
||||
}
|
||||
}
|
||||
|
||||
int box_apple_tls_client_wait_ready(box_apple_tls_client_t *client, int timeout_msec, char **error_out) {
|
||||
|
||||
+28
-20
@@ -45,16 +45,11 @@ func applyTLSSpoof(conn net.Conn, spoof string, method tlsspoof.Method) (net.Con
|
||||
return tlsspoof.NewConn(conn, method, spoof)
|
||||
}
|
||||
|
||||
func NewDialerFromOptions(ctx context.Context, logger logger.ContextLogger, dialer N.Dialer, serverAddress string, options option.OutboundTLSOptions) (N.Dialer, error) {
|
||||
if !options.Enabled {
|
||||
func NewDialerFromOptions(dialer N.Dialer, options ClientOptions) (N.Dialer, error) {
|
||||
if !options.Options.Enabled {
|
||||
return dialer, nil
|
||||
}
|
||||
config, err := NewClientWithOptions(ClientOptions{
|
||||
Context: ctx,
|
||||
Logger: logger,
|
||||
ServerAddress: serverAddress,
|
||||
Options: options,
|
||||
})
|
||||
config, err := NewClientWithOptions(options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -77,6 +72,8 @@ type ClientOptions struct {
|
||||
Options option.OutboundTLSOptions
|
||||
AllowEmptyServerName bool
|
||||
KTLSCompatible bool
|
||||
DomainResolver *option.DomainResolveOptions
|
||||
DirectResolver bool
|
||||
}
|
||||
|
||||
func NewClientWithOptions(options ClientOptions) (Config, error) {
|
||||
@@ -103,9 +100,9 @@ func NewClientWithOptions(options ClientOptions) (Config, error) {
|
||||
if options.Options.Reality != nil && options.Options.Reality.Enabled {
|
||||
return newRealityClient(options.Context, options.Logger, options.ServerAddress, options.Options, options.AllowEmptyServerName)
|
||||
} else if options.Options.UTLS != nil && options.Options.UTLS.Enabled {
|
||||
return newUTLSClient(options.Context, options.Logger, options.ServerAddress, options.Options, options.AllowEmptyServerName)
|
||||
return newUTLSClient(options.Context, options.Logger, options.ServerAddress, options.Options, options.AllowEmptyServerName, options.DomainResolver, options.DirectResolver)
|
||||
}
|
||||
return newSTDClient(options.Context, options.Logger, options.ServerAddress, options.Options, options.AllowEmptyServerName)
|
||||
return newSTDClient(options.Context, options.Logger, options.ServerAddress, options.Options, options.AllowEmptyServerName, options.DomainResolver, options.DirectResolver)
|
||||
}
|
||||
|
||||
func ClientHandshake(ctx context.Context, conn net.Conn, config Config) (Conn, error) {
|
||||
@@ -148,24 +145,35 @@ func (d *defaultDialer) ListenPacket(ctx context.Context, destination M.Socksadd
|
||||
}
|
||||
|
||||
func (d *defaultDialer) DialTLSContext(ctx context.Context, destination M.Socksaddr) (Conn, error) {
|
||||
return d.dialContext(ctx, destination, true)
|
||||
tlsConn, err := d.dialContext(ctx, destination, d.config)
|
||||
if err == nil {
|
||||
return tlsConn, nil
|
||||
}
|
||||
var echErr *tls.ECHRejectionError
|
||||
if !errors.As(err, &echErr) || len(echErr.RetryConfigList) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
retryConfig := d.config.Clone()
|
||||
echTarget := retryConfig
|
||||
if kTLSConfig, isKTLS := echTarget.(*KTLSClientConfig); isKTLS {
|
||||
echTarget = kTLSConfig.Config
|
||||
}
|
||||
echConfig, isECH := echTarget.(ECHCapableConfig)
|
||||
if !isECH {
|
||||
return nil, err
|
||||
}
|
||||
echConfig.SetECHConfigList(echErr.RetryConfigList)
|
||||
return d.dialContext(ctx, destination, retryConfig)
|
||||
}
|
||||
|
||||
func (d *defaultDialer) dialContext(ctx context.Context, destination M.Socksaddr, echRetry bool) (Conn, error) {
|
||||
func (d *defaultDialer) dialContext(ctx context.Context, destination M.Socksaddr, config Config) (Conn, error) {
|
||||
conn, err := d.dialer.DialContext(ctx, N.NetworkTCP, destination)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tlsConn, err := aTLS.ClientHandshake(ctx, conn, d.config)
|
||||
tlsConn, err := aTLS.ClientHandshake(ctx, conn, config)
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
var echErr *tls.ECHRejectionError
|
||||
if echRetry && errors.As(err, &echErr) && len(echErr.RetryConfigList) > 0 {
|
||||
if echConfig, isECH := d.config.(ECHCapableConfig); isECH {
|
||||
echConfig.SetECHConfigList(echErr.RetryConfigList)
|
||||
return d.dialContext(ctx, destination, false)
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return tlsConn, nil
|
||||
|
||||
+126
-51
@@ -5,7 +5,6 @@ package tls
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"encoding/pem"
|
||||
"net"
|
||||
"strings"
|
||||
@@ -13,6 +12,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/common/dialer"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/dns"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
@@ -24,7 +25,7 @@ import (
|
||||
"golang.org/x/crypto/cryptobyte"
|
||||
)
|
||||
|
||||
func parseECHClientConfig(ctx context.Context, clientConfig ECHCapableConfig, options option.OutboundTLSOptions) (Config, error) {
|
||||
func parseECHClientConfig(ctx context.Context, clientConfig ECHCapableConfig, options option.OutboundTLSOptions, domainResolver *option.DomainResolveOptions, directResolver bool) (Config, error) {
|
||||
var echConfig []byte
|
||||
if len(options.ECH.Config) > 0 {
|
||||
echConfig = []byte(strings.Join(options.ECH.Config, "\n"))
|
||||
@@ -47,10 +48,18 @@ func parseECHClientConfig(ctx context.Context, clientConfig ECHCapableConfig, op
|
||||
clientConfig.SetECHConfigList(block.Bytes)
|
||||
return clientConfig, nil
|
||||
} else {
|
||||
if directResolver && (domainResolver == nil || domainResolver.Server == "") {
|
||||
return nil, E.New("missing domain resolver for ECH config query")
|
||||
}
|
||||
return &ECHClientConfig{
|
||||
ECHCapableConfig: clientConfig,
|
||||
ctx: ctx,
|
||||
dnsRouter: service.FromContext[adapter.DNSRouter](ctx),
|
||||
domainResolver: domainResolver,
|
||||
queryServerName: options.ECH.QueryServerName,
|
||||
state: &echClientState{
|
||||
entries: make(map[string]echClientEntry),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
@@ -106,17 +115,31 @@ func parseECHKeys(echKey []byte) ([]tls.EncryptedClientHelloKey, error) {
|
||||
return echKeys, nil
|
||||
}
|
||||
|
||||
type echClientState struct {
|
||||
access sync.Mutex
|
||||
entries map[string]echClientEntry
|
||||
}
|
||||
|
||||
type echClientEntry struct {
|
||||
configList []byte
|
||||
expireAt time.Time
|
||||
}
|
||||
|
||||
type ECHClientConfig struct {
|
||||
ECHCapableConfig
|
||||
access sync.Mutex
|
||||
ctx context.Context
|
||||
dnsRouter adapter.DNSRouter
|
||||
domainResolver *option.DomainResolveOptions
|
||||
queryServerName string
|
||||
lastTTL time.Duration
|
||||
lastUpdate time.Time
|
||||
state *echClientState
|
||||
}
|
||||
|
||||
func (s *ECHClientConfig) ClientHandshake(ctx context.Context, conn net.Conn) (aTLS.Conn, error) {
|
||||
tlsConn, err := s.fetchAndHandshake(ctx, conn)
|
||||
tlsConfig, err := s.handshakeConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tlsConn, err := tlsConfig.Client(conn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -127,64 +150,116 @@ func (s *ECHClientConfig) ClientHandshake(ctx context.Context, conn net.Conn) (a
|
||||
return tlsConn, nil
|
||||
}
|
||||
|
||||
func (s *ECHClientConfig) fetchAndHandshake(ctx context.Context, conn net.Conn) (aTLS.Conn, error) {
|
||||
s.access.Lock()
|
||||
defer s.access.Unlock()
|
||||
if len(s.ECHConfigList()) == 0 || s.lastTTL == 0 || time.Since(s.lastUpdate) > s.lastTTL {
|
||||
queryServerName := s.queryServerName
|
||||
if queryServerName == "" {
|
||||
queryServerName = s.ServerName()
|
||||
func (s *ECHClientConfig) handshakeConfig(ctx context.Context) (ECHCapableConfig, error) {
|
||||
echConfigList, err := s.loadECHConfigList(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tlsConfig := s.ECHCapableConfig.Clone().(ECHCapableConfig)
|
||||
tlsConfig.SetECHConfigList(echConfigList)
|
||||
return tlsConfig, nil
|
||||
}
|
||||
|
||||
func (s *ECHClientConfig) echQueryServerName() string {
|
||||
if s.queryServerName != "" {
|
||||
return s.queryServerName
|
||||
}
|
||||
return s.ServerName()
|
||||
}
|
||||
|
||||
func (s *ECHClientConfig) loadECHConfigList(ctx context.Context) ([]byte, error) {
|
||||
queryServerName := s.echQueryServerName()
|
||||
s.state.access.Lock()
|
||||
cachedEntry := s.state.entries[queryServerName]
|
||||
s.state.access.Unlock()
|
||||
if time.Now().Before(cachedEntry.expireAt) {
|
||||
return cachedEntry.configList, nil
|
||||
}
|
||||
queryOptions, err := dialer.NewDNSQueryOptions(s.ctx, s.domainResolver, true)
|
||||
if err != nil {
|
||||
if s.domainResolver == nil || s.domainResolver.Server == "" {
|
||||
return nil, E.Cause(err, "fetch ECH config list for ", queryServerName, ": ECH config query requires `domain_resolver` or `route.default_domain_resolver`")
|
||||
}
|
||||
message := &mDNS.Msg{
|
||||
MsgHdr: mDNS.MsgHdr{
|
||||
RecursionDesired: true,
|
||||
},
|
||||
Question: []mDNS.Question{
|
||||
{
|
||||
Name: mDNS.Fqdn(queryServerName),
|
||||
Qtype: mDNS.TypeHTTPS,
|
||||
Qclass: mDNS.ClassINET,
|
||||
},
|
||||
return nil, E.Cause(err, "fetch ECH config list for ", queryServerName)
|
||||
}
|
||||
message := &mDNS.Msg{
|
||||
MsgHdr: mDNS.MsgHdr{
|
||||
RecursionDesired: true,
|
||||
},
|
||||
Question: []mDNS.Question{
|
||||
{
|
||||
Name: mDNS.Fqdn(queryServerName),
|
||||
Qtype: mDNS.TypeHTTPS,
|
||||
Qclass: mDNS.ClassINET,
|
||||
},
|
||||
},
|
||||
}
|
||||
response, err := s.dnsRouter.Exchange(ctx, message, queryOptions)
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "fetch ECH config list for ", queryServerName)
|
||||
}
|
||||
if response.Rcode != mDNS.RcodeSuccess {
|
||||
return nil, E.Cause(dns.RcodeError(response.Rcode), "fetch ECH config list for ", queryServerName)
|
||||
}
|
||||
var (
|
||||
echConfigList []byte
|
||||
timeToLive time.Duration
|
||||
)
|
||||
match:
|
||||
for _, rr := range response.Answer {
|
||||
record, isHTTPS := rr.(*mDNS.HTTPS)
|
||||
if !isHTTPS {
|
||||
continue
|
||||
}
|
||||
response, err := s.dnsRouter.Exchange(ctx, message, adapter.DNSQueryOptions{})
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "fetch ECH config list")
|
||||
}
|
||||
if response.Rcode != mDNS.RcodeSuccess {
|
||||
return nil, E.Cause(dns.RcodeError(response.Rcode), "fetch ECH config list")
|
||||
}
|
||||
match:
|
||||
for _, rr := range response.Answer {
|
||||
switch resource := rr.(type) {
|
||||
case *mDNS.HTTPS:
|
||||
for _, value := range resource.Value {
|
||||
if value.Key().String() == "ech" {
|
||||
echConfigList, err := base64.StdEncoding.DecodeString(value.String())
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "decode ECH config")
|
||||
}
|
||||
s.lastTTL = time.Duration(rr.Header().Ttl) * time.Second
|
||||
s.lastUpdate = time.Now()
|
||||
s.SetECHConfigList(echConfigList)
|
||||
break match
|
||||
}
|
||||
}
|
||||
for _, value := range record.Value {
|
||||
echConfig, isECHConfig := value.(*mDNS.SVCBECHConfig)
|
||||
if isECHConfig && len(echConfig.ECH) > 0 {
|
||||
echConfigList = echConfig.ECH
|
||||
timeToLive = time.Duration(rr.Header().Ttl) * time.Second
|
||||
break match
|
||||
}
|
||||
}
|
||||
if len(s.ECHConfigList()) == 0 {
|
||||
return nil, E.New("no ECH config found in DNS records")
|
||||
}
|
||||
}
|
||||
return s.Client(conn)
|
||||
if len(echConfigList) == 0 {
|
||||
return nil, E.New("no ECH config found in DNS records for ", queryServerName)
|
||||
}
|
||||
s.state.access.Lock()
|
||||
defer s.state.access.Unlock()
|
||||
currentEntry := s.state.entries[queryServerName]
|
||||
if currentEntry.expireAt.Equal(cachedEntry.expireAt) {
|
||||
currentEntry = echClientEntry{
|
||||
configList: echConfigList,
|
||||
expireAt: time.Now().Add(timeToLive),
|
||||
}
|
||||
s.state.entries[queryServerName] = currentEntry
|
||||
}
|
||||
return currentEntry.configList, nil
|
||||
}
|
||||
|
||||
func (s *ECHClientConfig) ECHConfigList() []byte {
|
||||
s.state.access.Lock()
|
||||
defer s.state.access.Unlock()
|
||||
return s.state.entries[s.echQueryServerName()].configList
|
||||
}
|
||||
|
||||
func (s *ECHClientConfig) SetECHConfigList(echConfigList []byte) {
|
||||
queryServerName := s.echQueryServerName()
|
||||
s.state.access.Lock()
|
||||
defer s.state.access.Unlock()
|
||||
s.state.entries[queryServerName] = echClientEntry{
|
||||
configList: echConfigList,
|
||||
expireAt: time.Now().Add(C.DefaultDNSTTL * time.Second),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ECHClientConfig) Clone() Config {
|
||||
return &ECHClientConfig{
|
||||
ECHCapableConfig: s.ECHCapableConfig.Clone().(ECHCapableConfig),
|
||||
ctx: s.ctx,
|
||||
dnsRouter: s.dnsRouter,
|
||||
domainResolver: s.domainResolver,
|
||||
queryServerName: s.queryServerName,
|
||||
lastUpdate: s.lastUpdate,
|
||||
state: s.state,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
//go:build go1.24 && with_quic
|
||||
|
||||
package tls
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/sagernet/quic-go"
|
||||
"github.com/sagernet/quic-go/http3"
|
||||
qtls "github.com/sagernet/sing-quic"
|
||||
)
|
||||
|
||||
func (s *ECHClientConfig) fetchSTDConfig(ctx context.Context) (*STDConfig, error) {
|
||||
tlsConfig, err := s.handshakeConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tlsConfig.STDConfig()
|
||||
}
|
||||
|
||||
func (s *ECHClientConfig) Dial(ctx context.Context, conn net.Conn, config *quic.Config) (*quic.Conn, error) {
|
||||
tlsConfig, err := s.fetchSTDConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return quic.DialConn(ctx, conn, tlsConfig, config)
|
||||
}
|
||||
|
||||
func (s *ECHClientConfig) DialEarly(ctx context.Context, conn net.Conn, config *quic.Config) (*quic.Conn, error) {
|
||||
tlsConfig, err := s.fetchSTDConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return quic.DialEarlyConn(ctx, conn, tlsConfig, config)
|
||||
}
|
||||
|
||||
func (s *ECHClientConfig) CreateTransport(conn net.Conn, quicConnPtr **quic.Conn, quicConfig *quic.Config) http.RoundTripper {
|
||||
return s.createHTTP3Transport(quicConnPtr, quicConfig, func(ctx context.Context, tlsConfig *tls.Config, config *quic.Config) (*quic.Conn, error) {
|
||||
return quic.DialEarlyConn(ctx, conn, tlsConfig, config)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *ECHClientConfig) CreatePacketTransport(conn net.PacketConn, remoteAddr net.Addr, quicConnPtr **quic.Conn, quicConfig *quic.Config) http.RoundTripper {
|
||||
return s.createHTTP3Transport(quicConnPtr, quicConfig, func(ctx context.Context, tlsConfig *tls.Config, config *quic.Config) (*quic.Conn, error) {
|
||||
return quic.DialEarly(ctx, conn, remoteAddr, tlsConfig, config)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *ECHClientConfig) createHTTP3Transport(quicConnPtr **quic.Conn, quicConfig *quic.Config, dial func(ctx context.Context, tlsConfig *tls.Config, config *quic.Config) (*quic.Conn, error)) http.RoundTripper {
|
||||
return &http3.Transport{
|
||||
QUICConfig: quicConfig,
|
||||
Dial: func(ctx context.Context, _ string, _ *tls.Config, config *quic.Config) (*quic.Conn, error) {
|
||||
tlsConfig, err := s.fetchSTDConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tlsConfig.NextProtos = []string{http3.NextProtoH3}
|
||||
quicConn, err := dial(ctx, tlsConfig, config)
|
||||
if err != nil {
|
||||
return nil, qtls.WrapError(err)
|
||||
}
|
||||
*quicConnPtr = quicConn
|
||||
return quicConn, nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
var _ qtls.Config = (*ECHClientConfig)(nil)
|
||||
@@ -27,14 +27,13 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
"github.com/sagernet/sing/common"
|
||||
"github.com/sagernet/sing/common/debug"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/logger"
|
||||
"github.com/sagernet/sing/common/ntp"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
aTLS "github.com/sagernet/sing/common/tls"
|
||||
|
||||
utls "github.com/metacubex/utls"
|
||||
@@ -45,7 +44,6 @@ import (
|
||||
var _ ConfigCompat = (*RealityClientConfig)(nil)
|
||||
|
||||
type RealityClientConfig struct {
|
||||
ctx context.Context
|
||||
uClient *UTLSClientConfig
|
||||
publicKey []byte
|
||||
shortID [8]byte
|
||||
@@ -64,7 +62,7 @@ func newRealityClient(ctx context.Context, logger logger.ContextLogger, serverAd
|
||||
return nil, E.New("spoof is unsupported in reality")
|
||||
}
|
||||
|
||||
uClient, err := newUTLSClient(ctx, logger, serverAddress, options, allowEmptyServerName)
|
||||
uClient, err := newUTLSClient(ctx, logger, serverAddress, options, allowEmptyServerName, nil, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -85,7 +83,7 @@ func newRealityClient(ctx context.Context, logger logger.ContextLogger, serverAd
|
||||
return nil, E.New("invalid short_id")
|
||||
}
|
||||
|
||||
var config Config = &RealityClientConfig{ctx, uClient.(*UTLSClientConfig), publicKey, shortID, options.Reality.SupportX25519MLKEM768}
|
||||
var config Config = &RealityClientConfig{uClient.(*UTLSClientConfig), publicKey, shortID, options.Reality.SupportX25519MLKEM768}
|
||||
if options.KernelRx || options.KernelTx {
|
||||
if !C.IsLinux {
|
||||
return nil, E.New("kTLS is only supported on Linux")
|
||||
@@ -133,10 +131,18 @@ func (e *RealityClientConfig) Client(conn net.Conn) (Conn, error) {
|
||||
}
|
||||
|
||||
func (e *RealityClientConfig) ClientHandshake(ctx context.Context, conn net.Conn) (aTLS.Conn, error) {
|
||||
verifier := &realityVerifier{
|
||||
serverName: e.uClient.ServerName(),
|
||||
}
|
||||
uConfig := e.uClient.config.Clone()
|
||||
var nowTime time.Time
|
||||
if uConfig.Time != nil {
|
||||
nowTime = uConfig.Time()
|
||||
} else {
|
||||
nowTime = time.Now()
|
||||
}
|
||||
verifier := &realityVerifier{
|
||||
serverName: e.uClient.ServerName(),
|
||||
rootCAs: uConfig.RootCAs,
|
||||
currentTime: nowTime,
|
||||
}
|
||||
uConfig.InsecureSkipVerify = true
|
||||
uConfig.SessionTicketsDisabled = true
|
||||
uConfig.VerifyPeerCertificate = verifier.VerifyPeerCertificate
|
||||
@@ -148,13 +154,13 @@ func (e *RealityClientConfig) ClientHandshake(ctx context.Context, conn net.Conn
|
||||
}
|
||||
if !e.supportX25519MLKEM768 {
|
||||
for _, extension := range uConn.Extensions {
|
||||
if ce, ok := extension.(*utls.SupportedCurvesExtension); ok {
|
||||
ce.Curves = common.Filter(ce.Curves, func(curveID utls.CurveID) bool {
|
||||
if curves, loaded := extension.(*utls.SupportedCurvesExtension); loaded {
|
||||
curves.Curves = common.Filter(curves.Curves, func(curveID utls.CurveID) bool {
|
||||
return curveID != utls.X25519MLKEM768
|
||||
})
|
||||
}
|
||||
if ks, ok := extension.(*utls.KeyShareExtension); ok {
|
||||
ks.KeyShares = common.Filter(ks.KeyShares, func(share utls.KeyShare) bool {
|
||||
if keyShares, loaded := extension.(*utls.KeyShareExtension); loaded {
|
||||
keyShares.KeyShares = common.Filter(keyShares.KeyShares, func(share utls.KeyShare) bool {
|
||||
return share.Group != utls.X25519MLKEM768
|
||||
})
|
||||
}
|
||||
@@ -165,31 +171,14 @@ func (e *RealityClientConfig) ClientHandshake(ctx context.Context, conn net.Conn
|
||||
}
|
||||
}
|
||||
|
||||
if len(uConfig.NextProtos) > 0 {
|
||||
for _, extension := range uConn.Extensions {
|
||||
if alpnExtension, isALPN := extension.(*utls.ALPNExtension); isALPN {
|
||||
alpnExtension.AlpnProtocols = uConfig.NextProtos
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hello := uConn.HandshakeState.Hello
|
||||
hello.SessionId = make([]byte, 32)
|
||||
copy(hello.Raw[39:], hello.SessionId)
|
||||
|
||||
var nowTime time.Time
|
||||
if uConfig.Time != nil {
|
||||
nowTime = uConfig.Time()
|
||||
} else {
|
||||
nowTime = time.Now()
|
||||
}
|
||||
binary.BigEndian.PutUint64(hello.SessionId, uint64(nowTime.Unix()))
|
||||
|
||||
hello.SessionId[0] = 26
|
||||
hello.SessionId[1] = 7
|
||||
hello.SessionId[2] = 11
|
||||
binary.BigEndian.PutUint32(hello.SessionId[4:], uint32(time.Now().Unix()))
|
||||
binary.BigEndian.PutUint32(hello.SessionId[4:], uint32(nowTime.Unix()))
|
||||
copy(hello.SessionId[8:], e.shortID[:])
|
||||
if debug.Enabled {
|
||||
fmt.Printf("REALITY hello.sessionId[:16]: %v\n", hello.SessionId[:16])
|
||||
@@ -237,7 +226,7 @@ func (e *RealityClientConfig) ClientHandshake(ctx context.Context, conn net.Conn
|
||||
}
|
||||
|
||||
if !verifier.verified {
|
||||
go realityClientFallback(e.ctx, uConn, e.uClient.ServerName(), e.uClient.id)
|
||||
realityClientFallback(ctx, uConn, e.uClient.ServerName(), e.uClient.id)
|
||||
return nil, E.New("reality verification failed")
|
||||
}
|
||||
|
||||
@@ -251,13 +240,17 @@ func realityClientFallback(ctx context.Context, uConn net.Conn, serverName strin
|
||||
DialTLSContext: func(ctx context.Context, network, addr string, config *tls.Config) (net.Conn, error) {
|
||||
return uConn, nil
|
||||
},
|
||||
TLSClientConfig: &tls.Config{
|
||||
Time: ntp.TimeFuncFromContext(ctx),
|
||||
RootCAs: adapter.RootPoolFromContext(ctx),
|
||||
},
|
||||
},
|
||||
}
|
||||
request, _ := http.NewRequest("GET", "https://"+serverName, nil)
|
||||
serverAddress := M.ParseSocksaddrHostPort(serverName, 0)
|
||||
host := serverAddress.AddrString()
|
||||
if serverAddress.IsIPv6() {
|
||||
host = "[" + host + "]"
|
||||
}
|
||||
request, err := http.NewRequestWithContext(ctx, "GET", "https://"+host, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
request.Header.Set("User-Agent", fingerprint.Client)
|
||||
request.AddCookie(&http.Cookie{Name: "padding", Value: strings.Repeat("0", mRand.Intn(32)+30)})
|
||||
response, err := client.Do(request)
|
||||
@@ -270,7 +263,6 @@ func realityClientFallback(ctx context.Context, uConn net.Conn, serverName strin
|
||||
|
||||
func (e *RealityClientConfig) Clone() Config {
|
||||
return &RealityClientConfig{
|
||||
e.ctx,
|
||||
e.uClient.Clone().(*UTLSClientConfig),
|
||||
e.publicKey,
|
||||
e.shortID,
|
||||
@@ -280,9 +272,11 @@ func (e *RealityClientConfig) Clone() Config {
|
||||
|
||||
type realityVerifier struct {
|
||||
*utls.UConn
|
||||
serverName string
|
||||
authKey []byte
|
||||
verified bool
|
||||
serverName string
|
||||
rootCAs *x509.CertPool
|
||||
currentTime time.Time
|
||||
authKey []byte
|
||||
verified bool
|
||||
}
|
||||
|
||||
func (c *realityVerifier) VerifyPeerCertificate(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error {
|
||||
@@ -297,6 +291,8 @@ func (c *realityVerifier) VerifyPeerCertificate(rawCerts [][]byte, verifiedChain
|
||||
}
|
||||
}
|
||||
opts := x509.VerifyOptions{
|
||||
Roots: c.rootCAs,
|
||||
CurrentTime: c.currentTime,
|
||||
DNSName: c.serverName,
|
||||
Intermediates: x509.NewCertPool(),
|
||||
}
|
||||
|
||||
@@ -112,10 +112,10 @@ func (c *STDClientConfig) SetECHConfigList(EncryptedClientHelloConfigList []byte
|
||||
}
|
||||
|
||||
func NewSTDClient(ctx context.Context, logger logger.ContextLogger, serverAddress string, options option.OutboundTLSOptions) (Config, error) {
|
||||
return newSTDClient(ctx, logger, serverAddress, options, false)
|
||||
return newSTDClient(ctx, logger, serverAddress, options, false, nil, false)
|
||||
}
|
||||
|
||||
func newSTDClient(ctx context.Context, logger logger.ContextLogger, serverAddress string, options option.OutboundTLSOptions, allowEmptyServerName bool) (Config, error) {
|
||||
func newSTDClient(ctx context.Context, logger logger.ContextLogger, serverAddress string, options option.OutboundTLSOptions, allowEmptyServerName bool, domainResolver *option.DomainResolveOptions, directResolver bool) (Config, error) {
|
||||
var serverName string
|
||||
if options.ServerName != "" {
|
||||
serverName = options.ServerName
|
||||
@@ -247,7 +247,7 @@ func newSTDClient(ctx context.Context, logger logger.ContextLogger, serverAddres
|
||||
config.SetServerName(serverName)
|
||||
if options.ECH != nil && options.ECH.Enabled {
|
||||
var err error
|
||||
config, err = parseECHClientConfig(ctx, config.(ECHCapableConfig), options)
|
||||
config, err = parseECHClientConfig(ctx, config.(ECHCapableConfig), options, domainResolver, directResolver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -276,6 +276,9 @@ func verifyConnection(rootCAs *x509.CertPool, timeFunc func() time.Time, serverN
|
||||
}
|
||||
|
||||
func VerifyPublicKeySHA256(knownHashValues [][]byte, rawCerts [][]byte) error {
|
||||
if len(rawCerts) == 0 {
|
||||
return E.New("missing remote certificate")
|
||||
}
|
||||
leafCertificate, err := x509.ParseCertificate(rawCerts[0])
|
||||
if err != nil {
|
||||
return E.Cause(err, "failed to parse leaf certificate")
|
||||
|
||||
+23
-61
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"net"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -25,7 +26,7 @@ import (
|
||||
var errInsecureUnused = E.New("tls: insecure unused")
|
||||
|
||||
type managedCertificateProvider interface {
|
||||
adapter.CertificateProvider
|
||||
adapter.ACMECertificateProvider
|
||||
adapter.SimpleLifecycle
|
||||
}
|
||||
|
||||
@@ -101,7 +102,6 @@ type STDServerConfig struct {
|
||||
handshakeTimeout time.Duration
|
||||
logger log.Logger
|
||||
certificateProvider managedCertificateProvider
|
||||
acmeService adapter.SimpleLifecycle
|
||||
certificate []byte
|
||||
key []byte
|
||||
certificatePath string
|
||||
@@ -128,9 +128,6 @@ func (c *STDServerConfig) SetServerName(serverName string) {
|
||||
func (c *STDServerConfig) NextProtos() []string {
|
||||
c.access.RLock()
|
||||
defer c.access.RUnlock()
|
||||
if c.hasACMEALPN() && len(c.config.NextProtos) > 1 && c.config.NextProtos[0] == C.ACMETLS1Protocol {
|
||||
return c.config.NextProtos[1:]
|
||||
}
|
||||
return c.config.NextProtos
|
||||
}
|
||||
|
||||
@@ -138,11 +135,7 @@ func (c *STDServerConfig) SetNextProtos(nextProto []string) {
|
||||
c.access.Lock()
|
||||
defer c.access.Unlock()
|
||||
config := c.config.Clone()
|
||||
if c.hasACMEALPN() && len(c.config.NextProtos) > 1 && c.config.NextProtos[0] == C.ACMETLS1Protocol {
|
||||
config.NextProtos = append(c.config.NextProtos[:1], nextProto...)
|
||||
} else {
|
||||
config.NextProtos = nextProto
|
||||
}
|
||||
config.NextProtos = nextProto
|
||||
c.config = config
|
||||
}
|
||||
|
||||
@@ -158,18 +151,6 @@ func (c *STDServerConfig) SetHandshakeTimeout(timeout time.Duration) {
|
||||
c.handshakeTimeout = timeout
|
||||
}
|
||||
|
||||
func (c *STDServerConfig) hasACMEALPN() bool {
|
||||
if c.acmeService != nil {
|
||||
return true
|
||||
}
|
||||
if c.certificateProvider != nil {
|
||||
if acmeProvider, isACME := c.certificateProvider.(adapter.ACMECertificateProvider); isACME {
|
||||
return len(acmeProvider.GetACMENextProtos()) > 0
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *STDServerConfig) STDConfig() (*STDConfig, error) {
|
||||
return c.config, nil
|
||||
}
|
||||
@@ -195,28 +176,6 @@ func (c *STDServerConfig) Start() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if acmeProvider, isACME := c.certificateProvider.(adapter.ACMECertificateProvider); isACME {
|
||||
nextProtos := acmeProvider.GetACMENextProtos()
|
||||
if len(nextProtos) > 0 {
|
||||
c.access.Lock()
|
||||
config := c.config.Clone()
|
||||
mergedNextProtos := append([]string{}, nextProtos...)
|
||||
for _, nextProto := range config.NextProtos {
|
||||
if !common.Contains(mergedNextProtos, nextProto) {
|
||||
mergedNextProtos = append(mergedNextProtos, nextProto)
|
||||
}
|
||||
}
|
||||
config.NextProtos = mergedNextProtos
|
||||
c.config = config
|
||||
c.access.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
if c.acmeService != nil {
|
||||
err := c.acmeService.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err := c.startWatcher()
|
||||
if err != nil {
|
||||
@@ -327,7 +286,7 @@ func (c *STDServerConfig) certificateUpdated(path string) error {
|
||||
}
|
||||
|
||||
func (c *STDServerConfig) Close() error {
|
||||
return common.Close(c.certificateProvider, c.acmeService, common.PtrOrNil(c.watcher))
|
||||
return common.Close(c.certificateProvider, common.PtrOrNil(c.watcher))
|
||||
}
|
||||
|
||||
func NewSTDServer(ctx context.Context, logger log.ContextLogger, options option.InboundTLSOptions) (ServerConfig, error) {
|
||||
@@ -338,41 +297,33 @@ func NewSTDServer(ctx context.Context, logger log.ContextLogger, options option.
|
||||
if options.CertificateProvider != nil && options.ACME != nil {
|
||||
return nil, E.New("certificate_provider and acme are mutually exclusive")
|
||||
}
|
||||
var tlsConfig *tls.Config
|
||||
var certificateProvider managedCertificateProvider
|
||||
var acmeService adapter.SimpleLifecycle
|
||||
var err error
|
||||
if options.CertificateProvider != nil {
|
||||
certificateProvider, err = newCertificateProvider(ctx, logger, options.CertificateProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tlsConfig = &tls.Config{
|
||||
GetCertificate: certificateProvider.GetCertificate,
|
||||
}
|
||||
if options.Insecure {
|
||||
return nil, errInsecureUnused
|
||||
}
|
||||
} else if options.ACME != nil && len(options.ACME.Domain) > 0 { //nolint:staticcheck
|
||||
deprecated.Report(ctx, deprecated.OptionInlineACME)
|
||||
//nolint:staticcheck
|
||||
tlsConfig, acmeService, err = startACME(ctx, logger, common.PtrValueOrDefault(options.ACME))
|
||||
certificateProvider, err = startACME(ctx, logger, common.PtrValueOrDefault(options.ACME))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
tlsConfig := &tls.Config{}
|
||||
if certificateProvider != nil {
|
||||
if options.Insecure {
|
||||
return nil, errInsecureUnused
|
||||
}
|
||||
} else {
|
||||
tlsConfig = &tls.Config{}
|
||||
tlsConfig.GetCertificate = certificateProvider.GetCertificate
|
||||
}
|
||||
tlsConfig.Time = ntp.TimeFuncFromContext(ctx)
|
||||
if options.ServerName != "" {
|
||||
tlsConfig.ServerName = options.ServerName
|
||||
}
|
||||
if len(options.ALPN) > 0 {
|
||||
tlsConfig.NextProtos = append(options.ALPN, tlsConfig.NextProtos...)
|
||||
}
|
||||
tlsConfig.NextProtos = options.ALPN
|
||||
if options.MinVersion != "" {
|
||||
minVersion, err := ParseTLSVersion(options.MinVersion)
|
||||
if err != nil {
|
||||
@@ -407,7 +358,7 @@ func NewSTDServer(ctx context.Context, logger log.ContextLogger, options option.
|
||||
certificate []byte
|
||||
key []byte
|
||||
)
|
||||
if certificateProvider == nil && acmeService == nil {
|
||||
if certificateProvider == nil {
|
||||
if len(options.Certificate) > 0 {
|
||||
certificate = []byte(strings.Join(options.Certificate, "\n"))
|
||||
} else if options.CertificatePath != "" {
|
||||
@@ -473,6 +424,7 @@ func NewSTDServer(ctx context.Context, logger log.ContextLogger, options option.
|
||||
}
|
||||
tlsConfig.ClientCAs = clientCertificateCA
|
||||
} else if len(options.ClientCertificatePublicKeySHA256) > 0 {
|
||||
verifyIfGiven := tlsConfig.ClientAuth == tls.VerifyClientCertIfGiven
|
||||
switch tlsConfig.ClientAuth {
|
||||
case tls.RequireAndVerifyClientCert:
|
||||
tlsConfig.ClientAuth = tls.RequireAnyClientCert
|
||||
@@ -480,6 +432,9 @@ func NewSTDServer(ctx context.Context, logger log.ContextLogger, options option.
|
||||
tlsConfig.ClientAuth = tls.RequestClientCert
|
||||
}
|
||||
tlsConfig.VerifyPeerCertificate = func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error {
|
||||
if verifyIfGiven && len(rawCerts) == 0 {
|
||||
return nil
|
||||
}
|
||||
return VerifyPublicKeySHA256(options.ClientCertificatePublicKeySHA256, rawCerts)
|
||||
}
|
||||
} else {
|
||||
@@ -505,7 +460,6 @@ func NewSTDServer(ctx context.Context, logger log.ContextLogger, options option.
|
||||
handshakeTimeout: handshakeTimeout,
|
||||
logger: logger,
|
||||
certificateProvider: certificateProvider,
|
||||
acmeService: acmeService,
|
||||
certificate: certificate,
|
||||
key: key,
|
||||
certificatePath: options.CertificatePath,
|
||||
@@ -516,6 +470,14 @@ func NewSTDServer(ctx context.Context, logger log.ContextLogger, options option.
|
||||
serverConfig.config.GetConfigForClient = func(info *tls.ClientHelloInfo) (*tls.Config, error) {
|
||||
serverConfig.access.RLock()
|
||||
defer serverConfig.access.RUnlock()
|
||||
if serverConfig.certificateProvider != nil && info.ServerName != "" {
|
||||
acmeNextProtos := serverConfig.certificateProvider.GetACMENextProtos()
|
||||
if len(acmeNextProtos) > 0 && slices.Equal(info.SupportedProtos, acmeNextProtos) {
|
||||
config := serverConfig.config.Clone()
|
||||
config.NextProtos = acmeNextProtos
|
||||
return config, nil
|
||||
}
|
||||
}
|
||||
return serverConfig.config, nil
|
||||
}
|
||||
var config ServerConfig = serverConfig
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"errors"
|
||||
"math/rand"
|
||||
"net"
|
||||
"strings"
|
||||
@@ -147,6 +148,15 @@ func (c *utlsConnWrapper) ConnectionState() tls.ConnectionState {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *utlsConnWrapper) HandshakeContext(ctx context.Context) error {
|
||||
err := c.UConn.HandshakeContext(ctx)
|
||||
var echErr *utls.ECHRejectionError
|
||||
if errors.As(err, &echErr) {
|
||||
return &tls.ECHRejectionError{RetryConfigList: echErr.RetryConfigList}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *utlsConnWrapper) Upstream() any {
|
||||
return c.UConn
|
||||
}
|
||||
@@ -181,14 +191,14 @@ func (c *utlsALPNWrapper) HandshakeContext(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
return c.UConn.HandshakeContext(ctx)
|
||||
return c.utlsConnWrapper.HandshakeContext(ctx)
|
||||
}
|
||||
|
||||
func NewUTLSClient(ctx context.Context, logger logger.ContextLogger, serverAddress string, options option.OutboundTLSOptions) (Config, error) {
|
||||
return newUTLSClient(ctx, logger, serverAddress, options, false)
|
||||
return newUTLSClient(ctx, logger, serverAddress, options, false, nil, false)
|
||||
}
|
||||
|
||||
func newUTLSClient(ctx context.Context, logger logger.ContextLogger, serverAddress string, options option.OutboundTLSOptions, allowEmptyServerName bool) (Config, error) {
|
||||
func newUTLSClient(ctx context.Context, logger logger.ContextLogger, serverAddress string, options option.OutboundTLSOptions, allowEmptyServerName bool, domainResolver *option.DomainResolveOptions, directResolver bool) (Config, error) {
|
||||
var serverName string
|
||||
if options.ServerName != "" {
|
||||
serverName = options.ServerName
|
||||
@@ -326,7 +336,7 @@ func newUTLSClient(ctx context.Context, logger logger.ContextLogger, serverAddre
|
||||
if options.Reality != nil && options.Reality.Enabled {
|
||||
return nil, E.New("Reality is conflict with ECH")
|
||||
}
|
||||
config, err = parseECHClientConfig(ctx, config.(ECHCapableConfig), options)
|
||||
config, err = parseECHClientConfig(ctx, config.(ECHCapableConfig), options, domainResolver, directResolver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -354,15 +364,15 @@ func init() {
|
||||
modernFingerprints := []utls.ClientHelloID{
|
||||
utls.HelloChrome_Auto,
|
||||
utls.HelloFirefox_Auto,
|
||||
utls.HelloEdge_Auto,
|
||||
utls.HelloSafari_Auto,
|
||||
utls.HelloIOS_Auto,
|
||||
}
|
||||
randomFingerprint = modernFingerprints[rand.Intn(len(modernFingerprints))]
|
||||
|
||||
weights := utls.DefaultWeights
|
||||
weights.TLSVersMax_Set_VersionTLS13 = 1
|
||||
weights.FirstKeyShare_Set_CurveP256 = 0
|
||||
weights.CurveIDs_Append_X25519 = 1
|
||||
weights.KeyShare_Append_RandomGroups = 1
|
||||
randomizedFingerprint = utls.HelloRandomized
|
||||
randomizedFingerprint.Seed, _ = utls.NewPRNGSeed()
|
||||
randomizedFingerprint.Weights = &weights
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
)
|
||||
|
||||
func NewUTLSClient(ctx context.Context, logger logger.ContextLogger, serverAddress string, options option.OutboundTLSOptions) (Config, error) {
|
||||
return newUTLSClient(ctx, logger, serverAddress, options, false)
|
||||
return newUTLSClient(ctx, logger, serverAddress, options, false, nil, false)
|
||||
}
|
||||
|
||||
func newUTLSClient(ctx context.Context, logger logger.ContextLogger, serverAddress string, options option.OutboundTLSOptions, allowEmptyServerName bool) (Config, error) {
|
||||
func newUTLSClient(ctx context.Context, logger logger.ContextLogger, serverAddress string, options option.OutboundTLSOptions, allowEmptyServerName bool, domainResolver *option.DomainResolveOptions, directResolver bool) (Config, error) {
|
||||
return nil, E.New(`uTLS is not included in this build, rebuild with -tags with_utls`)
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,13 @@ func newRawSpoofer(conn net.Conn, method Method) (rawSpoofer, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = control.Conn(tcpConn, func(raw uintptr) error {
|
||||
return inheritRouting(fd, int(raw), src)
|
||||
})
|
||||
if err != nil {
|
||||
unix.Close(fd)
|
||||
return nil, err
|
||||
}
|
||||
spoofer := &linuxSpoofer{
|
||||
method: method,
|
||||
src: src,
|
||||
@@ -75,6 +82,40 @@ func openLinuxRawSocket(dst netip.AddrPort) (int, unix.Sockaddr, error) {
|
||||
return fd, sockaddr, nil
|
||||
}
|
||||
|
||||
// Linux routes IP_HDRINCL packets by the raw socket's bound device, mark and
|
||||
// bound address (raw_sendmsg), not by the addresses in the supplied header.
|
||||
func inheritRouting(rawSocket, tcpSocket int, src netip.AddrPort) error {
|
||||
bindInterface, err := unix.GetsockoptString(tcpSocket, unix.SOL_SOCKET, unix.SO_BINDTODEVICE)
|
||||
if err != nil {
|
||||
return E.Cause(err, "read SO_BINDTODEVICE")
|
||||
}
|
||||
if bindInterface != "" {
|
||||
err = unix.BindToDevice(rawSocket, bindInterface)
|
||||
if err != nil {
|
||||
return E.Cause(err, "bind raw socket to interface ", bindInterface)
|
||||
}
|
||||
}
|
||||
routingMark, err := unix.GetsockoptInt(tcpSocket, unix.SOL_SOCKET, unix.SO_MARK)
|
||||
if err != nil {
|
||||
return E.Cause(err, "read SO_MARK")
|
||||
}
|
||||
if routingMark != 0 {
|
||||
err = unix.SetsockoptInt(rawSocket, unix.SOL_SOCKET, unix.SO_MARK, routingMark)
|
||||
if err != nil {
|
||||
return E.Cause(err, "set raw socket SO_MARK")
|
||||
}
|
||||
}
|
||||
if src.Addr().Is4() {
|
||||
err = unix.Bind(rawSocket, &unix.SockaddrInet4{Addr: src.Addr().As4()})
|
||||
} else {
|
||||
err = unix.Bind(rawSocket, &unix.SockaddrInet6{Addr: src.Addr().As16()})
|
||||
}
|
||||
if err != nil {
|
||||
return E.Cause(err, "bind raw socket to ", src.Addr())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// loadSequenceNumbers puts the socket briefly into TCP_REPAIR mode to read
|
||||
// snd_nxt and rcv_nxt from the kernel. TCP_REPAIR requires CAP_NET_ADMIN;
|
||||
// callers must run as root or grant both CAP_NET_RAW and CAP_NET_ADMIN.
|
||||
|
||||
@@ -35,8 +35,6 @@ var (
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
outbound adapter.OutboundManager
|
||||
|
||||
connections compatible.Map[uuid.UUID, Tracker]
|
||||
closedConnectionsAccess sync.Mutex
|
||||
closedConnections list.List[TrackerMetadata]
|
||||
@@ -47,9 +45,8 @@ type Manager struct {
|
||||
eventObserver *observable.Observer[ConnectionEvent]
|
||||
}
|
||||
|
||||
func NewManager(outbound adapter.OutboundManager) *Manager {
|
||||
func NewManager() *Manager {
|
||||
return &Manager{
|
||||
outbound: outbound,
|
||||
eventSubscriber: observable.NewSubscriber[ConnectionEvent](256),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package trafficcontrol
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"slices"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
@@ -66,41 +67,19 @@ func (m *Manager) RoutedFlow(ctx context.Context, metadata adapter.InboundContex
|
||||
|
||||
func (m *Manager) newTrackerMetadata(metadata adapter.InboundContext, matchedRule adapter.Rule, matchOutbound adapter.Outbound, upload *atomic.Int64, download *atomic.Int64) TrackerMetadata {
|
||||
id, _ := uuid.NewV4()
|
||||
var (
|
||||
chain []string
|
||||
next string
|
||||
outbound string
|
||||
outboundType string
|
||||
)
|
||||
if matchOutbound != nil {
|
||||
next = matchOutbound.Tag()
|
||||
} else {
|
||||
next = m.outbound.Default().Tag()
|
||||
}
|
||||
for {
|
||||
detour, loaded := m.outbound.Outbound(next)
|
||||
if !loaded {
|
||||
break
|
||||
}
|
||||
chain = append(chain, next)
|
||||
outbound = detour.Tag()
|
||||
outboundType = detour.Type()
|
||||
outboundGroup, isGroup := detour.(adapter.OutboundGroup)
|
||||
if !isGroup {
|
||||
break
|
||||
}
|
||||
next = outboundGroup.Now()
|
||||
}
|
||||
chain := common.Map(metadata.OutboundChain, adapter.Outbound.Tag)
|
||||
slices.Reverse(chain)
|
||||
outbound := metadata.OutboundChain[len(metadata.OutboundChain)-1]
|
||||
return TrackerMetadata{
|
||||
ID: id,
|
||||
Metadata: metadata,
|
||||
CreatedAt: time.Now(),
|
||||
Upload: upload,
|
||||
Download: download,
|
||||
Chain: common.Reverse(chain),
|
||||
Chain: chain,
|
||||
Rule: matchedRule,
|
||||
Outbound: outbound,
|
||||
OutboundType: outboundType,
|
||||
Outbound: outbound.Tag(),
|
||||
OutboundType: outbound.Type(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package urltest
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"maps"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -67,6 +68,15 @@ func (s *HistoryStorage) StoreURLTestHistory(tag string, history *adapter.URLTes
|
||||
s.access.Unlock()
|
||||
}
|
||||
|
||||
func (s *HistoryStorage) UpdateURLTestHistory(stored map[string]*adapter.URLTestHistory, deleted []string) {
|
||||
s.access.Lock()
|
||||
defer s.access.Unlock()
|
||||
for _, tag := range deleted {
|
||||
delete(s.delayHistory, tag)
|
||||
}
|
||||
maps.Copy(s.delayHistory, stored)
|
||||
}
|
||||
|
||||
func (s *HistoryStorage) notifyUpdated() {
|
||||
for _, updateHook := range s.updateHooks {
|
||||
updateHook.Emit(struct{}{})
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
F "github.com/sagernet/sing/common/format"
|
||||
)
|
||||
|
||||
const ICMPFlowMax = 1024
|
||||
|
||||
type InterfaceType uint8
|
||||
|
||||
const (
|
||||
|
||||
@@ -34,7 +34,6 @@ const (
|
||||
RuleActionTypeRouteOptions = "route-options"
|
||||
RuleActionTypeEvaluate = "evaluate"
|
||||
RuleActionTypeRespond = "respond"
|
||||
RuleActionTypeDirect = "direct"
|
||||
RuleActionTypeBypass = "bypass"
|
||||
RuleActionTypeReject = "reject"
|
||||
RuleActionTypeHijackDNS = "hijack-dns"
|
||||
|
||||
+14
-15
@@ -3,21 +3,20 @@ package constant
|
||||
import "time"
|
||||
|
||||
const (
|
||||
TCPKeepAliveInitial = 5 * time.Minute
|
||||
TCPKeepAliveInterval = 75 * time.Second
|
||||
TCPConnectTimeout = 5 * time.Second
|
||||
TCPTimeout = 15 * time.Second
|
||||
ReadPayloadTimeout = 300 * time.Millisecond
|
||||
DNSTimeout = 10 * time.Second
|
||||
UDPTimeout = 5 * time.Minute
|
||||
ICMPTimeout = 10 * time.Second
|
||||
DefaultURLTestInterval = 3 * time.Minute
|
||||
DefaultURLTestIdleTimeout = 30 * time.Minute
|
||||
StartTimeout = 10 * time.Second
|
||||
StopTimeout = 5 * time.Second
|
||||
FatalStopTimeout = 10 * time.Second
|
||||
FakeIPMetadataSaveInterval = 10 * time.Second
|
||||
TLSFragmentFallbackDelay = 500 * time.Millisecond
|
||||
TCPKeepAliveInitial = 5 * time.Minute
|
||||
TCPKeepAliveInterval = 75 * time.Second
|
||||
TCPConnectTimeout = 5 * time.Second
|
||||
TCPTimeout = 15 * time.Second
|
||||
ReadPayloadTimeout = 300 * time.Millisecond
|
||||
DNSTimeout = 10 * time.Second
|
||||
UDPTimeout = 5 * time.Minute
|
||||
ICMPTimeout = 10 * time.Second
|
||||
DefaultURLTestInterval = 3 * time.Minute
|
||||
DefaultURLTestIdleTimeout = 30 * time.Minute
|
||||
StartTimeout = 10 * time.Second
|
||||
StopTimeout = 5 * time.Second
|
||||
FatalStopTimeout = 10 * time.Second
|
||||
TLSFragmentFallbackDelay = 500 * time.Millisecond
|
||||
)
|
||||
|
||||
var PortProtocols = map[uint16]string{
|
||||
|
||||
@@ -200,6 +200,10 @@ func (i *Instance) registerPowerReport(ctx context.Context, reloading bool) {
|
||||
})
|
||||
}
|
||||
|
||||
func (i *Instance) Context() context.Context {
|
||||
return i.ctx
|
||||
}
|
||||
|
||||
func (i *Instance) Box() *box.Box {
|
||||
return i.instance
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ import (
|
||||
"github.com/sagernet/sing-box/protocol/group"
|
||||
"github.com/sagernet/sing-box/service/oomkiller"
|
||||
"github.com/sagernet/sing/common"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/memory"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
"github.com/sagernet/sing/common/observable"
|
||||
"github.com/sagernet/sing/service"
|
||||
|
||||
@@ -601,7 +603,9 @@ func (s *StartedService) readGroups() *Groups {
|
||||
g.Tag = iGroup.Tag()
|
||||
g.Type = iGroup.Type()
|
||||
_, g.Selectable = iGroup.(*group.Selector)
|
||||
g.Selected = iGroup.Now()
|
||||
if selected := iGroup.Selected(N.NetworkTCP); selected != nil {
|
||||
g.Selected = selected.Tag()
|
||||
}
|
||||
if boxService.cacheFile != nil {
|
||||
if isExpand, loaded := boxService.cacheFile.LoadGroupExpand(g.Tag); loaded {
|
||||
g.IsExpand = isExpand
|
||||
@@ -617,7 +621,7 @@ func (s *StartedService) readGroups() *Groups {
|
||||
var item GroupItem
|
||||
item.Tag = itemTag
|
||||
item.Type = itemOutbound.Type()
|
||||
if history := historyStorage.LoadURLTestHistory(group.RealTag(boxService.outboundManager, itemOutbound)); history != nil {
|
||||
if history := historyStorage.LoadURLTestHistory(group.RealTag(itemOutbound, N.NetworkTCP)); history != nil {
|
||||
item.UrlTestTime = history.Time.Unix()
|
||||
item.UrlTestDelay = int32(history.Delay)
|
||||
}
|
||||
@@ -1177,7 +1181,7 @@ func (s *StartedService) SubscribeOutbounds(_ *emptypb.Empty, server grpc.Server
|
||||
Tag: ob.Tag(),
|
||||
Type: ob.Type(),
|
||||
}
|
||||
if history := historyStorage.LoadURLTestHistory(group.RealTag(boxService.outboundManager, ob)); history != nil {
|
||||
if history := historyStorage.LoadURLTestHistory(group.RealTag(ob, N.NetworkTCP)); history != nil {
|
||||
item.UrlTestTime = history.Time.Unix()
|
||||
item.UrlTestDelay = int32(history.Delay)
|
||||
}
|
||||
@@ -1188,7 +1192,7 @@ func (s *StartedService) SubscribeOutbounds(_ *emptypb.Empty, server grpc.Server
|
||||
Tag: ep.Tag(),
|
||||
Type: ep.Type(),
|
||||
}
|
||||
if history := historyStorage.LoadURLTestHistory(group.RealTag(boxService.outboundManager, ep)); history != nil {
|
||||
if history := historyStorage.LoadURLTestHistory(group.RealTag(ep, N.NetworkTCP)); history != nil {
|
||||
item.UrlTestTime = history.Time.Unix()
|
||||
item.UrlTestDelay = int32(history.Delay)
|
||||
}
|
||||
@@ -2113,3 +2117,35 @@ func (s *StartedService) Instance() *Instance {
|
||||
defer s.serviceAccess.RUnlock()
|
||||
return s.instance
|
||||
}
|
||||
|
||||
func (s *StartedService) WaitStartedInstance(ctx context.Context) (*Instance, error) {
|
||||
subscription, done, err := s.serviceStatusObserver.Subscribe()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer s.serviceStatusObserver.UnSubscribe(subscription)
|
||||
for {
|
||||
s.serviceAccess.RLock()
|
||||
currentStatus := s.serviceStatus
|
||||
instance := s.instance
|
||||
s.serviceAccess.RUnlock()
|
||||
switch currentStatus.Status {
|
||||
case ServiceStatus_STARTED:
|
||||
return instance, nil
|
||||
case ServiceStatus_STARTING, ServiceStatus_STOPPING:
|
||||
case ServiceStatus_FATAL:
|
||||
return nil, E.New(currentStatus.ErrorMessage)
|
||||
default:
|
||||
return nil, os.ErrInvalid
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
case <-s.ctx.Done():
|
||||
return nil, s.ctx.Err()
|
||||
case <-subscription:
|
||||
case <-done:
|
||||
return nil, os.ErrClosed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -14,6 +14,8 @@ import (
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/json"
|
||||
"github.com/sagernet/sing/common/json/badjson"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
@@ -62,7 +64,7 @@ func startDebugHTTPServer(options option.DebugOptions) (*http.Server, error) {
|
||||
Addr: options.Listen,
|
||||
Handler: r,
|
||||
}
|
||||
listener, err := net.Listen("tcp", options.Listen)
|
||||
listener, err := net.Listen(M.NetworkFromNetAddr(N.NetworkTCP, M.ParseSocksaddr(options.Listen).Addr), options.Listen)
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "listen debug HTTP server")
|
||||
}
|
||||
|
||||
+26
-32
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/common/compatible"
|
||||
"github.com/sagernet/sing-box/common/interrupt"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing/common"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
@@ -310,19 +311,22 @@ func (c *Client) beginExchange(ctx context.Context, transport adapter.DNSTranspo
|
||||
}
|
||||
for {
|
||||
response, ttl, isStale := c.loadResponse(cacheKey)
|
||||
if response != nil {
|
||||
if isStale && !options.DisableOptimisticCache {
|
||||
c.backgroundRefreshDNS(transport, cacheKey, message.Copy(), options, responseChecker)
|
||||
logOptimisticResponse(c.logger, ctx, response)
|
||||
response.Id = message.Id
|
||||
operation.release()
|
||||
return nil, response, exchangeDone, nil
|
||||
} else if !isStale {
|
||||
logCachedResponse(c.logger, ctx, response, ttl)
|
||||
response.Id = message.Id
|
||||
operation.release()
|
||||
return nil, response, exchangeDone, nil
|
||||
if response != nil && (!isStale || !options.DisableOptimisticCache) {
|
||||
operation.release()
|
||||
if isStale {
|
||||
c.backgroundRefreshDNS(transport, cacheKey, message.Copy(), options)
|
||||
}
|
||||
if responseChecker != nil && !responseChecker(response) {
|
||||
logRejectedResponse(c.logger, ctx, response)
|
||||
return nil, nil, exchangeDone, ErrResponseRejectedCached
|
||||
}
|
||||
if isStale {
|
||||
logOptimisticResponse(c.logger, ctx, response)
|
||||
} else {
|
||||
logCachedResponse(c.logger, ctx, response, ttl)
|
||||
}
|
||||
response.Id = message.Id
|
||||
return nil, response, exchangeDone, nil
|
||||
}
|
||||
if !loaded {
|
||||
break
|
||||
@@ -345,7 +349,7 @@ func (c *Client) beginExchange(ctx context.Context, transport adapter.DNSTranspo
|
||||
}
|
||||
}
|
||||
|
||||
operation.ctx = adapter.ContextWithDNSTransportTag(ctx, transport.Tag())
|
||||
operation.ctx = adapter.ContextWithDNSTransportTag(interrupt.ContextWithIsExternalConnection(ctx, false), transport.Tag())
|
||||
if !disableCache && responseChecker != nil && c.rdrc != nil {
|
||||
rejected := c.rdrc.LoadRDRC(transport.Tag(), question.Name, question.Qtype)
|
||||
if rejected {
|
||||
@@ -575,7 +579,13 @@ func (c *Client) questionCache(ctx context.Context, transport adapter.DNSTranspo
|
||||
if options.DisableOptimisticCache {
|
||||
return nil, ErrNotCached
|
||||
}
|
||||
c.backgroundRefreshDNS(transport, cacheKey, c.prepareExchangeMessage(message.Copy(), options), options, responseChecker)
|
||||
c.backgroundRefreshDNS(transport, cacheKey, c.prepareExchangeMessage(message.Copy(), options), options)
|
||||
}
|
||||
if responseChecker != nil && !responseChecker(response) {
|
||||
logRejectedResponse(c.logger, ctx, response)
|
||||
return nil, ErrResponseRejectedCached
|
||||
}
|
||||
if isStale {
|
||||
logOptimisticResponse(c.logger, ctx, response)
|
||||
}
|
||||
if response.Rcode != dns.RcodeSuccess {
|
||||
@@ -669,7 +679,7 @@ func applyResponseOptions(question dns.Question, response *dns.Msg, options adap
|
||||
return timeToLive
|
||||
}
|
||||
|
||||
func (c *Client) backgroundRefreshDNS(transport adapter.DNSTransport, key dnsCacheKey, message *dns.Msg, options adapter.DNSQueryOptions, responseChecker func(response *dns.Msg) bool) {
|
||||
func (c *Client) backgroundRefreshDNS(transport adapter.DNSTransport, key dnsCacheKey, message *dns.Msg, options adapter.DNSQueryOptions) {
|
||||
_, loaded := c.backgroundRefresh.LoadOrStore(key, struct{}{})
|
||||
if loaded {
|
||||
return
|
||||
@@ -690,23 +700,7 @@ func (c *Client) backgroundRefreshDNS(transport adapter.DNSTransport, key dnsCac
|
||||
}
|
||||
return
|
||||
}
|
||||
if responseChecker != nil {
|
||||
var rejected bool
|
||||
if response.Rcode != dns.RcodeSuccess && response.Rcode != dns.RcodeNameError {
|
||||
rejected = true
|
||||
} else {
|
||||
rejected = !responseChecker(response)
|
||||
}
|
||||
if rejected {
|
||||
if c.logger != nil {
|
||||
c.logger.DebugContext(ctx, "optimistic refresh rejected for ", FqdnToDomain(key.Name))
|
||||
}
|
||||
if c.rdrc != nil {
|
||||
c.rdrc.SaveRDRCAsync(transport.Tag(), key.Name, key.Qtype, c.logger)
|
||||
}
|
||||
return
|
||||
}
|
||||
} else if response.Rcode != dns.RcodeSuccess && response.Rcode != dns.RcodeNameError {
|
||||
if response.Rcode != dns.RcodeSuccess && response.Rcode != dns.RcodeNameError {
|
||||
return
|
||||
}
|
||||
storeKey, storable := c.finishCacheKey(transport, key)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"github.com/sagernet/sing/common"
|
||||
"github.com/sagernet/sing/common/buf"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
@@ -14,17 +15,19 @@ func TruncateDNSMessage(request *dns.Msg, response *dns.Msg, frontHeadroom int,
|
||||
}
|
||||
}
|
||||
responseLen := response.Len()
|
||||
if responseLen > maxLen {
|
||||
response = response.Copy()
|
||||
response.Truncate(maxLen)
|
||||
compressedResponse := response.Copy()
|
||||
compressedResponse.Compress = true
|
||||
if compressedResponse.Len() > maxLen {
|
||||
compressedResponse.Truncate(maxLen)
|
||||
compressedResponse.Compress = true
|
||||
}
|
||||
buffer := buf.NewSize(frontHeadroom + responseLen + 1 + rearHeadroom)
|
||||
buffer.Resize(frontHeadroom, 0)
|
||||
rawMessage, err := response.PackBuffer(buffer.FreeBytes())
|
||||
rawMessage, err := compressedResponse.PackBuffer(buffer.FreeBytes())
|
||||
if err != nil {
|
||||
buffer.Release()
|
||||
return nil, err
|
||||
}
|
||||
buffer.Truncate(len(rawMessage))
|
||||
common.Must1(buffer.Write(rawMessage))
|
||||
return buffer, nil
|
||||
}
|
||||
|
||||
+116
-25
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"maps"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -28,6 +29,7 @@ import (
|
||||
"github.com/sagernet/sing/service"
|
||||
|
||||
mDNS "github.com/miekg/dns"
|
||||
"golang.org/x/crypto/cryptobyte"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -46,6 +48,7 @@ type Router struct {
|
||||
rules []adapter.DNSRule
|
||||
defaultDomainStrategy C.DomainStrategy
|
||||
dnsReverseMapping *freelru.Cache[netip.Addr, string]
|
||||
dnsECHPublicNames *freelru.Cache[string, string]
|
||||
platformInterface adapter.PlatformInterface
|
||||
legacyDNSMode bool
|
||||
rulesAccess sync.RWMutex
|
||||
@@ -116,6 +119,11 @@ func NewRouter(ctx context.Context, logFactory log.Factory, options option.DNSOp
|
||||
if options.ReverseMapping {
|
||||
router.dnsReverseMapping = common.Must1(freelru.New[netip.Addr, string](1024, maphash.NewHasher[netip.Addr]().Hash32, true))
|
||||
}
|
||||
if options.ReverseMapping || slices.ContainsFunc(options.Servers, func(it option.DNSServerOptions) bool {
|
||||
return it.Type == C.DNSTypeFakeIP
|
||||
}) {
|
||||
router.dnsECHPublicNames = common.Must1(freelru.New[string, string](1024, maphash.NewHasher[string]().Hash32, true))
|
||||
}
|
||||
return router, nil
|
||||
}
|
||||
|
||||
@@ -194,7 +202,7 @@ func (r *Router) buildRules(startRules bool) ([]adapter.DNSRule, bool, dnsRuleMo
|
||||
r.logger.Warn(warning)
|
||||
}
|
||||
}
|
||||
err = validateEvaluateFakeIPRules(r.rawRules, r.transport)
|
||||
err = validateRuleActionServers(r.rawRules, r.transport)
|
||||
if err != nil {
|
||||
return nil, false, dnsRuleModeFlags{}, err
|
||||
}
|
||||
@@ -1119,18 +1127,89 @@ func (r *Router) prepareExchange(ctx context.Context, message *mDNS.Msg) (*dnsEx
|
||||
}
|
||||
|
||||
func (r *Router) recordReverseMapping(message *mDNS.Msg, response *mDNS.Msg, transport adapter.DNSTransport) {
|
||||
if r.dnsReverseMapping != nil && len(message.Question) > 0 && response != nil && len(response.Answer) > 0 {
|
||||
if transport == nil || transport.Type() != C.DNSTypeFakeIP {
|
||||
for _, answer := range response.Answer {
|
||||
switch record := answer.(type) {
|
||||
case *mDNS.A:
|
||||
r.dnsReverseMapping.AddWithLifetime(M.AddrFromIP(record.A), FqdnToDomain(record.Hdr.Name), time.Duration(record.Hdr.Ttl)*time.Second)
|
||||
case *mDNS.AAAA:
|
||||
r.dnsReverseMapping.AddWithLifetime(M.AddrFromIP(record.AAAA), FqdnToDomain(record.Hdr.Name), time.Duration(record.Hdr.Ttl)*time.Second)
|
||||
if r.dnsECHPublicNames == nil || len(message.Question) == 0 || response == nil || response.Rcode != mDNS.RcodeSuccess {
|
||||
return
|
||||
}
|
||||
if transport != nil && transport.Type() == C.DNSTypeFakeIP {
|
||||
return
|
||||
}
|
||||
question := message.Question[0]
|
||||
domain := FqdnToDomain(question.Name)
|
||||
if port, origin, found := strings.Cut(domain, "._https."); found && question.Qtype == mDNS.TypeHTTPS && strings.HasPrefix(port, "_") {
|
||||
domain = origin
|
||||
}
|
||||
var (
|
||||
addresses []netip.Addr
|
||||
foundPublicName bool
|
||||
)
|
||||
for _, answer := range response.Answer {
|
||||
lifetime := time.Duration(max(answer.Header().Ttl, 1)) * time.Second
|
||||
if record, isHTTPS := answer.(*mDNS.HTTPS); isHTTPS {
|
||||
publicName := echPublicName(record)
|
||||
if publicName != "" {
|
||||
foundPublicName = true
|
||||
publicNameLifetime := max(lifetime, C.DefaultDNSTTL*time.Second)
|
||||
mappedName, expireAt, loaded := r.dnsECHPublicNames.GetWithLifetime(domain)
|
||||
if !loaded || mappedName != publicName || time.Until(expireAt) < publicNameLifetime {
|
||||
r.dnsECHPublicNames.AddWithLifetime(domain, publicName, publicNameLifetime)
|
||||
}
|
||||
}
|
||||
}
|
||||
if r.dnsReverseMapping == nil {
|
||||
continue
|
||||
}
|
||||
addresses = adapter.AppendDNSRecordAddresses(addresses[:0], answer)
|
||||
for _, address := range addresses {
|
||||
mappedDomain, expireAt, loaded := r.dnsReverseMapping.GetWithLifetime(address)
|
||||
if loaded && mappedDomain == domain && time.Until(expireAt) >= lifetime {
|
||||
continue
|
||||
}
|
||||
r.dnsReverseMapping.AddWithLifetime(address, domain, lifetime)
|
||||
}
|
||||
}
|
||||
if question.Qtype == mDNS.TypeHTTPS && !foundPublicName {
|
||||
r.dnsECHPublicNames.Remove(domain)
|
||||
}
|
||||
}
|
||||
|
||||
func echPublicName(record *mDNS.HTTPS) string {
|
||||
const extensionEncryptedClientHello = 0xfe0d
|
||||
for _, value := range record.Value {
|
||||
echConfig, isECHConfig := value.(*mDNS.SVCBECHConfig)
|
||||
if !isECHConfig {
|
||||
continue
|
||||
}
|
||||
configList := cryptobyte.String(echConfig.ECH)
|
||||
var configs cryptobyte.String
|
||||
if !configList.ReadUint16LengthPrefixed(&configs) {
|
||||
return ""
|
||||
}
|
||||
for !configs.Empty() {
|
||||
var (
|
||||
version uint16
|
||||
contents cryptobyte.String
|
||||
configID uint8
|
||||
kemID uint16
|
||||
publicKey cryptobyte.String
|
||||
cipherSuites cryptobyte.String
|
||||
maximumNameLength uint8
|
||||
publicName cryptobyte.String
|
||||
)
|
||||
if !configs.ReadUint16(&version) || !configs.ReadUint16LengthPrefixed(&contents) {
|
||||
return ""
|
||||
}
|
||||
if version == extensionEncryptedClientHello &&
|
||||
contents.ReadUint8(&configID) &&
|
||||
contents.ReadUint16(&kemID) &&
|
||||
contents.ReadUint16LengthPrefixed(&publicKey) &&
|
||||
contents.ReadUint16LengthPrefixed(&cipherSuites) &&
|
||||
contents.ReadUint8(&maximumNameLength) &&
|
||||
contents.ReadUint8LengthPrefixed(&publicName) {
|
||||
return string(publicName)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (r *Router) exchangeLegacy(ctx context.Context, exchangeCtx *dnsExchangeContext, message *mDNS.Msg, options adapter.DNSQueryOptions) (*mDNS.Msg, adapter.DNSTransport, error) {
|
||||
@@ -1209,7 +1288,9 @@ func (r *Router) Exchange(ctx context.Context, message *mDNS.Msg, options adapte
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.recordReverseMapping(message, response, transport)
|
||||
if !options.DisableReverseMapping {
|
||||
r.recordReverseMapping(message, response, transport)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
@@ -1223,26 +1304,28 @@ func (r *Router) ExchangeAsync(ctx context.Context, message *mDNS.Msg, options a
|
||||
if options.Transport != nil {
|
||||
transport := options.Transport
|
||||
r.client.ExchangeAsync(ctx, transport, message, r.finalizeExchangeOptions(options), nil, func(response *mDNS.Msg, exchangeErr error) {
|
||||
r.finishExchangeAsync(message, transport, response, exchangeErr, callback)
|
||||
r.finishExchangeAsync(message, options, transport, response, exchangeErr, callback)
|
||||
})
|
||||
} else if !exchangeCtx.legacyDNSMode {
|
||||
r.exchangeWithRulesAsync(ctx, exchangeCtx.rules, message, options, true, func(result exchangeWithRulesResult) {
|
||||
r.finishExchangeAsync(message, result.transport, result.response, result.err, callback)
|
||||
r.finishExchangeAsync(message, options, result.transport, result.response, result.err, callback)
|
||||
})
|
||||
} else {
|
||||
go func() {
|
||||
response, transport, exchangeErr := r.exchangeLegacy(ctx, exchangeCtx, message, options)
|
||||
r.finishExchangeAsync(message, transport, response, exchangeErr, callback)
|
||||
r.finishExchangeAsync(message, options, transport, response, exchangeErr, callback)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Router) finishExchangeAsync(message *mDNS.Msg, transport adapter.DNSTransport, response *mDNS.Msg, err error, callback func(response *mDNS.Msg, err error)) {
|
||||
func (r *Router) finishExchangeAsync(message *mDNS.Msg, options adapter.DNSQueryOptions, transport adapter.DNSTransport, response *mDNS.Msg, err error, callback func(response *mDNS.Msg, err error)) {
|
||||
if err != nil {
|
||||
callback(nil, err)
|
||||
return
|
||||
}
|
||||
r.recordReverseMapping(message, response, transport)
|
||||
if !options.DisableReverseMapping {
|
||||
r.recordReverseMapping(message, response, transport)
|
||||
}
|
||||
callback(response, nil)
|
||||
}
|
||||
|
||||
@@ -1376,9 +1459,13 @@ func (r *Router) ClearCache() {
|
||||
if r.platformInterface != nil {
|
||||
r.platformInterface.ClearDNSCache()
|
||||
}
|
||||
service.FromContext[adapter.NetworkManager](r.ctx).FlushSystemDNSCache()
|
||||
if r.dnsReverseMapping != nil {
|
||||
r.dnsReverseMapping.Purge()
|
||||
}
|
||||
if r.dnsECHPublicNames != nil {
|
||||
r.dnsECHPublicNames.Purge()
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Router) LookupReverseMapping(ip netip.Addr) (string, bool) {
|
||||
@@ -1389,6 +1476,14 @@ func (r *Router) LookupReverseMapping(ip netip.Addr) (string, bool) {
|
||||
return domain, loaded
|
||||
}
|
||||
|
||||
func (r *Router) LookupECHPublicName(domain string) string {
|
||||
if r.dnsECHPublicNames == nil {
|
||||
return ""
|
||||
}
|
||||
publicName, _ := r.dnsECHPublicNames.Get(domain)
|
||||
return publicName
|
||||
}
|
||||
|
||||
func (r *Router) ResetNetwork() {
|
||||
for _, transport := range r.transport.Transports() {
|
||||
transport.Reset()
|
||||
@@ -1588,23 +1683,19 @@ func validateLegacyDNSModeDisabledRules(router adapter.Router, rules []option.DN
|
||||
return warnings, nil
|
||||
}
|
||||
|
||||
func validateEvaluateFakeIPRules(rules []option.DNSRule, transportManager adapter.DNSTransportManager) error {
|
||||
if transportManager == nil {
|
||||
return nil
|
||||
}
|
||||
func validateRuleActionServers(rules []option.DNSRule, transportManager adapter.DNSTransportManager) error {
|
||||
for i, rule := range rules {
|
||||
if dnsRuleActionType(rule) != C.RuleActionTypeEvaluate {
|
||||
continue
|
||||
}
|
||||
server := dnsRuleActionServer(rule)
|
||||
if server == "" {
|
||||
continue
|
||||
}
|
||||
transport, loaded := transportManager.Transport(server)
|
||||
if !loaded || transport.Type() != C.DNSTypeFakeIP {
|
||||
continue
|
||||
if !loaded {
|
||||
return E.New("dns rule[", i, "]: server not found: ", server)
|
||||
}
|
||||
if dnsRuleActionType(rule) == C.RuleActionTypeEvaluate && transport.Type() == C.DNSTypeFakeIP {
|
||||
return E.New("dns rule[", i, "]: evaluate action cannot use fakeip server: ", server)
|
||||
}
|
||||
return E.New("dns rule[", i, "]: evaluate action cannot use fakeip server: ", server)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+18
-31
@@ -56,7 +56,6 @@ type Transport struct {
|
||||
updateCancel context.CancelFunc
|
||||
refreshAccess sync.Mutex
|
||||
savedState atomic.Pointer[transportState]
|
||||
ndots int
|
||||
attempts int
|
||||
optional bool
|
||||
}
|
||||
@@ -83,7 +82,6 @@ func NewTransport(ctx context.Context, logger log.ContextLogger, tag string, opt
|
||||
networkManager: service.FromContext[adapter.NetworkManager](ctx),
|
||||
platformInterface: service.FromContext[adapter.PlatformInterface](ctx),
|
||||
interfaceName: options.Interface,
|
||||
ndots: 1,
|
||||
attempts: 2,
|
||||
}, nil
|
||||
}
|
||||
@@ -96,7 +94,6 @@ func NewRawTransport(transportAdapter dns.TransportAdapter, ctx context.Context,
|
||||
logger: logger,
|
||||
networkManager: service.FromContext[adapter.NetworkManager](ctx),
|
||||
platformInterface: service.FromContext[adapter.PlatformInterface](ctx),
|
||||
ndots: 1,
|
||||
attempts: 2,
|
||||
optional: true,
|
||||
}
|
||||
@@ -147,7 +144,7 @@ func (t *Transport) Reset() {
|
||||
|
||||
func (t *Transport) Environment() []string {
|
||||
state := t.savedState.Load()
|
||||
if state == nil {
|
||||
if state == nil || state.lastError != nil {
|
||||
return nil
|
||||
}
|
||||
environment := make([]string, 0, len(state.servers)+len(state.search))
|
||||
@@ -174,15 +171,7 @@ func (t *Transport) Exchange(ctx context.Context, message *mDNS.Msg) (*mDNS.Msg,
|
||||
|
||||
func (t *Transport) ExchangeAsync(ctx context.Context, message *mDNS.Msg, callback func(response *mDNS.Msg, err error)) {
|
||||
state := t.savedState.Load()
|
||||
if state == nil {
|
||||
go t.exchangeCold(ctx, message, callback)
|
||||
return
|
||||
}
|
||||
if state.lastError != nil {
|
||||
callback(nil, E.Cause(state.lastError, "dhcp: fetch DNS servers"))
|
||||
return
|
||||
}
|
||||
if len(state.serverTransports) == 0 {
|
||||
if state == nil || len(state.serverTransports) == 0 {
|
||||
go t.exchangeCold(ctx, message, callback)
|
||||
return
|
||||
}
|
||||
@@ -221,9 +210,10 @@ func (t *Transport) fetch(ctx context.Context) error {
|
||||
state := t.savedState.Load()
|
||||
if state != nil {
|
||||
if state.lastError != nil {
|
||||
return state.lastError
|
||||
}
|
||||
if time.Since(state.updatedAt) < C.DHCPTTL {
|
||||
if time.Since(state.updatedAt) < C.DHCPTimeout {
|
||||
return state.lastError
|
||||
}
|
||||
} else if time.Since(state.updatedAt) < C.DHCPTTL {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -232,9 +222,10 @@ func (t *Transport) fetch(ctx context.Context) error {
|
||||
state = t.savedState.Load()
|
||||
if state != nil {
|
||||
if state.lastError != nil {
|
||||
return state.lastError
|
||||
}
|
||||
if time.Since(state.updatedAt) < C.DHCPTTL {
|
||||
if time.Since(state.updatedAt) < C.DHCPTimeout {
|
||||
return state.lastError
|
||||
}
|
||||
} else if time.Since(state.updatedAt) < C.DHCPTTL {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -316,18 +307,13 @@ func (t *Transport) updateServersLocked(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (t *Transport) storeFailureLocked(err error) {
|
||||
newState := &transportState{
|
||||
previousState := t.savedState.Swap(&transportState{
|
||||
updatedAt: time.Now(),
|
||||
lastError: err,
|
||||
})
|
||||
if previousState != nil && previousState.serverScope != nil {
|
||||
previousState.serverScope.Close()
|
||||
}
|
||||
previousState := t.savedState.Load()
|
||||
if previousState != nil {
|
||||
newState.search = previousState.search
|
||||
newState.servers = previousState.servers
|
||||
newState.serverTransports = previousState.serverTransports
|
||||
newState.serverScope = previousState.serverScope
|
||||
}
|
||||
t.savedState.Store(newState)
|
||||
}
|
||||
|
||||
func (t *Transport) interfaceUpdated(ctx context.Context) {
|
||||
@@ -342,6 +328,10 @@ func (t *Transport) interfaceUpdated(ctx context.Context) {
|
||||
go func() {
|
||||
defer updateCancel()
|
||||
t.refreshAccess.Lock()
|
||||
previousState := t.savedState.Swap(nil)
|
||||
if previousState != nil && previousState.serverScope != nil {
|
||||
previousState.serverScope.Close()
|
||||
}
|
||||
err := t.updateServersLocked(updateContext)
|
||||
t.refreshAccess.Unlock()
|
||||
if err == nil || updateContext.Err() != nil {
|
||||
@@ -444,9 +434,6 @@ func (t *Transport) fetchServersResponse(iface *control.Interface, packetConn ne
|
||||
func (t *Transport) recreateServersLocked(iface *control.Interface, dhcpPacket *dhcpv4.DHCPv4) error {
|
||||
previousState := t.savedState.Load()
|
||||
newState := &transportState{updatedAt: time.Now()}
|
||||
if previousState != nil {
|
||||
newState.search = previousState.search
|
||||
}
|
||||
searchList := dhcpPacket.DomainSearch()
|
||||
if searchList != nil && len(searchList.Labels) > 0 {
|
||||
newState.search = common.Filter(common.Map(searchList.Labels, mDNS.Fqdn), func(it string) bool {
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/dns"
|
||||
"github.com/sagernet/sing-box/dns/transport"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
|
||||
@@ -14,10 +13,9 @@ import (
|
||||
|
||||
func (t *Transport) exchangeWithTransports(ctx context.Context, message *mDNS.Msg, state *transportState, callback func(response *mDNS.Msg, err error)) {
|
||||
question := message.Question[0]
|
||||
domain := dns.FqdnToDomain(question.Name)
|
||||
names := t.nameList(state.search, domain)
|
||||
names := nameList(state.search, question.Name)
|
||||
if len(names) == 0 {
|
||||
callback(nil, E.New("invalid domain: ", domain))
|
||||
callback(nil, E.New("invalid domain: ", question.Name))
|
||||
return
|
||||
}
|
||||
transport.ExchangeNames(ctx, names, question, func(fqdn string) transport.AsyncExchanger {
|
||||
@@ -44,38 +42,21 @@ func (t *Transport) newNameExchanger(message *mDNS.Msg, fqdn string, serverTrans
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Transport) nameList(search []string, name string) []string {
|
||||
l := len(name)
|
||||
rooted := l > 0 && name[l-1] == '.'
|
||||
if l > 254 || l == 254 && !rooted {
|
||||
func nameList(search []string, name string) []string {
|
||||
if len(name) > 254 || avoidDNS(name) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if rooted {
|
||||
if avoidDNS(name) {
|
||||
return nil
|
||||
}
|
||||
if mDNS.CountLabel(name) != 1 {
|
||||
return []string{name}
|
||||
}
|
||||
|
||||
hasNdots := strings.Count(name, ".") >= t.ndots
|
||||
name += "."
|
||||
// l++
|
||||
|
||||
names := make([]string, 0, 1+len(search))
|
||||
if hasNdots && !avoidDNS(name) {
|
||||
names = append(names, name)
|
||||
}
|
||||
names := make([]string, 0, len(search)+1)
|
||||
for _, suffix := range search {
|
||||
fqdn := name + suffix
|
||||
if !avoidDNS(fqdn) && len(fqdn) <= 254 {
|
||||
names = append(names, fqdn)
|
||||
}
|
||||
}
|
||||
if !hasNdots && !avoidDNS(name) {
|
||||
names = append(names, name)
|
||||
}
|
||||
return names
|
||||
return append(names, name)
|
||||
}
|
||||
|
||||
func avoidDNS(name string) bool {
|
||||
|
||||
@@ -35,7 +35,10 @@ func NewTransport(ctx context.Context, logger log.ContextLogger, tag string, opt
|
||||
if !inet4Range.IsValid() && !inet6Range.IsValid() {
|
||||
return nil, E.New("at least one of inet4_range or inet6_range must be set")
|
||||
}
|
||||
store := NewStore(ctx, logger, inet4Range, inet6Range)
|
||||
store, err := NewStore(ctx, logger, inet4Range, inet6Range)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Transport{
|
||||
TransportAdapter: dns.NewTransportAdapter(C.DNSTypeFakeIP, tag, nil),
|
||||
logger: logger,
|
||||
|
||||
@@ -34,7 +34,8 @@ func (s *MemoryStorage) FakeIPSaveMetadata(metadata *adapter.FakeIPMetadata) err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *MemoryStorage) FakeIPSaveMetadataAsync(metadata *adapter.FakeIPMetadata) {
|
||||
func (s *MemoryStorage) FakeIPReserve(metadata *adapter.FakeIPMetadata, current netip.Addr, reservedEnd netip.Addr) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *MemoryStorage) FakeIPStore(address netip.Addr, domain string) error {
|
||||
|
||||
+113
-63
@@ -11,36 +11,59 @@ import (
|
||||
"github.com/sagernet/sing/service"
|
||||
)
|
||||
|
||||
const reservedAddressCount = 1024
|
||||
|
||||
var _ adapter.FakeIPStore = (*Store)(nil)
|
||||
|
||||
type Store struct {
|
||||
ctx context.Context
|
||||
logger logger.Logger
|
||||
inet4Range netip.Prefix
|
||||
inet6Range netip.Prefix
|
||||
inet4Last netip.Addr
|
||||
inet6Last netip.Addr
|
||||
storage adapter.FakeIPStorage
|
||||
ctx context.Context
|
||||
logger logger.Logger
|
||||
storage adapter.FakeIPStorage
|
||||
|
||||
addressAccess sync.Mutex
|
||||
inet4Current netip.Addr
|
||||
inet6Current netip.Addr
|
||||
inet4 addressPool
|
||||
inet6 addressPool
|
||||
}
|
||||
|
||||
func NewStore(ctx context.Context, logger logger.Logger, inet4Range netip.Prefix, inet6Range netip.Prefix) *Store {
|
||||
store := &Store{
|
||||
ctx: ctx,
|
||||
logger: logger,
|
||||
inet4Range: inet4Range,
|
||||
inet6Range: inet6Range,
|
||||
type addressPool struct {
|
||||
addressRange netip.Prefix
|
||||
last netip.Addr
|
||||
reservedStep int
|
||||
current netip.Addr
|
||||
reservedEnd netip.Addr
|
||||
reservedCount int
|
||||
}
|
||||
|
||||
func NewStore(ctx context.Context, logger logger.Logger, inet4Range netip.Prefix, inet6Range netip.Prefix) (*Store, error) {
|
||||
if inet4Range.IsValid() && inet4Range.Addr().BitLen()-inet4Range.Bits() < 2 {
|
||||
return nil, E.New("inet4_range must have at least 2 host bits")
|
||||
}
|
||||
if inet4Range.IsValid() {
|
||||
store.inet4Last = broadcastAddress(inet4Range)
|
||||
if inet6Range.IsValid() && inet6Range.Addr().BitLen()-inet6Range.Bits() < 2 {
|
||||
return nil, E.New("inet6_range must have at least 2 host bits")
|
||||
}
|
||||
if inet6Range.IsValid() {
|
||||
store.inet6Last = broadcastAddress(inet6Range)
|
||||
return &Store{
|
||||
ctx: ctx,
|
||||
logger: logger,
|
||||
inet4: newAddressPool(inet4Range),
|
||||
inet6: newAddressPool(inet6Range),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newAddressPool(addressRange netip.Prefix) addressPool {
|
||||
pool := addressPool{
|
||||
addressRange: addressRange,
|
||||
}
|
||||
return store
|
||||
if addressRange.IsValid() {
|
||||
pool.last = broadcastAddress(addressRange)
|
||||
hostBits := addressRange.Addr().BitLen() - addressRange.Bits()
|
||||
if hostBits > 11 {
|
||||
pool.reservedStep = reservedAddressCount
|
||||
} else {
|
||||
addressCount := 1 << hostBits
|
||||
pool.reservedStep = max((addressCount-3)/2, 1)
|
||||
}
|
||||
}
|
||||
return pool
|
||||
}
|
||||
|
||||
func broadcastAddress(prefix netip.Prefix) netip.Addr {
|
||||
@@ -59,6 +82,19 @@ func broadcastAddress(prefix netip.Prefix) netip.Addr {
|
||||
return netip.AddrFrom16(raw)
|
||||
}
|
||||
|
||||
func (p *addressPool) next(current netip.Addr) netip.Addr {
|
||||
address := current.Next()
|
||||
if address == p.last || !p.addressRange.Contains(address) {
|
||||
address = p.addressRange.Addr().Next().Next()
|
||||
}
|
||||
return address
|
||||
}
|
||||
|
||||
func (p *addressPool) resetReservation() {
|
||||
p.reservedCount = 0
|
||||
p.reservedEnd = p.current
|
||||
}
|
||||
|
||||
func (s *Store) Start() error {
|
||||
var storage adapter.FakeIPStorage
|
||||
cacheFile := service.FromContext[adapter.CacheFile](s.ctx)
|
||||
@@ -69,24 +105,26 @@ func (s *Store) Start() error {
|
||||
storage = NewMemoryStorage()
|
||||
}
|
||||
metadata := storage.FakeIPMetadata()
|
||||
if metadata != nil && metadata.Inet4Range == s.inet4Range && metadata.Inet6Range == s.inet6Range {
|
||||
s.inet4Current = metadata.Inet4Current
|
||||
s.inet6Current = metadata.Inet6Current
|
||||
if metadata != nil && metadata.Inet4Range == s.inet4.addressRange && metadata.Inet6Range == s.inet6.addressRange {
|
||||
s.inet4.current = metadata.Inet4Current
|
||||
s.inet6.current = metadata.Inet6Current
|
||||
} else {
|
||||
if s.inet4Range.IsValid() {
|
||||
s.inet4Current = s.inet4Range.Addr().Next()
|
||||
if s.inet4.addressRange.IsValid() {
|
||||
s.inet4.current = s.inet4.addressRange.Addr().Next()
|
||||
}
|
||||
if s.inet6Range.IsValid() {
|
||||
s.inet6Current = s.inet6Range.Addr().Next()
|
||||
if s.inet6.addressRange.IsValid() {
|
||||
s.inet6.current = s.inet6.addressRange.Addr().Next()
|
||||
}
|
||||
_ = storage.FakeIPReset()
|
||||
}
|
||||
s.inet4.reservedEnd = s.inet4.current
|
||||
s.inet6.reservedEnd = s.inet6.current
|
||||
s.storage = storage
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) Contains(address netip.Addr) bool {
|
||||
return s.inet4Range.Contains(address) || s.inet6Range.Contains(address)
|
||||
return s.inet4.addressRange.Contains(address) || s.inet6.addressRange.Contains(address)
|
||||
}
|
||||
|
||||
func (s *Store) Close() error {
|
||||
@@ -94,14 +132,15 @@ func (s *Store) Close() error {
|
||||
return nil
|
||||
}
|
||||
s.addressAccess.Lock()
|
||||
metadata := &adapter.FakeIPMetadata{
|
||||
Inet4Range: s.inet4Range,
|
||||
Inet6Range: s.inet6Range,
|
||||
Inet4Current: s.inet4Current,
|
||||
Inet6Current: s.inet6Current,
|
||||
}
|
||||
s.addressAccess.Unlock()
|
||||
return s.storage.FakeIPSaveMetadata(metadata)
|
||||
defer s.addressAccess.Unlock()
|
||||
s.inet4.resetReservation()
|
||||
s.inet6.resetReservation()
|
||||
return s.storage.FakeIPSaveMetadata(&adapter.FakeIPMetadata{
|
||||
Inet4Range: s.inet4.addressRange,
|
||||
Inet6Range: s.inet6.addressRange,
|
||||
Inet4Current: s.inet4.current,
|
||||
Inet6Current: s.inet6.current,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Store) Create(domain string, isIPv6 bool) (netip.Addr, error) {
|
||||
@@ -117,39 +156,46 @@ func (s *Store) Create(domain string, isIPv6 bool) (netip.Addr, error) {
|
||||
return address, nil
|
||||
}
|
||||
|
||||
var address netip.Addr
|
||||
if !isIPv6 {
|
||||
if !s.inet4Current.IsValid() {
|
||||
return netip.Addr{}, E.New("missing IPv4 fakeip address range")
|
||||
}
|
||||
nextAddress := s.inet4Current.Next()
|
||||
if nextAddress == s.inet4Last || !s.inet4Range.Contains(nextAddress) {
|
||||
nextAddress = s.inet4Range.Addr().Next().Next()
|
||||
}
|
||||
s.inet4Current = nextAddress
|
||||
address = nextAddress
|
||||
} else {
|
||||
if !s.inet6Current.IsValid() {
|
||||
pool := &s.inet4
|
||||
if isIPv6 {
|
||||
pool = &s.inet6
|
||||
}
|
||||
if !pool.current.IsValid() {
|
||||
if isIPv6 {
|
||||
return netip.Addr{}, E.New("missing IPv6 fakeip address range")
|
||||
}
|
||||
nextAddress := s.inet6Current.Next()
|
||||
if nextAddress == s.inet6Last || !s.inet6Range.Contains(nextAddress) {
|
||||
nextAddress = s.inet6Range.Addr().Next().Next()
|
||||
}
|
||||
s.inet6Current = nextAddress
|
||||
address = nextAddress
|
||||
return netip.Addr{}, E.New("missing IPv4 fakeip address range")
|
||||
}
|
||||
err := s.storage.FakeIPStore(address, domain)
|
||||
if pool.reservedCount == 0 {
|
||||
reservedEnd := pool.current
|
||||
for range pool.reservedStep {
|
||||
reservedEnd = pool.next(reservedEnd)
|
||||
}
|
||||
metadata := &adapter.FakeIPMetadata{
|
||||
Inet4Range: s.inet4.addressRange,
|
||||
Inet6Range: s.inet6.addressRange,
|
||||
Inet4Current: s.inet4.reservedEnd,
|
||||
Inet6Current: s.inet6.reservedEnd,
|
||||
}
|
||||
if isIPv6 {
|
||||
metadata.Inet6Current = reservedEnd
|
||||
} else {
|
||||
metadata.Inet4Current = reservedEnd
|
||||
}
|
||||
err := s.storage.FakeIPReserve(metadata, pool.current, reservedEnd)
|
||||
if err != nil {
|
||||
return netip.Addr{}, E.Cause(err, "save fakeip metadata")
|
||||
}
|
||||
pool.reservedEnd = reservedEnd
|
||||
pool.reservedCount = pool.reservedStep
|
||||
}
|
||||
pool.reservedCount--
|
||||
pool.current = pool.next(pool.current)
|
||||
err := s.storage.FakeIPStore(pool.current, domain)
|
||||
if err != nil {
|
||||
s.logger.Warn("save FakeIP cache: ", err)
|
||||
}
|
||||
s.storage.FakeIPSaveMetadataAsync(&adapter.FakeIPMetadata{
|
||||
Inet4Range: s.inet4Range,
|
||||
Inet6Range: s.inet6Range,
|
||||
Inet4Current: s.inet4Current,
|
||||
Inet6Current: s.inet6Current,
|
||||
})
|
||||
return address, nil
|
||||
return pool.current, nil
|
||||
}
|
||||
|
||||
func (s *Store) Lookup(address netip.Addr) (string, bool) {
|
||||
@@ -157,5 +203,9 @@ func (s *Store) Lookup(address netip.Addr) (string, bool) {
|
||||
}
|
||||
|
||||
func (s *Store) Reset() error {
|
||||
s.addressAccess.Lock()
|
||||
defer s.addressAccess.Unlock()
|
||||
s.inet4.resetReservation()
|
||||
s.inet6.resetReservation()
|
||||
return s.storage.FakeIPReset()
|
||||
}
|
||||
|
||||
+16
-12
@@ -5,10 +5,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -64,7 +62,14 @@ func NewHTTPS(ctx context.Context, logger log.ContextLogger, tag string, options
|
||||
}
|
||||
tlsOptions := common.PtrValueOrDefault(options.TLS)
|
||||
tlsOptions.Enabled = true
|
||||
tlsConfig, err := tls.NewClient(ctx, logger, options.Server, tlsOptions)
|
||||
tlsConfig, err := tls.NewClientWithOptions(tls.ClientOptions{
|
||||
Context: ctx,
|
||||
Logger: logger,
|
||||
ServerAddress: options.Server,
|
||||
Options: tlsOptions,
|
||||
DomainResolver: options.DomainResolver,
|
||||
DirectResolver: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -82,15 +87,14 @@ func NewHTTPS(ctx context.Context, logger log.ContextLogger, tag string, options
|
||||
host = options.Server
|
||||
}
|
||||
}
|
||||
destinationURL := url.URL{
|
||||
Scheme: "https",
|
||||
Host: host,
|
||||
}
|
||||
if destinationURL.Host == "" {
|
||||
destinationURL.Host = options.Server
|
||||
}
|
||||
destinationAddress := M.ParseSocksaddrHostPort(host, options.ServerPort)
|
||||
destinationURL := url.URL{Scheme: "https"}
|
||||
if options.ServerPort != 0 && options.ServerPort != 443 {
|
||||
destinationURL.Host = net.JoinHostPort(destinationURL.Host, strconv.Itoa(int(options.ServerPort)))
|
||||
destinationURL.Host = destinationAddress.String()
|
||||
} else if destinationAddress.IsIPv6() {
|
||||
destinationURL.Host = "[" + destinationAddress.AddrString() + "]"
|
||||
} else {
|
||||
destinationURL.Host = destinationAddress.AddrString()
|
||||
}
|
||||
path := options.Path
|
||||
if path == "" {
|
||||
@@ -213,7 +217,7 @@ func (t *HTTPSTransport) ExchangeAsync(ctx context.Context, message *mDNS.Msg, c
|
||||
}
|
||||
|
||||
func (t *HTTPSTransport) exchange(ctx context.Context, message *mDNS.Msg) (*mDNS.Msg, error) {
|
||||
exMessage := *message
|
||||
exMessage := message.Copy()
|
||||
exMessage.Id = 0
|
||||
exMessage.Compress = true
|
||||
requestBuffer := buf.NewSize(1 + message.Len())
|
||||
|
||||
@@ -2,6 +2,7 @@ package local
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
@@ -12,9 +13,11 @@ import (
|
||||
"github.com/sagernet/sing-box/dns/transport/mdns"
|
||||
"github.com/sagernet/sing-box/log"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
"github.com/sagernet/sing-tun"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/logger"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
"github.com/sagernet/sing/service"
|
||||
|
||||
mDNS "github.com/miekg/dns"
|
||||
)
|
||||
@@ -36,6 +39,7 @@ type Transport struct {
|
||||
preferredResolver *PreferredDomainResolver
|
||||
dialer N.Dialer
|
||||
preferGo bool
|
||||
interfaceMonitor tun.DefaultInterfaceMonitor
|
||||
resolved ResolvedResolver
|
||||
mdnsTransport adapter.DNSTransport
|
||||
mdnsScope *adapter.Scope
|
||||
@@ -61,6 +65,7 @@ func NewTransport(ctx context.Context, logger log.ContextLogger, tag string, opt
|
||||
preferredResolver: preferredResolver,
|
||||
dialer: transportDialer,
|
||||
preferGo: options.PreferGo,
|
||||
interfaceMonitor: service.FromContext[adapter.NetworkManager](ctx).InterfaceMonitor(),
|
||||
configSource: systemconfig.NewSource(ctx),
|
||||
}, nil
|
||||
}
|
||||
@@ -70,7 +75,7 @@ func (t *Transport) Start(stage adapter.StartStage, scope *adapter.Scope) error
|
||||
switch stage {
|
||||
case adapter.StartStateInitialize:
|
||||
scope.Add(t.configSource.Close)
|
||||
if !t.preferGo && isSystemdResolvedManaged() {
|
||||
if !t.preferGo {
|
||||
resolvedResolver, err := NewResolvedResolver(t.ctx, t.logger)
|
||||
if err == nil {
|
||||
scope.Add(resolvedResolver.Close)
|
||||
@@ -132,11 +137,25 @@ func (t *Transport) PreferredDomain(domain string) bool {
|
||||
return t.preferredResolver.PreferredDomain(domain)
|
||||
}
|
||||
|
||||
func (t *Transport) useSystemResolver() bool {
|
||||
return C.IsDarwin && (!t.preferGo || C.IsIos || (t.interfaceMonitor != nil && len(t.interfaceMonitor.MyInterfaces()) > 0))
|
||||
}
|
||||
|
||||
func (t *Transport) Environment() []string {
|
||||
if t.resolved != nil {
|
||||
if t.useSystemResolver() {
|
||||
if t.interfaceMonitor != nil {
|
||||
defaultInterface := t.interfaceMonitor.DefaultInterface()
|
||||
if defaultInterface != nil {
|
||||
return []string{defaultInterface.Name, strconv.Itoa(defaultInterface.Index)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
systemConfig := t.configSource.Configuration()
|
||||
if t.resolved != nil && systemConfig.SystemdResolved {
|
||||
return t.resolved.Environment()
|
||||
}
|
||||
return t.configSource.Configuration().Signature()
|
||||
return systemConfig.Signature()
|
||||
}
|
||||
|
||||
func (t *Transport) Exchange(ctx context.Context, message *mDNS.Msg) (*mDNS.Msg, error) {
|
||||
@@ -161,17 +180,18 @@ func (t *Transport) ExchangeAsync(ctx context.Context, message *mDNS.Msg, callba
|
||||
callback(response, nil)
|
||||
return
|
||||
}
|
||||
if t.useSystemResolver() || C.IsDarwin && mdns.IsLocalDomain(question.Name) {
|
||||
t.systemExchangeAsync(ctx, message, callback)
|
||||
return
|
||||
}
|
||||
if mdns.IsLocalDomain(question.Name) {
|
||||
if C.IsDarwin {
|
||||
t.systemExchangeAsync(ctx, message, callback)
|
||||
return
|
||||
}
|
||||
t.mdnsTransport.ExchangeAsync(ctx, message, callback)
|
||||
return
|
||||
}
|
||||
if t.resolved != nil {
|
||||
systemConfig := t.configSource.Configuration()
|
||||
if t.resolved != nil && systemConfig.SystemdResolved {
|
||||
t.resolved.ExchangeAsync(ctx, message, callback)
|
||||
return
|
||||
}
|
||||
t.exchangeAsync(ctx, message, question.Name, callback)
|
||||
t.exchangeAsync(ctx, message, systemConfig, question.Name, callback)
|
||||
}
|
||||
|
||||
@@ -10,10 +10,12 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"slices"
|
||||
"sync"
|
||||
|
||||
"github.com/sagernet/sing-box/dns"
|
||||
dnsTransport "github.com/sagernet/sing-box/dns/transport"
|
||||
"github.com/sagernet/sing-box/dns/transport/mdns"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
|
||||
mDNS "github.com/miekg/dns"
|
||||
@@ -21,7 +23,14 @@ import (
|
||||
|
||||
func (t *Transport) systemExchangeAsync(ctx context.Context, message *mDNS.Msg, callback func(response *mDNS.Msg, err error)) {
|
||||
question := message.Question[0]
|
||||
t.system.exchangeAsync(ctx, question.Name, question.Qtype, question.Qclass, func(response *mDNS.Msg, err error) {
|
||||
var interfaceIndex uint32
|
||||
if t.interfaceMonitor != nil && !mdns.IsLocalDomain(question.Name) {
|
||||
defaultInterface := t.interfaceMonitor.DefaultInterface()
|
||||
if defaultInterface != nil && !slices.Contains(t.interfaceMonitor.MyInterfaces(), defaultInterface.Name) {
|
||||
interfaceIndex = uint32(defaultInterface.Index)
|
||||
}
|
||||
}
|
||||
t.system.exchangeAsync(ctx, interfaceIndex, question.Name, question.Qtype, question.Qclass, func(response *mDNS.Msg, err error) {
|
||||
if err != nil {
|
||||
var rcodeError dns.RcodeError
|
||||
if errors.As(err, &rcodeError) {
|
||||
@@ -127,7 +136,7 @@ func (r *systemResolver) reset() {
|
||||
r.connection.Reset()
|
||||
}
|
||||
|
||||
func (r *systemResolver) exchangeAsync(ctx context.Context, name string, qtype uint16, qclass uint16, callback func(response *mDNS.Msg, err error)) {
|
||||
func (r *systemResolver) exchangeAsync(ctx context.Context, interfaceIndex uint32, name string, qtype uint16, qclass uint16, callback func(response *mDNS.Msg, err error)) {
|
||||
r.initOnce.Do(r.init)
|
||||
for firstAttempt := true; ; firstAttempt = false {
|
||||
conn, connCtx, created, err := r.connection.AcquireShared(ctx, r.dial)
|
||||
@@ -139,7 +148,7 @@ func (r *systemResolver) exchangeAsync(ctx context.Context, name string, qtype u
|
||||
go r.recvLoop(conn)
|
||||
}
|
||||
queryId := r.register(ctx, connCtx, conn, name, qtype, qclass, callback)
|
||||
_, writeErr := conn.Write(buildQueryRequest(queryId, name, qtype, qclass))
|
||||
_, writeErr := conn.Write(buildQueryRequest(queryId, interfaceIndex, name, qtype, qclass))
|
||||
if writeErr == nil {
|
||||
return
|
||||
}
|
||||
@@ -365,12 +374,12 @@ func appendResponderHeader(buffer []byte, operation uint32, dataLength int, clie
|
||||
return buffer
|
||||
}
|
||||
|
||||
func buildQueryRequest(queryId uint64, name string, qtype uint16, qclass uint16) []byte {
|
||||
func buildQueryRequest(queryId uint64, interfaceIndex uint32, name string, qtype uint16, qclass uint16) []byte {
|
||||
payloadLength := 4 + 4 + len(name) + 1 + 2 + 2
|
||||
message := make([]byte, 0, mdnsResponderHeaderLength+payloadLength)
|
||||
message = appendResponderHeader(message, mdnsResponderQueryRequest, payloadLength, queryId, mdnsResponderIPCFlagNoErrorSocket)
|
||||
message = binary.BigEndian.AppendUint32(message, mdnsResponderFlagShareConnection|mdnsResponderFlagReturnIntermediates|mdnsResponderFlagTimeout)
|
||||
message = binary.BigEndian.AppendUint32(message, 0) // interfaceIndex
|
||||
message = binary.BigEndian.AppendUint32(message, interfaceIndex)
|
||||
message = append(message, name...)
|
||||
message = append(message, 0)
|
||||
message = binary.BigEndian.AppendUint16(message, qtype)
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package local
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"errors"
|
||||
"net/netip"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -33,28 +31,10 @@ import (
|
||||
mDNS "github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func isSystemdResolvedManaged() bool {
|
||||
resolvContent, err := os.Open("/etc/resolv.conf")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer resolvContent.Close()
|
||||
scanner := bufio.NewScanner(resolvContent)
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
if line == "" || line[0] != '#' {
|
||||
return false
|
||||
}
|
||||
if strings.Contains(line, "systemd-resolved") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type DBusResolvedResolver struct {
|
||||
ctx context.Context
|
||||
logger logger.ContextLogger
|
||||
networkManager adapter.NetworkManager
|
||||
interfaceFinder control.InterfaceFinder
|
||||
interfaceMonitor tun.DefaultInterfaceMonitor
|
||||
interfaceCallback *list.Element[tun.DefaultInterfaceUpdateCallback]
|
||||
@@ -69,9 +49,10 @@ type DBusResolvedResolver struct {
|
||||
}
|
||||
|
||||
type resolvedServerSet struct {
|
||||
scopes []*resolvedScope
|
||||
signature []string
|
||||
serverScope *adapter.Scope
|
||||
specifications []resolvedScopeSpecification
|
||||
scopes []*resolvedScope
|
||||
signature []string
|
||||
serverScope *adapter.Scope
|
||||
}
|
||||
|
||||
// Match levels of dns_scope_good_domain() in systemd-resolved: a routing or search
|
||||
@@ -111,6 +92,7 @@ type resolvedScopeSpecification struct {
|
||||
interfaceName string
|
||||
dnsOverTLSMode string
|
||||
domains []string
|
||||
search []string
|
||||
defaultRoute bool
|
||||
fallback bool
|
||||
servers []resolvedServerSpecification
|
||||
@@ -155,13 +137,14 @@ func NewResolvedResolver(ctx context.Context, logger logger.ContextLogger) (Reso
|
||||
if interfaceMonitor == nil {
|
||||
return nil, os.ErrInvalid
|
||||
}
|
||||
systemBus, err := dbus.SystemBus()
|
||||
systemBus, err := dbus.ConnectSystemBus()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &DBusResolvedResolver{
|
||||
ctx: ctx,
|
||||
logger: logger,
|
||||
networkManager: networkManager,
|
||||
interfaceFinder: networkManager.InterfaceFinder(),
|
||||
interfaceMonitor: interfaceMonitor,
|
||||
networkMonitor: networkManager.NetworkMonitor(),
|
||||
@@ -170,30 +153,32 @@ func NewResolvedResolver(ctx context.Context, logger logger.ContextLogger) (Reso
|
||||
}
|
||||
|
||||
func (t *DBusResolvedResolver) Start() error {
|
||||
t.updateStatus(t.ctx)
|
||||
t.interfaceCallback = t.interfaceMonitor.RegisterCallback(t.updateDefaultInterface)
|
||||
if t.networkMonitor != nil {
|
||||
t.networkCallback = t.networkMonitor.RegisterCallback(t.postUpdateStatus)
|
||||
}
|
||||
err := t.systemBus.BusObject().AddMatchSignal(
|
||||
"org.freedesktop.DBus",
|
||||
"NameOwnerChanged",
|
||||
err := t.systemBus.AddMatchSignal(
|
||||
dbus.WithMatchSender("org.freedesktop.DBus"),
|
||||
dbus.WithMatchInterface("org.freedesktop.DBus"),
|
||||
dbus.WithMatchMember("NameOwnerChanged"),
|
||||
dbus.WithMatchArg(0, "org.freedesktop.resolve1"),
|
||||
).Err
|
||||
)
|
||||
if err != nil {
|
||||
return E.Cause(err, "configure resolved restart listener")
|
||||
}
|
||||
err = t.systemBus.BusObject().AddMatchSignal(
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"PropertiesChanged",
|
||||
err = t.systemBus.AddMatchSignal(
|
||||
dbus.WithMatchSender("org.freedesktop.resolve1"),
|
||||
dbus.WithMatchInterface("org.freedesktop.DBus.Properties"),
|
||||
dbus.WithMatchMember("PropertiesChanged"),
|
||||
dbus.WithMatchArg(0, "org.freedesktop.resolve1.Manager"),
|
||||
).Err
|
||||
)
|
||||
if err != nil {
|
||||
return E.Cause(err, "configure resolved properties listener")
|
||||
}
|
||||
go t.loopUpdateStatus()
|
||||
signalChan := make(chan *dbus.Signal, 1)
|
||||
t.systemBus.Signal(signalChan)
|
||||
go t.loopUpdateStatus(signalChan)
|
||||
t.updateStatus(t.ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -379,9 +364,7 @@ func (s *resolvedScope) match(name string) int {
|
||||
return resolvedScopeMaybe
|
||||
}
|
||||
|
||||
func (t *DBusResolvedResolver) loopUpdateStatus() {
|
||||
signalChan := make(chan *dbus.Signal, 1)
|
||||
t.systemBus.Signal(signalChan)
|
||||
func (t *DBusResolvedResolver) loopUpdateStatus(signalChan <-chan *dbus.Signal) {
|
||||
for signal := range signalChan {
|
||||
switch signal.Name {
|
||||
case "org.freedesktop.DBus.NameOwnerChanged":
|
||||
@@ -433,16 +416,18 @@ func (t *DBusResolvedResolver) updateStatus(ctx context.Context) error {
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
}
|
||||
serverSet, err := t.checkResolved(ctx)
|
||||
if t.closed || ctx.Err() != nil {
|
||||
if serverSet != nil {
|
||||
_ = serverSet.serverScope.Close()
|
||||
}
|
||||
if t.closed {
|
||||
return os.ErrClosed
|
||||
}
|
||||
scopeSpecifications, err := t.checkResolved(ctx)
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
}
|
||||
var serverSet *resolvedServerSet
|
||||
if err == nil {
|
||||
currentServerSet := t.savedServerSet.Load()
|
||||
if currentServerSet != nil && slices.EqualFunc(currentServerSet.specifications, scopeSpecifications, resolvedScopeSpecification.equal) {
|
||||
return nil
|
||||
}
|
||||
serverSet, err = t.createResolvedServerSet(scopeSpecifications)
|
||||
}
|
||||
oldServerSet := t.savedServerSet.Swap(serverSet)
|
||||
if oldServerSet != nil {
|
||||
_ = oldServerSet.serverScope.Close()
|
||||
@@ -457,14 +442,15 @@ func (t *DBusResolvedResolver) updateStatus(ctx context.Context) error {
|
||||
}
|
||||
return err
|
||||
} else if oldServerSet == nil {
|
||||
t.logger.Debug("using systemd-resolved service as resolver")
|
||||
t.logger.Debug("systemd-resolved service is available")
|
||||
}
|
||||
t.networkManager.FlushSystemDNSCache()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *DBusResolvedResolver) checkResolved(ctx context.Context) (*resolvedServerSet, error) {
|
||||
func (t *DBusResolvedResolver) checkResolved(ctx context.Context) ([]resolvedScopeSpecification, error) {
|
||||
managerObject := t.systemBus.Object("org.freedesktop.resolve1", "/org/freedesktop/resolve1")
|
||||
err := managerObject.CallWithContext(ctx, "org.freedesktop.DBus.Peer.Ping", 0).Err
|
||||
err := managerObject.CallWithContext(ctx, "org.freedesktop.DBus.Peer.Ping", dbus.FlagNoAutoStart).Err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -528,13 +514,17 @@ func (t *DBusResolvedResolver) checkResolved(ctx context.Context) (*resolvedServ
|
||||
}
|
||||
for _, domain := range managerDomains {
|
||||
domainName := mDNS.Fqdn(domain.Domain)
|
||||
if domain.InterfaceIndex == 0 {
|
||||
globalScope.domains = append(globalScope.domains, domainName)
|
||||
continue
|
||||
scope := &globalScope
|
||||
if domain.InterfaceIndex != 0 {
|
||||
scopeIndex, loaded := linkScopeIndexes[domain.InterfaceIndex]
|
||||
if !loaded || scopeIndex < 0 {
|
||||
continue
|
||||
}
|
||||
scope = &linkScopes[scopeIndex]
|
||||
}
|
||||
scopeIndex, loaded := linkScopeIndexes[domain.InterfaceIndex]
|
||||
if loaded && scopeIndex >= 0 {
|
||||
linkScopes[scopeIndex].domains = append(linkScopes[scopeIndex].domains, domainName)
|
||||
scope.domains = append(scope.domains, domainName)
|
||||
if !domain.RoutingOnly && domainName != "." {
|
||||
scope.search = append(scope.search, domainName)
|
||||
}
|
||||
}
|
||||
if len(globalScope.servers) == 0 && !slices.ContainsFunc(linkScopes, func(it resolvedScopeSpecification) bool {
|
||||
@@ -558,9 +548,25 @@ func (t *DBusResolvedResolver) checkResolved(ctx context.Context) (*resolvedServ
|
||||
if len(scopeSpecifications) == 0 {
|
||||
return nil, E.New("no DNS servers configured")
|
||||
}
|
||||
return scopeSpecifications, nil
|
||||
}
|
||||
|
||||
func (s resolvedScopeSpecification) equal(other resolvedScopeSpecification) bool {
|
||||
return s.interfaceName == other.interfaceName &&
|
||||
s.dnsOverTLSMode == other.dnsOverTLSMode &&
|
||||
slices.Equal(s.domains, other.domains) &&
|
||||
slices.Equal(s.search, other.search) &&
|
||||
s.defaultRoute == other.defaultRoute &&
|
||||
s.fallback == other.fallback &&
|
||||
slices.Equal(s.servers, other.servers)
|
||||
}
|
||||
|
||||
func (t *DBusResolvedResolver) createResolvedServerSet(scopeSpecifications []resolvedScopeSpecification) (*resolvedServerSet, error) {
|
||||
serverSet := &resolvedServerSet{
|
||||
serverScope: adapter.NewScope(t.ctx, t.logger),
|
||||
specifications: scopeSpecifications,
|
||||
serverScope: adapter.NewScope(t.ctx, t.logger),
|
||||
}
|
||||
var search []string
|
||||
for _, scopeSpecification := range scopeSpecifications {
|
||||
scope, createErr := t.createResolvedScope(serverSet.serverScope, scopeSpecification)
|
||||
if createErr != nil {
|
||||
@@ -571,7 +577,9 @@ func (t *DBusResolvedResolver) checkResolved(ctx context.Context) (*resolvedServ
|
||||
for _, serverSpecification := range scopeSpecification.servers {
|
||||
serverSet.signature = append(serverSet.signature, scopeSpecification.interfaceName+"/"+M.SocksaddrFrom(serverSpecification.address, serverSpecification.port).String())
|
||||
}
|
||||
search = append(search, scopeSpecification.search...)
|
||||
}
|
||||
serverSet.signature = append(serverSet.signature, common.Uniq(search)...)
|
||||
return serverSet, nil
|
||||
}
|
||||
|
||||
@@ -581,7 +589,7 @@ func (t *DBusResolvedResolver) loadResolvedLinkScope(ctx context.Context, manage
|
||||
return resolvedScopeSpecification{}, false, nil
|
||||
}
|
||||
var linkPath dbus.ObjectPath
|
||||
err = managerObject.CallWithContext(ctx, "org.freedesktop.resolve1.Manager.GetLink", 0, interfaceIndex).Store(&linkPath)
|
||||
err = managerObject.CallWithContext(ctx, "org.freedesktop.resolve1.Manager.GetLink", dbus.FlagNoAutoStart, interfaceIndex).Store(&linkPath)
|
||||
if err != nil {
|
||||
return resolvedScopeSpecification{}, false, err
|
||||
}
|
||||
@@ -729,7 +737,7 @@ func resolvedServerPort(port uint16, useTLS bool) uint16 {
|
||||
|
||||
func loadResolvedProperties(ctx context.Context, object dbus.BusObject, interfaceName string) (map[string]dbus.Variant, error) {
|
||||
var properties map[string]dbus.Variant
|
||||
err := object.CallWithContext(ctx, "org.freedesktop.DBus.Properties.GetAll", 0, interfaceName).Store(&properties)
|
||||
err := object.CallWithContext(ctx, "org.freedesktop.DBus.Properties.GetAll", dbus.FlagNoAutoStart, interfaceName).Store(&properties)
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "load ", interfaceName, " properties")
|
||||
}
|
||||
@@ -788,7 +796,7 @@ func shouldUpdateResolvedServerSet(signal *dbus.Signal) bool {
|
||||
}
|
||||
for propertyName := range changedProperties {
|
||||
switch propertyName {
|
||||
case "DNS", "DNSEx", "DNSOverTLS":
|
||||
case "DNS", "DNSEx", "DNSOverTLS", "Domains", "FallbackDNS":
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -798,7 +806,7 @@ func shouldUpdateResolvedServerSet(signal *dbus.Signal) bool {
|
||||
}
|
||||
for _, propertyName := range invalidatedProperties {
|
||||
switch propertyName {
|
||||
case "DNS", "DNSEx", "DNSOverTLS":
|
||||
case "DNS", "DNSEx", "DNSOverTLS", "Domains", "FallbackDNS":
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,6 @@ import (
|
||||
"github.com/sagernet/sing/common/logger"
|
||||
)
|
||||
|
||||
func isSystemdResolvedManaged() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func NewResolvedResolver(ctx context.Context, logger logger.ContextLogger) (ResolvedResolver, error) {
|
||||
return nil, os.ErrInvalid
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user