mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-11-21 09:01:39 +00:00
Compare commits
46
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02cf0f60ea | ||
|
|
f73471e6b4 | ||
|
|
8e07407486 | ||
|
|
febc082f03 | ||
|
|
09b1b0701f | ||
|
|
ce074ce572 | ||
|
|
b1dfdf25e7 | ||
|
|
1c5a1fbf70 | ||
|
|
b983473390 | ||
|
|
5e861653c2 | ||
|
|
36112cd886 | ||
|
|
b1905088c3 | ||
|
|
381e450943 | ||
|
|
7daa8e4b6a | ||
|
|
a32023be5f | ||
|
|
82b5b76bc5 | ||
|
|
f781c68715 | ||
|
|
5d17b872ed | ||
|
|
c456141815 | ||
|
|
f082058590 | ||
|
|
e184d774a2 | ||
|
|
14df0738f3 | ||
|
|
36cc9ff510 | ||
|
|
c43ee98ec7 | ||
|
|
676eaf66f8 | ||
|
|
af8f9673af | ||
|
|
924a5e7814 | ||
|
|
2a773ffb3d | ||
|
|
3a88ccb2d3 | ||
|
|
a5d52d2d95 | ||
|
|
3d3a504159 | ||
|
|
2d287bbdee | ||
|
|
5745dea2b4 | ||
|
|
2e4c13d8c4 | ||
|
|
bb335c6b0c | ||
|
|
043d2e47fc | ||
|
|
36756ad672 | ||
|
|
abecd7d9f1 | ||
|
|
a52db8f6ed | ||
|
|
858c44f410 | ||
|
|
fff4acac52 | ||
|
|
ad98ffd42b | ||
|
|
63ca2e0c1d | ||
|
|
ab88e0118f | ||
|
|
556767e40b | ||
|
|
967ade1e03 |
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"android-arm64": { "friendlyName": "android-arm64-v8a" },
|
"android-arm64": { "friendlyName": "android-arm64-v8a" },
|
||||||
|
"android-amd64": { "friendlyName": "android-amd64" },
|
||||||
"darwin-amd64": { "friendlyName": "macos-64" },
|
"darwin-amd64": { "friendlyName": "macos-64" },
|
||||||
"darwin-arm64": { "friendlyName": "macos-arm64-v8a" },
|
"darwin-arm64": { "friendlyName": "macos-arm64-v8a" },
|
||||||
"freebsd-386": { "friendlyName": "freebsd-32" },
|
"freebsd-386": { "friendlyName": "freebsd-32" },
|
||||||
@@ -14,9 +15,7 @@
|
|||||||
"linux-arm7": { "friendlyName": "linux-arm32-v7a" },
|
"linux-arm7": { "friendlyName": "linux-arm32-v7a" },
|
||||||
"linux-mips64le": { "friendlyName": "linux-mips64le" },
|
"linux-mips64le": { "friendlyName": "linux-mips64le" },
|
||||||
"linux-mips64": { "friendlyName": "linux-mips64" },
|
"linux-mips64": { "friendlyName": "linux-mips64" },
|
||||||
"linux-mipslesoftfloat": { "friendlyName": "linux-mips32le-softfloat" },
|
|
||||||
"linux-mipsle": { "friendlyName": "linux-mips32le" },
|
"linux-mipsle": { "friendlyName": "linux-mips32le" },
|
||||||
"linux-mipssoftfloat": { "friendlyName": "linux-mips32-softfloat" },
|
|
||||||
"linux-mips": { "friendlyName": "linux-mips32" },
|
"linux-mips": { "friendlyName": "linux-mips32" },
|
||||||
"linux-ppc64le": { "friendlyName": "linux-ppc64le" },
|
"linux-ppc64le": { "friendlyName": "linux-ppc64le" },
|
||||||
"linux-ppc64": { "friendlyName": "linux-ppc64" },
|
"linux-ppc64": { "friendlyName": "linux-ppc64" },
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ ARG TARGETARCH
|
|||||||
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags "-s -w -buildid=" ./main
|
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags "-s -w -buildid=" ./main
|
||||||
|
|
||||||
# Download geodat into a staging directory
|
# Download geodat into a staging directory
|
||||||
ADD https://raw.githubusercontent.com/XTLS/Xray-rules-dat/release/geoip/geoip-full.dat /tmp/geodat/geoip.dat
|
ADD https://github.com/XTLS/Xray-rules-dat/releases/latest/download/geoip-full.dat /tmp/geodat/geoip.dat
|
||||||
ADD https://raw.githubusercontent.com/XTLS/Xray-rules-dat/release/geosite/geosite-expand.dat /tmp/geodat/geosite.dat
|
ADD https://github.com/XTLS/Xray-rules-dat/releases/latest/download/geosite-expand.dat /tmp/geodat/geosite.dat
|
||||||
|
|
||||||
RUN mkdir -p /tmp/empty
|
RUN mkdir -p /tmp/empty
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ RUN cat <<EOF >/tmp/usr/local/etc/xray/00_log.json
|
|||||||
{
|
{
|
||||||
"log": {
|
"log": {
|
||||||
"error": "/var/log/xray/error.log",
|
"error": "/var/log/xray/error.log",
|
||||||
"loglevel": "warning",
|
"logLevel": "warning",
|
||||||
"access": "none",
|
"access": "none",
|
||||||
"dnsLog": false
|
"dnsLog": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ ARG TARGETARCH
|
|||||||
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags "-s -w -buildid=" ./main
|
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags "-s -w -buildid=" ./main
|
||||||
|
|
||||||
# Download geodat into a staging directory
|
# Download geodat into a staging directory
|
||||||
ADD https://raw.githubusercontent.com/XTLS/Xray-rules-dat/release/geoip/geoip-full.dat /tmp/geodat/geoip.dat
|
ADD https://github.com/XTLS/Xray-rules-dat/releases/latest/download/geoip-full.dat /tmp/geodat/geoip.dat
|
||||||
ADD https://raw.githubusercontent.com/XTLS/Xray-rules-dat/release/geosite/geosite-expand.dat /tmp/geodat/geosite.dat
|
ADD https://github.com/XTLS/Xray-rules-dat/releases/latest/download/geosite-expand.dat /tmp/geodat/geosite.dat
|
||||||
|
|
||||||
RUN mkdir -p /tmp/empty
|
RUN mkdir -p /tmp/empty
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ RUN cat <<EOF >/tmp/usr/local/etc/xray/00_log.json
|
|||||||
{
|
{
|
||||||
"log": {
|
"log": {
|
||||||
"error": "/var/log/xray/error.log",
|
"error": "/var/log/xray/error.log",
|
||||||
"loglevel": "warning",
|
"logLevel": "warning",
|
||||||
"access": "none",
|
"access": "none",
|
||||||
"dnsLog": false
|
"dnsLog": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ jobs:
|
|||||||
uses: docker/setup-buildx-action@v4
|
uses: docker/setup-buildx-action@v4
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v4.7.0
|
uses: docker/login-action@v4.8.0
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
name: Build and Release for Windows 7
|
name: Build and Release for Windows 7
|
||||||
|
# Pre-compiling support removal since 1.29
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [published]
|
||||||
push:
|
|
||||||
pull_request:
|
|
||||||
types: [opened, synchronize, reopened]
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check-assets:
|
check-assets:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
|
||||||
steps:
|
steps:
|
||||||
- name: Restore Geodat Cache
|
- name: Restore Geodat Cache
|
||||||
uses: actions/cache/restore@v6
|
uses: actions/cache/restore@v6
|
||||||
@@ -115,8 +112,6 @@ jobs:
|
|||||||
COMMID=$(git describe --always --dirty)
|
COMMID=$(git describe --always --dirty)
|
||||||
echo 'Building Xray for Windows 7...'
|
echo 'Building Xray for Windows 7...'
|
||||||
go build -o build_assets/xray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
|
go build -o build_assets/xray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
|
||||||
# The line below is for without running conhost.exe version. Commented for not being used. Provided for reference.
|
|
||||||
# go build -o build_assets/wxray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-H windowsgui -X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
|
|
||||||
|
|
||||||
- name: Restore Geodat Cache
|
- name: Restore Geodat Cache
|
||||||
uses: actions/cache/restore@v6
|
uses: actions/cache/restore@v6
|
||||||
@@ -152,6 +147,13 @@ jobs:
|
|||||||
cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
|
cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
|
||||||
cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
|
cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
|
||||||
|
|
||||||
|
- name: Upload files to Artifacts
|
||||||
|
uses: actions/upload-artifact@v7
|
||||||
|
with:
|
||||||
|
name: Xray-${{ env.ASSET_NAME }}
|
||||||
|
path: |
|
||||||
|
./build_assets/*
|
||||||
|
|
||||||
- name: Create ZIP archive
|
- name: Create ZIP archive
|
||||||
if: github.event_name == 'release'
|
if: github.event_name == 'release'
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -175,10 +177,3 @@ jobs:
|
|||||||
file: ./Xray-${{ env.ASSET_NAME }}.zip*
|
file: ./Xray-${{ env.ASSET_NAME }}.zip*
|
||||||
tag: ${{ github.ref }}
|
tag: ${{ github.ref }}
|
||||||
file_glob: true
|
file_glob: true
|
||||||
|
|
||||||
- name: Upload files to Artifacts
|
|
||||||
uses: actions/upload-artifact@v7
|
|
||||||
with:
|
|
||||||
name: Xray-${{ env.ASSET_NAME }}
|
|
||||||
path: |
|
|
||||||
./build_assets/*
|
|
||||||
|
|||||||
+178
-85
@@ -79,86 +79,23 @@ jobs:
|
|||||||
contents: write
|
contents: write
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
# Include amd64 on all platforms.
|
# Include amd64 and arm64 on all platforms.
|
||||||
goos: [windows, freebsd, openbsd, linux, darwin]
|
goos: [windows, freebsd, openbsd, linux, darwin, android]
|
||||||
goarch: [amd64, 386]
|
goarch: [amd64, arm64]
|
||||||
patch-assetname: [""]
|
patch-assetname: [""]
|
||||||
exclude:
|
|
||||||
# Exclude i386 on darwin
|
|
||||||
- goarch: 386
|
|
||||||
goos: darwin
|
|
||||||
include:
|
include:
|
||||||
# BEGIN MacOS ARM64
|
# BEGIN Linux specified
|
||||||
- goos: darwin
|
|
||||||
goarch: arm64
|
|
||||||
# END MacOS ARM64
|
|
||||||
# BEGIN Linux ARM 5 6 7
|
|
||||||
- goos: linux
|
|
||||||
goarch: arm
|
|
||||||
goarm: 7
|
|
||||||
- goos: linux
|
|
||||||
goarch: arm
|
|
||||||
goarm: 6
|
|
||||||
- goos: linux
|
|
||||||
goarch: arm
|
|
||||||
goarm: 5
|
|
||||||
# END Linux ARM 5 6 7
|
|
||||||
# BEGIN Android ARM 8
|
|
||||||
- goos: android
|
|
||||||
goarch: arm64
|
|
||||||
# END Android ARM 8
|
|
||||||
# BEGIN Android AMD64
|
|
||||||
- goos: android
|
|
||||||
goarch: amd64
|
|
||||||
patch-assetname: android-amd64
|
|
||||||
# END Android AMD64
|
|
||||||
# Windows ARM
|
|
||||||
- goos: windows
|
|
||||||
goarch: arm64
|
|
||||||
# BEGIN Other architectures
|
|
||||||
# BEGIN riscv64 & ARM64 & LOONG64
|
|
||||||
- goos: linux
|
|
||||||
goarch: arm64
|
|
||||||
- goos: linux
|
|
||||||
goarch: riscv64
|
|
||||||
- goos: linux
|
|
||||||
goarch: loong64
|
|
||||||
# END riscv64 & ARM64 & LOONG64
|
|
||||||
# BEGIN MIPS
|
|
||||||
- goos: linux
|
|
||||||
goarch: mips64
|
|
||||||
- goos: linux
|
|
||||||
goarch: mips64le
|
|
||||||
- goos: linux
|
|
||||||
goarch: mipsle
|
|
||||||
- goos: linux
|
|
||||||
goarch: mips
|
|
||||||
# END MIPS
|
|
||||||
# BEGIN PPC
|
|
||||||
- goos: linux
|
- goos: linux
|
||||||
goarch: ppc64
|
goarch: ppc64
|
||||||
- goos: linux
|
- goos: linux
|
||||||
goarch: ppc64le
|
goarch: ppc64le
|
||||||
# END PPC
|
|
||||||
# BEGIN FreeBSD ARM
|
|
||||||
- goos: freebsd
|
|
||||||
goarch: arm64
|
|
||||||
- goos: freebsd
|
|
||||||
goarch: arm
|
|
||||||
goarm: 7
|
|
||||||
# END FreeBSD ARM
|
|
||||||
# BEGIN S390X
|
|
||||||
- goos: linux
|
- goos: linux
|
||||||
goarch: s390x
|
goarch: s390x
|
||||||
# END S390X
|
- goos: linux
|
||||||
# END Other architectures
|
goarch: riscv64
|
||||||
# BEGIN OPENBSD ARM
|
- goos: linux
|
||||||
- goos: openbsd
|
goarch: loong64
|
||||||
goarch: arm64
|
# END Linux specified
|
||||||
- goos: openbsd
|
|
||||||
goarch: arm
|
|
||||||
goarm: 7
|
|
||||||
# END OPENBSD ARM
|
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -166,7 +103,6 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GOOS: ${{ matrix.goos }}
|
GOOS: ${{ matrix.goos }}
|
||||||
GOARCH: ${{ matrix.goarch }}
|
GOARCH: ${{ matrix.goarch }}
|
||||||
GOARM: ${{ matrix.goarm }}
|
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout codebase
|
- name: Checkout codebase
|
||||||
@@ -188,8 +124,8 @@ jobs:
|
|||||||
- name: Show workflow information
|
- name: Show workflow information
|
||||||
run: |
|
run: |
|
||||||
_NAME=${{ matrix.patch-assetname }}
|
_NAME=${{ matrix.patch-assetname }}
|
||||||
[ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json)
|
[ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH\"].friendlyName" -r < .github/build/friendly-filenames.json)
|
||||||
echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME"
|
echo "GOOS: $GOOS, GOARCH: $GOARCH, RELEASE_NAME: $_NAME"
|
||||||
echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
|
echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
@@ -203,6 +139,18 @@ jobs:
|
|||||||
|
|
||||||
- name: Build Xray
|
- name: Build Xray
|
||||||
run: |
|
run: |
|
||||||
|
case "${GOARCH}:${GOOS}" in
|
||||||
|
# Special processing for x86-64 and ARM64
|
||||||
|
amd64:windows|amd64:darwin)
|
||||||
|
GOAMD64="v2"
|
||||||
|
;;
|
||||||
|
arm64:windows)
|
||||||
|
GOARM64="v8.2"
|
||||||
|
;;
|
||||||
|
arm64:darwin)
|
||||||
|
GOARM64="v8.4"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
mkdir -p build_assets
|
mkdir -p build_assets
|
||||||
COMMID=$(git describe --always --dirty)
|
COMMID=$(git describe --always --dirty)
|
||||||
if [[ ${GOOS} == 'windows' ]]; then
|
if [[ ${GOOS} == 'windows' ]]; then
|
||||||
@@ -212,17 +160,11 @@ jobs:
|
|||||||
# go build -o build_assets/wxray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-H windowsgui -X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
|
# go build -o build_assets/wxray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-H windowsgui -X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
|
||||||
elif [[ ${GOOS} == 'android' ]]; then
|
elif [[ ${GOOS} == 'android' ]]; then
|
||||||
echo 'Building Xray for Android...'
|
echo 'Building Xray for Android...'
|
||||||
go build -o build_assets/xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid= -checklinkname=0" -v ./main
|
go build -o build_assets/xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid= -checklinkname=0 -extldflags=-Wl,--pack-dyn-relocs=android" -v ./main
|
||||||
else
|
else
|
||||||
echo 'Building Xray...'
|
echo 'Building Xray...'
|
||||||
if [[ ${GOARCH} == 'mips' || ${GOARCH} == 'mipsle' ]]; then
|
|
||||||
go build -o build_assets/xray -trimpath -buildvcs=false -gcflags="-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
|
|
||||||
echo 'Building soft-float Xray for MIPS/MIPSLE 32-bit...'
|
|
||||||
GOMIPS=softfloat go build -o build_assets/xray_softfloat -trimpath -buildvcs=false -gcflags="-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
|
|
||||||
else
|
|
||||||
go build -o build_assets/xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
|
go build -o build_assets/xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Restore Geodat Cache
|
- name: Restore Geodat Cache
|
||||||
uses: actions/cache/restore@v6
|
uses: actions/cache/restore@v6
|
||||||
@@ -248,9 +190,6 @@ jobs:
|
|||||||
if [[ ${GOARCH} == 'amd64' ]]; then
|
if [[ ${GOARCH} == 'amd64' ]]; then
|
||||||
mv resources/wintun/bin/amd64/wintun.dll build_assets/
|
mv resources/wintun/bin/amd64/wintun.dll build_assets/
|
||||||
fi
|
fi
|
||||||
if [[ ${GOARCH} == '386' ]]; then
|
|
||||||
mv resources/wintun/bin/x86/wintun.dll build_assets/
|
|
||||||
fi
|
|
||||||
if [[ ${GOARCH} == 'arm64' ]]; then
|
if [[ ${GOARCH} == 'arm64' ]]; then
|
||||||
mv resources/wintun/bin/arm64/wintun.dll build_assets/
|
mv resources/wintun/bin/arm64/wintun.dll build_assets/
|
||||||
fi
|
fi
|
||||||
@@ -262,6 +201,13 @@ jobs:
|
|||||||
cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
|
cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
|
||||||
cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
|
cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
|
||||||
|
|
||||||
|
- name: Upload files to Artifacts
|
||||||
|
uses: actions/upload-artifact@v7
|
||||||
|
with:
|
||||||
|
name: Xray-${{ env.ASSET_NAME }}
|
||||||
|
path: |
|
||||||
|
./build_assets/*
|
||||||
|
|
||||||
- name: Create ZIP archive
|
- name: Create ZIP archive
|
||||||
if: github.event_name == 'release'
|
if: github.event_name == 'release'
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -286,9 +232,156 @@ jobs:
|
|||||||
tag: ${{ github.ref }}
|
tag: ${{ github.ref }}
|
||||||
file_glob: true
|
file_glob: true
|
||||||
|
|
||||||
|
build-release-only:
|
||||||
|
needs: check-assets
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
# First batch (since Go 1.29) of removal:
|
||||||
|
# x86: windows, linux, freebsd, openbsd
|
||||||
|
# arm: linux(v5), linux(v6)
|
||||||
|
# other: linux(mips), linux(mips64), linux(mips64le)
|
||||||
|
# Second batch (needs discussion) of removal
|
||||||
|
# arm(v7): freebsd, openbsd, linux
|
||||||
|
# other: linux(mipsle)
|
||||||
|
goos: [windows, freebsd, openbsd, linux]
|
||||||
|
goarch: [arm, 386]
|
||||||
|
goarm: [7]
|
||||||
|
exclude:
|
||||||
|
- goos: windows
|
||||||
|
goarch: arm
|
||||||
|
include:
|
||||||
|
# Second batch of removal [In the future]
|
||||||
|
- goos: linux
|
||||||
|
goarch: mipsle
|
||||||
|
# END of second batch
|
||||||
|
# First batch of removal [Go 1.29]
|
||||||
|
- goos: linux
|
||||||
|
goarch: arm
|
||||||
|
goarm: 5
|
||||||
|
- goos: linux
|
||||||
|
goarch: arm
|
||||||
|
goarm: 6
|
||||||
|
- goos: linux
|
||||||
|
goarch: mips
|
||||||
|
- goos: linux
|
||||||
|
goarch: mips64
|
||||||
|
- goos: linux
|
||||||
|
goarch: mips64le
|
||||||
|
# END of first batch
|
||||||
|
fail-fast: false
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
|
||||||
|
env:
|
||||||
|
GOOS: ${{ matrix.goos }}
|
||||||
|
GOARCH: ${{ matrix.goarch }}
|
||||||
|
GOARM: ${{ matrix.goarm }}
|
||||||
|
CGO_ENABLED: 0
|
||||||
|
steps:
|
||||||
|
- name: Checkout codebase
|
||||||
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
|
- name: Show workflow information
|
||||||
|
run: |
|
||||||
|
_NAME=${{ matrix.patch-assetname }}
|
||||||
|
if [[ ${GOARCH} == 'arm' ]]; then
|
||||||
|
[ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM\"].friendlyName" -r < .github/build/friendly-filenames.json)
|
||||||
|
echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, RELEASE_NAME: $_NAME"
|
||||||
|
else
|
||||||
|
echo "GOARM=''" >> $GITHUB_ENV
|
||||||
|
[ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH\"].friendlyName" -r < .github/build/friendly-filenames.json)
|
||||||
|
echo "GOOS: $GOOS, GOARCH: $GOARCH, RELEASE_NAME: $_NAME"
|
||||||
|
fi
|
||||||
|
echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v7
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
check-latest: true
|
||||||
|
|
||||||
|
- name: Get project dependencies
|
||||||
|
run: go mod download
|
||||||
|
|
||||||
|
- name: Build Xray
|
||||||
|
run: |
|
||||||
|
mkdir -p build_assets
|
||||||
|
COMMID=$(git describe --always --dirty)
|
||||||
|
if [[ ${GOOS} == 'windows' ]]; then
|
||||||
|
echo 'Building Xray for Windows...'
|
||||||
|
go build -o build_assets/xray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
|
||||||
|
else
|
||||||
|
echo 'Building Xray...'
|
||||||
|
if [[ ${GOARCH} == 'mips' || ${GOARCH} == 'mipsle' ]]; then
|
||||||
|
go build -o build_assets/xray -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
|
||||||
|
echo 'Building soft-float Xray for MIPS/MIPSLE 32-bit...'
|
||||||
|
GOMIPS=softfloat go build -o build_assets/xray_softfloat -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
|
||||||
|
else
|
||||||
|
go build -o build_assets/xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Restore Geodat Cache
|
||||||
|
uses: actions/cache/restore@v6
|
||||||
|
with:
|
||||||
|
path: resources
|
||||||
|
key: xray-geodat-
|
||||||
|
|
||||||
|
- name: Restore Wintun Cache
|
||||||
|
if: matrix.goos == 'windows'
|
||||||
|
uses: actions/cache/restore@v6
|
||||||
|
with:
|
||||||
|
path: resources
|
||||||
|
key: xray-wintun-
|
||||||
|
|
||||||
|
- name: Add additional assets into package
|
||||||
|
run: |
|
||||||
|
mv -f resources/geo* build_assets/
|
||||||
|
if [[ ${GOOS} == 'windows' ]]; then
|
||||||
|
cp .github/build/windows/* build_assets/
|
||||||
|
fi
|
||||||
|
if [[ ${GOOS} == 'windows' ]]; then
|
||||||
|
echo 'Adding Wintun into packages'
|
||||||
|
if [[ ${GOARCH} == '386' ]]; then
|
||||||
|
mv resources/wintun/bin/x86/wintun.dll build_assets/
|
||||||
|
fi
|
||||||
|
mv resources/wintun/LICENSE.txt build_assets/LICENSE-Wintun
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Copy README.md & LICENSE
|
||||||
|
run: |
|
||||||
|
cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
|
||||||
|
cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
|
||||||
|
|
||||||
- name: Upload files to Artifacts
|
- name: Upload files to Artifacts
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: Xray-${{ env.ASSET_NAME }}
|
name: Xray-${{ env.ASSET_NAME }}
|
||||||
path: |
|
path: |
|
||||||
./build_assets/*
|
./build_assets/*
|
||||||
|
|
||||||
|
- name: Create ZIP archive
|
||||||
|
if: github.event_name == 'release'
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
pushd build_assets || exit 1
|
||||||
|
touch -mt $(date +%Y01010000) *
|
||||||
|
zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip .
|
||||||
|
popd || exit 1
|
||||||
|
FILE=./Xray-${{ env.ASSET_NAME }}.zip
|
||||||
|
DGST=$FILE.dgst
|
||||||
|
for METHOD in {"md5","sha1","sha256","sha512"}
|
||||||
|
do
|
||||||
|
openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Upload binaries to release
|
||||||
|
uses: svenstaro/upload-release-action@v2
|
||||||
|
if: github.event_name == 'release'
|
||||||
|
with:
|
||||||
|
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
file: ./Xray-${{ env.ASSET_NAME }}.zip*
|
||||||
|
tag: ${{ github.ref }}
|
||||||
|
file_glob: true
|
||||||
|
|||||||
@@ -231,17 +231,34 @@ Make sure that you are using the same Go version, and remember to set the git co
|
|||||||
CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
|
CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For Windows (x86-64 and AArch64, not win7):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
GOOS=windows GOARCH=amd64 GOAMD64=v2 CGO_ENABLED=0 go build -o xray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
|
||||||
|
GOOS=windows GOARCH=arm64 GOARM64=v8.2 CGO_ENABLED=0 go build -o xray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
|
||||||
|
```
|
||||||
|
|
||||||
|
For macOS:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
GOOS=darwin GOARCH=amd64 GOAMD64=v2 CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
|
||||||
|
GOOS=darwin GOARCH=arm64 GOARM64=v8.4 CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
|
||||||
|
```
|
||||||
|
|
||||||
For Android:
|
For Android:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
GOOS=android GOARCH=arm64 CGO_ENABLED=1 CC=/path/to/aarch64-linux-android24-clang go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid= -checklinkname=0" -v ./main
|
GOOS=android GOARCH=arm64 CGO_ENABLED=1 CC=/path/to/aarch64-linux-android24-clang go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid= -checklinkname=0 -extldflags=-Wl,--pack-dyn-relocs=android" -v ./main
|
||||||
GOOS=android GOARCH=amd64 CGO_ENABLED=1 CC=/path/to/x86_64-linux-android24-clang go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid= -checklinkname=0" -v ./main
|
GOOS=android GOARCH=amd64 CGO_ENABLED=1 CC=/path/to/x86_64-linux-android24-clang go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid= -checklinkname=0 -extldflags=-Wl,--pack-dyn-relocs=android" -v ./main
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are compiling a 32-bit MIPS/MIPSLE target, use this command instead:
|
For Linux (MIPS32 and MIPS32LE):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
|
GOOS=linux GOARCH=mips GOMIPS=hardfloat CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
|
||||||
|
GOOS=linux GOARCH=mips GOMIPS=softfloat CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
|
||||||
|
GOOS=linux GOARCH=mipsle GOMIPS=hardfloat CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
|
||||||
|
GOOS=linux GOARCH=mipsle GOMIPS=softfloat CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
|
||||||
```
|
```
|
||||||
|
|
||||||
## Stargazers over time
|
## Stargazers over time
|
||||||
|
|||||||
@@ -124,14 +124,17 @@ func (c *CacheController) writeAndShrink(expiredKeys []string) {
|
|||||||
if rec == nil {
|
if rec == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if rec.A != nil && rec.A.Expire.Before(now) {
|
a, aaaa := rec.A, rec.AAAA
|
||||||
rec.A = nil
|
if a != nil && a.Expire.Before(now) {
|
||||||
|
a = nil
|
||||||
}
|
}
|
||||||
if rec.AAAA != nil && rec.AAAA.Expire.Before(now) {
|
if aaaa != nil && aaaa.Expire.Before(now) {
|
||||||
rec.AAAA = nil
|
aaaa = nil
|
||||||
}
|
}
|
||||||
if rec.A == nil && rec.AAAA == nil {
|
if a == nil && aaaa == nil {
|
||||||
delete(c.ips, domain)
|
delete(c.ips, domain)
|
||||||
|
} else if a != rec.A || aaaa != rec.AAAA {
|
||||||
|
c.ips[domain] = &record{A: a, AAAA: aaaa}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-8
@@ -148,7 +148,7 @@ func TestUDPServerSubnet(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -210,7 +210,7 @@ func TestUDPServer(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -350,7 +350,7 @@ func TestPrioritizedDomain(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -421,7 +421,7 @@ func TestUDPServerIPv6(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -490,7 +490,7 @@ func TestStaticHostDomain(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -577,7 +577,7 @@ func TestIPMatch(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -696,7 +696,7 @@ func TestLocalDomain(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -953,7 +953,7 @@ func TestMultiMatchPrioritizedDomain(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ func NewServer(ctx context.Context, dest net.Destination, dispatcher routing.Dis
|
|||||||
return NewTCPNameServer(u, dispatcher, disableCache, serveStale, serveExpiredTTL, clientIP)
|
return NewTCPNameServer(u, dispatcher, disableCache, serveStale, serveExpiredTTL, clientIP)
|
||||||
case strings.EqualFold(u.Scheme, "tcp+local"): // DNS-over-TCP Local mode
|
case strings.EqualFold(u.Scheme, "tcp+local"): // DNS-over-TCP Local mode
|
||||||
return NewTCPLocalNameServer(u, disableCache, serveStale, serveExpiredTTL, clientIP)
|
return NewTCPLocalNameServer(u, disableCache, serveStale, serveExpiredTTL, clientIP)
|
||||||
|
case strings.EqualFold(u.Scheme, "udp"): // UDP DNS Remote mode
|
||||||
|
return NewUDPNameServer(u, dispatcher, false, disableCache, serveStale, serveExpiredTTL, clientIP)
|
||||||
|
case strings.EqualFold(u.Scheme, "udp+local"): // UDP DNS Local mode
|
||||||
|
return NewUDPNameServer(u, dispatcher, true, disableCache, serveStale, serveExpiredTTL, clientIP)
|
||||||
case strings.EqualFold(u.String(), "fakedns"):
|
case strings.EqualFold(u.String(), "fakedns"):
|
||||||
var fd dns.FakeDNSEngine
|
var fd dns.FakeDNSEngine
|
||||||
err = core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) {
|
err = core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) {
|
||||||
|
|||||||
@@ -2,12 +2,15 @@ package dns
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"io"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
|
"github.com/xtls/xray-core/common/buf"
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/protocol/dns"
|
"github.com/xtls/xray-core/common/protocol/dns"
|
||||||
@@ -15,6 +18,8 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/task"
|
"github.com/xtls/xray-core/common/task"
|
||||||
dns_feature "github.com/xtls/xray-core/features/dns"
|
dns_feature "github.com/xtls/xray-core/features/dns"
|
||||||
"github.com/xtls/xray-core/features/routing"
|
"github.com/xtls/xray-core/features/routing"
|
||||||
|
"github.com/xtls/xray-core/transport"
|
||||||
|
"github.com/xtls/xray-core/transport/internet"
|
||||||
"github.com/xtls/xray-core/transport/internet/udp"
|
"github.com/xtls/xray-core/transport/internet/udp"
|
||||||
"golang.org/x/net/dns/dnsmessage"
|
"golang.org/x/net/dns/dnsmessage"
|
||||||
)
|
)
|
||||||
@@ -59,6 +64,46 @@ func NewClassicNameServer(address net.Destination, dispatcher routing.Dispatcher
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewUDPNameServer creates a UDP DNS client from a URL.
|
||||||
|
func NewUDPNameServer(url *url.URL, dispatcher routing.Dispatcher, local bool, disableCache bool, serveStale bool, serveExpiredTTL uint32, clientIP net.IP) (*ClassicNameServer, error) {
|
||||||
|
if url.Hostname() == "" {
|
||||||
|
return nil, errors.New("missing UDP nameserver host")
|
||||||
|
}
|
||||||
|
port := net.Port(53)
|
||||||
|
if url.Port() != "" {
|
||||||
|
var err error
|
||||||
|
if port, err = net.PortFromString(url.Port()); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if local {
|
||||||
|
dispatcher = &localUDPDispatcher{dispatcher}
|
||||||
|
}
|
||||||
|
s := NewClassicNameServer(net.UDPDestination(net.ParseAddress(url.Hostname()), port), dispatcher, disableCache, serveStale, serveExpiredTTL, clientIP)
|
||||||
|
if local {
|
||||||
|
s.cacheController.name = "UDPL//" + s.address.NetAddr()
|
||||||
|
}
|
||||||
|
return s, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type localUDPDispatcher struct {
|
||||||
|
routing.Dispatcher
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*localUDPDispatcher) Dispatch(ctx context.Context, dest net.Destination) (*transport.Link, error) {
|
||||||
|
conn, err := internet.DialSystem(ctx, dest, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &transport.Link{
|
||||||
|
Reader: &struct {
|
||||||
|
buf.Reader
|
||||||
|
io.Closer
|
||||||
|
}{buf.NewPacketReader(conn), conn},
|
||||||
|
Writer: buf.NewWriter(conn),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Name implements Server.
|
// Name implements Server.
|
||||||
func (s *ClassicNameServer) Name() string {
|
func (s *ClassicNameServer) Name() string {
|
||||||
return s.cacheController.name
|
return s.cacheController.name
|
||||||
|
|||||||
+13
-5
@@ -29,6 +29,7 @@ type MetricsHandler struct {
|
|||||||
listen string
|
listen string
|
||||||
tcpListener xnet.Listener
|
tcpListener xnet.Listener
|
||||||
listener *OutboundListener
|
listener *OutboundListener
|
||||||
|
server *http.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMetricsHandler creates a new MetricsHandler based on the given config.
|
// NewMetricsHandler creates a new MetricsHandler based on the given config.
|
||||||
@@ -50,7 +51,8 @@ func (p *MetricsHandler) Type() interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *MetricsHandler) Start() error {
|
func (p *MetricsHandler) Start() error {
|
||||||
handler := p.httpHandler()
|
server := &http.Server{Handler: p.httpHandler()}
|
||||||
|
p.server = server
|
||||||
|
|
||||||
// direct listen a port if listen is set
|
// direct listen a port if listen is set
|
||||||
if p.listen != "" {
|
if p.listen != "" {
|
||||||
@@ -61,7 +63,7 @@ func (p *MetricsHandler) Start() error {
|
|||||||
p.tcpListener = TCPlistener
|
p.tcpListener = TCPlistener
|
||||||
errors.LogInfo(context.Background(), "Metrics server listening on ", p.listen)
|
errors.LogInfo(context.Background(), "Metrics server listening on ", p.listen)
|
||||||
|
|
||||||
go p.serve(TCPlistener, handler)
|
go p.serve(TCPlistener, server)
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.tag == "" {
|
if p.tag == "" {
|
||||||
@@ -77,7 +79,7 @@ func (p *MetricsHandler) Start() error {
|
|||||||
}
|
}
|
||||||
p.listener = listener
|
p.listener = listener
|
||||||
|
|
||||||
go p.serve(listener, handler)
|
go p.serve(listener, server)
|
||||||
|
|
||||||
if err := p.ohm.RemoveHandler(context.Background(), p.tag); err != nil {
|
if err := p.ohm.RemoveHandler(context.Background(), p.tag); err != nil {
|
||||||
errors.LogInfo(context.Background(), "failed to remove existing handler")
|
errors.LogInfo(context.Background(), "failed to remove existing handler")
|
||||||
@@ -106,6 +108,12 @@ func (p *MetricsHandler) Close() error {
|
|||||||
errs = append(errs, p.listener.Close())
|
errs = append(errs, p.listener.Close())
|
||||||
p.listener = nil
|
p.listener = nil
|
||||||
}
|
}
|
||||||
|
if p.server != nil {
|
||||||
|
if err := p.server.Close(); !isClosedListenerError(err) {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
p.server = nil
|
||||||
|
}
|
||||||
if p.ohm != nil && p.tag != "" {
|
if p.ohm != nil && p.tag != "" {
|
||||||
if err := p.ohm.RemoveHandler(context.Background(), p.tag); err != nil {
|
if err := p.ohm.RemoveHandler(context.Background(), p.tag); err != nil {
|
||||||
errors.LogInfo(context.Background(), "failed to remove metrics handler")
|
errors.LogInfo(context.Background(), "failed to remove metrics handler")
|
||||||
@@ -114,8 +122,8 @@ func (p *MetricsHandler) Close() error {
|
|||||||
return errors.Combine(errs...)
|
return errors.Combine(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MetricsHandler) serve(listener xnet.Listener, handler http.Handler) {
|
func (p *MetricsHandler) serve(listener xnet.Listener, server *http.Server) {
|
||||||
if err := http.Serve(listener, handler); err != nil && !isClosedListenerError(err) {
|
if err := server.Serve(listener); err != nil && !isClosedListenerError(err) {
|
||||||
errors.LogErrorInner(context.Background(), err, "failed to start metrics server")
|
errors.LogErrorInner(context.Background(), err, "failed to start metrics server")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,17 @@ func (m *Manager) AddHandler(ctx context.Context, handler inbound.Handler) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
if m.running {
|
if m.running {
|
||||||
return handler.Start()
|
if err := handler.Start(); err != nil {
|
||||||
|
if len(tag) > 0 {
|
||||||
|
delete(m.taggedHandlers, tag)
|
||||||
|
} else {
|
||||||
|
m.untaggedHandlers = m.untaggedHandlers[:len(m.untaggedHandlers)-1]
|
||||||
|
}
|
||||||
|
if err := handler.Close(); err != nil {
|
||||||
|
errors.LogWarningInner(ctx, err, "failed to close handler ", tag)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -274,7 +274,6 @@ type udpWorker struct {
|
|||||||
activeConn map[connID]*udpConn
|
activeConn map[connID]*udpConn
|
||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cone bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *udpWorker) getConnection(id connID) (*udpConn, bool) {
|
func (w *udpWorker) getConnection(id connID) (*udpConn, bool) {
|
||||||
@@ -316,9 +315,6 @@ func (w *udpWorker) callback(b *buf.Buffer, source net.Destination, originalDest
|
|||||||
src: source,
|
src: source,
|
||||||
}
|
}
|
||||||
if originalDest.IsValid() {
|
if originalDest.IsValid() {
|
||||||
if !w.cone {
|
|
||||||
id.dest = originalDest
|
|
||||||
}
|
|
||||||
b.UDP = &originalDest
|
b.UDP = &originalDest
|
||||||
}
|
}
|
||||||
conn, existing := w.getConnection(id)
|
conn, existing := w.getConnection(id)
|
||||||
@@ -418,8 +414,6 @@ func (w *udpWorker) Start() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
w.cone = w.ctx.Value("cone").(bool)
|
|
||||||
|
|
||||||
w.checker = &task.Periodic{
|
w.checker = &task.Periodic{
|
||||||
Interval: time.Minute,
|
Interval: time.Minute,
|
||||||
Execute: w.clean,
|
Execute: w.clean,
|
||||||
|
|||||||
@@ -125,6 +125,9 @@ func NewHandler(ctx context.Context, config *core.OutboundHandlerConfig) (outbou
|
|||||||
if config.Concurrency == 0 {
|
if config.Concurrency == 0 {
|
||||||
config.Concurrency = 8 // same as before
|
config.Concurrency = 8 // same as before
|
||||||
}
|
}
|
||||||
|
if config.Concurrency > 0 && config.Concurrency < 128 && h.streamSettings != nil && h.streamSettings.ProtocolName == "xdrive" {
|
||||||
|
config.Concurrency = 128
|
||||||
|
}
|
||||||
if config.Concurrency > 0 {
|
if config.Concurrency > 0 {
|
||||||
h.mux = &mux.ClientManager{
|
h.mux = &mux.ClientManager{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
@@ -134,7 +137,7 @@ func NewHandler(ctx context.Context, config *core.OutboundHandlerConfig) (outbou
|
|||||||
Dialer: h,
|
Dialer: h,
|
||||||
Strategy: mux.ClientStrategy{
|
Strategy: mux.ClientStrategy{
|
||||||
MaxConcurrency: uint32(config.Concurrency),
|
MaxConcurrency: uint32(config.Concurrency),
|
||||||
MaxConnection: 128,
|
MaxConnection: 1024,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -155,7 +158,7 @@ func NewHandler(ctx context.Context, config *core.OutboundHandlerConfig) (outbou
|
|||||||
Dialer: h,
|
Dialer: h,
|
||||||
Strategy: mux.ClientStrategy{
|
Strategy: mux.ClientStrategy{
|
||||||
MaxConcurrency: uint32(config.XudpConcurrency),
|
MaxConcurrency: uint32(config.XudpConcurrency),
|
||||||
MaxConnection: 128,
|
MaxConnection: 1024,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func TestOutboundWithoutStatCounter(t *testing.T) {
|
|||||||
ctx = session.ContextWithOutbounds(ctx, []*session.Outbound{{}})
|
ctx = session.ContextWithOutbounds(ctx, []*session.Outbound{{}})
|
||||||
h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{
|
h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{
|
||||||
Tag: "tag",
|
Tag: "tag",
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}}}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}}}),
|
||||||
})
|
})
|
||||||
conn, _ := h.(*Handler).Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146))
|
conn, _ := h.(*Handler).Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146))
|
||||||
_, ok := conn.(*stat.CounterConnection)
|
_, ok := conn.(*stat.CounterConnection)
|
||||||
@@ -78,7 +78,7 @@ func TestOutboundWithStatCounter(t *testing.T) {
|
|||||||
ctx = session.ContextWithOutbounds(ctx, []*session.Outbound{{}})
|
ctx = session.ContextWithOutbounds(ctx, []*session.Outbound{{}})
|
||||||
h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{
|
h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{
|
||||||
Tag: "tag",
|
Tag: "tag",
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}}}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}}}),
|
||||||
})
|
})
|
||||||
conn, _ := h.(*Handler).Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146))
|
conn, _ := h.(*Handler).Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146))
|
||||||
_, ok := conn.(*stat.CounterConnection)
|
_, ok := conn.(*stat.CounterConnection)
|
||||||
@@ -117,7 +117,7 @@ func TestTagsCache(t *testing.T) {
|
|||||||
tag := fmt.Sprintf("%s%d", tags_prefix, idx)
|
tag := fmt.Sprintf("%s%d", tags_prefix, idx)
|
||||||
cfg := &core.OutboundHandlerConfig{
|
cfg := &core.OutboundHandlerConfig{
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}}}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}}}),
|
||||||
}
|
}
|
||||||
if h, err := NewHandler(ctx, cfg); err == nil {
|
if h, err := NewHandler(ctx, cfg); err == nil {
|
||||||
if err := ohm.AddHandler(ctx, h); err == nil {
|
if err := ohm.AddHandler(ctx, h); err == nil {
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import (
|
|||||||
"github.com/xtls/xray-core/features/outbound"
|
"github.com/xtls/xray-core/features/outbound"
|
||||||
"github.com/xtls/xray-core/features/routing"
|
"github.com/xtls/xray-core/features/routing"
|
||||||
routing_session "github.com/xtls/xray-core/features/routing/session"
|
routing_session "github.com/xtls/xray-core/features/routing/session"
|
||||||
"github.com/xtls/xray-core/proxy/blackhole"
|
|
||||||
"github.com/xtls/xray-core/proxy/freedom"
|
"github.com/xtls/xray-core/proxy/freedom"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -397,9 +396,9 @@ end`)
|
|||||||
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
||||||
},
|
},
|
||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{Tag: "default", ProxySettings: serial.ToTypedMessage(&blackhole.Config{})},
|
{Tag: "default", ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Block, Delay: &freedom.Range{}}}})},
|
||||||
{Tag: "direct", ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
{Tag: "direct", ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
})},
|
})},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ func (r *TimeoutWrapperReader) ReadMultiBufferTimeout(duration time.Duration) (M
|
|||||||
}
|
}
|
||||||
return r.mb, r.err
|
return r.mb, r.err
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
return nil, nil
|
return nil, ErrReadTimeout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build !windows && !wasm && !illumos && !openbsd
|
//go:build !windows && !openbsd
|
||||||
// +build !windows,!wasm,!illumos,!openbsd
|
|
||||||
|
|
||||||
package buf
|
package buf
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build !wasm && !openbsd
|
//go:build !openbsd
|
||||||
// +build !wasm,!openbsd
|
|
||||||
|
|
||||||
package buf
|
package buf
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build wasm || openbsd
|
//go:build openbsd
|
||||||
// +build wasm openbsd
|
|
||||||
|
|
||||||
package buf
|
package buf
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build !wasm && !openbsd
|
//go:build !openbsd
|
||||||
// +build !wasm,!openbsd
|
|
||||||
|
|
||||||
package buf_test
|
package buf_test
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
//go:build illumos
|
|
||||||
// +build illumos
|
|
||||||
|
|
||||||
package buf
|
|
||||||
|
|
||||||
import "golang.org/x/sys/unix"
|
|
||||||
|
|
||||||
type unixReader struct {
|
|
||||||
iovs [][]byte
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *unixReader) Init(bs []*Buffer) {
|
|
||||||
iovs := r.iovs
|
|
||||||
if iovs == nil {
|
|
||||||
iovs = make([][]byte, 0, len(bs))
|
|
||||||
}
|
|
||||||
for _, b := range bs {
|
|
||||||
iovs = append(iovs, b.v)
|
|
||||||
}
|
|
||||||
r.iovs = iovs
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *unixReader) Read(fd uintptr) int32 {
|
|
||||||
n, e := unix.Readv(int(fd), r.iovs)
|
|
||||||
if e != nil {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
return int32(n)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *unixReader) Clear() {
|
|
||||||
r.iovs = r.iovs[:0]
|
|
||||||
}
|
|
||||||
|
|
||||||
func newMultiReader() multiReader {
|
|
||||||
return &unixReader{}
|
|
||||||
}
|
|
||||||
@@ -236,6 +236,10 @@ func (w *BufferedWriter) Close() error {
|
|||||||
return common.Close(w.writer)
|
return common.Close(w.writer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *BufferedWriter) Interrupt() {
|
||||||
|
common.Interrupt(w.writer)
|
||||||
|
}
|
||||||
|
|
||||||
// SequentialWriter is a Writer that writes MultiBuffer sequentially into the underlying io.Writer.
|
// SequentialWriter is a Writer that writes MultiBuffer sequentially into the underlying io.Writer.
|
||||||
type SequentialWriter struct {
|
type SequentialWriter struct {
|
||||||
io.Writer
|
io.Writer
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build generate
|
//go:build generate
|
||||||
// +build generate
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|||||||
@@ -188,6 +188,9 @@ var (
|
|||||||
|
|
||||||
// NewClientWorker creates a new mux.Client.
|
// NewClientWorker creates a new mux.Client.
|
||||||
func NewClientWorker(stream transport.Link, s ClientStrategy) (*ClientWorker, error) {
|
func NewClientWorker(stream transport.Link, s ClientStrategy) (*ClientWorker, error) {
|
||||||
|
writer := buf.NewBufferedWriter(stream.Writer)
|
||||||
|
writer.SetBuffered(false)
|
||||||
|
stream.Writer = writer
|
||||||
c := &ClientWorker{
|
c := &ClientWorker{
|
||||||
sessionManager: NewSessionManager(),
|
sessionManager: NewSessionManager(),
|
||||||
link: stream,
|
link: stream,
|
||||||
|
|||||||
@@ -93,9 +93,11 @@ type ServerWorker struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewServerWorker(ctx context.Context, d routing.Dispatcher, link *transport.Link) (*ServerWorker, error) {
|
func NewServerWorker(ctx context.Context, d routing.Dispatcher, link *transport.Link) (*ServerWorker, error) {
|
||||||
|
writer := buf.NewBufferedWriter(link.Writer)
|
||||||
|
writer.SetBuffered(false)
|
||||||
worker := &ServerWorker{
|
worker := &ServerWorker{
|
||||||
dispatcher: d,
|
dispatcher: d,
|
||||||
link: link,
|
link: &transport.Link{Reader: link.Reader, Writer: writer},
|
||||||
sessionManager: NewSessionManager(),
|
sessionManager: NewSessionManager(),
|
||||||
done: done.New(),
|
done: done.New(),
|
||||||
timer: time.NewTicker(60 * time.Second),
|
timer: time.NewTicker(60 * time.Second),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ func FindProcess(network, srcIP string, srcPort uint16, destIP string, destPort
|
|||||||
switch network {
|
switch network {
|
||||||
case "tcp":
|
case "tcp":
|
||||||
if net.ParseIP(srcIP).To4() != nil {
|
if net.ParseIP(srcIP).To4() != nil {
|
||||||
procFiles = []string{"/proc/net/tcp"}
|
procFiles = []string{"/proc/net/tcp", "/proc/net/tcp6"}
|
||||||
} else {
|
} else {
|
||||||
procFiles = []string{"/proc/net/tcp6"}
|
procFiles = []string{"/proc/net/tcp6"}
|
||||||
}
|
}
|
||||||
@@ -45,14 +46,18 @@ func FindProcess(network, srcIP string, srcPort uint16, destIP string, destPort
|
|||||||
panic("Unsupported network type for process lookup.")
|
panic("Unsupported network type for process lookup.")
|
||||||
}
|
}
|
||||||
|
|
||||||
targetHexAddr := formatProcNetAddress(net.ParseIP(srcIP), Port(srcPort))
|
targetHexAddrs := []string{formatProcNetAddress(net.ParseIP(srcIP).To16(), Port(srcPort))}
|
||||||
|
if ipv4 := net.ParseIP(srcIP).To4(); ipv4 != nil {
|
||||||
|
// the one above is then the IPv4-mapped IPv6 address that an IPv6 socket has it as, in the IPv6 file
|
||||||
|
targetHexAddrs = append(targetHexAddrs, formatProcNetAddress(ipv4, Port(srcPort)))
|
||||||
|
}
|
||||||
|
|
||||||
portFallback := ""
|
portFallback := ""
|
||||||
if network == "udp" {
|
if network == "udp" {
|
||||||
portFallback = fmt.Sprintf(":%04X", srcPort)
|
portFallback = fmt.Sprintf(":%04X", srcPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
inode, err := findInodeInFiles(procFiles, targetHexAddr, portFallback)
|
inode, err := findInodeInFiles(procFiles, targetHexAddrs, portFallback)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, "", "", errors.New("could not search in ", strings.Join(procFiles, " and ")).Base(err)
|
return 0, "", "", errors.New("could not search in ", strings.Join(procFiles, " and ")).Base(err)
|
||||||
}
|
}
|
||||||
@@ -84,13 +89,9 @@ func FindProcess(network, srcIP string, srcPort uint16, destIP string, destPort
|
|||||||
return pid, procName, absPath, nil
|
return pid, procName, absPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// formatProcNetAddress formats the 4 or 16 bytes of addr as they are: an IPv4-mapped IPv6 address stays one
|
||||||
func formatProcNetAddress(addr net.IP, port Port) string {
|
func formatProcNetAddress(addr net.IP, port Port) string {
|
||||||
var ipBytes []byte
|
ipBytes := []byte(addr)
|
||||||
if ipv4 := addr.To4(); ipv4 != nil {
|
|
||||||
ipBytes = ipv4
|
|
||||||
} else {
|
|
||||||
ipBytes = addr.To16()
|
|
||||||
}
|
|
||||||
|
|
||||||
var formatted strings.Builder
|
var formatted strings.Builder
|
||||||
formatted.Grow(len(ipBytes)*2 + 5)
|
formatted.Grow(len(ipBytes)*2 + 5)
|
||||||
@@ -101,7 +102,7 @@ func formatProcNetAddress(addr net.IP, port Port) string {
|
|||||||
return formatted.String()
|
return formatted.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func findInodeInFiles(filePaths []string, targetHexAddr, portFallback string) (string, error) {
|
func findInodeInFiles(filePaths []string, targetHexAddrs []string, portFallback string) (string, error) {
|
||||||
onlyMatchedPort := ""
|
onlyMatchedPort := ""
|
||||||
|
|
||||||
for i, filePath := range filePaths {
|
for i, filePath := range filePaths {
|
||||||
@@ -122,7 +123,7 @@ func findInodeInFiles(filePaths []string, targetHexAddr, portFallback string) (s
|
|||||||
}
|
}
|
||||||
|
|
||||||
localAddress := fields[1]
|
localAddress := fields[1]
|
||||||
if localAddress == targetHexAddr {
|
if slices.Contains(targetHexAddrs, localAddress) {
|
||||||
return fields[9], nil
|
return fields[9], nil
|
||||||
}
|
}
|
||||||
if portFallback != "" && strings.HasSuffix(localAddress, portFallback) {
|
if portFallback != "" && strings.HasSuffix(localAddress, portFallback) {
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
//go:build linux && !android
|
||||||
|
|
||||||
|
package net
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
stdnet "net"
|
||||||
|
"net/netip"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFindProcessIPv4Mapped(t *testing.T) {
|
||||||
|
listener, err := stdnet.Listen("tcp4", "127.0.0.1:0")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer listener.Close()
|
||||||
|
peer, err := stdnet.ListenPacket("udp4", "127.0.0.1:0")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer peer.Close()
|
||||||
|
|
||||||
|
// an IPv6 socket that connects to an IPv4 address, as the sockets of Java and .NET are
|
||||||
|
for _, c := range []struct{ local, remote stdnet.Addr }{
|
||||||
|
{&stdnet.TCPAddr{IP: stdnet.IPv6zero}, listener.Addr()},
|
||||||
|
{&stdnet.UDPAddr{IP: stdnet.IPv6zero}, peer.LocalAddr()},
|
||||||
|
} {
|
||||||
|
network := c.remote.Network()
|
||||||
|
conn, err := (&stdnet.Dialer{LocalAddr: c.local}).Dial(network, c.remote.String())
|
||||||
|
if errors.Is(err, syscall.EAFNOSUPPORT) {
|
||||||
|
t.Skip("no IPv6 sockets here")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
local := netip.MustParseAddrPort(conn.LocalAddr().String())
|
||||||
|
remote := netip.MustParseAddrPort(c.remote.String())
|
||||||
|
pid, _, _, err := FindProcess(network, "127.0.0.1", local.Port(), "127.0.0.1", remote.Port())
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%s: %v", network, err)
|
||||||
|
} else if pid != os.Getpid() {
|
||||||
|
t.Errorf("%s: found PID %d, want %d", network, pid, os.Getpid())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build !windows
|
//go:build !windows
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ const (
|
|||||||
UseReadV = "xray.buf.readv"
|
UseReadV = "xray.buf.readv"
|
||||||
UseFreedomSplice = "xray.buf.splice"
|
UseFreedomSplice = "xray.buf.splice"
|
||||||
UseVmessPadding = "xray.vmess.padding"
|
UseVmessPadding = "xray.vmess.padding"
|
||||||
UseCone = "xray.cone.disabled"
|
|
||||||
UseStrictJSON = "xray.json.strict"
|
UseStrictJSON = "xray.json.strict"
|
||||||
|
|
||||||
BufferSize = "xray.ray.buffer.size"
|
BufferSize = "xray.ray.buffer.size"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build windows
|
//go:build windows
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ func TestMarshalConfigJson(t *testing.T) {
|
|||||||
func getConfig() string {
|
func getConfig() string {
|
||||||
return `{
|
return `{
|
||||||
"log": {
|
"log": {
|
||||||
"loglevel": "debug"
|
"logLevel": "debug"
|
||||||
},
|
},
|
||||||
"stats": {},
|
"stats": {},
|
||||||
"policy": {
|
"policy": {
|
||||||
|
|||||||
@@ -63,9 +63,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetGlobalID(ctx context.Context) (globalID [8]byte) {
|
func GetGlobalID(ctx context.Context) (globalID [8]byte) {
|
||||||
if cone := ctx.Value("cone"); cone == nil || !cone.(bool) { // cone is nil only in some unit tests
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if inbound := session.InboundFromContext(ctx); inbound != nil && inbound.Source.Network == net.Network_UDP &&
|
if inbound := session.InboundFromContext(ctx); inbound != nil && inbound.Source.Network == net.Network_UDP &&
|
||||||
(inbound.Name == "dokodemo-door" || inbound.Name == "socks" || inbound.Name == "shadowsocks" || inbound.Name == "tun") {
|
(inbound.Name == "dokodemo-door" || inbound.Name == "socks" || inbound.Name == "shadowsocks" || inbound.Name == "tun") {
|
||||||
h := blake3.New(8, ensureBaseKey())
|
h := blake3.New(8, ensureBaseKey())
|
||||||
|
|||||||
+2
-2
@@ -19,8 +19,8 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
Version_x byte = 26
|
Version_x byte = 26
|
||||||
Version_y byte = 10
|
Version_y byte = 11
|
||||||
Version_z byte = 31
|
Version_z byte = 9
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func TestXrayDial(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -105,7 +105,7 @@ func TestXrayDialUDPConn(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -174,7 +174,7 @@ func TestXrayDialUDP(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -192,8 +192,6 @@ func initInstanceWithConfig(config *Config, server *Instance) (bool, error) {
|
|||||||
if err := platform.ReloadEnvSettings(); err != nil {
|
if err := platform.ReloadEnvSettings(); err != nil {
|
||||||
return true, errors.New("failed to reload environment settings").Base(err)
|
return true, errors.New("failed to reload environment settings").Base(err)
|
||||||
}
|
}
|
||||||
server.ctx = context.WithValue(server.ctx, "cone",
|
|
||||||
platform.NewEnvFlag(platform.UseCone).GetValue(func() string { return "" }) != "true")
|
|
||||||
|
|
||||||
for _, appSettings := range config.App {
|
for _, appSettings := range config.App {
|
||||||
settings, err := appSettings.GetInstance()
|
settings, err := appSettings.GetInstance()
|
||||||
|
|||||||
@@ -3,24 +3,24 @@ module github.com/xtls/xray-core
|
|||||||
go 1.27
|
go 1.27
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/apernet/quic-go v0.61.1-0.20260806010916-184d081eef3e
|
github.com/apernet/quic-go v0.63.1-0.20261004180939-a10df75c260c
|
||||||
github.com/bufbuild/protocompile v0.14.1
|
github.com/bufbuild/protocompile v0.14.1
|
||||||
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344
|
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344
|
||||||
github.com/golang/mock v1.7.0-rc.1
|
github.com/golang/mock v1.7.0-rc.1
|
||||||
github.com/google/go-cmp v0.7.0
|
github.com/google/go-cmp v0.7.0
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/gorilla/websocket v1.5.3
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/klauspost/cpuid/v2 v2.4.1
|
github.com/klauspost/cpuid/v2 v2.4.2
|
||||||
github.com/libp2p/go-nat v1.0.1-0.20250821073202-01afc089f138
|
github.com/libp2p/go-nat v1.0.1-0.20250821073202-01afc089f138
|
||||||
github.com/miekg/dns v1.1.73
|
github.com/miekg/dns v1.1.73
|
||||||
github.com/pelletier/go-toml v1.9.5
|
github.com/pelletier/go-toml v1.9.5
|
||||||
github.com/pion/stun/v3 v3.1.7
|
github.com/pion/stun/v3 v3.1.7
|
||||||
github.com/pires/go-proxyproto v0.16.0
|
github.com/pires/go-proxyproto v0.16.0
|
||||||
github.com/refraction-networking/utls v1.8.3-0.20260301010127-aa6edf4b11af
|
github.com/refraction-networking/utls v1.8.3-0.20261108164504-a13c59ffe98b
|
||||||
github.com/robfig/cron/v3 v3.0.1
|
github.com/robfig/cron/v3 v3.0.1
|
||||||
github.com/stretchr/testify v1.12.1
|
github.com/stretchr/testify v1.12.1
|
||||||
github.com/vishvananda/netlink v1.3.1
|
github.com/vishvananda/netlink v1.3.1
|
||||||
github.com/xtls/reality v0.0.0-20261014101318-83f621788ca8
|
github.com/xtls/reality v0.0.0-20261108101329-4bb46b2afd8b
|
||||||
github.com/yuin/gopher-lua v1.1.2
|
github.com/yuin/gopher-lua v1.1.2
|
||||||
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba
|
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba
|
||||||
golang.org/x/crypto v0.58.0
|
golang.org/x/crypto v0.58.0
|
||||||
@@ -41,14 +41,14 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/andybalholm/brotli v1.2.3 // indirect
|
|
||||||
github.com/google/gopacket v1.1.19 // indirect
|
github.com/google/gopacket v1.1.19 // indirect
|
||||||
github.com/huin/goupnp v1.2.0 // indirect
|
github.com/huin/goupnp v1.2.0 // indirect
|
||||||
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
|
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
|
||||||
github.com/juju/ratelimit v1.0.2 // indirect
|
github.com/juju/ratelimit v1.0.2 // indirect
|
||||||
github.com/klauspost/compress v1.20.0 // indirect
|
github.com/klauspost/compress v1.20.4 // indirect
|
||||||
github.com/koron/go-ssdp v0.0.4 // indirect
|
github.com/koron/go-ssdp v0.0.4 // indirect
|
||||||
github.com/libp2p/go-netroute v0.2.1 // indirect
|
github.com/libp2p/go-netroute v0.2.1 // indirect
|
||||||
|
github.com/molecule-man/go-brrr v1.2.0 // indirect
|
||||||
github.com/pion/dtls/v3 v3.1.5 // indirect
|
github.com/pion/dtls/v3 v3.1.5 // indirect
|
||||||
github.com/pion/logging v0.2.4 // indirect
|
github.com/pion/logging v0.2.4 // indirect
|
||||||
github.com/pion/transport/v4 v4.1.0 // indirect
|
github.com/pion/transport/v4 v4.1.0 // indirect
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
github.com/andybalholm/brotli v1.2.3 h1:8H1qwOkl2LPfjf3YezB90JnCliZb6SInJ/OJkEbA5NQ=
|
github.com/apernet/quic-go v0.63.1-0.20261004180939-a10df75c260c h1:cxK8qTA0YCsj68A7zLYDCfPgMTOyt3ePkHh+oXEmYU0=
|
||||||
github.com/andybalholm/brotli v1.2.3/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
|
github.com/apernet/quic-go v0.63.1-0.20261004180939-a10df75c260c/go.mod h1:J7UZVOMF2M1LiE3iiUZWPuy8YCPAcLJOwVURrfJCvc0=
|
||||||
github.com/apernet/quic-go v0.61.1-0.20260806010916-184d081eef3e h1:5mgtR5gwIgBKMiGI1QdXldZZ+SNor06Nbu1wCBulQBg=
|
|
||||||
github.com/apernet/quic-go v0.61.1-0.20260806010916-184d081eef3e/go.mod h1:x7qxEvX6MCVtDuBKHj3E+88+BtrbEMuAL5qGUKItjW8=
|
|
||||||
github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw=
|
github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw=
|
||||||
github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c=
|
github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c=
|
||||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||||
@@ -33,10 +31,12 @@ github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7Bd
|
|||||||
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
|
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
|
||||||
github.com/juju/ratelimit v1.0.2 h1:sRxmtRiajbvrcLQT7S+JbqU0ntsb9W2yhSdNN8tWfaI=
|
github.com/juju/ratelimit v1.0.2 h1:sRxmtRiajbvrcLQT7S+JbqU0ntsb9W2yhSdNN8tWfaI=
|
||||||
github.com/juju/ratelimit v1.0.2/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
|
github.com/juju/ratelimit v1.0.2/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
|
||||||
github.com/klauspost/compress v1.20.0 h1:a3C1ke2ohxFymNlb2HWAHjDeKCI90scRskErZkR0ezA=
|
github.com/klauspost/compress v1.20.1 h1:T7kKElXUMXrUJ2E9QhQhxFtcK5rPyLdsGZvdbLMPdiQ=
|
||||||
github.com/klauspost/compress v1.20.0/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
|
github.com/klauspost/compress v1.20.1/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
|
||||||
github.com/klauspost/cpuid/v2 v2.4.1 h1:I9KxadAkvo+QjtcEE2f2tyfEvmIla/T0m+14PrZNl0U=
|
github.com/klauspost/compress v1.20.4 h1:dD0v/bvxtjCBqQu6sx1TNWkalEY5lNTIe+HY9w8TeNI=
|
||||||
github.com/klauspost/cpuid/v2 v2.4.1/go.mod h1:19jmZ9mjzoF//ddRSUsv0zfBTJWh3QJh9FNxZTMrGxU=
|
github.com/klauspost/compress v1.20.4/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.4.2 h1:xRw7IZEsAgVCp6trS/DgWbTAqpixhmywgVgBjYGg1bQ=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.4.2/go.mod h1:19jmZ9mjzoF//ddRSUsv0zfBTJWh3QJh9FNxZTMrGxU=
|
||||||
github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0=
|
github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0=
|
||||||
github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk=
|
github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk=
|
||||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
@@ -49,6 +49,8 @@ github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9t
|
|||||||
github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ=
|
github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ=
|
||||||
github.com/miekg/dns v1.1.73 h1:uhT8nJxmTrPJYClxVxTCX+CVn6qnzSiybRk72Z6DgrE=
|
github.com/miekg/dns v1.1.73 h1:uhT8nJxmTrPJYClxVxTCX+CVn6qnzSiybRk72Z6DgrE=
|
||||||
github.com/miekg/dns v1.1.73/go.mod h1:RW2Obtfd5NZHvOFe3zYG0W8koWOQtAzyHaLo8vASBuQ=
|
github.com/miekg/dns v1.1.73/go.mod h1:RW2Obtfd5NZHvOFe3zYG0W8koWOQtAzyHaLo8vASBuQ=
|
||||||
|
github.com/molecule-man/go-brrr v1.2.0 h1:dOJU45BC3Gc2WXoxAW0rgCAgVuu2gruAOGncfieA0Jw=
|
||||||
|
github.com/molecule-man/go-brrr v1.2.0/go.mod h1:7ybW6/7gA3oKY45jOfVNjSJDtrr6ea4tzbsTkjmQDC4=
|
||||||
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
|
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
|
||||||
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
||||||
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc=
|
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc=
|
||||||
@@ -67,8 +69,8 @@ github.com/quic-go/go-ossfuzz-seeds v0.1.0 h1:APacT+iIaNF6fd8AGEiN3bT/Jtkd2jz4v4
|
|||||||
github.com/quic-go/go-ossfuzz-seeds v0.1.0/go.mod h1:3IOHRbJIc+L6YKMwfDtJAM9Vj9k0YY4muhuyUYk5tbk=
|
github.com/quic-go/go-ossfuzz-seeds v0.1.0/go.mod h1:3IOHRbJIc+L6YKMwfDtJAM9Vj9k0YY4muhuyUYk5tbk=
|
||||||
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
|
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
|
||||||
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
|
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
|
||||||
github.com/refraction-networking/utls v1.8.3-0.20260301010127-aa6edf4b11af h1:er2acxbi3N1nvEq6HXHUAR1nTWEJmQfqiGR8EVT9rfs=
|
github.com/refraction-networking/utls v1.8.3-0.20261108164504-a13c59ffe98b h1:Mi/DuaTxHeNIQ9g1ylZicAqa6Cb9wkHRiNtQH9uZ7Ts=
|
||||||
github.com/refraction-networking/utls v1.8.3-0.20260301010127-aa6edf4b11af/go.mod h1:jkSOEkLqn+S/jtpEHPOsVv/4V4EVnelwbMQl4vCWXAM=
|
github.com/refraction-networking/utls v1.8.3-0.20261108164504-a13c59ffe98b/go.mod h1:rc/ctWeKlh9LSk5k90KlSPcwF7P6D31mn/9GI2NAfBI=
|
||||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||||
github.com/rogpeppe/go-internal v1.16.0 h1:O9DK+vNMDVGLr2BeZqmpLeMjiMNkuXfcqntWbZV6S5g=
|
github.com/rogpeppe/go-internal v1.16.0 h1:O9DK+vNMDVGLr2BeZqmpLeMjiMNkuXfcqntWbZV6S5g=
|
||||||
@@ -81,10 +83,8 @@ github.com/vishvananda/netns v0.0.5 h1:DfiHV+j8bA32MFM7bfEunvT8IAqQ/NzSJHtcmW5zd
|
|||||||
github.com/vishvananda/netns v0.0.5/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
|
github.com/vishvananda/netns v0.0.5/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
|
||||||
github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU=
|
github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU=
|
||||||
github.com/wlynxg/anet v0.0.5/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
|
github.com/wlynxg/anet v0.0.5/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
|
||||||
github.com/xtls/reality v0.0.0-20261014101318-83f621788ca8 h1:RjLnVvlzK4q6zWaSBPNRGsrgx2fbJDeUWffjw574uzs=
|
github.com/xtls/reality v0.0.0-20261108101329-4bb46b2afd8b h1:fAn11r21QiUY2oAGwENWb5ummjhWwMcs2WzkbjDMh+k=
|
||||||
github.com/xtls/reality v0.0.0-20261014101318-83f621788ca8/go.mod h1:ptlSkJ8k/7IDauNH0SA96JPOo+nYGLTv2Y3UMpwvAsY=
|
github.com/xtls/reality v0.0.0-20261108101329-4bb46b2afd8b/go.mod h1:ptlSkJ8k/7IDauNH0SA96JPOo+nYGLTv2Y3UMpwvAsY=
|
||||||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
|
||||||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
|
||||||
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
github.com/yuin/gopher-lua v0.0.0-20190206043414-8bfc7677f583/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
|
github.com/yuin/gopher-lua v0.0.0-20190206043414-8bfc7677f583/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
|
||||||
github.com/yuin/gopher-lua v1.1.2 h1:yF/FjE3hD65tBbt0VXLE13HWS9h34fdzJmrWRXwobGA=
|
github.com/yuin/gopher-lua v1.1.2 h1:yF/FjE3hD65tBbt0VXLE13HWS9h34fdzJmrWRXwobGA=
|
||||||
|
|||||||
+12
-6
@@ -5,7 +5,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/proxy/blackhole"
|
"github.com/xtls/xray-core/common/log"
|
||||||
|
"github.com/xtls/xray-core/proxy/freedom"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,24 +20,29 @@ type BlackholeConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *BlackholeConfig) Build() (proto.Message, error) {
|
func (v *BlackholeConfig) Build() (proto.Message, error) {
|
||||||
config := new(blackhole.Config)
|
errors.PrintDeprecatedFeatureWarning(`"blackhole" outbound`, `"freedom" outbound with a blocking "firewall" rule`)
|
||||||
|
rule := &freedom.FirewallConfig{
|
||||||
|
Action: freedom.RuleAction_Block,
|
||||||
|
Delay: &freedom.Range{},
|
||||||
|
LogLevel: log.Severity_Unknown.Enum(),
|
||||||
|
}
|
||||||
if v.Response != nil {
|
if v.Response != nil {
|
||||||
responseName := strings.ToLower(v.Response.Type)
|
responseName := strings.ToLower(v.Response.Type)
|
||||||
switch responseName {
|
switch responseName {
|
||||||
case "none", "":
|
case "none", "":
|
||||||
config.Response = &blackhole.Response{Type: "none"}
|
rule.Reply = &freedom.Reply{Type: "none"}
|
||||||
case "http":
|
case "http":
|
||||||
config.Response = &blackhole.Response{Type: "http"}
|
rule.Reply = &freedom.Reply{Type: "http"}
|
||||||
case "custom":
|
case "custom":
|
||||||
data, err := base64.StdEncoding.DecodeString(v.Response.CustomResponseData)
|
data, err := base64.StdEncoding.DecodeString(v.Response.CustomResponseData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("failed to decode custom response data: " + err.Error())
|
return nil, errors.New("failed to decode custom response data: " + err.Error())
|
||||||
}
|
}
|
||||||
config.Response = &blackhole.Response{Type: "custom", CustomResponseData: data}
|
rule.Reply = &freedom.Reply{Type: "custom", CustomResponseData: data}
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("unknown blackhole response: " + responseName)
|
return nil, errors.New("unknown blackhole response: " + responseName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return config, nil
|
return &freedom.Config{Firewall: []*freedom.FirewallConfig{rule}}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ package conf_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/xtls/xray-core/common/log"
|
||||||
. "github.com/xtls/xray-core/infra/conf"
|
. "github.com/xtls/xray-core/infra/conf"
|
||||||
"github.com/xtls/xray-core/proxy/blackhole"
|
"github.com/xtls/xray-core/proxy/freedom"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHTTPResponseJSON(t *testing.T) {
|
func TestHTTPResponseJSON(t *testing.T) {
|
||||||
@@ -20,14 +21,25 @@ func TestHTTPResponseJSON(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
Parser: loadJSON(creator),
|
Parser: loadJSON(creator),
|
||||||
Output: &blackhole.Config{
|
Output: &freedom.Config{
|
||||||
Response: &blackhole.Response{Type: "http"},
|
Firewall: []*freedom.FirewallConfig{{
|
||||||
|
Action: freedom.RuleAction_Block,
|
||||||
|
Delay: &freedom.Range{},
|
||||||
|
LogLevel: log.Severity_Unknown.Enum(),
|
||||||
|
Reply: &freedom.Reply{Type: "http"},
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Input: `{}`,
|
Input: `{}`,
|
||||||
Parser: loadJSON(creator),
|
Parser: loadJSON(creator),
|
||||||
Output: &blackhole.Config{},
|
Output: &freedom.Config{
|
||||||
|
Firewall: []*freedom.FirewallConfig{{
|
||||||
|
Action: freedom.RuleAction_Block,
|
||||||
|
Delay: &freedom.Range{},
|
||||||
|
LogLevel: log.Severity_Unknown.Enum(),
|
||||||
|
}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -46,11 +58,16 @@ func TestCustomResponseJSON(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
Parser: loadJSON(creator),
|
Parser: loadJSON(creator),
|
||||||
Output: &blackhole.Config{
|
Output: &freedom.Config{
|
||||||
Response: &blackhole.Response{
|
Firewall: []*freedom.FirewallConfig{{
|
||||||
|
Action: freedom.RuleAction_Block,
|
||||||
|
Delay: &freedom.Range{},
|
||||||
|
LogLevel: log.Severity_Unknown.Enum(),
|
||||||
|
Reply: &freedom.Reply{
|
||||||
Type: "custom",
|
Type: "custom",
|
||||||
CustomResponseData: []byte("custom response"),
|
CustomResponseData: []byte("custom response"),
|
||||||
},
|
},
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
+81
-11
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/geodata"
|
"github.com/xtls/xray-core/common/geodata"
|
||||||
|
"github.com/xtls/xray-core/common/log"
|
||||||
xnet "github.com/xtls/xray-core/common/net"
|
xnet "github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/proxy/freedom"
|
"github.com/xtls/xray-core/proxy/freedom"
|
||||||
@@ -26,7 +27,8 @@ type FreedomConfig struct {
|
|||||||
Noises []*Noise `json:"noises"`
|
Noises []*Noise `json:"noises"`
|
||||||
ProxyProtocol uint32 `json:"proxyProtocol"`
|
ProxyProtocol uint32 `json:"proxyProtocol"`
|
||||||
IPsBlocked *StringList `json:"ipsBlocked"`
|
IPsBlocked *StringList `json:"ipsBlocked"`
|
||||||
FinalRules []*FreedomFinalRuleConfig `json:"finalRules"`
|
Firewall []*FreedomFirewallConfig `json:"firewall"`
|
||||||
|
FinalRules []*FreedomFirewallConfig `json:"finalRules"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Fragment struct {
|
type Fragment struct {
|
||||||
@@ -43,19 +45,45 @@ type Noise struct {
|
|||||||
ApplyTo string `json:"applyTo"`
|
ApplyTo string `json:"applyTo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FreedomFinalRuleConfig struct {
|
type FreedomFirewallConfig struct {
|
||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
Network *NetworkList `json:"network"`
|
Network *NetworkList `json:"network"`
|
||||||
Port *PortList `json:"port"`
|
Port *PortList `json:"port"`
|
||||||
IP *StringList `json:"ip"`
|
IP *StringList `json:"ip"`
|
||||||
|
Delay *Int32Range `json:"delay"`
|
||||||
|
LogLevel string `json:"logLevel"`
|
||||||
|
Reply *FreedomReplyConfig `json:"reply"`
|
||||||
BlockDelay *Int32Range `json:"blockDelay"`
|
BlockDelay *Int32Range `json:"blockDelay"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FreedomReplyConfig struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
CustomResponseData string `json:"customResponseData"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *FreedomReplyConfig) Build() (*freedom.Reply, error) {
|
||||||
|
replyType := strings.ToLower(c.Type)
|
||||||
|
switch replyType {
|
||||||
|
case "none", "":
|
||||||
|
return &freedom.Reply{Type: "none"}, nil
|
||||||
|
case "http":
|
||||||
|
return &freedom.Reply{Type: "http"}, nil
|
||||||
|
case "custom":
|
||||||
|
data, err := base64.StdEncoding.DecodeString(c.CustomResponseData)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("failed to decode custom reply data: " + err.Error())
|
||||||
|
}
|
||||||
|
return &freedom.Reply{Type: "custom", CustomResponseData: data}, nil
|
||||||
|
default:
|
||||||
|
return nil, errors.New("unknown firewall reply: " + replyType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Build implements Buildable
|
// Build implements Buildable
|
||||||
func (c *FreedomConfig) Build() (proto.Message, error) {
|
func (c *FreedomConfig) Build() (proto.Message, error) {
|
||||||
if c.IPsBlocked != nil {
|
if c.IPsBlocked != nil {
|
||||||
// todo: remove legacy
|
// todo: remove legacy
|
||||||
errors.LogWarning(context.Background(), `The feature "ipsBlocked" has been removed and migrated to "finalRules". Please update your config(s) according to release note and documentation.`)
|
errors.LogWarning(context.Background(), `The feature "ipsBlocked" has been removed and migrated to "firewall". Please update your config(s) according to release note and documentation.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
config := new(freedom.Config)
|
config := new(freedom.Config)
|
||||||
@@ -181,15 +209,22 @@ func (c *FreedomConfig) Build() (proto.Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.ProxyProtocol > 0 && c.ProxyProtocol <= 2 {
|
if c.ProxyProtocol > 0 && c.ProxyProtocol <= 2 {
|
||||||
config.ProxyProtocol = c.ProxyProtocol
|
errors.PrintDeprecatedFeatureWarning(`"proxyProtocol" in Freedom`, `"proxy-protocol" in "streamSettings.finalmask.tcp"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, r := range c.FinalRules {
|
firewall := c.Firewall
|
||||||
|
if c.FinalRules != nil {
|
||||||
|
errors.PrintDeprecatedFeatureWarning("finalRules", "firewall")
|
||||||
|
if firewall == nil {
|
||||||
|
firewall = c.FinalRules
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, r := range firewall {
|
||||||
rule, err := r.Build()
|
rule, err := r.Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
config.FinalRules = append(config.FinalRules, rule)
|
config.Firewall = append(config.Firewall, rule)
|
||||||
}
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
@@ -251,8 +286,8 @@ func ParseNoise(noise *Noise) (*freedom.Noise, error) {
|
|||||||
return NConfig, nil
|
return NConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FreedomFinalRuleConfig) Build() (*freedom.FinalRuleConfig, error) {
|
func (c *FreedomFirewallConfig) Build() (*freedom.FirewallConfig, error) {
|
||||||
rule := &freedom.FinalRuleConfig{}
|
rule := &freedom.FirewallConfig{}
|
||||||
|
|
||||||
switch strings.ToLower(c.Action) {
|
switch strings.ToLower(c.Action) {
|
||||||
case "allow":
|
case "allow":
|
||||||
@@ -280,10 +315,45 @@ func (c *FreedomFinalRuleConfig) Build() (*freedom.FinalRuleConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.BlockDelay != nil {
|
if c.BlockDelay != nil {
|
||||||
rule.BlockDelay = &freedom.Range{
|
errors.PrintDeprecatedFeatureWarning("firewall.blockDelay", "firewall.delay")
|
||||||
Min: uint64(c.BlockDelay.From),
|
c.Delay = c.BlockDelay
|
||||||
Max: uint64(c.BlockDelay.To),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rule.Action != freedom.RuleAction_Block {
|
||||||
|
if c.Delay != nil || c.LogLevel != "" || c.Reply != nil {
|
||||||
|
return nil, errors.New("delay, logLevel and reply are only supported for firewall action block")
|
||||||
|
}
|
||||||
|
return rule, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Delay != nil {
|
||||||
|
rule.Delay = &freedom.Range{
|
||||||
|
Min: uint64(c.Delay.From),
|
||||||
|
Max: uint64(c.Delay.To),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Reply != nil {
|
||||||
|
reply, err := c.Reply.Build()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
rule.Reply = reply
|
||||||
|
}
|
||||||
|
|
||||||
|
switch strings.ToLower(c.LogLevel) {
|
||||||
|
case "", "info":
|
||||||
|
rule.LogLevel = log.Severity_Info.Enum()
|
||||||
|
case "none":
|
||||||
|
rule.LogLevel = log.Severity_Unknown.Enum()
|
||||||
|
case "debug":
|
||||||
|
rule.LogLevel = log.Severity_Debug.Enum()
|
||||||
|
case "warning":
|
||||||
|
rule.LogLevel = log.Severity_Warning.Enum()
|
||||||
|
case "error":
|
||||||
|
rule.LogLevel = log.Severity_Error.Enum()
|
||||||
|
default:
|
||||||
|
return nil, errors.New("unknown firewall.logLevel: ", c.LogLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
return rule, nil
|
return rule, nil
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common/geodata"
|
"github.com/xtls/xray-core/common/geodata"
|
||||||
|
"github.com/xtls/xray-core/common/log"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
. "github.com/xtls/xray-core/infra/conf"
|
. "github.com/xtls/xray-core/infra/conf"
|
||||||
@@ -41,12 +42,17 @@ func TestFreedomConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Input: `{
|
Input: `{
|
||||||
"finalRules": [{
|
"firewall": [{
|
||||||
"action": "block",
|
"action": "block",
|
||||||
"network": "tcp,udp",
|
"network": "tcp,udp",
|
||||||
"port": "53,443",
|
"port": "53,443",
|
||||||
"ip": ["10.0.0.0/8", "2001:db8::/32"],
|
"ip": ["10.0.0.0/8", "2001:db8::/32"],
|
||||||
"blockDelay": "30-60"
|
"delay": "30-60",
|
||||||
|
"logLevel": "debug",
|
||||||
|
"reply": {
|
||||||
|
"type": "custom",
|
||||||
|
"customResponseData": "Y3VzdG9tIHJlc3BvbnNl"
|
||||||
|
}
|
||||||
}, {
|
}, {
|
||||||
"action": "allow",
|
"action": "allow",
|
||||||
"network": ["udp"]
|
"network": ["udp"]
|
||||||
@@ -54,7 +60,7 @@ func TestFreedomConfig(t *testing.T) {
|
|||||||
}`,
|
}`,
|
||||||
Parser: loadJSON(creator),
|
Parser: loadJSON(creator),
|
||||||
Output: &freedom.Config{
|
Output: &freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{
|
Firewall: []*freedom.FirewallConfig{
|
||||||
{
|
{
|
||||||
Action: freedom.RuleAction_Block,
|
Action: freedom.RuleAction_Block,
|
||||||
Networks: []net.Network{net.Network_TCP, net.Network_UDP},
|
Networks: []net.Network{net.Network_TCP, net.Network_UDP},
|
||||||
@@ -86,9 +92,11 @@ func TestFreedomConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
BlockDelay: &freedom.Range{
|
Delay: &freedom.Range{Min: 30, Max: 60},
|
||||||
Min: 30,
|
LogLevel: log.Severity_Debug.Enum(),
|
||||||
Max: 60,
|
Reply: &freedom.Reply{
|
||||||
|
Type: "custom",
|
||||||
|
CustomResponseData: []byte("custom response"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
+11
-1
@@ -2,6 +2,7 @@ package conf
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
"github.com/xtls/xray-core/app/geodata"
|
"github.com/xtls/xray-core/app/geodata"
|
||||||
@@ -19,11 +20,20 @@ func (c *GeodataAssetConfig) Build() (*geodata.Asset, error) {
|
|||||||
return nil, errors.New("invalid geodata asset url: ", c.URL).Base(err)
|
return nil, errors.New("invalid geodata asset url: ", c.URL).Base(err)
|
||||||
}
|
}
|
||||||
return &geodata.Asset{
|
return &geodata.Asset{
|
||||||
Url: c.URL,
|
Url: migrateGeodataURL(c.URL),
|
||||||
File: c.File,
|
File: c.File,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func migrateGeodataURL(assetURL string) string {
|
||||||
|
if strings.HasSuffix(strings.ToLower(assetURL), ".dat") && (strings.HasPrefix(strings.ToLower(assetURL), "https://github.com/xtls/xray-rules-dat/") ||
|
||||||
|
strings.HasPrefix(strings.ToLower(assetURL), "https://raw.githubusercontent.com/xtls/xray-rules-dat/")) {
|
||||||
|
errors.PrintDeprecatedFeatureWarning(assetURL, assetURL+".gz")
|
||||||
|
return assetURL + ".gz"
|
||||||
|
}
|
||||||
|
return assetURL
|
||||||
|
}
|
||||||
|
|
||||||
func validateHTTPS(s string) error {
|
func validateHTTPS(s string) error {
|
||||||
u, err := url.ParseRequestURI(s)
|
u, err := url.ParseRequestURI(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ func DefaultLogConfig() *log.Config {
|
|||||||
type LogConfig struct {
|
type LogConfig struct {
|
||||||
AccessLog string `json:"access"`
|
AccessLog string `json:"access"`
|
||||||
ErrorLog string `json:"error"`
|
ErrorLog string `json:"error"`
|
||||||
LogLevel string `json:"loglevel"`
|
LogLevel string `json:"logLevel"`
|
||||||
DNSLog bool `json:"dnsLog"`
|
DNSLog bool `json:"dnsLog"`
|
||||||
MaskAddress string `json:"maskAddress"`
|
MaskAddress string `json:"maskAddress"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func TestLoaderError(t *testing.T) {
|
|||||||
"log": {
|
"log": {
|
||||||
// abcd
|
// abcd
|
||||||
0,
|
0,
|
||||||
"loglevel": "info"
|
"logLevel": "info"
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
Output: "line 4 char 6",
|
Output: "line 4 char 6",
|
||||||
@@ -27,7 +27,7 @@ func TestLoaderError(t *testing.T) {
|
|||||||
Input: `{
|
Input: `{
|
||||||
"log": {
|
"log": {
|
||||||
// abcd
|
// abcd
|
||||||
"loglevel": "info",
|
"logLevel": "info",
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
Output: "line 5 char 5",
|
Output: "line 5 char 5",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/geodata"
|
"github.com/xtls/xray-core/common/geodata"
|
||||||
xlua "github.com/xtls/xray-core/common/lua"
|
xlua "github.com/xtls/xray-core/common/lua"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
"github.com/xtls/xray-core/transport/internet"
|
||||||
"github.com/xtls/xray-core/transport/internet/finalmask/filter"
|
"github.com/xtls/xray-core/transport/internet/finalmask/filter"
|
||||||
"github.com/xtls/xray-core/transport/internet/finalmask/fragment"
|
"github.com/xtls/xray-core/transport/internet/finalmask/fragment"
|
||||||
@@ -26,6 +27,7 @@ import (
|
|||||||
"github.com/xtls/xray-core/transport/internet/finalmask/mkcp/header"
|
"github.com/xtls/xray-core/transport/internet/finalmask/mkcp/header"
|
||||||
"github.com/xtls/xray-core/transport/internet/finalmask/mkcp/original"
|
"github.com/xtls/xray-core/transport/internet/finalmask/mkcp/original"
|
||||||
"github.com/xtls/xray-core/transport/internet/finalmask/noise"
|
"github.com/xtls/xray-core/transport/internet/finalmask/noise"
|
||||||
|
"github.com/xtls/xray-core/transport/internet/finalmask/proxyprotocol"
|
||||||
"github.com/xtls/xray-core/transport/internet/finalmask/realm"
|
"github.com/xtls/xray-core/transport/internet/finalmask/realm"
|
||||||
"github.com/xtls/xray-core/transport/internet/finalmask/salamander"
|
"github.com/xtls/xray-core/transport/internet/finalmask/salamander"
|
||||||
"github.com/xtls/xray-core/transport/internet/finalmask/sudoku"
|
"github.com/xtls/xray-core/transport/internet/finalmask/sudoku"
|
||||||
@@ -78,6 +80,7 @@ var (
|
|||||||
tcpmaskLoader = NewJSONConfigLoader(ConfigCreatorCache{
|
tcpmaskLoader = NewJSONConfigLoader(ConfigCreatorCache{
|
||||||
"filter": func() interface{} { return new(Filter) },
|
"filter": func() interface{} { return new(Filter) },
|
||||||
"header-custom": func() interface{} { return new(HeaderCustomTCP) },
|
"header-custom": func() interface{} { return new(HeaderCustomTCP) },
|
||||||
|
"proxy-protocol": func() interface{} { return new(ProxyProtocol) },
|
||||||
"fragment": func() interface{} { return new(FragmentMask) },
|
"fragment": func() interface{} { return new(FragmentMask) },
|
||||||
"sudoku": func() interface{} { return new(Sudoku) },
|
"sudoku": func() interface{} { return new(Sudoku) },
|
||||||
"xmc": func() interface{} { return new(XMC) },
|
"xmc": func() interface{} { return new(XMC) },
|
||||||
@@ -97,6 +100,32 @@ var (
|
|||||||
}, "type", "settings")
|
}, "type", "settings")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ProxyProtocol struct {
|
||||||
|
Version uint32 `json:"version"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ProxyProtocol) Build() (proto.Message, error) {
|
||||||
|
version := c.Version
|
||||||
|
if version == 0 {
|
||||||
|
version = 2
|
||||||
|
}
|
||||||
|
if version != 1 && version != 2 {
|
||||||
|
return nil, errors.New("PROXY protocol version must be 1 or 2")
|
||||||
|
}
|
||||||
|
return &proxyprotocol.Config{Version: version}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func addProxyProtocolMask(config *internet.StreamConfig, version uint32) {
|
||||||
|
mask := serial.ToTypedMessage(&proxyprotocol.Config{Version: version})
|
||||||
|
for _, existing := range config.Tcpmasks {
|
||||||
|
if existing.Type == mask.Type {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Put the header directly on the socket, before the other masks.
|
||||||
|
config.Tcpmasks = append(config.Tcpmasks, mask)
|
||||||
|
}
|
||||||
|
|
||||||
type Filter struct {
|
type Filter struct {
|
||||||
BlockedSourceIPs []string `json:"blockedSourceIPs"`
|
BlockedSourceIPs []string `json:"blockedSourceIPs"`
|
||||||
AllowedSourceIPs []string `json:"allowedSourceIPs"`
|
AllowedSourceIPs []string `json:"allowedSourceIPs"`
|
||||||
@@ -935,6 +964,22 @@ type XMC struct {
|
|||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname"`
|
||||||
Profiles []XMCProfile `json:"profiles"`
|
Profiles []XMCProfile `json:"profiles"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
|
Paddings []XMCPaddingTurn `json:"paddings,omitempty"`
|
||||||
|
// A configured list is the complete padding schedule and replaces the
|
||||||
|
// built-in preset entirely, including the preset's Play-state join tail.
|
||||||
|
// NoPadding disables padding. An explicit empty "paddings" array means the
|
||||||
|
// same; an absent one keeps the built-in preset.
|
||||||
|
NoPadding bool `json:"noPadding,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type XMCPaddingTurn struct {
|
||||||
|
Length string `json:"length"`
|
||||||
|
Direction string `json:"direction"`
|
||||||
|
// Delay is an optional millisecond value or inclusive min-max range: the
|
||||||
|
// pause that leads into this turn, written on the turn that follows the gap
|
||||||
|
// it reproduces. The sending side samples the range, the peer spends its
|
||||||
|
// minimum, and nothing pauses after the last turn.
|
||||||
|
Delay string `json:"delay,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type XMCProfile struct {
|
type XMCProfile struct {
|
||||||
@@ -977,6 +1022,48 @@ func (c *XMC) Build() (proto.Message, error) {
|
|||||||
if c.Password == "" {
|
if c.Password == "" {
|
||||||
return nil, fmt.Errorf("empty password")
|
return nil, fmt.Errorf("empty password")
|
||||||
}
|
}
|
||||||
|
if len(c.Password) > xmc.MaxLegacyPasswordLength {
|
||||||
|
return nil, fmt.Errorf("minecraft password is longer than %d bytes", xmc.MaxLegacyPasswordLength)
|
||||||
|
}
|
||||||
|
// An explicit empty array is different from an absent field: json leaves
|
||||||
|
// Paddings nil when it is absent, so the user can turn padding off without
|
||||||
|
// a second switch.
|
||||||
|
noPadding := c.NoPadding || (c.Paddings != nil && len(c.Paddings) == 0)
|
||||||
|
if noPadding && len(c.Paddings) > 0 {
|
||||||
|
return nil, fmt.Errorf("minecraft padding: noPadding and paddings are exclusive")
|
||||||
|
}
|
||||||
|
config := &xmc.Config{Password: c.Password, Hostname: c.Hostname, NoPadding: noPadding}
|
||||||
|
for i, turn := range c.Paddings {
|
||||||
|
minimum, maximum, err := ParseRangeString(turn.Length)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("minecraft padding turn %d length: %w", i, err)
|
||||||
|
}
|
||||||
|
delayMinimum, delayMaximum, err := ParseRangeString(turn.Delay)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("minecraft padding turn %d delay: %w", i, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var direction int32
|
||||||
|
switch turn.Direction {
|
||||||
|
case "c2s", "client-to-server":
|
||||||
|
direction = 1
|
||||||
|
case "s2c", "server-to-client":
|
||||||
|
direction = 2
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("minecraft padding turn %d: invalid direction %q (must be \"c2s\" or \"s2c\")", i, turn.Direction)
|
||||||
|
}
|
||||||
|
|
||||||
|
config.Paddings = append(config.Paddings, &xmc.Padding{
|
||||||
|
LengthMin: int64(minimum),
|
||||||
|
LengthMax: int64(maximum),
|
||||||
|
Direction: direction,
|
||||||
|
DelayMin: int64(delayMinimum),
|
||||||
|
DelayMax: int64(delayMaximum),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := config.ValidatePadding(); err != nil {
|
||||||
|
return nil, fmt.Errorf("minecraft padding: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
rsaPrivateKey, err := xmc.DeriveRSAKey(c.Password)
|
rsaPrivateKey, err := xmc.DeriveRSAKey(c.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -997,13 +1084,10 @@ func (c *XMC) Build() (proto.Message, error) {
|
|||||||
profiles = append(profiles, profile)
|
profiles = append(profiles, profile)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &xmc.Config{
|
config.RsaPrivateKey = x509.MarshalPKCS1PrivateKey(rsaPrivateKey)
|
||||||
Password: c.Password,
|
config.RsaPublicKey = rsaPublicKey
|
||||||
Hostname: c.Hostname,
|
config.Profiles = profiles
|
||||||
RsaPrivateKey: x509.MarshalPKCS1PrivateKey(rsaPrivateKey),
|
return config, nil
|
||||||
RsaPublicKey: rsaPublicKey,
|
|
||||||
Profiles: profiles,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Xicmp struct {
|
type Xicmp struct {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package conf
|
package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -10,6 +11,11 @@ import (
|
|||||||
func TestXMCBuildProfile(t *testing.T) {
|
func TestXMCBuildProfile(t *testing.T) {
|
||||||
built, err := (&XMC{
|
built, err := (&XMC{
|
||||||
Password: "test-password",
|
Password: "test-password",
|
||||||
|
Paddings: []XMCPaddingTurn{
|
||||||
|
{Length: "3", Direction: "c2s"},
|
||||||
|
{Length: "127-129", Direction: "s2c", Delay: "100"},
|
||||||
|
{Length: "8388608", Direction: "c2s", Delay: "50-150"},
|
||||||
|
},
|
||||||
Profiles: []XMCProfile{
|
Profiles: []XMCProfile{
|
||||||
{
|
{
|
||||||
Username: "TestUser",
|
Username: "TestUser",
|
||||||
@@ -26,6 +32,19 @@ func TestXMCBuildProfile(t *testing.T) {
|
|||||||
if len(config.Profiles) != 1 || len(config.Profiles[0].Uuid) != 16 {
|
if len(config.Profiles) != 1 || len(config.Profiles[0].Uuid) != 16 {
|
||||||
t.Fatalf("unexpected profiles: %+v", config.Profiles)
|
t.Fatalf("unexpected profiles: %+v", config.Profiles)
|
||||||
}
|
}
|
||||||
|
if len(config.Paddings) != 3 || config.Paddings[0].LengthMin != 3 || config.Paddings[0].LengthMax != 3 ||
|
||||||
|
config.Paddings[1].LengthMin != 127 || config.Paddings[1].LengthMax != 129 ||
|
||||||
|
config.Paddings[2].LengthMin != 8388608 || config.Paddings[2].LengthMax != 8388608 {
|
||||||
|
t.Fatalf("unexpected padding: %v", config.Paddings)
|
||||||
|
}
|
||||||
|
if config.Paddings[0].Direction != 1 || config.Paddings[1].Direction != 2 || config.Paddings[2].Direction != 1 {
|
||||||
|
t.Fatalf("unexpected padding directions: %v, %v, %v", config.Paddings[0].Direction, config.Paddings[1].Direction, config.Paddings[2].Direction)
|
||||||
|
}
|
||||||
|
if config.Paddings[0].DelayMin != 0 || config.Paddings[0].DelayMax != 0 ||
|
||||||
|
config.Paddings[1].DelayMin != 100 || config.Paddings[1].DelayMax != 100 ||
|
||||||
|
config.Paddings[2].DelayMin != 50 || config.Paddings[2].DelayMax != 150 {
|
||||||
|
t.Fatalf("unexpected padding delays: %v, %v, %v", config.Paddings[0].DelayMin, config.Paddings[1].DelayMin, config.Paddings[2].DelayMin)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestXMCBuildRequiresProfile(t *testing.T) {
|
func TestXMCBuildRequiresProfile(t *testing.T) {
|
||||||
@@ -34,3 +53,101 @@ func TestXMCBuildRequiresProfile(t *testing.T) {
|
|||||||
t.Fatalf("expected required profiles error, got %v", err)
|
t.Fatalf("expected required profiles error, got %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestXMCBuildRejectsPadding(t *testing.T) {
|
||||||
|
for name, padding := range map[string]string{
|
||||||
|
"empty_length": `[{"length": "", "direction": "c2s"}]`,
|
||||||
|
"zero_length": `[{"length": "0", "direction": "c2s"}]`,
|
||||||
|
"one_length": `[{"length": "1", "direction": "c2s"}]`,
|
||||||
|
"two_length": `[{"length": "2", "direction": "c2s"}]`,
|
||||||
|
"negative_length": `[{"length": "-1", "direction": "c2s"}]`,
|
||||||
|
"reversed_range": `[{"length": "64-32", "direction": "c2s"}]`,
|
||||||
|
"oversized_length": `[{"length": "8388609", "direction": "c2s"}]`,
|
||||||
|
"huge_length": `[{"length": "4294967299", "direction": "c2s"}]`,
|
||||||
|
"overflow_length": `[{"length": "9223372036854775808", "direction": "c2s"}]`,
|
||||||
|
"invalid_range_format": `[{"length": "1-2-3", "direction": "c2s"}]`,
|
||||||
|
"invalid_direction": `[{"length": "3", "direction": "invalid"}]`,
|
||||||
|
"missing_direction": `[{"length": "3"}]`,
|
||||||
|
"numeric_direction": `[{"length": "3", "direction": "1"}]`,
|
||||||
|
"negative_delay": `[{"length": "3", "direction": "c2s", "delay": "-1"}]`,
|
||||||
|
"reversed_delay": `[{"length": "3", "direction": "c2s", "delay": "10-5"}]`,
|
||||||
|
"invalid_delay_format": `[{"length": "3", "direction": "c2s", "delay": "abc"}]`,
|
||||||
|
"huge_delay": `[{"length": "3", "direction": "c2s", "delay": "9223372036854775807"}]`,
|
||||||
|
} {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
var config XMC
|
||||||
|
if err := json.Unmarshal([]byte(`{"paddings":`+padding+`}`), &config); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
config.Password = "test-password"
|
||||||
|
config.Profiles = []XMCProfile{{
|
||||||
|
Username: "TestUser", UUID: "00112233-4455-6677-8899-aabbccddeeff",
|
||||||
|
TexturesValue: "textures-value", TexturesSignature: "textures-signature",
|
||||||
|
}}
|
||||||
|
if _, err := config.Build(); err == nil {
|
||||||
|
t.Fatalf("expected error for padding %s, got success", padding)
|
||||||
|
} else {
|
||||||
|
t.Logf("correctly rejected: %v", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestXMCBuildRejectsLongPassword(t *testing.T) {
|
||||||
|
profile := XMCProfile{
|
||||||
|
Username: "TestUser", UUID: "00112233-4455-6677-8899-aabbccddeeff",
|
||||||
|
TexturesValue: "textures-value", TexturesSignature: "textures-signature",
|
||||||
|
}
|
||||||
|
|
||||||
|
// The verify token and the password share one RSA-1024 PKCS#1 v1.5 block,
|
||||||
|
// so the password cannot exceed xmc.MaxLegacyPasswordLength bytes.
|
||||||
|
valid := strings.Repeat("p", xmc.MaxLegacyPasswordLength)
|
||||||
|
if _, err := (&XMC{Password: valid, Profiles: []XMCProfile{profile}}).Build(); err != nil {
|
||||||
|
t.Fatalf("password of %d bytes was rejected: %v", len(valid), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tooLong := valid + "p"
|
||||||
|
_, err := (&XMC{Password: tooLong, Profiles: []XMCProfile{profile}}).Build()
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "longer than") {
|
||||||
|
t.Fatalf("expected a password length error, got %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestXMCBuildDisablesPadding(t *testing.T) {
|
||||||
|
profile := XMCProfile{
|
||||||
|
Username: "TestUser", UUID: "00112233-4455-6677-8899-aabbccddeeff",
|
||||||
|
TexturesValue: "textures-value", TexturesSignature: "textures-signature",
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, settings := range map[string]string{
|
||||||
|
"explicit_empty_array": `{"paddings": []}`,
|
||||||
|
"no_padding_switch": `{"noPadding": true}`,
|
||||||
|
} {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
var config XMC
|
||||||
|
if err := json.Unmarshal([]byte(settings), &config); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
config.Password = "test-password"
|
||||||
|
config.Profiles = []XMCProfile{profile}
|
||||||
|
built, err := config.Build()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("build XMC config: %v", err)
|
||||||
|
}
|
||||||
|
builtConfig := built.(*xmc.Config)
|
||||||
|
if !builtConfig.NoPadding || len(builtConfig.Paddings) != 0 {
|
||||||
|
t.Fatalf("padding was not disabled: %+v", builtConfig)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var config XMC
|
||||||
|
if err := json.Unmarshal([]byte(`{"noPadding": true, "paddings": [{"length": "3", "direction": "c2s"}]}`), &config); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
config.Password = "test-password"
|
||||||
|
config.Profiles = []XMCProfile{profile}
|
||||||
|
if _, err := config.Build(); err == nil || !strings.Contains(err.Error(), "exclusive") {
|
||||||
|
t.Fatalf("expected an exclusive padding error, got %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -697,10 +697,10 @@ func (c *HttpUpgradeConfig) Build() (proto.Message, error) {
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
Byte = 1
|
Byte = 1
|
||||||
Kilobyte = 1024 * Byte
|
Kilobyte = 1000 * Byte
|
||||||
Megabyte = 1024 * Kilobyte
|
Megabyte = 1000 * Kilobyte
|
||||||
Gigabyte = 1024 * Megabyte
|
Gigabyte = 1000 * Megabyte
|
||||||
Terabyte = 1024 * Gigabyte
|
Terabyte = 1000 * Gigabyte
|
||||||
)
|
)
|
||||||
|
|
||||||
type Bandwidth string
|
type Bandwidth string
|
||||||
|
|||||||
+1
-1
@@ -52,7 +52,7 @@ func (v *TunConfig) Build() (proto.Message, error) {
|
|||||||
return nil, errors.New("autoSystemWfpBlockLeak needs autoSystemRoutingTable to be set")
|
return nil, errors.New("autoSystemWfpBlockLeak needs autoSystemRoutingTable to be set")
|
||||||
}
|
}
|
||||||
if tun.BlocksSystemDNS(leaks) && len(v.DNS) == 0 {
|
if tun.BlocksSystemDNS(leaks) && len(v.DNS) == 0 {
|
||||||
return nil, errors.New(`autoSystemWfpBlockLeak "dns", "udp/53", "tcp/53" or "windnsclient" needs dns to be set`)
|
return nil, errors.New(`autoSystemWfpBlockLeak "all", "allexceptlan", "dns", "windnsclient", or TCP or UDP port 53, needs dns to be set`)
|
||||||
}
|
}
|
||||||
case "linux", "freebsd":
|
case "linux", "freebsd":
|
||||||
if v.AutoSystemDnsToGateway && len(v.Gateway) == 0 {
|
if v.AutoSystemDnsToGateway && len(v.Gateway) == 0 {
|
||||||
|
|||||||
+49
-5
@@ -29,18 +29,38 @@ func TestTunConfigAutoSystem(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Input: `{"name": "xray0", "dns": ["1.1.1.1"], "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["dns", "misconfigtun"]}`,
|
Input: `{"name": "xray0", "dns": ["1.1.1.1"], "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["dns", "misconfigtun"]}`,
|
||||||
Parser: loadJSON(creator),
|
Parser: loadJSON(creator),
|
||||||
Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, DNS: []string{"1.1.1.1"}, AutoSystemRoutingTable: []string{"0.0.0.0/0"}, AutoOutboundsInterface: "auto", AutoSystemWfpBlockLeak: []string{"udp/53", "tcp/53", "windnsclient", "tcp/853", "udp/853", "misconfigtun"}},
|
Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, DNS: []string{"1.1.1.1"}, AutoSystemRoutingTable: []string{"0.0.0.0/0"}, AutoOutboundsInterface: "auto", AutoSystemWfpBlockLeak: []string{"53", "853", "windnsclient", "misconfigtun"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Input: `{"name": "xray0", "dns": ["1.1.1.1"], "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["DNS"]}`,
|
Input: `{"name": "xray0", "dns": ["1.1.1.1"], "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["DNS"]}`,
|
||||||
Parser: loadJSON(creator),
|
Parser: loadJSON(creator),
|
||||||
Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, DNS: []string{"1.1.1.1"}, AutoSystemRoutingTable: []string{"0.0.0.0/0"}, AutoOutboundsInterface: "auto", AutoSystemWfpBlockLeak: []string{"udp/53", "tcp/53", "windnsclient", "tcp/853", "udp/853"}},
|
Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, DNS: []string{"1.1.1.1"}, AutoSystemRoutingTable: []string{"0.0.0.0/0"}, AutoOutboundsInterface: "auto", AutoSystemWfpBlockLeak: []string{"53", "853", "windnsclient"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Input: `{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["TCP/853", "udp/853", "tcp/0853"]}`,
|
Input: `{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["TCP/853", "udp/853", "tcp/0853"]}`,
|
||||||
Parser: loadJSON(creator),
|
Parser: loadJSON(creator),
|
||||||
Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, AutoSystemRoutingTable: []string{"0.0.0.0/0"}, AutoOutboundsInterface: "auto", AutoSystemWfpBlockLeak: []string{"tcp/853", "udp/853"}},
|
Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, AutoSystemRoutingTable: []string{"0.0.0.0/0"}, AutoOutboundsInterface: "auto", AutoSystemWfpBlockLeak: []string{"tcp/853", "udp/853"}},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Input: `{"name": "xray0", "dns": ["1.1.1.1"], "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["All", "UDP", "tcp/8000-9000", "icmp"]}`,
|
||||||
|
Parser: loadJSON(creator),
|
||||||
|
Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, DNS: []string{"1.1.1.1"}, AutoSystemRoutingTable: []string{"0.0.0.0/0"}, AutoOutboundsInterface: "auto", AutoSystemWfpBlockLeak: []string{"all", "udp", "tcp/8000-9000", "icmp"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: `{"name": "xray0", "dns": ["1.1.1.1"], "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["AllExceptLAN"]}`,
|
||||||
|
Parser: loadJSON(creator),
|
||||||
|
Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, DNS: []string{"1.1.1.1"}, AutoSystemRoutingTable: []string{"0.0.0.0/0"}, AutoOutboundsInterface: "auto", AutoSystemWfpBlockLeak: []string{"allexceptlan", "53", "853", "windnsclient"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: `{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["1.1.1.1/24:TCP/853", "[2001:DB8::/32]:udp/10-20", "[::/0]:ICMP", "853"]}`,
|
||||||
|
Parser: loadJSON(creator),
|
||||||
|
Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, AutoSystemRoutingTable: []string{"0.0.0.0/0"}, AutoOutboundsInterface: "auto", AutoSystemWfpBlockLeak: []string{"1.1.1.0/24:tcp/853", "[2001:db8::/32]:udp/10-20", "[::/0]:icmp", "853"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: `{"name": "xray0", "dns": ["1.1.1.1"], "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["0.0.0.0/0:dns", "[::/0]:All", "53"]}`,
|
||||||
|
Parser: loadJSON(creator),
|
||||||
|
Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, DNS: []string{"1.1.1.1"}, AutoSystemRoutingTable: []string{"0.0.0.0/0"}, AutoOutboundsInterface: "auto", AutoSystemWfpBlockLeak: []string{"0.0.0.0/0:53", "0.0.0.0/0:853", "0.0.0.0/0:windnsclient", "[::/0]:all", "53"}},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +77,21 @@ func TestTunConfigAutoSystemNeeds(t *testing.T) {
|
|||||||
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["udp/53"]}`, []string{"windows"}},
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["udp/53"]}`, []string{"windows"}},
|
||||||
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["windnsclient"]}`, []string{"windows"}},
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["windnsclient"]}`, []string{"windows"}},
|
||||||
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["tcp/853", "udp/853"]}`, nil},
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["tcp/853", "udp/853"]}`, nil},
|
||||||
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["all"]}`, []string{"windows"}},
|
||||||
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["udp"]}`, []string{"windows"}},
|
||||||
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["tcp/50-60"]}`, []string{"windows"}},
|
||||||
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["tcp/54-60", "icmp"]}`, nil},
|
||||||
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["53"]}`, []string{"windows"}},
|
||||||
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["50-60"]}`, []string{"windows"}},
|
||||||
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["[::/0]:udp/53"]}`, []string{"windows"}},
|
||||||
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["1.1.1.1/32:dns"]}`, []string{"windows"}},
|
||||||
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["[2001:db8::/32]:all"]}`, []string{"windows"}},
|
||||||
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["0.0.0.0/0:windnsclient"]}`, []string{"windows"}},
|
||||||
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["0.0.0.0/0:tcp/853", "1.1.1.0/24:icmp", "[::/0]:misconfigtun", "54-60"]}`, nil},
|
||||||
|
{`{"name": "xray0", "autoSystemWfpBlockLeak": ["[::/0]:misconfigtun"]}`, []string{"windows"}},
|
||||||
|
{`{"name": "xray0", "autoSystemWfpBlockLeak": ["all"]}`, []string{"windows"}},
|
||||||
|
{`{"name": "xray0", "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["allexceptlan"]}`, []string{"windows"}},
|
||||||
|
{`{"name": "xray0", "dns": ["1.1.1.1"], "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["allexceptlan"]}`, nil},
|
||||||
{`{"name": "xray0", "autoSystemDnsToGateway": true}`, []string{"linux", "freebsd"}},
|
{`{"name": "xray0", "autoSystemDnsToGateway": true}`, []string{"linux", "freebsd"}},
|
||||||
} {
|
} {
|
||||||
config := new(TunConfig)
|
config := new(TunConfig)
|
||||||
@@ -70,12 +105,21 @@ func TestTunConfigAutoSystemNeeds(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTunConfigAutoSystemWfpBlockLeakUnknown(t *testing.T) {
|
func TestTunConfigAutoSystemWfpBlockLeakUnknown(t *testing.T) {
|
||||||
for _, value := range []string{"ip", "tcp/0", "icmp/1"} {
|
// With the settings the values need on Windows, so that only an unknown
|
||||||
|
// one fails.
|
||||||
|
build := func(value string) error {
|
||||||
config := new(TunConfig)
|
config := new(TunConfig)
|
||||||
if err := json.Unmarshal([]byte(`{"name": "xray0", "autoSystemWfpBlockLeak": ["dns", "`+value+`"]}`), config); err != nil {
|
if err := json.Unmarshal([]byte(`{"name": "xray0", "dns": ["1.1.1.1"], "autoSystemRoutingTable": ["0.0.0.0/0"], "autoSystemWfpBlockLeak": ["dns", "`+value+`"]}`), config); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if _, err := config.Build(); err == nil {
|
_, err := config.Build()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := build("1.1.1.0/24:53"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, value := range []string{"ip", "tcp/0", "tcp/0-10", "icmp/1", "udp/20-10", "0", "20-10", "53/tcp", "tcpv4", "ipv4:udp", "1.1.1.1:53", "2001:db8::/32:53", "[1.1.1.0/24]:53", "[::ffff:1.1.1.0/120]:53", "1.1.1.0/24"} {
|
||||||
|
if build(value) == nil {
|
||||||
t.Errorf("autoSystemWfpBlockLeak value %q was accepted", value)
|
t.Errorf("autoSystemWfpBlockLeak value %q was accepted", value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-1
@@ -407,7 +407,16 @@ func (c *OutboundDetourConfig) Build() (*core.OutboundHandlerConfig, error) {
|
|||||||
return nil, errors.New("the masque transport can only be used by the masque outbound")
|
return nil, errors.New("the masque transport can only be used by the masque outbound")
|
||||||
}
|
}
|
||||||
|
|
||||||
if fc, ok := ts.(*freedom.Config); ok {
|
if _, ok := rawConfig.(*BlackholeConfig); ok {
|
||||||
|
// The legacy blackhole outbound never used its transport settings.
|
||||||
|
senderSettings.StreamSettings = nil
|
||||||
|
} else if fc, ok := ts.(*freedom.Config); ok {
|
||||||
|
if legacy := rawConfig.(*FreedomConfig); legacy.ProxyProtocol > 0 && legacy.ProxyProtocol <= 2 {
|
||||||
|
if senderSettings.StreamSettings == nil {
|
||||||
|
senderSettings.StreamSettings = &internet.StreamConfig{}
|
||||||
|
}
|
||||||
|
addProxyProtocolMask(senderSettings.StreamSettings, legacy.ProxyProtocol)
|
||||||
|
}
|
||||||
if senderSettings.StreamSettings != nil &&
|
if senderSettings.StreamSettings != nil &&
|
||||||
senderSettings.StreamSettings.SocketSettings != nil &&
|
senderSettings.StreamSettings.SocketSettings != nil &&
|
||||||
senderSettings.StreamSettings.SocketSettings.AddressPortStrategy != internet.AddressPortStrategy_None {
|
senderSettings.StreamSettings.SocketSettings.AddressPortStrategy != internet.AddressPortStrategy_None {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func TestXrayConfig(t *testing.T) {
|
|||||||
Input: `{
|
Input: `{
|
||||||
"log": {
|
"log": {
|
||||||
"access": "/var/log/xray/access.log",
|
"access": "/var/log/xray/access.log",
|
||||||
"loglevel": "error",
|
"logLevel": "error",
|
||||||
"error": "/var/log/xray/error.log"
|
"error": "/var/log/xray/error.log"
|
||||||
},
|
},
|
||||||
"inbounds": [{
|
"inbounds": [{
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import (
|
|||||||
_ "github.com/xtls/xray-core/app/observatory"
|
_ "github.com/xtls/xray-core/app/observatory"
|
||||||
|
|
||||||
// Inbound and outbound proxies.
|
// Inbound and outbound proxies.
|
||||||
_ "github.com/xtls/xray-core/proxy/blackhole"
|
|
||||||
_ "github.com/xtls/xray-core/proxy/dns"
|
_ "github.com/xtls/xray-core/proxy/dns"
|
||||||
_ "github.com/xtls/xray-core/proxy/dokodemo"
|
_ "github.com/xtls/xray-core/proxy/dokodemo"
|
||||||
_ "github.com/xtls/xray-core/proxy/freedom"
|
_ "github.com/xtls/xray-core/proxy/freedom"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build coveragemain
|
//go:build coveragemain
|
||||||
// +build coveragemain
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
// Package blackhole is an outbound handler that blocks all connections.
|
|
||||||
package blackhole
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
|
||||||
"github.com/xtls/xray-core/common/buf"
|
|
||||||
"github.com/xtls/xray-core/common/dice"
|
|
||||||
"github.com/xtls/xray-core/common/errors"
|
|
||||||
"github.com/xtls/xray-core/common/net"
|
|
||||||
"github.com/xtls/xray-core/common/session"
|
|
||||||
"github.com/xtls/xray-core/common/signal"
|
|
||||||
"github.com/xtls/xray-core/transport"
|
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Handler is an outbound connection that silently swallow the entire payload.
|
|
||||||
type Handler struct {
|
|
||||||
response []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
var http403response = http.Response{
|
|
||||||
StatusCode: 403,
|
|
||||||
ProtoMajor: 1,
|
|
||||||
ProtoMinor: 1,
|
|
||||||
Header: http.Header{
|
|
||||||
"Connection": {"close"},
|
|
||||||
"Cache-Control": {"max-age=3600, public"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// New creates a new blackhole handler.
|
|
||||||
func New(ctx context.Context, config *Config) (*Handler, error) {
|
|
||||||
response := []byte{}
|
|
||||||
if config.Response != nil {
|
|
||||||
switch config.Response.Type {
|
|
||||||
case "", "none":
|
|
||||||
case "http":
|
|
||||||
var data bytes.Buffer
|
|
||||||
common.Must(http403response.Write(&data))
|
|
||||||
response = data.Bytes()
|
|
||||||
case "custom":
|
|
||||||
response = config.Response.CustomResponseData
|
|
||||||
default:
|
|
||||||
return nil, errors.New("unknown blackhole response: " + config.Response.Type)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return &Handler{
|
|
||||||
response: response,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process implements OutboundHandler.Dispatch().
|
|
||||||
func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error {
|
|
||||||
outbounds := session.OutboundsFromContext(ctx)
|
|
||||||
ob := outbounds[len(outbounds)-1]
|
|
||||||
ob.Name = "blackhole"
|
|
||||||
|
|
||||||
if len(h.response) > 0 {
|
|
||||||
mbc := buf.MultiBufferContainer{}
|
|
||||||
common.Must2(mbc.Write(h.response))
|
|
||||||
link.Writer.WriteMultiBuffer(mbc.MultiBuffer)
|
|
||||||
// Sleep a little here to make sure the response is sent to client.
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
}
|
|
||||||
defer common.Interrupt(link.Writer)
|
|
||||||
defer common.Interrupt(link.Reader)
|
|
||||||
// wait to drain all the possible incoming UDP data
|
|
||||||
if ob.Target.Network == net.Network_UDP {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
timer := signal.CancelAfterInactivity(ctx, func() {
|
|
||||||
cancel()
|
|
||||||
}, time.Duration(30+dice.Roll(61))*time.Second)
|
|
||||||
go buf.Copy(link.Reader, buf.Discard, buf.UpdateActivity(timer))
|
|
||||||
<-ctx.Done()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
|
||||||
return New(ctx, config.(*Config))
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
package blackhole_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"crypto/rand"
|
|
||||||
"net/http"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
|
||||||
"github.com/xtls/xray-core/common/buf"
|
|
||||||
"github.com/xtls/xray-core/common/session"
|
|
||||||
"github.com/xtls/xray-core/proxy/blackhole"
|
|
||||||
"github.com/xtls/xray-core/transport"
|
|
||||||
"github.com/xtls/xray-core/transport/pipe"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestBlackholeHTTPResponse(t *testing.T) {
|
|
||||||
ctx := session.ContextWithOutbounds(context.Background(), []*session.Outbound{{}})
|
|
||||||
handler, err := blackhole.New(ctx, &blackhole.Config{
|
|
||||||
Response: &blackhole.Response{Type: "http"},
|
|
||||||
})
|
|
||||||
common.Must(err)
|
|
||||||
|
|
||||||
reader, writer := pipe.New(pipe.WithoutSizeLimit())
|
|
||||||
|
|
||||||
dataCh := make(chan buf.MultiBuffer, 1)
|
|
||||||
go func() {
|
|
||||||
mb := common.Must2(reader.ReadMultiBuffer())
|
|
||||||
dataCh <- mb
|
|
||||||
}()
|
|
||||||
link := transport.Link{
|
|
||||||
Reader: reader,
|
|
||||||
Writer: writer,
|
|
||||||
}
|
|
||||||
common.Must(handler.Process(ctx, &link, nil))
|
|
||||||
mb := <-dataCh
|
|
||||||
data := make([]byte, mb.Len())
|
|
||||||
mb.Copy(data)
|
|
||||||
resp := common.Must2(http.ReadResponse(bufio.NewReader(bytes.NewBuffer(data)), nil))
|
|
||||||
if resp.StatusCode != 403 {
|
|
||||||
t.Errorf("expected 403 response, got %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBlackholeCustomResponse(t *testing.T) {
|
|
||||||
ctx := session.ContextWithOutbounds(context.Background(), []*session.Outbound{{}})
|
|
||||||
// slightly bigger than a buffer
|
|
||||||
expected := make([]byte, buf.Size+1000)
|
|
||||||
if _, err := rand.Read(expected); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
handler, err := blackhole.New(ctx, &blackhole.Config{
|
|
||||||
Response: &blackhole.Response{
|
|
||||||
Type: "custom",
|
|
||||||
CustomResponseData: expected,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
common.Must(err)
|
|
||||||
|
|
||||||
reader, writer := pipe.New(pipe.WithoutSizeLimit())
|
|
||||||
var actual buf.MultiBuffer
|
|
||||||
var rerr error
|
|
||||||
go func() {
|
|
||||||
actual, rerr = reader.ReadMultiBuffer()
|
|
||||||
}()
|
|
||||||
|
|
||||||
link := transport.Link{Reader: reader, Writer: writer}
|
|
||||||
common.Must(handler.Process(ctx, &link, nil))
|
|
||||||
common.Must(rerr)
|
|
||||||
|
|
||||||
if actual.String() != string(expected) {
|
|
||||||
t.Errorf("custom response mismatch")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
|
||||||
// versions:
|
|
||||||
// protoc-gen-go v1.36.12
|
|
||||||
// protoc (unknown)
|
|
||||||
// source: proxy/blackhole/config.proto
|
|
||||||
|
|
||||||
package blackhole
|
|
||||||
|
|
||||||
import (
|
|
||||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
|
||||||
reflect "reflect"
|
|
||||||
sync "sync"
|
|
||||||
unsafe "unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Verify that this generated code is sufficiently up-to-date.
|
|
||||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
|
||||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
|
||||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
|
||||||
)
|
|
||||||
|
|
||||||
type Response struct {
|
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
|
||||||
Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
|
|
||||||
CustomResponseData []byte `protobuf:"bytes,2,opt,name=custom_response_data,json=customResponseData,proto3" json:"custom_response_data,omitempty"`
|
|
||||||
unknownFields protoimpl.UnknownFields
|
|
||||||
sizeCache protoimpl.SizeCache
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Response) Reset() {
|
|
||||||
*x = Response{}
|
|
||||||
mi := &file_proxy_blackhole_config_proto_msgTypes[0]
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Response) String() string {
|
|
||||||
return protoimpl.X.MessageStringOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*Response) ProtoMessage() {}
|
|
||||||
|
|
||||||
func (x *Response) ProtoReflect() protoreflect.Message {
|
|
||||||
mi := &file_proxy_blackhole_config_proto_msgTypes[0]
|
|
||||||
if x != nil {
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
if ms.LoadMessageInfo() == nil {
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
return ms
|
|
||||||
}
|
|
||||||
return mi.MessageOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Use Response.ProtoReflect.Descriptor instead.
|
|
||||||
func (*Response) Descriptor() ([]byte, []int) {
|
|
||||||
return file_proxy_blackhole_config_proto_rawDescGZIP(), []int{0}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Response) GetType() string {
|
|
||||||
if x != nil {
|
|
||||||
return x.Type
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Response) GetCustomResponseData() []byte {
|
|
||||||
if x != nil {
|
|
||||||
return x.CustomResponseData
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
|
||||||
Response *Response `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"`
|
|
||||||
unknownFields protoimpl.UnknownFields
|
|
||||||
sizeCache protoimpl.SizeCache
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Config) Reset() {
|
|
||||||
*x = Config{}
|
|
||||||
mi := &file_proxy_blackhole_config_proto_msgTypes[1]
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Config) String() string {
|
|
||||||
return protoimpl.X.MessageStringOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*Config) ProtoMessage() {}
|
|
||||||
|
|
||||||
func (x *Config) ProtoReflect() protoreflect.Message {
|
|
||||||
mi := &file_proxy_blackhole_config_proto_msgTypes[1]
|
|
||||||
if x != nil {
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
if ms.LoadMessageInfo() == nil {
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
return ms
|
|
||||||
}
|
|
||||||
return mi.MessageOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Use Config.ProtoReflect.Descriptor instead.
|
|
||||||
func (*Config) Descriptor() ([]byte, []int) {
|
|
||||||
return file_proxy_blackhole_config_proto_rawDescGZIP(), []int{1}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Config) GetResponse() *Response {
|
|
||||||
if x != nil {
|
|
||||||
return x.Response
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var File_proxy_blackhole_config_proto protoreflect.FileDescriptor
|
|
||||||
|
|
||||||
const file_proxy_blackhole_config_proto_rawDesc = "" +
|
|
||||||
"\n" +
|
|
||||||
"\x1cproxy/blackhole/config.proto\x12\x14xray.proxy.blackhole\"P\n" +
|
|
||||||
"\bResponse\x12\x12\n" +
|
|
||||||
"\x04type\x18\x01 \x01(\tR\x04type\x120\n" +
|
|
||||||
"\x14custom_response_data\x18\x02 \x01(\fR\x12customResponseData\"D\n" +
|
|
||||||
"\x06Config\x12:\n" +
|
|
||||||
"\bresponse\x18\x01 \x01(\v2\x1e.xray.proxy.blackhole.ResponseR\bresponseB^\n" +
|
|
||||||
"\x18com.xray.proxy.blackholeP\x01Z)github.com/xtls/xray-core/proxy/blackhole\xaa\x02\x14Xray.Proxy.Blackholeb\x06proto3"
|
|
||||||
|
|
||||||
var (
|
|
||||||
file_proxy_blackhole_config_proto_rawDescOnce sync.Once
|
|
||||||
file_proxy_blackhole_config_proto_rawDescData []byte
|
|
||||||
)
|
|
||||||
|
|
||||||
func file_proxy_blackhole_config_proto_rawDescGZIP() []byte {
|
|
||||||
file_proxy_blackhole_config_proto_rawDescOnce.Do(func() {
|
|
||||||
file_proxy_blackhole_config_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_proxy_blackhole_config_proto_rawDesc), len(file_proxy_blackhole_config_proto_rawDesc)))
|
|
||||||
})
|
|
||||||
return file_proxy_blackhole_config_proto_rawDescData
|
|
||||||
}
|
|
||||||
|
|
||||||
var file_proxy_blackhole_config_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
|
||||||
var file_proxy_blackhole_config_proto_goTypes = []any{
|
|
||||||
(*Response)(nil), // 0: xray.proxy.blackhole.Response
|
|
||||||
(*Config)(nil), // 1: xray.proxy.blackhole.Config
|
|
||||||
}
|
|
||||||
var file_proxy_blackhole_config_proto_depIdxs = []int32{
|
|
||||||
0, // 0: xray.proxy.blackhole.Config.response:type_name -> xray.proxy.blackhole.Response
|
|
||||||
1, // [1:1] is the sub-list for method output_type
|
|
||||||
1, // [1:1] is the sub-list for method input_type
|
|
||||||
1, // [1:1] is the sub-list for extension type_name
|
|
||||||
1, // [1:1] is the sub-list for extension extendee
|
|
||||||
0, // [0:1] is the sub-list for field type_name
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { file_proxy_blackhole_config_proto_init() }
|
|
||||||
func file_proxy_blackhole_config_proto_init() {
|
|
||||||
if File_proxy_blackhole_config_proto != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
type x struct{}
|
|
||||||
out := protoimpl.TypeBuilder{
|
|
||||||
File: protoimpl.DescBuilder{
|
|
||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
|
||||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_proxy_blackhole_config_proto_rawDesc), len(file_proxy_blackhole_config_proto_rawDesc)),
|
|
||||||
NumEnums: 0,
|
|
||||||
NumMessages: 2,
|
|
||||||
NumExtensions: 0,
|
|
||||||
NumServices: 0,
|
|
||||||
},
|
|
||||||
GoTypes: file_proxy_blackhole_config_proto_goTypes,
|
|
||||||
DependencyIndexes: file_proxy_blackhole_config_proto_depIdxs,
|
|
||||||
MessageInfos: file_proxy_blackhole_config_proto_msgTypes,
|
|
||||||
}.Build()
|
|
||||||
File_proxy_blackhole_config_proto = out.File
|
|
||||||
file_proxy_blackhole_config_proto_goTypes = nil
|
|
||||||
file_proxy_blackhole_config_proto_depIdxs = nil
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package xray.proxy.blackhole;
|
|
||||||
option csharp_namespace = "Xray.Proxy.Blackhole";
|
|
||||||
option go_package = "github.com/xtls/xray-core/proxy/blackhole";
|
|
||||||
option java_package = "com.xray.proxy.blackhole";
|
|
||||||
option java_multiple_files = true;
|
|
||||||
|
|
||||||
message Response {
|
|
||||||
string type = 1;
|
|
||||||
bytes custom_response_data = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message Config {
|
|
||||||
Response response = 1;
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package blackhole_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
|
||||||
"github.com/xtls/xray-core/proxy/blackhole"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestHTTPResponse(t *testing.T) {
|
|
||||||
handler, err := blackhole.New(context.Background(), &blackhole.Config{
|
|
||||||
Response: &blackhole.Response{Type: "http"},
|
|
||||||
})
|
|
||||||
common.Must(err)
|
|
||||||
if handler == nil {
|
|
||||||
t.Error("expected HTTP response handler")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build linux
|
//go:build linux
|
||||||
// +build linux
|
|
||||||
|
|
||||||
package dokodemo
|
package dokodemo
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build openbsd
|
//go:build openbsd
|
||||||
// +build openbsd
|
|
||||||
|
|
||||||
package dokodemo
|
package dokodemo
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build !linux && !openbsd
|
//go:build !linux && !openbsd
|
||||||
// +build !linux,!openbsd
|
|
||||||
|
|
||||||
package dokodemo
|
package dokodemo
|
||||||
|
|
||||||
|
|||||||
+139
-69
@@ -8,6 +8,7 @@ package freedom
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
geodata "github.com/xtls/xray-core/common/geodata"
|
geodata "github.com/xtls/xray-core/common/geodata"
|
||||||
|
log "github.com/xtls/xray-core/common/log"
|
||||||
net "github.com/xtls/xray-core/common/net"
|
net "github.com/xtls/xray-core/common/net"
|
||||||
protocol "github.com/xtls/xray-core/common/protocol"
|
protocol "github.com/xtls/xray-core/common/protocol"
|
||||||
internet "github.com/xtls/xray-core/transport/internet"
|
internet "github.com/xtls/xray-core/transport/internet"
|
||||||
@@ -351,31 +352,28 @@ func (x *Range) GetMax() uint64 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
type FinalRuleConfig struct {
|
type Reply struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Action RuleAction `protobuf:"varint,1,opt,name=action,proto3,enum=xray.proxy.freedom.RuleAction" json:"action,omitempty"`
|
Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
|
||||||
Networks []net.Network `protobuf:"varint,2,rep,packed,name=networks,proto3,enum=xray.common.net.Network" json:"networks,omitempty"`
|
CustomResponseData []byte `protobuf:"bytes,2,opt,name=custom_response_data,json=customResponseData,proto3" json:"custom_response_data,omitempty"`
|
||||||
PortList *net.PortList `protobuf:"bytes,3,opt,name=port_list,json=portList,proto3" json:"port_list,omitempty"`
|
|
||||||
Ip []*geodata.IPRule `protobuf:"bytes,4,rep,name=ip,proto3" json:"ip,omitempty"`
|
|
||||||
BlockDelay *Range `protobuf:"bytes,5,opt,name=block_delay,json=blockDelay,proto3" json:"block_delay,omitempty"`
|
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *FinalRuleConfig) Reset() {
|
func (x *Reply) Reset() {
|
||||||
*x = FinalRuleConfig{}
|
*x = Reply{}
|
||||||
mi := &file_proxy_freedom_config_proto_msgTypes[4]
|
mi := &file_proxy_freedom_config_proto_msgTypes[4]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *FinalRuleConfig) String() string {
|
func (x *Reply) String() string {
|
||||||
return protoimpl.X.MessageStringOf(x)
|
return protoimpl.X.MessageStringOf(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*FinalRuleConfig) ProtoMessage() {}
|
func (*Reply) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *FinalRuleConfig) ProtoReflect() protoreflect.Message {
|
func (x *Reply) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_proxy_freedom_config_proto_msgTypes[4]
|
mi := &file_proxy_freedom_config_proto_msgTypes[4]
|
||||||
if x != nil {
|
if x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
@@ -387,42 +385,113 @@ func (x *FinalRuleConfig) ProtoReflect() protoreflect.Message {
|
|||||||
return mi.MessageOf(x)
|
return mi.MessageOf(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: Use FinalRuleConfig.ProtoReflect.Descriptor instead.
|
// Deprecated: Use Reply.ProtoReflect.Descriptor instead.
|
||||||
func (*FinalRuleConfig) Descriptor() ([]byte, []int) {
|
func (*Reply) Descriptor() ([]byte, []int) {
|
||||||
return file_proxy_freedom_config_proto_rawDescGZIP(), []int{4}
|
return file_proxy_freedom_config_proto_rawDescGZIP(), []int{4}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *FinalRuleConfig) GetAction() RuleAction {
|
func (x *Reply) GetType() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Type
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Reply) GetCustomResponseData() []byte {
|
||||||
|
if x != nil {
|
||||||
|
return x.CustomResponseData
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type FirewallConfig struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Action RuleAction `protobuf:"varint,1,opt,name=action,proto3,enum=xray.proxy.freedom.RuleAction" json:"action,omitempty"`
|
||||||
|
Networks []net.Network `protobuf:"varint,2,rep,packed,name=networks,proto3,enum=xray.common.net.Network" json:"networks,omitempty"`
|
||||||
|
PortList *net.PortList `protobuf:"bytes,3,opt,name=port_list,json=portList,proto3" json:"port_list,omitempty"`
|
||||||
|
Ip []*geodata.IPRule `protobuf:"bytes,4,rep,name=ip,proto3" json:"ip,omitempty"`
|
||||||
|
Delay *Range `protobuf:"bytes,5,opt,name=delay,proto3" json:"delay,omitempty"`
|
||||||
|
LogLevel *log.Severity `protobuf:"varint,6,opt,name=log_level,json=logLevel,proto3,enum=xray.common.log.Severity,oneof" json:"log_level,omitempty"`
|
||||||
|
Reply *Reply `protobuf:"bytes,7,opt,name=reply,proto3" json:"reply,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *FirewallConfig) Reset() {
|
||||||
|
*x = FirewallConfig{}
|
||||||
|
mi := &file_proxy_freedom_config_proto_msgTypes[5]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *FirewallConfig) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*FirewallConfig) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *FirewallConfig) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_proxy_freedom_config_proto_msgTypes[5]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use FirewallConfig.ProtoReflect.Descriptor instead.
|
||||||
|
func (*FirewallConfig) Descriptor() ([]byte, []int) {
|
||||||
|
return file_proxy_freedom_config_proto_rawDescGZIP(), []int{5}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *FirewallConfig) GetAction() RuleAction {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Action
|
return x.Action
|
||||||
}
|
}
|
||||||
return RuleAction_Allow
|
return RuleAction_Allow
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *FinalRuleConfig) GetNetworks() []net.Network {
|
func (x *FirewallConfig) GetNetworks() []net.Network {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Networks
|
return x.Networks
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *FinalRuleConfig) GetPortList() *net.PortList {
|
func (x *FirewallConfig) GetPortList() *net.PortList {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.PortList
|
return x.PortList
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *FinalRuleConfig) GetIp() []*geodata.IPRule {
|
func (x *FirewallConfig) GetIp() []*geodata.IPRule {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Ip
|
return x.Ip
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *FinalRuleConfig) GetBlockDelay() *Range {
|
func (x *FirewallConfig) GetDelay() *Range {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.BlockDelay
|
return x.Delay
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *FirewallConfig) GetLogLevel() log.Severity {
|
||||||
|
if x != nil && x.LogLevel != nil {
|
||||||
|
return *x.LogLevel
|
||||||
|
}
|
||||||
|
return log.Severity(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *FirewallConfig) GetReply() *Reply {
|
||||||
|
if x != nil {
|
||||||
|
return x.Reply
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -433,16 +502,15 @@ type Config struct {
|
|||||||
DestinationOverride *DestinationOverride `protobuf:"bytes,3,opt,name=destination_override,json=destinationOverride,proto3" json:"destination_override,omitempty"`
|
DestinationOverride *DestinationOverride `protobuf:"bytes,3,opt,name=destination_override,json=destinationOverride,proto3" json:"destination_override,omitempty"`
|
||||||
UserLevel uint32 `protobuf:"varint,4,opt,name=user_level,json=userLevel,proto3" json:"user_level,omitempty"`
|
UserLevel uint32 `protobuf:"varint,4,opt,name=user_level,json=userLevel,proto3" json:"user_level,omitempty"`
|
||||||
Fragment *Fragment `protobuf:"bytes,5,opt,name=fragment,proto3" json:"fragment,omitempty"`
|
Fragment *Fragment `protobuf:"bytes,5,opt,name=fragment,proto3" json:"fragment,omitempty"`
|
||||||
ProxyProtocol uint32 `protobuf:"varint,6,opt,name=proxy_protocol,json=proxyProtocol,proto3" json:"proxy_protocol,omitempty"`
|
|
||||||
Noises []*Noise `protobuf:"bytes,7,rep,name=noises,proto3" json:"noises,omitempty"`
|
Noises []*Noise `protobuf:"bytes,7,rep,name=noises,proto3" json:"noises,omitempty"`
|
||||||
FinalRules []*FinalRuleConfig `protobuf:"bytes,8,rep,name=final_rules,json=finalRules,proto3" json:"final_rules,omitempty"`
|
Firewall []*FirewallConfig `protobuf:"bytes,8,rep,name=firewall,proto3" json:"firewall,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Config) Reset() {
|
func (x *Config) Reset() {
|
||||||
*x = Config{}
|
*x = Config{}
|
||||||
mi := &file_proxy_freedom_config_proto_msgTypes[5]
|
mi := &file_proxy_freedom_config_proto_msgTypes[6]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@@ -454,7 +522,7 @@ func (x *Config) String() string {
|
|||||||
func (*Config) ProtoMessage() {}
|
func (*Config) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *Config) ProtoReflect() protoreflect.Message {
|
func (x *Config) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_proxy_freedom_config_proto_msgTypes[5]
|
mi := &file_proxy_freedom_config_proto_msgTypes[6]
|
||||||
if x != nil {
|
if x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@@ -467,7 +535,7 @@ func (x *Config) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use Config.ProtoReflect.Descriptor instead.
|
// Deprecated: Use Config.ProtoReflect.Descriptor instead.
|
||||||
func (*Config) Descriptor() ([]byte, []int) {
|
func (*Config) Descriptor() ([]byte, []int) {
|
||||||
return file_proxy_freedom_config_proto_rawDescGZIP(), []int{5}
|
return file_proxy_freedom_config_proto_rawDescGZIP(), []int{6}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Config) GetDomainStrategy() internet.DomainStrategy {
|
func (x *Config) GetDomainStrategy() internet.DomainStrategy {
|
||||||
@@ -498,13 +566,6 @@ func (x *Config) GetFragment() *Fragment {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Config) GetProxyProtocol() uint32 {
|
|
||||||
if x != nil {
|
|
||||||
return x.ProxyProtocol
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Config) GetNoises() []*Noise {
|
func (x *Config) GetNoises() []*Noise {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Noises
|
return x.Noises
|
||||||
@@ -512,9 +573,9 @@ func (x *Config) GetNoises() []*Noise {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Config) GetFinalRules() []*FinalRuleConfig {
|
func (x *Config) GetFirewall() []*FirewallConfig {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.FinalRules
|
return x.Firewall
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -523,7 +584,7 @@ var File_proxy_freedom_config_proto protoreflect.FileDescriptor
|
|||||||
|
|
||||||
const file_proxy_freedom_config_proto_rawDesc = "" +
|
const file_proxy_freedom_config_proto_rawDesc = "" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"\x1aproxy/freedom/config.proto\x12\x12xray.proxy.freedom\x1a!common/protocol/server_spec.proto\x1a\x1ftransport/internet/config.proto\x1a\x15common/net/port.proto\x1a\x18common/net/network.proto\x1a\x1bcommon/geodata/geodat.proto\"S\n" +
|
"\x1aproxy/freedom/config.proto\x12\x12xray.proxy.freedom\x1a!common/protocol/server_spec.proto\x1a\x1ftransport/internet/config.proto\x1a\x15common/net/port.proto\x1a\x18common/net/network.proto\x1a\x1bcommon/geodata/geodat.proto\x1a\x14common/log/log.proto\"S\n" +
|
||||||
"\x13DestinationOverride\x12<\n" +
|
"\x13DestinationOverride\x12<\n" +
|
||||||
"\x06server\x18\x01 \x01(\v2$.xray.common.protocol.ServerEndpointR\x06server\"\x98\x02\n" +
|
"\x06server\x18\x01 \x01(\v2$.xray.common.protocol.ServerEndpointR\x06server\"\x98\x02\n" +
|
||||||
"\bFragment\x12!\n" +
|
"\bFragment\x12!\n" +
|
||||||
@@ -549,24 +610,28 @@ const file_proxy_freedom_config_proto_rawDesc = "" +
|
|||||||
"\bapply_to\x18\x06 \x01(\tR\aapplyTo\"+\n" +
|
"\bapply_to\x18\x06 \x01(\tR\aapplyTo\"+\n" +
|
||||||
"\x05Range\x12\x10\n" +
|
"\x05Range\x12\x10\n" +
|
||||||
"\x03min\x18\x01 \x01(\x04R\x03min\x12\x10\n" +
|
"\x03min\x18\x01 \x01(\x04R\x03min\x12\x10\n" +
|
||||||
"\x03max\x18\x02 \x01(\x04R\x03max\"\xa0\x02\n" +
|
"\x03max\x18\x02 \x01(\x04R\x03max\"M\n" +
|
||||||
"\x0fFinalRuleConfig\x126\n" +
|
"\x05Reply\x12\x12\n" +
|
||||||
|
"\x04type\x18\x01 \x01(\tR\x04type\x120\n" +
|
||||||
|
"\x14custom_response_data\x18\x02 \x01(\fR\x12customResponseData\"\x90\x03\n" +
|
||||||
|
"\x0eFirewallConfig\x126\n" +
|
||||||
"\x06action\x18\x01 \x01(\x0e2\x1e.xray.proxy.freedom.RuleActionR\x06action\x124\n" +
|
"\x06action\x18\x01 \x01(\x0e2\x1e.xray.proxy.freedom.RuleActionR\x06action\x124\n" +
|
||||||
"\bnetworks\x18\x02 \x03(\x0e2\x18.xray.common.net.NetworkR\bnetworks\x126\n" +
|
"\bnetworks\x18\x02 \x03(\x0e2\x18.xray.common.net.NetworkR\bnetworks\x126\n" +
|
||||||
"\tport_list\x18\x03 \x01(\v2\x19.xray.common.net.PortListR\bportList\x12+\n" +
|
"\tport_list\x18\x03 \x01(\v2\x19.xray.common.net.PortListR\bportList\x12+\n" +
|
||||||
"\x02ip\x18\x04 \x03(\v2\x1b.xray.common.geodata.IPRuleR\x02ip\x12:\n" +
|
"\x02ip\x18\x04 \x03(\v2\x1b.xray.common.geodata.IPRuleR\x02ip\x12/\n" +
|
||||||
"\vblock_delay\x18\x05 \x01(\v2\x19.xray.proxy.freedom.RangeR\n" +
|
"\x05delay\x18\x05 \x01(\v2\x19.xray.proxy.freedom.RangeR\x05delay\x12;\n" +
|
||||||
"blockDelay\"\xaf\x03\n" +
|
"\tlog_level\x18\x06 \x01(\x0e2\x19.xray.common.log.SeverityH\x00R\blogLevel\x88\x01\x01\x12/\n" +
|
||||||
|
"\x05reply\x18\a \x01(\v2\x19.xray.proxy.freedom.ReplyR\x05replyB\f\n" +
|
||||||
|
"\n" +
|
||||||
|
"_log_level\"\x88\x03\n" +
|
||||||
"\x06Config\x12P\n" +
|
"\x06Config\x12P\n" +
|
||||||
"\x0fdomain_strategy\x18\x01 \x01(\x0e2'.xray.transport.internet.DomainStrategyR\x0edomainStrategy\x12Z\n" +
|
"\x0fdomain_strategy\x18\x01 \x01(\x0e2'.xray.transport.internet.DomainStrategyR\x0edomainStrategy\x12Z\n" +
|
||||||
"\x14destination_override\x18\x03 \x01(\v2'.xray.proxy.freedom.DestinationOverrideR\x13destinationOverride\x12\x1d\n" +
|
"\x14destination_override\x18\x03 \x01(\v2'.xray.proxy.freedom.DestinationOverrideR\x13destinationOverride\x12\x1d\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"user_level\x18\x04 \x01(\rR\tuserLevel\x128\n" +
|
"user_level\x18\x04 \x01(\rR\tuserLevel\x128\n" +
|
||||||
"\bfragment\x18\x05 \x01(\v2\x1c.xray.proxy.freedom.FragmentR\bfragment\x12%\n" +
|
"\bfragment\x18\x05 \x01(\v2\x1c.xray.proxy.freedom.FragmentR\bfragment\x121\n" +
|
||||||
"\x0eproxy_protocol\x18\x06 \x01(\rR\rproxyProtocol\x121\n" +
|
"\x06noises\x18\a \x03(\v2\x19.xray.proxy.freedom.NoiseR\x06noises\x12>\n" +
|
||||||
"\x06noises\x18\a \x03(\v2\x19.xray.proxy.freedom.NoiseR\x06noises\x12D\n" +
|
"\bfirewall\x18\b \x03(\v2\".xray.proxy.freedom.FirewallConfigR\bfirewallJ\x04\b\x06\x10\a*\"\n" +
|
||||||
"\vfinal_rules\x18\b \x03(\v2#.xray.proxy.freedom.FinalRuleConfigR\n" +
|
|
||||||
"finalRules*\"\n" +
|
|
||||||
"\n" +
|
"\n" +
|
||||||
"RuleAction\x12\t\n" +
|
"RuleAction\x12\t\n" +
|
||||||
"\x05Allow\x10\x00\x12\t\n" +
|
"\x05Allow\x10\x00\x12\t\n" +
|
||||||
@@ -586,38 +651,42 @@ func file_proxy_freedom_config_proto_rawDescGZIP() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var file_proxy_freedom_config_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
var file_proxy_freedom_config_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||||
var file_proxy_freedom_config_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
|
var file_proxy_freedom_config_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
|
||||||
var file_proxy_freedom_config_proto_goTypes = []any{
|
var file_proxy_freedom_config_proto_goTypes = []any{
|
||||||
(RuleAction)(0), // 0: xray.proxy.freedom.RuleAction
|
(RuleAction)(0), // 0: xray.proxy.freedom.RuleAction
|
||||||
(*DestinationOverride)(nil), // 1: xray.proxy.freedom.DestinationOverride
|
(*DestinationOverride)(nil), // 1: xray.proxy.freedom.DestinationOverride
|
||||||
(*Fragment)(nil), // 2: xray.proxy.freedom.Fragment
|
(*Fragment)(nil), // 2: xray.proxy.freedom.Fragment
|
||||||
(*Noise)(nil), // 3: xray.proxy.freedom.Noise
|
(*Noise)(nil), // 3: xray.proxy.freedom.Noise
|
||||||
(*Range)(nil), // 4: xray.proxy.freedom.Range
|
(*Range)(nil), // 4: xray.proxy.freedom.Range
|
||||||
(*FinalRuleConfig)(nil), // 5: xray.proxy.freedom.FinalRuleConfig
|
(*Reply)(nil), // 5: xray.proxy.freedom.Reply
|
||||||
(*Config)(nil), // 6: xray.proxy.freedom.Config
|
(*FirewallConfig)(nil), // 6: xray.proxy.freedom.FirewallConfig
|
||||||
(*protocol.ServerEndpoint)(nil), // 7: xray.common.protocol.ServerEndpoint
|
(*Config)(nil), // 7: xray.proxy.freedom.Config
|
||||||
(net.Network)(0), // 8: xray.common.net.Network
|
(*protocol.ServerEndpoint)(nil), // 8: xray.common.protocol.ServerEndpoint
|
||||||
(*net.PortList)(nil), // 9: xray.common.net.PortList
|
(net.Network)(0), // 9: xray.common.net.Network
|
||||||
(*geodata.IPRule)(nil), // 10: xray.common.geodata.IPRule
|
(*net.PortList)(nil), // 10: xray.common.net.PortList
|
||||||
(internet.DomainStrategy)(0), // 11: xray.transport.internet.DomainStrategy
|
(*geodata.IPRule)(nil), // 11: xray.common.geodata.IPRule
|
||||||
|
(log.Severity)(0), // 12: xray.common.log.Severity
|
||||||
|
(internet.DomainStrategy)(0), // 13: xray.transport.internet.DomainStrategy
|
||||||
}
|
}
|
||||||
var file_proxy_freedom_config_proto_depIdxs = []int32{
|
var file_proxy_freedom_config_proto_depIdxs = []int32{
|
||||||
7, // 0: xray.proxy.freedom.DestinationOverride.server:type_name -> xray.common.protocol.ServerEndpoint
|
8, // 0: xray.proxy.freedom.DestinationOverride.server:type_name -> xray.common.protocol.ServerEndpoint
|
||||||
0, // 1: xray.proxy.freedom.FinalRuleConfig.action:type_name -> xray.proxy.freedom.RuleAction
|
0, // 1: xray.proxy.freedom.FirewallConfig.action:type_name -> xray.proxy.freedom.RuleAction
|
||||||
8, // 2: xray.proxy.freedom.FinalRuleConfig.networks:type_name -> xray.common.net.Network
|
9, // 2: xray.proxy.freedom.FirewallConfig.networks:type_name -> xray.common.net.Network
|
||||||
9, // 3: xray.proxy.freedom.FinalRuleConfig.port_list:type_name -> xray.common.net.PortList
|
10, // 3: xray.proxy.freedom.FirewallConfig.port_list:type_name -> xray.common.net.PortList
|
||||||
10, // 4: xray.proxy.freedom.FinalRuleConfig.ip:type_name -> xray.common.geodata.IPRule
|
11, // 4: xray.proxy.freedom.FirewallConfig.ip:type_name -> xray.common.geodata.IPRule
|
||||||
4, // 5: xray.proxy.freedom.FinalRuleConfig.block_delay:type_name -> xray.proxy.freedom.Range
|
4, // 5: xray.proxy.freedom.FirewallConfig.delay:type_name -> xray.proxy.freedom.Range
|
||||||
11, // 6: xray.proxy.freedom.Config.domain_strategy:type_name -> xray.transport.internet.DomainStrategy
|
12, // 6: xray.proxy.freedom.FirewallConfig.log_level:type_name -> xray.common.log.Severity
|
||||||
1, // 7: xray.proxy.freedom.Config.destination_override:type_name -> xray.proxy.freedom.DestinationOverride
|
5, // 7: xray.proxy.freedom.FirewallConfig.reply:type_name -> xray.proxy.freedom.Reply
|
||||||
2, // 8: xray.proxy.freedom.Config.fragment:type_name -> xray.proxy.freedom.Fragment
|
13, // 8: xray.proxy.freedom.Config.domain_strategy:type_name -> xray.transport.internet.DomainStrategy
|
||||||
3, // 9: xray.proxy.freedom.Config.noises:type_name -> xray.proxy.freedom.Noise
|
1, // 9: xray.proxy.freedom.Config.destination_override:type_name -> xray.proxy.freedom.DestinationOverride
|
||||||
5, // 10: xray.proxy.freedom.Config.final_rules:type_name -> xray.proxy.freedom.FinalRuleConfig
|
2, // 10: xray.proxy.freedom.Config.fragment:type_name -> xray.proxy.freedom.Fragment
|
||||||
11, // [11:11] is the sub-list for method output_type
|
3, // 11: xray.proxy.freedom.Config.noises:type_name -> xray.proxy.freedom.Noise
|
||||||
11, // [11:11] is the sub-list for method input_type
|
6, // 12: xray.proxy.freedom.Config.firewall:type_name -> xray.proxy.freedom.FirewallConfig
|
||||||
11, // [11:11] is the sub-list for extension type_name
|
13, // [13:13] is the sub-list for method output_type
|
||||||
11, // [11:11] is the sub-list for extension extendee
|
13, // [13:13] is the sub-list for method input_type
|
||||||
0, // [0:11] is the sub-list for field type_name
|
13, // [13:13] is the sub-list for extension type_name
|
||||||
|
13, // [13:13] is the sub-list for extension extendee
|
||||||
|
0, // [0:13] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_proxy_freedom_config_proto_init() }
|
func init() { file_proxy_freedom_config_proto_init() }
|
||||||
@@ -625,13 +694,14 @@ func file_proxy_freedom_config_proto_init() {
|
|||||||
if File_proxy_freedom_config_proto != nil {
|
if File_proxy_freedom_config_proto != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
file_proxy_freedom_config_proto_msgTypes[5].OneofWrappers = []any{}
|
||||||
type x struct{}
|
type x struct{}
|
||||||
out := protoimpl.TypeBuilder{
|
out := protoimpl.TypeBuilder{
|
||||||
File: protoimpl.DescBuilder{
|
File: protoimpl.DescBuilder{
|
||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_proxy_freedom_config_proto_rawDesc), len(file_proxy_freedom_config_proto_rawDesc)),
|
RawDescriptor: unsafe.Slice(unsafe.StringData(file_proxy_freedom_config_proto_rawDesc), len(file_proxy_freedom_config_proto_rawDesc)),
|
||||||
NumEnums: 1,
|
NumEnums: 1,
|
||||||
NumMessages: 6,
|
NumMessages: 7,
|
||||||
NumExtensions: 0,
|
NumExtensions: 0,
|
||||||
NumServices: 0,
|
NumServices: 0,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import "transport/internet/config.proto";
|
|||||||
import "common/net/port.proto";
|
import "common/net/port.proto";
|
||||||
import "common/net/network.proto";
|
import "common/net/network.proto";
|
||||||
import "common/geodata/geodat.proto";
|
import "common/geodata/geodat.proto";
|
||||||
|
import "common/log/log.proto";
|
||||||
|
|
||||||
message DestinationOverride {
|
message DestinationOverride {
|
||||||
xray.common.protocol.ServerEndpoint server = 1;
|
xray.common.protocol.ServerEndpoint server = 1;
|
||||||
@@ -46,20 +47,27 @@ enum RuleAction {
|
|||||||
Block = 1;
|
Block = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message FinalRuleConfig {
|
message Reply {
|
||||||
|
string type = 1;
|
||||||
|
bytes custom_response_data = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message FirewallConfig {
|
||||||
RuleAction action = 1;
|
RuleAction action = 1;
|
||||||
repeated xray.common.net.Network networks = 2;
|
repeated xray.common.net.Network networks = 2;
|
||||||
xray.common.net.PortList port_list = 3;
|
xray.common.net.PortList port_list = 3;
|
||||||
repeated xray.common.geodata.IPRule ip = 4;
|
repeated xray.common.geodata.IPRule ip = 4;
|
||||||
Range block_delay = 5;
|
Range delay = 5;
|
||||||
|
optional xray.common.log.Severity log_level = 6;
|
||||||
|
Reply reply = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Config {
|
message Config {
|
||||||
|
reserved 6;
|
||||||
xray.transport.internet.DomainStrategy domain_strategy = 1;
|
xray.transport.internet.DomainStrategy domain_strategy = 1;
|
||||||
DestinationOverride destination_override = 3;
|
DestinationOverride destination_override = 3;
|
||||||
uint32 user_level = 4;
|
uint32 user_level = 4;
|
||||||
Fragment fragment = 5;
|
Fragment fragment = 5;
|
||||||
uint32 proxy_protocol = 6;
|
|
||||||
repeated Noise noises = 7;
|
repeated Noise noises = 7;
|
||||||
repeated FinalRuleConfig final_rules = 8;
|
repeated FirewallConfig firewall = 8;
|
||||||
}
|
}
|
||||||
|
|||||||
+112
-61
@@ -1,20 +1,22 @@
|
|||||||
package freedom
|
package freedom
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pires/go-proxyproto"
|
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
"github.com/xtls/xray-core/common/buf"
|
"github.com/xtls/xray-core/common/buf"
|
||||||
"github.com/xtls/xray-core/common/crypto"
|
"github.com/xtls/xray-core/common/crypto"
|
||||||
"github.com/xtls/xray-core/common/dice"
|
"github.com/xtls/xray-core/common/dice"
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/geodata"
|
"github.com/xtls/xray-core/common/geodata"
|
||||||
|
"github.com/xtls/xray-core/common/log"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/platform"
|
"github.com/xtls/xray-core/common/platform"
|
||||||
"github.com/xtls/xray-core/common/retry"
|
"github.com/xtls/xray-core/common/retry"
|
||||||
@@ -34,10 +36,20 @@ import (
|
|||||||
var (
|
var (
|
||||||
useSplice atomic.Bool
|
useSplice atomic.Bool
|
||||||
allNetworks [8]bool
|
allNetworks [8]bool
|
||||||
defaultBlockPrivateRule *FinalRule
|
defaultBlockPrivateRule *Firewall
|
||||||
defaultBlockAllRule *FinalRule
|
defaultBlockAllRule *Firewall
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var http403response = http.Response{
|
||||||
|
StatusCode: 403,
|
||||||
|
ProtoMajor: 1,
|
||||||
|
ProtoMinor: 1,
|
||||||
|
Header: http.Header{
|
||||||
|
"Connection": {"close"},
|
||||||
|
"Cache-Control": {"max-age=3600, public"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
func reloadEnvSettings() error {
|
func reloadEnvSettings() error {
|
||||||
const defaultFlagValue = "NOT_DEFINED_AT_ALL"
|
const defaultFlagValue = "NOT_DEFINED_AT_ALL"
|
||||||
value := platform.NewEnvFlag(platform.UseFreedomSplice).GetValue(func() string { return defaultFlagValue })
|
value := platform.NewEnvFlag(platform.UseFreedomSplice).GetValue(func() string { return defaultFlagValue })
|
||||||
@@ -71,39 +83,58 @@ func init() {
|
|||||||
allNetworks[i] = true
|
allNetworks[i] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultBlockPrivateRule = &FinalRule{
|
defaultBlockPrivateRule = &Firewall{
|
||||||
action: RuleAction_Block,
|
action: RuleAction_Block,
|
||||||
network: allNetworks,
|
network: allNetworks,
|
||||||
ip: geodata.GetPrivateIPMatcher(),
|
ip: geodata.GetPrivateIPMatcher(),
|
||||||
|
logLevel: log.Severity_Warning.Enum(),
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultBlockAllRule = &FinalRule{
|
defaultBlockAllRule = &Firewall{
|
||||||
action: RuleAction_Block,
|
action: RuleAction_Block,
|
||||||
network: allNetworks,
|
network: allNetworks,
|
||||||
|
logLevel: log.Severity_Warning.Enum(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type FinalRule struct {
|
type Firewall struct {
|
||||||
action RuleAction
|
action RuleAction
|
||||||
network [8]bool
|
network [8]bool
|
||||||
port net.MemoryPortList
|
port net.MemoryPortList
|
||||||
ip geodata.IPMatcher
|
ip geodata.IPMatcher
|
||||||
blockDelay *Range
|
delay *Range
|
||||||
|
logLevel *log.Severity
|
||||||
|
reply []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler handles Freedom connections.
|
// Handler handles Freedom connections.
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
policyManager policy.Manager
|
policyManager policy.Manager
|
||||||
config *Config
|
config *Config
|
||||||
finalRules []*FinalRule
|
firewall []*Firewall
|
||||||
resolveStrategy internet.DomainStrategy
|
resolveStrategy internet.DomainStrategy
|
||||||
usesDialerProxy bool
|
usesDialerProxy bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildFinalRule(config *FinalRuleConfig) (*FinalRule, error) {
|
func buildRule(config *FirewallConfig) (*Firewall, error) {
|
||||||
rule := &FinalRule{
|
rule := &Firewall{
|
||||||
action: config.GetAction(),
|
action: config.GetAction(),
|
||||||
blockDelay: config.GetBlockDelay(),
|
delay: config.GetDelay(),
|
||||||
|
logLevel: config.LogLevel,
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Reply != nil {
|
||||||
|
switch config.Reply.Type {
|
||||||
|
case "", "none":
|
||||||
|
case "http":
|
||||||
|
var data bytes.Buffer
|
||||||
|
common.Must(http403response.Write(&data))
|
||||||
|
rule.reply = data.Bytes()
|
||||||
|
case "custom":
|
||||||
|
rule.reply = config.Reply.CustomResponseData
|
||||||
|
default:
|
||||||
|
return nil, errors.New("unknown firewall reply: " + config.Reply.Type)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(config.Networks) == 0 {
|
if len(config.Networks) == 0 {
|
||||||
@@ -129,25 +160,25 @@ func buildFinalRule(config *FinalRuleConfig) (*FinalRule, error) {
|
|||||||
return rule, nil
|
return rule, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FinalRule) matchNetwork(network net.Network) bool {
|
func (r *Firewall) matchNetwork(network net.Network) bool {
|
||||||
return r.network[int(network)]
|
return r.network[int(network)]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FinalRule) matchPort(port net.Port) bool {
|
func (r *Firewall) matchPort(port net.Port) bool {
|
||||||
if len(r.port) == 0 {
|
if len(r.port) == 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return r.port.Contains(port)
|
return r.port.Contains(port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FinalRule) matchIP(addr net.Address) bool {
|
func (r *Firewall) matchIP(addr net.Address) bool {
|
||||||
if r.ip == nil {
|
if r.ip == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return addr != nil && addr.Family().IsIP() && r.ip.Match(addr.IP())
|
return addr != nil && addr.Family().IsIP() && r.ip.Match(addr.IP())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FinalRule) Apply(network net.Network, address net.Address, port net.Port) bool {
|
func (r *Firewall) Apply(network net.Network, address net.Address, port net.Port) bool {
|
||||||
if !r.matchNetwork(network) {
|
if !r.matchNetwork(network) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -157,14 +188,14 @@ func (r *FinalRule) Apply(network net.Network, address net.Address, port net.Por
|
|||||||
return r.matchIP(address)
|
return r.matchIP(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultFinalRule(inbound *session.Inbound) *FinalRule {
|
func getDefaultRule(inbound *session.Inbound) *Firewall {
|
||||||
if inbound == nil {
|
if inbound == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
switch inbound.Name {
|
switch inbound.Name {
|
||||||
case "vless-reverse":
|
case "vless-reverse":
|
||||||
return defaultBlockAllRule
|
return defaultBlockAllRule
|
||||||
case "vless", "vmess", "trojan", "hysteria", "wireguard":
|
case "vless", "vmess", "trojan", "hysteria", "wireguard", "masque":
|
||||||
return defaultBlockPrivateRule
|
return defaultBlockPrivateRule
|
||||||
default:
|
default:
|
||||||
if strings.HasPrefix(inbound.Name, "shadowsocks") {
|
if strings.HasPrefix(inbound.Name, "shadowsocks") {
|
||||||
@@ -174,8 +205,8 @@ func getDefaultFinalRule(inbound *session.Inbound) *FinalRule {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) matchFinalRule(network net.Network, address net.Address, port net.Port, defaultRule *FinalRule) *FinalRule {
|
func (h *Handler) matchRule(network net.Network, address net.Address, port net.Port, defaultRule *Firewall) *Firewall {
|
||||||
for _, rule := range h.finalRules {
|
for _, rule := range h.firewall {
|
||||||
if rule.Apply(network, address, port) {
|
if rule.Apply(network, address, port) {
|
||||||
return rule
|
return rule
|
||||||
}
|
}
|
||||||
@@ -190,19 +221,19 @@ func (h *Handler) matchFinalRule(network net.Network, address net.Address, port
|
|||||||
func (h *Handler) Init(config *Config, pm policy.Manager) error {
|
func (h *Handler) Init(config *Config, pm policy.Manager) error {
|
||||||
h.config = config
|
h.config = config
|
||||||
h.policyManager = pm
|
h.policyManager = pm
|
||||||
if h.usesDialerProxy { // freedom is not the final outbound, final rules do not apply
|
if h.usesDialerProxy { // freedom is not the final outbound, firewall does not apply
|
||||||
if len(config.FinalRules) > 0 {
|
if len(config.Firewall) > 0 {
|
||||||
errors.LogWarning(context.Background(), `The "finalRules" setting is ignored when "sockopt.dialerProxy" is set, since freedom is not the final outbound.`)
|
errors.LogWarning(context.Background(), `The "firewall" setting is ignored when "sockopt.dialerProxy" is set, since freedom is not the final outbound.`)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
h.finalRules = make([]*FinalRule, 0, len(config.FinalRules))
|
h.firewall = make([]*Firewall, 0, len(config.Firewall))
|
||||||
for _, rc := range config.FinalRules {
|
for _, rc := range config.Firewall {
|
||||||
rule, err := buildFinalRule(rc)
|
rule, err := buildRule(rc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("failed to build final rule").Base(err)
|
return errors.New("failed to build firewall rule").Base(err)
|
||||||
}
|
}
|
||||||
h.finalRules = append(h.finalRules, rule)
|
h.firewall = append(h.firewall, rule)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -212,12 +243,12 @@ func (h *Handler) policy() policy.Session {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) blockDelay(rule *FinalRule) time.Duration {
|
func (r *Firewall) blockDuration() time.Duration {
|
||||||
min := uint64(30)
|
min := uint64(30)
|
||||||
max := uint64(90)
|
max := uint64(90)
|
||||||
if rule.blockDelay != nil {
|
if r.delay != nil {
|
||||||
min = rule.blockDelay.Min
|
min = r.delay.Min
|
||||||
max = rule.blockDelay.Max
|
max = r.delay.Max
|
||||||
}
|
}
|
||||||
span := max - min
|
span := max - min
|
||||||
if max < min {
|
if max < min {
|
||||||
@@ -226,10 +257,34 @@ func (h *Handler) blockDelay(rule *FinalRule) time.Duration {
|
|||||||
return time.Duration(min+uint64(dice.Roll(int(span+1)))) * time.Second
|
return time.Duration(min+uint64(dice.Roll(int(span+1)))) * time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) blackhole(ctx context.Context, input buf.Reader, output buf.Writer, rule *FinalRule, dest *net.Destination) error {
|
func (r *Firewall) log(ctx context.Context, msg ...interface{}) {
|
||||||
delay := h.blockDelay(rule)
|
level := log.Severity_Info
|
||||||
errors.LogInfo(ctx, "blocked target: ", *dest, ", blackholing connection for ", delay)
|
if r.logLevel != nil {
|
||||||
|
level = *r.logLevel
|
||||||
|
}
|
||||||
|
switch level {
|
||||||
|
case log.Severity_Debug:
|
||||||
|
errors.LogDebug(ctx, msg...)
|
||||||
|
case log.Severity_Info:
|
||||||
|
errors.LogInfo(ctx, msg...)
|
||||||
|
case log.Severity_Warning:
|
||||||
|
errors.LogWarning(ctx, msg...)
|
||||||
|
case log.Severity_Error:
|
||||||
|
errors.LogError(ctx, msg...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) blackhole(ctx context.Context, input buf.Reader, output buf.Writer, rule *Firewall, dest *net.Destination) error {
|
||||||
|
delay := rule.blockDuration()
|
||||||
|
rule.log(ctx, "target blocked by a firewall rule: ", *dest, ", blackholing connection for ", delay)
|
||||||
defer common.Close(output)
|
defer common.Close(output)
|
||||||
|
if len(rule.reply) > 0 {
|
||||||
|
mbc := buf.MultiBufferContainer{}
|
||||||
|
common.Must2(mbc.Write(rule.reply))
|
||||||
|
output.WriteMultiBuffer(mbc.MultiBuffer)
|
||||||
|
// Sleep a little here to make sure the reply is sent to client.
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() { // a DispatchLink inbound's reader ignores Interrupt, so don't wait for this copy
|
go func() { // a DispatchLink inbound's reader ignores Interrupt, so don't wait for this copy
|
||||||
_ = buf.Copy(input, buf.Discard)
|
_ = buf.Copy(input, buf.Discard)
|
||||||
@@ -240,7 +295,7 @@ func (h *Handler) blackhole(ctx context.Context, input buf.Reader, output buf.Wr
|
|||||||
case <-time.After(delay):
|
case <-time.After(delay):
|
||||||
common.Interrupt(input)
|
common.Interrupt(input)
|
||||||
common.Interrupt(output)
|
common.Interrupt(output)
|
||||||
errors.LogInfo(ctx, "closed blackholed connection to blocked target: ", *dest)
|
rule.log(ctx, "closed blackholed connection to blocked target: ", *dest)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -263,10 +318,16 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||||||
}
|
}
|
||||||
ob.Name = "freedom"
|
ob.Name = "freedom"
|
||||||
ob.CanSpliceCopy = 1
|
ob.CanSpliceCopy = 1
|
||||||
|
if !h.usesDialerProxy && len(h.firewall) > 0 {
|
||||||
|
rule := h.firewall[0]
|
||||||
|
if rule.action == RuleAction_Block && rule.network == allNetworks && len(rule.port) == 0 && rule.ip == nil {
|
||||||
|
return h.blackhole(ctx, link.Reader, link.Writer, rule, &ob.Target)
|
||||||
|
}
|
||||||
|
}
|
||||||
inbound := session.InboundFromContext(ctx)
|
inbound := session.InboundFromContext(ctx)
|
||||||
var defaultRule *FinalRule
|
var defaultRule *Firewall
|
||||||
if !h.usesDialerProxy { // freedom is not the final outbound, final rules do not apply (and the domain is not resolved)
|
if !h.usesDialerProxy { // freedom is not the final outbound, firewall does not apply (and the domain is not resolved)
|
||||||
defaultRule = getDefaultFinalRule(inbound)
|
defaultRule = getDefaultRule(inbound)
|
||||||
}
|
}
|
||||||
|
|
||||||
destination := ob.Target
|
destination := ob.Target
|
||||||
@@ -294,10 +355,10 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||||||
|
|
||||||
var conn stat.Connection
|
var conn stat.Connection
|
||||||
var blockedDest *net.Destination
|
var blockedDest *net.Destination
|
||||||
var blockedRule *FinalRule
|
var blockedRule *Firewall
|
||||||
err := retry.ExponentialBackoff(5, 100).On(func() error {
|
err := retry.ExponentialBackoff(5, 100).On(func() error {
|
||||||
if destination.Address.Family().IsDomain() {
|
if destination.Address.Family().IsDomain() {
|
||||||
if defaultRule != nil || len(h.finalRules) > 0 {
|
if defaultRule != nil || len(h.firewall) > 0 {
|
||||||
if strategy := h.resolveStrategy; strategy.HasStrategy() {
|
if strategy := h.resolveStrategy; strategy.HasStrategy() {
|
||||||
ips, err := internet.LookupForIP(destination.Address.Domain(), strategy, outGateway)
|
ips, err := internet.LookupForIP(destination.Address.Domain(), strategy, outGateway)
|
||||||
if err != nil { // non-force may still dial with system DNS
|
if err != nil { // non-force may still dial with system DNS
|
||||||
@@ -308,7 +369,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||||||
}
|
}
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
if addr := net.IPAddress(ip); addr != nil {
|
if addr := net.IPAddress(ip); addr != nil {
|
||||||
if rule := h.matchFinalRule(destination.Network, addr, destination.Port, defaultRule); rule != nil && rule.action == RuleAction_Block {
|
if rule := h.matchRule(destination.Network, addr, destination.Port, defaultRule); rule != nil && rule.action == RuleAction_Block {
|
||||||
blockedDest = &destination
|
blockedDest = &destination
|
||||||
blockedDest.Address = addr
|
blockedDest.Address = addr
|
||||||
blockedRule = rule
|
blockedRule = rule
|
||||||
@@ -323,7 +384,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||||||
}
|
}
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
if ipAddr := net.IPAddress(addr.IP); ipAddr != nil {
|
if ipAddr := net.IPAddress(addr.IP); ipAddr != nil {
|
||||||
if rule := h.matchFinalRule(destination.Network, ipAddr, destination.Port, defaultRule); rule != nil && rule.action == RuleAction_Block {
|
if rule := h.matchRule(destination.Network, ipAddr, destination.Port, defaultRule); rule != nil && rule.action == RuleAction_Block {
|
||||||
blockedDest = &destination
|
blockedDest = &destination
|
||||||
blockedDest.Address = ipAddr
|
blockedDest.Address = ipAddr
|
||||||
blockedRule = rule
|
blockedRule = rule
|
||||||
@@ -334,7 +395,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if rule := h.matchFinalRule(destination.Network, destination.Address, destination.Port, defaultRule); rule != nil && rule.action == RuleAction_Block {
|
if rule := h.matchRule(destination.Network, destination.Address, destination.Port, defaultRule); rule != nil && rule.action == RuleAction_Block {
|
||||||
blockedDest = &destination
|
blockedDest = &destination
|
||||||
blockedRule = rule
|
blockedRule = rule
|
||||||
return nil
|
return nil
|
||||||
@@ -355,25 +416,15 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||||||
if blockedDest != nil {
|
if blockedDest != nil {
|
||||||
return h.blackhole(ctx, input, output, blockedRule, blockedDest)
|
return h.blackhole(ctx, input, output, blockedRule, blockedDest)
|
||||||
}
|
}
|
||||||
if destination.Address.Family().IsDomain() && (defaultRule != nil || len(h.finalRules) > 0) {
|
if destination.Address.Family().IsDomain() && (defaultRule != nil || len(h.firewall) > 0) {
|
||||||
// pre-check may fail or dialer may select another IP
|
// pre-check may fail or dialer may select another IP
|
||||||
remoteDest := net.DestinationFromAddr(conn.RemoteAddr())
|
remoteDest := net.DestinationFromAddr(conn.RemoteAddr())
|
||||||
if rule := h.matchFinalRule(remoteDest.Network, remoteDest.Address, remoteDest.Port, defaultRule); rule != nil && rule.action == RuleAction_Block {
|
if rule := h.matchRule(remoteDest.Network, remoteDest.Address, remoteDest.Port, defaultRule); rule != nil && rule.action == RuleAction_Block {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return h.blackhole(ctx, input, output, rule, &remoteDest)
|
return h.blackhole(ctx, input, output, rule, &remoteDest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.config.ProxyProtocol > 0 && h.config.ProxyProtocol <= 2 {
|
|
||||||
version := byte(h.config.ProxyProtocol)
|
|
||||||
srcAddr := inbound.Source.RawNetAddr()
|
|
||||||
dstAddr := conn.RemoteAddr()
|
|
||||||
header := proxyproto.HeaderProxyFromAddrs(version, srcAddr, dstAddr)
|
|
||||||
if _, err = header.WriteTo(conn); err != nil {
|
|
||||||
conn.Close()
|
|
||||||
return errors.New("failed to set PROXY protocol v", version).Base(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
errors.LogInfo(ctx, "connection opened to ", destination, ", local endpoint ", conn.LocalAddr(), ", remote endpoint ", conn.RemoteAddr())
|
errors.LogInfo(ctx, "connection opened to ", destination, ", local endpoint ", conn.LocalAddr(), ", remote endpoint ", conn.RemoteAddr())
|
||||||
|
|
||||||
@@ -462,7 +513,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPacketReader(conn net.Conn, h *Handler, defaultRule *FinalRule, UDPOverride net.Destination, DialDest net.Destination) buf.Reader {
|
func NewPacketReader(conn net.Conn, h *Handler, defaultRule *Firewall, UDPOverride net.Destination, DialDest net.Destination) buf.Reader {
|
||||||
iConn := conn
|
iConn := conn
|
||||||
statConn, ok := iConn.(*stat.CounterConnection)
|
statConn, ok := iConn.(*stat.CounterConnection)
|
||||||
if ok {
|
if ok {
|
||||||
@@ -495,7 +546,7 @@ type PacketReader struct {
|
|||||||
*net.PacketConnWrapper
|
*net.PacketConnWrapper
|
||||||
stats.Counter
|
stats.Counter
|
||||||
Handler *Handler
|
Handler *Handler
|
||||||
DefaultRule *FinalRule
|
DefaultRule *Firewall
|
||||||
IsOverridden bool
|
IsOverridden bool
|
||||||
InitUnchangedAddr net.Address
|
InitUnchangedAddr net.Address
|
||||||
InitChangedAddr net.Address
|
InitChangedAddr net.Address
|
||||||
@@ -512,7 +563,7 @@ func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
|||||||
}
|
}
|
||||||
udpAddr := d.(*net.UDPAddr)
|
udpAddr := d.(*net.UDPAddr)
|
||||||
sourceAddr := net.IPAddress(udpAddr.IP)
|
sourceAddr := net.IPAddress(udpAddr.IP)
|
||||||
if rule := r.Handler.matchFinalRule(net.Network_UDP, sourceAddr, net.Port(udpAddr.Port), r.DefaultRule); rule != nil && rule.action == RuleAction_Block {
|
if rule := r.Handler.matchRule(net.Network_UDP, sourceAddr, net.Port(udpAddr.Port), r.DefaultRule); rule != nil && rule.action == RuleAction_Block {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
b.Resize(0, int32(n))
|
b.Resize(0, int32(n))
|
||||||
@@ -537,7 +588,7 @@ func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DialDest means the dial target used in the dialer when creating conn
|
// DialDest means the dial target used in the dialer when creating conn
|
||||||
func NewPacketWriter(conn net.Conn, h *Handler, defaultRule *FinalRule, UDPOverride net.Destination, DialDest net.Destination, outGateway net.Address) buf.Writer {
|
func NewPacketWriter(conn net.Conn, h *Handler, defaultRule *Firewall, UDPOverride net.Destination, DialDest net.Destination, outGateway net.Address) buf.Writer {
|
||||||
iConn := conn
|
iConn := conn
|
||||||
statConn, ok := iConn.(*stat.CounterConnection)
|
statConn, ok := iConn.(*stat.CounterConnection)
|
||||||
if ok {
|
if ok {
|
||||||
@@ -571,7 +622,7 @@ type PacketWriter struct {
|
|||||||
*net.PacketConnWrapper
|
*net.PacketConnWrapper
|
||||||
stats.Counter
|
stats.Counter
|
||||||
*Handler
|
*Handler
|
||||||
DefaultRule *FinalRule
|
DefaultRule *Firewall
|
||||||
UDPOverride net.Destination
|
UDPOverride net.Destination
|
||||||
|
|
||||||
// Dest of udp packets might be a domain, we will resolve them to IP
|
// Dest of udp packets might be a domain, we will resolve them to IP
|
||||||
@@ -630,7 +681,7 @@ func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if rule := w.matchFinalRule(net.Network_UDP, b.UDP.Address, b.UDP.Port, w.DefaultRule); rule != nil && rule.action == RuleAction_Block {
|
if rule := w.matchRule(net.Network_UDP, b.UDP.Address, b.UDP.Port, w.DefaultRule); rule != nil && rule.action == RuleAction_Block {
|
||||||
b.Release()
|
b.Release()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package freedom
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/xtls/xray-core/common/buf"
|
||||||
|
"github.com/xtls/xray-core/common/net"
|
||||||
|
"github.com/xtls/xray-core/common/session"
|
||||||
|
"github.com/xtls/xray-core/transport"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUnconditionalBlockFastPath(t *testing.T) {
|
||||||
|
for _, network := range []net.Network{net.Network_TCP, net.Network_UDP} {
|
||||||
|
t.Run(network.String(), func(t *testing.T) {
|
||||||
|
const reply = "blocked"
|
||||||
|
h := new(Handler)
|
||||||
|
if err := h.Init(&Config{Firewall: []*FirewallConfig{{
|
||||||
|
Action: RuleAction_Block,
|
||||||
|
Delay: &Range{},
|
||||||
|
Reply: &Reply{Type: "custom", CustomResponseData: []byte(reply)},
|
||||||
|
}}}, nil); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
ctx := session.ContextWithOutbounds(context.Background(), []*session.Outbound{{
|
||||||
|
Target: net.Destination{Network: network, Address: net.DomainAddress("blocked.invalid"), Port: 443},
|
||||||
|
}})
|
||||||
|
var output bytes.Buffer
|
||||||
|
link := &transport.Link{
|
||||||
|
Reader: buf.NewReader(bytes.NewReader(nil)),
|
||||||
|
Writer: &buf.BufferToBytesWriter{Writer: &output},
|
||||||
|
}
|
||||||
|
// An unconditional block must finish without touching the dialer or resolving the domain.
|
||||||
|
if err := h.Process(ctx, link, nil); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if output.String() != reply {
|
||||||
|
t.Fatalf("reply = %q, want %q", output.String(), reply)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFirewallReply(t *testing.T) {
|
||||||
|
custom := bytes.Repeat([]byte("custom response"), buf.Size)
|
||||||
|
for _, test := range []struct {
|
||||||
|
name string
|
||||||
|
reply *Reply
|
||||||
|
want []byte
|
||||||
|
}{
|
||||||
|
{name: "default"},
|
||||||
|
{name: "none", reply: &Reply{Type: "none"}},
|
||||||
|
{name: "http", reply: &Reply{Type: "http"}},
|
||||||
|
{name: "custom", reply: &Reply{Type: "custom", CustomResponseData: custom}, want: custom},
|
||||||
|
} {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
rule, err := buildRule(&FirewallConfig{
|
||||||
|
Action: RuleAction_Block,
|
||||||
|
Delay: &Range{},
|
||||||
|
Reply: test.reply,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var output bytes.Buffer
|
||||||
|
dest := net.TCPDestination(net.LocalHostIP, 80)
|
||||||
|
if err := new(Handler).blackhole(context.Background(), buf.NewReader(bytes.NewReader(nil)), &buf.BufferToBytesWriter{Writer: &output}, rule, &dest); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if test.name == "http" {
|
||||||
|
response, err := http.ReadResponse(bufio.NewReader(&output), nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
|
if response.StatusCode != http.StatusForbidden {
|
||||||
|
t.Fatalf("HTTP status = %d, want 403", response.StatusCode)
|
||||||
|
}
|
||||||
|
} else if !bytes.Equal(output.Bytes(), test.want) {
|
||||||
|
t.Fatalf("reply has %d bytes, want %d", output.Len(), len(test.want))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -150,6 +150,7 @@ Start:
|
|||||||
To: request.URL,
|
To: request.URL,
|
||||||
Status: log.AccessAccepted,
|
Status: log.AccessAccepted,
|
||||||
Reason: "",
|
Reason: "",
|
||||||
|
Email: inbound.User.Email,
|
||||||
})
|
})
|
||||||
|
|
||||||
if strings.EqualFold(request.Method, "CONNECT") {
|
if strings.EqualFold(request.Method, "CONNECT") {
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ type Server struct {
|
|||||||
config *ServerConfig
|
config *ServerConfig
|
||||||
validator *Validator
|
validator *Validator
|
||||||
policyManager policy.Manager
|
policyManager policy.Manager
|
||||||
cone bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer create a new Shadowsocks server.
|
// NewServer create a new Shadowsocks server.
|
||||||
@@ -47,7 +46,6 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
|
|||||||
config: config,
|
config: config,
|
||||||
validator: validator,
|
validator: validator,
|
||||||
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
||||||
cone: ctx.Value("cone").(bool),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
@@ -185,7 +183,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dis
|
|||||||
|
|
||||||
data.UDP = &destination
|
data.UDP = &destination
|
||||||
|
|
||||||
if !s.cone || dest == nil {
|
if dest == nil {
|
||||||
dest = &destination
|
dest = &destination
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import (
|
|||||||
type Server struct {
|
type Server struct {
|
||||||
config *ServerConfig
|
config *ServerConfig
|
||||||
policyManager policy.Manager
|
policyManager policy.Manager
|
||||||
cone bool
|
|
||||||
httpServer *http.Server
|
httpServer *http.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +38,6 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
|
|||||||
s := &Server{
|
s := &Server{
|
||||||
config: config,
|
config: config,
|
||||||
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
||||||
cone: ctx.Value("cone").(bool),
|
|
||||||
}
|
}
|
||||||
httpConfig := &http.ServerConfig{
|
httpConfig := &http.ServerConfig{
|
||||||
UserLevel: config.UserLevel,
|
UserLevel: config.UserLevel,
|
||||||
@@ -149,6 +147,7 @@ func (s *Server) processTCP(ctx context.Context, conn stat.Connection, dispatche
|
|||||||
To: dest,
|
To: dest,
|
||||||
Status: log.AccessAccepted,
|
Status: log.AccessAccepted,
|
||||||
Reason: "",
|
Reason: "",
|
||||||
|
Email: inbound.User.Email,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if inbound.CanSpliceCopy == 2 {
|
if inbound.CanSpliceCopy == 2 {
|
||||||
@@ -270,12 +269,13 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dis
|
|||||||
To: destination,
|
To: destination,
|
||||||
Status: log.AccessAccepted,
|
Status: log.AccessAccepted,
|
||||||
Reason: "",
|
Reason: "",
|
||||||
|
Email: inbound.User.Email,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
payload.UDP = &destination
|
payload.UDP = &destination
|
||||||
|
|
||||||
if !s.cone || dest == nil {
|
if dest == nil {
|
||||||
dest = &destination
|
dest = &destination
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ type Server struct {
|
|||||||
policyManager policy.Manager
|
policyManager policy.Manager
|
||||||
validator *Validator
|
validator *Validator
|
||||||
fallbacks map[string]map[string]map[string]*Fallback // or nil
|
fallbacks map[string]map[string]map[string]*Fallback // or nil
|
||||||
cone bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates a new trojan inbound handler.
|
// NewServer creates a new trojan inbound handler.
|
||||||
@@ -59,7 +58,6 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
|
|||||||
server := &Server{
|
server := &Server{
|
||||||
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
||||||
validator: validator,
|
validator: validator,
|
||||||
cone: ctx.Value("cone").(bool),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Fallbacks != nil {
|
if config.Fallbacks != nil {
|
||||||
@@ -302,7 +300,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, sessionPolicy policy.Sess
|
|||||||
}
|
}
|
||||||
errors.LogInfo(ctx, "tunnelling request to ", destination)
|
errors.LogInfo(ctx, "tunnelling request to ", destination)
|
||||||
|
|
||||||
if !s.cone || dest == nil {
|
if dest == nil {
|
||||||
dest = &destination
|
dest = &destination
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-12
@@ -4,7 +4,7 @@ TUN interface support bridges the gap between network layer 3 and layer 7, intro
|
|||||||
|
|
||||||
This functionality is targeted to assist applications/end devices that don't have proxy support, or can't run external applications (like Smart TV's). Making it possible to run Xray proxy right on network edge devices (routers) with support to route raw network traffic. \
|
This functionality is targeted to assist applications/end devices that don't have proxy support, or can't run external applications (like Smart TV's). Making it possible to run Xray proxy right on network edge devices (routers) with support to route raw network traffic. \
|
||||||
Primary targets are Linux based router devices. Like most popular OpenWRT option. \
|
Primary targets are Linux based router devices. Like most popular OpenWRT option. \
|
||||||
Support for Windows, macOS, Android and iOS is also implemented (see below).
|
Support for Windows, macOS, FreeBSD, Android and iOS is also implemented (see below).
|
||||||
|
|
||||||
## PLEASE READ FOLLOWING CAREFULLY
|
## PLEASE READ FOLLOWING CAREFULLY
|
||||||
|
|
||||||
@@ -25,6 +25,8 @@ Examples of how to achieve this on a simple Linux system (Ubuntu with systemd-ne
|
|||||||
|
|
||||||
Packets are handled by Xray-core's own lightweight TCP/IP stack, which replaced gVisor (XTLS/Xray-core#7130).
|
Packets are handled by Xray-core's own lightweight TCP/IP stack, which replaced gVisor (XTLS/Xray-core#7130).
|
||||||
|
|
||||||
|
On Linux, as on Android, the TUN can also be a file descriptor handed over through the environment variable `xray.tun.fd` (or `XRAY_TUN_FD`), e.g. for lightweight or unprivileged setups.
|
||||||
|
|
||||||
With `autoSystemRoutingTable`, Xray's own connections are kept out of the TUN through `autoOutboundsInterface` (then `"auto"` by default): each of their sockets is bound to another interface, the one named there, or with `"auto"` the one of the default route (Android needs the name). Linux and Android bind with `SO_BINDTODEVICE`, Windows with `IP_UNICAST_IF` and `IPV6_UNICAST_IF`, macOS and iOS with `IP_BOUND_IF` and `IPV6_BOUND_IF`, and FreeBSD switches them to another routing table (see [FreeBSD SUPPORT](#freebsd-support)). Connections to loopback addresses, TCP and UDP, stay unbound. If a socket cannot be bound, the connection fails rather than leave unbound, where it could loop back into the TUN (XTLS/Xray-core#7173).
|
With `autoSystemRoutingTable`, Xray's own connections are kept out of the TUN through `autoOutboundsInterface` (then `"auto"` by default): each of their sockets is bound to another interface, the one named there, or with `"auto"` the one of the default route (Android needs the name). Linux and Android bind with `SO_BINDTODEVICE`, Windows with `IP_UNICAST_IF` and `IPV6_UNICAST_IF`, macOS and iOS with `IP_BOUND_IF` and `IPV6_BOUND_IF`, and FreeBSD switches them to another routing table (see [FreeBSD SUPPORT](#freebsd-support)). Connections to loopback addresses, TCP and UDP, stay unbound. If a socket cannot be bound, the connection fails rather than leave unbound, where it could loop back into the TUN (XTLS/Xray-core#7173).
|
||||||
|
|
||||||
### SYSTEM DNS ON LINUX AND FREEBSD (`autoSystemDnsToGateway`)
|
### SYSTEM DNS ON LINUX AND FREEBSD (`autoSystemDnsToGateway`)
|
||||||
@@ -221,23 +223,26 @@ To make it start, wintun.dll specific for your Windows/arch must be present next
|
|||||||
|
|
||||||
After the start network adapter with the name you chose in the config will be created in the system, and exist while Xray is running. A Wintun adapter that already has that name is reused.
|
After the start network adapter with the name you chose in the config will be created in the system, and exist while Xray is running. A Wintun adapter that already has that name is reused.
|
||||||
|
|
||||||
With IPv6 disabled system-wide (the `DisabledComponents` registry value), the adapter has no IPv6, and the TUN starts with IPv4 only, unless `gateway` or `autoSystemRoutingTable` has IPv6 entries, which then keep it from starting.
|
With IPv6 turned off by the `DisabledComponents` registry value (0x10 set, as in 0xFF), errors setting up IPv6 for `gateway`, `dns` and `autoSystemRoutingTable`, clearing the IPv6 DNS servers when `dns` has none included, are only logged. Otherwise, they keep the TUN from starting.
|
||||||
|
|
||||||
When `dns` is set, those servers are applied to the adapter. Windows is kept from registering the TUN's addresses in DNS, and its DNS cache is flushed when the TUN starts and stops.
|
When `dns` is set, those servers are applied to the adapter. Windows is kept from registering the TUN's addresses in DNS, and its DNS cache is flushed when the TUN starts and stops. Xray's own lookups through the system's DNS servers, like those of the `localhost` DNS server with `autoOutboundsInterface`, skip them, unless another interface uses them as well, as they would lead back into the TUN.
|
||||||
|
|
||||||
With `autoSystemWfpBlockLeak`, which needs `autoSystemRoutingTable` (the config is rejected otherwise), Xray also adds Windows Filtering Platform filters that keep traffic of every program but Xray itself from leaving outside the TUN, each kind chosen by a value in the list, e.g. `"autoSystemWfpBlockLeak": ["dns", "misconfigtun"]`:
|
Setting `autoSystemWfpBlockLeak` to at least `["dns", "misconfigtun"]` is recommended, to block DNS leaks and the traffic of an IP version without routes. It needs `autoSystemRoutingTable` (the config is rejected otherwise), and adds Windows Filtering Platform filters that let traffic of every program but Xray itself leave only through the TUN, each kind chosen by a value:
|
||||||
- `"tcp/<port>"`, `"udp/<port>"`: connections to that TCP or UDP port only go through the TUN, e.g. `"tcp/853"`.
|
- `"dns"`: stands for `"53"`, `"853"` (DNS over TLS and QUIC) and `"windnsclient"`. Windows also queries the DNS servers of the other interfaces, through those interfaces whatever the routes say, and other programs reach a resolver on the local network (e.g. `192.168.1.1` from DHCP) through its more specific route.
|
||||||
- `"windnsclient"`: Windows' DNS Client service cannot connect outside the TUN at all, except for name resolution on the local network (LLMNR, mDNS). On Windows 11 and Server 2022 and later, it may send name queries over HTTPS or TLS, to any port. Earlier versions only query port 53, so there it does nothing.
|
- `"windnsclient"`: Windows' DNS Client service, except for name resolution on the local network (LLMNR, mDNS). Since Windows 11 and Server 2022, it may query over HTTPS or TLS, to any port; earlier versions only query port 53, so there it does nothing.
|
||||||
- `"dns"`: stands for `"udp/53"`, `"tcp/53"`, `"windnsclient"`, `"tcp/853"` (DNS over TLS) and `"udp/853"` (DNS over QUIC). Windows keeps sending name queries to the DNS servers of the other interfaces as well, out through those interfaces whatever the routes say, and other programs reach a resolver on the local network (e.g. `192.168.1.1` handed out by DHCP) through its more specific LAN route instead of the TUN. Keeping the system's DNS inside the TUN like this, with `"dns"`, `"udp/53"`, `"tcp/53"` or `"windnsclient"`, needs `dns` (the config is rejected otherwise). The `dns` servers then have to lie within `gateway` or `autoSystemRoutingTable` (a warning is logged otherwise), and DNS servers that should be reached directly belong in Xray's own `dns` settings.
|
- `"tcp"`, `"udp"`: that protocol, to all ports, or with `/<port>` or `/<low>-<high>` (1 to 65535) to some, e.g. `"tcp/853"` or `"udp/10-20"`. The ports alone stand for both, e.g. `"53"` or `"10-20"`.
|
||||||
- `"misconfigtun"`: an IP version without routes in `autoSystemRoutingTable`, IPv4 or IPv6, is blocked entirely, in both directions, as it would bypass the TUN. Only loopback and what Windows itself needs on the local link (DHCP, and for IPv6 neighbor and multicast listener discovery) remain allowed. An address of that version in `gateway` is not needed: without one, Windows gives the TUN link-local addresses itself, an IPv6 one at once and an IPv4 one from `169.254.0.0/16` after some seconds (until then, IPv4 routed to the TUN is unreachable), and what is routed to the TUN goes through it with those.
|
- `"icmp"`: ICMP and ICMPv6, e.g. `ping`.
|
||||||
|
- `"misconfigtun"`: an IP version without routes in `autoSystemRoutingTable`, which would bypass the TUN. With IPv6 turned off by `DisabledComponents`, it covers IPv6 whatever the routes, as IPv6 setup errors are then only logged, and IPv6 still works until the reboot that applies the value.
|
||||||
|
- `"all"`: everything, in both directions. Access to the local network then breaks unless it is routed into the TUN as well, and so do incoming connections to other programs, other VPNs, and virtual machines whose NAT runs on the host.
|
||||||
|
- `"allexceptlan"`: like `"all"`, but traffic to and from the local network stays allowed, e.g. for printers or casting to a TV: private, link-local, multicast and broadcast addresses (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`, `169.254.0.0/16`, `224.0.0.0/4`, `255.255.255.255`, `fc00::/7`, `fe80::/10`, `ff00::/8`), not global IPv6 ones. It includes `"dns"`, and the other values apply there as well. `"all"` overrides it.
|
||||||
|
|
||||||
With the filters in place, Xray's own connections out also get past Windows Firewall's block rules (other firewalls may still block them), while connections to Xray's inbounds stay subject to them.
|
A CIDR in front limits a value to its addresses, an IPv6 one in brackets, e.g. `"8.8.8.8/32:all"`, `"1.1.1.0/24:53"` or `"[::/0]:all"` (IPv6 only). It limits what the value stands for or includes as well: `"0.0.0.0/0:allexceptlan"`, for instance, leaves DNS over IPv6 open.
|
||||||
|
|
||||||
Names that Xray resolves through the system resolver, such as an outbound's server address given as a domain with the default `AsIs` domain strategy, would be looked up by Windows on Xray's behalf, and those queries would then go into the TUN too. While DNS is restricted this way and `autoOutboundsInterface` is in use (the default with `autoSystemRoutingTable`), Xray therefore resolves them itself, with its own queries to the DNS servers of the other interfaces. That bypasses Windows' DNS cache, and its name resolution on the local network (LLMNR, mDNS): a server address given as a domain is looked up again for every connection, and a DNS server that does not answer delays each lookup. Having Xray's own `dns` resolve it, through the outbound's `sockopt.domainStrategy`, avoids that. The `localhost` DNS server queries the same servers whenever `autoOutboundsInterface` is in use. Both skip the TUN's own DNS servers, unless another interface uses them as well: queried from Xray itself, they would lead back into it, or nowhere.
|
Loopback, DHCP, DHCPv6 and IPv6 neighbor discovery always stay allowed. Xray's own connections out also get past Windows Firewall's block rules, while connections to its inbounds stay subject to them. If the filters cannot be added, Xray does not start; they are removed when it exits. `"dns"` leaves name resolution on the local network (LLMNR, mDNS, NetBIOS) alone; `"all"` or `"udp"`, for instance, block it as well.
|
||||||
|
|
||||||
If the filters cannot be added, Xray does not start. They are removed when Xray exits. Not covered is name resolution on the local network (LLMNR, mDNS, NetBIOS), except over an IP version that is blocked.
|
Keeping the system's DNS inside the TUN, with `"all"`, `"allexceptlan"`, `"dns"`, `"windnsclient"`, or anything covering TCP or UDP port 53, even to some addresses only, needs `dns` (the config is rejected otherwise), whose servers have to lie within `gateway` or `autoSystemRoutingTable`, or be loopback addresses like `127.0.0.1` (a warning is logged otherwise); DNS servers to be reached directly belong in Xray's own `dns` settings. With `autoOutboundsInterface`, names that Xray would look up through the system, e.g. an outbound's server address with the default `AsIs` domain strategy, are then resolved by Xray itself, from the DNS servers of the other interfaces, as Windows would send those queries into the TUN. That bypasses Windows' DNS cache, so such a name is looked up for every connection; resolving it with Xray's own `dns`, through the outbound's `sockopt.domainStrategy`, avoids that.
|
||||||
|
|
||||||
`autoSystemWfpBlockLeak` (Windows only) is empty by default, as the filters break some setups: with `"dns"`, a local DNS resolver other programs use (e.g. on `127.0.0.1:53`), the DNS of another VPN on its own interface, virtual machines whose NAT resolves names on the host, or signing in to a captive portal; with `"misconfigtun"`, IPv4 or IPv6 on the local network while no route of that version leads to the TUN. Without the filters, DNS may leak as described above. To keep an IP version out of the TUN on purpose while still blocking DNS leaks, use only `["dns"]`.
|
`autoSystemWfpBlockLeak` is empty by default, as the filters break some setups: with `"dns"`, a local DNS resolver that queries through another interface, the DNS of another VPN, virtual machines whose NAT resolves names on the host, and captive portals; with `"misconfigtun"`, IPv4 or IPv6 on the local network while not routed into the TUN.
|
||||||
|
|
||||||
`autoOutboundsInterface` (the default with `autoSystemRoutingTable`) keeps Xray's own connections out of the TUN by binding them to another interface, which Windows only honors while that interface has weak host send and forwarding off for the IP versions routed to the TUN. Otherwise, Windows sends them into the TUN, from that interface's address, and they stall. While the TUN runs, Xray therefore turns weak host send off on that interface, and on again when it stops or another interface takes over. Forwarding cannot be turned off this way, as Mobile Hotspot and Internet Connection Sharing need it, so a warning is logged while it is on. Having the hotspot share the TUN instead of that interface (Settings, Mobile hotspot, Share my internet connection from) moves forwarding to the TUN, where it does no harm, and sends the hotspot's devices through Xray as well.
|
`autoOutboundsInterface` (the default with `autoSystemRoutingTable`) keeps Xray's own connections out of the TUN by binding them to another interface, which Windows only honors while that interface has weak host send and forwarding off for the IP versions routed to the TUN. Otherwise, Windows sends them into the TUN, from that interface's address, and they stall. While the TUN runs, Xray therefore turns weak host send off on that interface, and on again when it stops or another interface takes over. Forwarding cannot be turned off this way, as Mobile Hotspot and Internet Connection Sharing need it, so a warning is logged while it is on. Having the hotspot share the TUN instead of that interface (Settings, Mobile hotspot, Share my internet connection from) moves forwarding to the TUN, where it does no harm, and sends the hotspot's devices through Xray as well.
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ import (
|
|||||||
|
|
||||||
// Handler is managing object that tie together tun interface, ip stack and dispatch connections to the routing
|
// Handler is managing object that tie together tun interface, ip stack and dispatch connections to the routing
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
|
// ctx is detached from the instance's; cancel ends it, and with it every dispatch started from it,
|
||||||
|
// when the handler closes, since nothing else would
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
|
cancel context.CancelFunc
|
||||||
config *Config
|
config *Config
|
||||||
stack Stack
|
stack Stack
|
||||||
tun Tun
|
tun Tun
|
||||||
@@ -96,7 +99,7 @@ func (t *Handler) Init(ctx context.Context, pm policy.Manager, dispatcher routin
|
|||||||
t.sniffingRequest = content.SniffingRequest
|
t.sniffingRequest = content.SniffingRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
t.ctx = core.ToBackgroundDetachedContext(ctx)
|
t.ctx, t.cancel = context.WithCancel(core.ToBackgroundDetachedContext(ctx))
|
||||||
t.policyManager = pm
|
t.policyManager = pm
|
||||||
t.dispatcher = dispatcher
|
t.dispatcher = dispatcher
|
||||||
|
|
||||||
@@ -265,6 +268,11 @@ func (t *Handler) HandleConnection(conn net.Conn, destination net.Destination) {
|
|||||||
|
|
||||||
// Close implements common.Closable.
|
// Close implements common.Closable.
|
||||||
func (t *Handler) Close() error {
|
func (t *Handler) Close() error {
|
||||||
|
// cancel first so every dispatch in flight unwinds, then close the stack (resets TCP, ends UDP flows)
|
||||||
|
// and the tun
|
||||||
|
if t.cancel != nil {
|
||||||
|
t.cancel()
|
||||||
|
}
|
||||||
return errors.Combine(common.CloseIfExists(t.stack), common.CloseIfExists(t.tun))
|
return errors.Combine(common.CloseIfExists(t.stack), common.CloseIfExists(t.tun))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -179,3 +179,37 @@ func TestHandlerCountsTunConnectionTraffic(t *testing.T) {
|
|||||||
t.Fatalf("connection write mismatch: got %q, want %q", got, "downlink")
|
t.Fatalf("connection write mismatch: got %q, want %q", got, "downlink")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// a dispatcher that only returns when its context ends
|
||||||
|
type blockingDispatcher struct {
|
||||||
|
testDispatcher
|
||||||
|
entered chan struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *blockingDispatcher) DispatchLink(ctx context.Context, dest xnet.Destination, link *transport.Link) error {
|
||||||
|
close(d.entered)
|
||||||
|
<-ctx.Done()
|
||||||
|
return ctx.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Closing the handler must end a dispatch that is not reading its connection: the handler's context
|
||||||
|
// is detached from the instance's, so Close is what cancels it
|
||||||
|
func TestHandlerCloseCancelsDispatches(t *testing.T) {
|
||||||
|
dispatcher := &blockingDispatcher{entered: make(chan struct{})}
|
||||||
|
handler := &Handler{config: &Config{}, dispatcher: dispatcher}
|
||||||
|
handler.ctx, handler.cancel = context.WithCancel(context.Background())
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
handler.HandleConnection(newTestConn(nil), xnet.TCPDestination(xnet.LocalHostIP, 443))
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
<-dispatcher.entered
|
||||||
|
if err := handler.Close(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
case <-time.After(2 * time.Second):
|
||||||
|
t.Fatal("dispatch still running after Close")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -148,6 +148,11 @@ func (s *stack) Close() error {
|
|||||||
for _, u := range sockets {
|
for _, u := range sockets {
|
||||||
u.queue.close()
|
u.queue.close()
|
||||||
}
|
}
|
||||||
|
// the UDP flows the other side opened are in neither conns nor sockets; end them too, or their
|
||||||
|
// dispatches and what they hold survive the instance
|
||||||
|
if s.udp != nil {
|
||||||
|
s.udp.closeAll()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/serial"
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
"github.com/xtls/xray-core/proxy/blackhole"
|
|
||||||
proxydns "github.com/xtls/xray-core/proxy/dns"
|
proxydns "github.com/xtls/xray-core/proxy/dns"
|
||||||
"github.com/xtls/xray-core/proxy/freedom"
|
"github.com/xtls/xray-core/proxy/freedom"
|
||||||
)
|
)
|
||||||
@@ -73,7 +72,7 @@ func newRouteTestContext(t *testing.T, withDNSApp bool, nameServers []*appdns.Na
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{Tag: "direct", ProxySettings: serial.ToTypedMessage(&freedom.Config{})},
|
{Tag: "direct", ProxySettings: serial.ToTypedMessage(&freedom.Config{})},
|
||||||
{Tag: "dns", ProxySettings: serial.ToTypedMessage(&proxydns.Config{})},
|
{Tag: "dns", ProxySettings: serial.ToTypedMessage(&proxydns.Config{})},
|
||||||
{Tag: "block", ProxySettings: serial.ToTypedMessage(&blackhole.Config{})},
|
{Tag: "block", ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Block, Delay: &freedom.Range{}}}})},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+56
-16
@@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
"github.com/xtls/xray-core/transport/internet"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
|
"golang.org/x/sys/windows/registry"
|
||||||
"golang.zx2c4.com/wintun"
|
"golang.zx2c4.com/wintun"
|
||||||
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
|
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
|
||||||
)
|
)
|
||||||
@@ -98,6 +99,19 @@ func open(name, desc string) (*wintun.Adapter, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ipv6Off tells whether DisabledComponents turns IPv6 off on the non-tunnel
|
||||||
|
// interfaces (0x10, as 0xFF does), the TUN among them. Windows applies it at
|
||||||
|
// boot only.
|
||||||
|
func ipv6Off() bool {
|
||||||
|
key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters`, registry.QUERY_VALUE)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer key.Close()
|
||||||
|
value, _, err := key.GetIntegerValue("DisabledComponents")
|
||||||
|
return err == nil && value&0x10 != 0
|
||||||
|
}
|
||||||
|
|
||||||
func (t *WindowsTun) Start() (err error) {
|
func (t *WindowsTun) Start() (err error) {
|
||||||
var address4, address6 bool
|
var address4, address6 bool
|
||||||
addresses := make([]netip.Prefix, 0, len(t.options.Gateway))
|
addresses := make([]netip.Prefix, 0, len(t.options.Gateway))
|
||||||
@@ -139,6 +153,17 @@ func (t *WindowsTun) Start() (err error) {
|
|||||||
routesData = append(routesData, &r)
|
routesData = append(routesData, &r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// With IPv6 off by DisabledComponents, setting it up may fail, clearing
|
||||||
|
// its DNS servers too, which is then only logged.
|
||||||
|
off6 := ipv6Off()
|
||||||
|
ignored := func(family winipcfg.AddressFamily, err error) bool {
|
||||||
|
if family != windows.AF_INET6 || !off6 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
errors.LogErrorInner(context.Background(), err, "[tun] ignored, as DisabledComponents turns IPv6 off")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
var retryTimes int
|
var retryTimes int
|
||||||
var firstErr error
|
var firstErr error
|
||||||
startOver:
|
startOver:
|
||||||
@@ -155,6 +180,9 @@ startOver:
|
|||||||
err = t.luid.SetRoutesForFamily(family, routesData)
|
err = t.luid.SetRoutesForFamily(family, routesData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
firstErr = errors.New("unable to set routes").Base(err)
|
firstErr = errors.New("unable to set routes").Base(err)
|
||||||
|
if ignored(family, firstErr) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err == windows.ERROR_NOT_FOUND {
|
if err == windows.ERROR_NOT_FOUND {
|
||||||
goto startOver
|
goto startOver
|
||||||
}
|
}
|
||||||
@@ -165,6 +193,9 @@ startOver:
|
|||||||
err = t.luid.SetIPAddressesForFamily(family, addresses)
|
err = t.luid.SetIPAddressesForFamily(family, addresses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
firstErr = errors.New("unable to set ips").Base(err)
|
firstErr = errors.New("unable to set ips").Base(err)
|
||||||
|
if ignored(family, firstErr) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err == windows.ERROR_NOT_FOUND {
|
if err == windows.ERROR_NOT_FOUND {
|
||||||
goto startOver
|
goto startOver
|
||||||
}
|
}
|
||||||
@@ -173,9 +204,7 @@ startOver:
|
|||||||
}
|
}
|
||||||
ipif, err := t.luid.IPInterface(family)
|
ipif, err := t.luid.IPInterface(family)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// With IPv6 disabled system-wide (DisabledComponents), the adapter has no
|
if ignored(family, errors.New("unable to get the interface").Base(err)) {
|
||||||
// IPv6 interface at all. Skip the family unless the config asks for it.
|
|
||||||
if err == windows.ERROR_NOT_FOUND && family == windows.AF_INET6 && !address6 && !route6 {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -194,6 +223,9 @@ startOver:
|
|||||||
err = ipif.Set()
|
err = ipif.Set()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
firstErr = errors.New("unable to set metric and MTU").Base(err)
|
firstErr = errors.New("unable to set metric and MTU").Base(err)
|
||||||
|
if ignored(family, firstErr) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err == windows.ERROR_NOT_FOUND {
|
if err == windows.ERROR_NOT_FOUND {
|
||||||
goto startOver
|
goto startOver
|
||||||
}
|
}
|
||||||
@@ -202,6 +234,9 @@ startOver:
|
|||||||
err = t.luid.SetDNS(family, dns, nil)
|
err = t.luid.SetDNS(family, dns, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
firstErr = errors.New("unable to set DNS").Base(err)
|
firstErr = errors.New("unable to set DNS").Base(err)
|
||||||
|
if ignored(family, firstErr) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err == windows.ERROR_NOT_FOUND {
|
if err == windows.ERROR_NOT_FOUND {
|
||||||
goto startOver
|
goto startOver
|
||||||
}
|
}
|
||||||
@@ -247,18 +282,25 @@ startOver:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// With autoSystemWfpBlockLeak, once the system routes lead to the TUN,
|
// With autoSystemWfpBlockLeak, once the system routes lead to the TUN,
|
||||||
// keep connections to the ports given ("dns" stands for those of DNS),
|
// keep the protocols and ports given ("dns" stands for those of DNS),
|
||||||
// Windows' DNS Client service, and an IP version no route of which leads
|
// Windows' DNS Client service, an IP version no route of which leads to
|
||||||
// to the TUN ("misconfigtun"), from leaving through the other interfaces.
|
// the TUN ("misconfigtun"), or everything ("all", or "allexceptlan" but
|
||||||
// Addresses do not matter: without one of a version in gateway, Windows
|
// for the local network), to the addresses of a CIDR or to all, from
|
||||||
// gives the TUN a link-local one.
|
// leaving through the other interfaces. The TUN's own addresses do not
|
||||||
|
// matter: without one of a version in gateway, Windows gives it a
|
||||||
|
// link-local one.
|
||||||
leaks, err := ExpandWfpBlockLeak(t.options.AutoSystemWfpBlockLeak)
|
leaks, err := ExpandWfpBlockLeak(t.options.AutoSystemWfpBlockLeak)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
block := newLeakFilters(leaks, route4, route6)
|
// With IPv6 off by DisabledComponents, IPv6 setup failures are only logged,
|
||||||
|
// and IPv6 still works until the reboot that applies it. So "misconfigtun"
|
||||||
|
// then blocks IPv6 outside the TUN whatever the routes.
|
||||||
|
block := newLeakFilters(leaks, route4, route6 && !off6)
|
||||||
if route4 || route6 {
|
if route4 || route6 {
|
||||||
if slices.Contains(leaks, "windnsclient") && !block.dnsClient {
|
dnsClient := func(l leak) bool { return l.name == "windnsclient" }
|
||||||
|
if slices.ContainsFunc(block, dnsClient) && !dnsClientUsesAnyPort() {
|
||||||
|
block = slices.DeleteFunc(block, dnsClient)
|
||||||
errors.LogInfo(context.Background(), "[tun] windnsclient skipped: before Windows 11 and Server 2022, the DNS Client service only queries port 53")
|
errors.LogInfo(context.Background(), "[tun] windnsclient skipped: before Windows 11 and Server 2022, the DNS Client service only queries port 53")
|
||||||
}
|
}
|
||||||
if block.systemDNS() && len(dns) == 0 {
|
if block.systemDNS() && len(dns) == 0 {
|
||||||
@@ -271,21 +313,19 @@ startOver:
|
|||||||
return errors.New("unable to block ", blocked, " outside the TUN (remove autoSystemWfpBlockLeak to run without)").Base(err)
|
return errors.New("unable to block ", blocked, " outside the TUN (remove autoSystemWfpBlockLeak to run without)").Base(err)
|
||||||
}
|
}
|
||||||
errors.LogInfo(context.Background(), "[tun] blocked outside the TUN: ", blocked)
|
errors.LogInfo(context.Background(), "[tun] blocked outside the TUN: ", blocked)
|
||||||
if block.systemDNS() {
|
|
||||||
covered := slices.Clone(addresses)
|
covered := slices.Clone(addresses)
|
||||||
for _, route := range routesData {
|
for _, route := range routesData {
|
||||||
covered = append(covered, route.Destination)
|
covered = append(covered, route.Destination)
|
||||||
}
|
}
|
||||||
for _, server := range dnsOutsideTUN(dns, covered) {
|
for _, server := range dnsOutsideTUN(dns, covered, block) {
|
||||||
errors.LogWarning(context.Background(), "[tun] DNS server ", server, " is in neither gateway nor autoSystemRoutingTable, so queries to it cannot go through the TUN and are blocked")
|
errors.LogWarning(context.Background(), "[tun] DNS server ", server, " is in neither gateway nor autoSystemRoutingTable, so queries to it cannot go through the TUN and are blocked")
|
||||||
}
|
}
|
||||||
// With updater, the dialer controllers bind Xray's own sockets
|
// With updater, the dialer controllers bind Xray's own sockets to the
|
||||||
// to the physical interface.
|
// physical interface.
|
||||||
if updater != nil {
|
if block.systemDNS() && updater != nil {
|
||||||
t.resolver = resolveOnOwn()
|
t.resolver = resolveOnOwn()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if len(dns) > 0 || route4 || route6 {
|
if len(dns) > 0 || route4 || route6 {
|
||||||
if err := flushDNSCache(); err != nil {
|
if err := flushDNSCache(); err != nil {
|
||||||
errors.LogInfoInner(context.Background(), err, "[tun] unable to flush DNS cache")
|
errors.LogInfoInner(context.Background(), err, "[tun] unable to flush DNS cache")
|
||||||
|
|||||||
+317
-150
@@ -3,6 +3,7 @@
|
|||||||
package tun
|
package tun
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -44,8 +45,12 @@ const (
|
|||||||
fwpByteArray16Type = 11 // FWP_BYTE_ARRAY16_TYPE
|
fwpByteArray16Type = 11 // FWP_BYTE_ARRAY16_TYPE
|
||||||
fwpByteBlobType = 12 // FWP_BYTE_BLOB_TYPE
|
fwpByteBlobType = 12 // FWP_BYTE_BLOB_TYPE
|
||||||
fwpSecurityDescriptorType = 14 // FWP_SECURITY_DESCRIPTOR_TYPE
|
fwpSecurityDescriptorType = 14 // FWP_SECURITY_DESCRIPTOR_TYPE
|
||||||
|
fwpV4AddrMask = 0x100 // FWP_V4_ADDR_MASK
|
||||||
|
fwpV6AddrMask = 0x101 // FWP_V6_ADDR_MASK
|
||||||
|
fwpRangeType = 0x102 // FWP_RANGE_TYPE
|
||||||
|
|
||||||
fwpMatchEqual = 0 // FWP_MATCH_EQUAL
|
fwpMatchEqual = 0 // FWP_MATCH_EQUAL
|
||||||
|
fwpMatchRange = 5 // FWP_MATCH_RANGE
|
||||||
fwpMatchFlagsAllSet = 6 // FWP_MATCH_FLAGS_ALL_SET
|
fwpMatchFlagsAllSet = 6 // FWP_MATCH_FLAGS_ALL_SET
|
||||||
|
|
||||||
fwpConditionFlagIsLoopback = 1 // FWP_CONDITION_FLAG_IS_LOOPBACK
|
fwpConditionFlagIsLoopback = 1 // FWP_CONDITION_FLAG_IS_LOOPBACK
|
||||||
@@ -94,6 +99,37 @@ type fwpValue0 struct {
|
|||||||
value uintptr
|
value uintptr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fwpRange0 is FWP_RANGE0, which an FWP_RANGE_TYPE condition points to.
|
||||||
|
type fwpRange0 struct {
|
||||||
|
low, high fwpValue0
|
||||||
|
}
|
||||||
|
|
||||||
|
// fwpV4AddrAndMask is FWP_V4_ADDR_AND_MASK, in host byte order.
|
||||||
|
type fwpV4AddrAndMask struct {
|
||||||
|
addr, mask uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
// fwpV6AddrAndMask is FWP_V6_ADDR_AND_MASK.
|
||||||
|
type fwpV6AddrAndMask struct {
|
||||||
|
addr [16]byte
|
||||||
|
prefixLength uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
// lanPrefixes are what "allexceptlan" leaves to the local network: private
|
||||||
|
// and link-local addresses, and multicast and broadcast, which discovery on
|
||||||
|
// it uses.
|
||||||
|
var lanPrefixes = []netip.Prefix{
|
||||||
|
netip.MustParsePrefix("10.0.0.0/8"),
|
||||||
|
netip.MustParsePrefix("172.16.0.0/12"),
|
||||||
|
netip.MustParsePrefix("192.168.0.0/16"),
|
||||||
|
netip.MustParsePrefix("169.254.0.0/16"),
|
||||||
|
netip.MustParsePrefix("224.0.0.0/4"),
|
||||||
|
netip.MustParsePrefix("255.255.255.255/32"),
|
||||||
|
netip.MustParsePrefix("fc00::/7"),
|
||||||
|
netip.MustParsePrefix("fe80::/10"),
|
||||||
|
netip.MustParsePrefix("ff00::/8"),
|
||||||
|
}
|
||||||
|
|
||||||
type fwpmDisplayData0 struct {
|
type fwpmDisplayData0 struct {
|
||||||
name *uint16
|
name *uint16
|
||||||
description *uint16
|
description *uint16
|
||||||
@@ -171,27 +207,36 @@ func condition(field *windows.GUID, typ uint32, value uintptr) fwpmFilterConditi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// leakFilters is what blockLeaks keeps from leaving outside the TUN.
|
// leakFilters are the values of autoSystemWfpBlockLeak that blockLeaks keeps
|
||||||
type leakFilters struct {
|
// from leaving outside the TUN.
|
||||||
ports []leakPort // connections to these ports
|
type leakFilters []leak
|
||||||
dnsClient bool // Windows' DNS Client service
|
|
||||||
ipv4, ipv6 bool // an IP version altogether
|
|
||||||
}
|
|
||||||
|
|
||||||
// newLeakFilters turns expanded autoSystemWfpBlockLeak values into the filters
|
// newLeakFilters turns expanded autoSystemWfpBlockLeak values into the filters
|
||||||
// for a TUN that the routes of route4 (IPv4) and route6 (IPv6) lead to.
|
// for a TUN that the routes of route4 (IPv4) and route6 (IPv6) lead to, which
|
||||||
|
// leave "misconfigtun" over the IP versions without such routes only.
|
||||||
func newLeakFilters(leaks []string, route4, route6 bool) leakFilters {
|
func newLeakFilters(leaks []string, route4, route6 bool) leakFilters {
|
||||||
var block leakFilters
|
var block leakFilters
|
||||||
for _, leak := range leaks {
|
for _, value := range leaks {
|
||||||
switch leak {
|
l, ok := parseLeak(value)
|
||||||
case "windnsclient":
|
if !ok {
|
||||||
block.dnsClient = dnsClientUsesAnyPort()
|
continue
|
||||||
case "misconfigtun":
|
|
||||||
block.ipv4, block.ipv6 = !route4, !route6
|
|
||||||
default:
|
|
||||||
if port, ok := parseLeakPort(leak); ok {
|
|
||||||
block.ports = append(block.ports, port)
|
|
||||||
}
|
}
|
||||||
|
if l.name == "misconfigtun" {
|
||||||
|
unrouted4, unrouted6 := !route4, !route6
|
||||||
|
if l.prefix.IsValid() {
|
||||||
|
unrouted4, unrouted6 = unrouted4 && l.prefix.Addr().Is4(), unrouted6 && l.prefix.Addr().Is6()
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case !unrouted4 && !unrouted6:
|
||||||
|
continue
|
||||||
|
case !l.prefix.IsValid() && !unrouted4:
|
||||||
|
l.prefix = allAddresses(true)
|
||||||
|
case !l.prefix.IsValid() && !unrouted6:
|
||||||
|
l.prefix = allAddresses(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !slices.Contains(block, l) {
|
||||||
|
block = append(block, l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return block
|
return block
|
||||||
@@ -199,24 +244,69 @@ func newLeakFilters(leaks []string, route4, route6 bool) leakFilters {
|
|||||||
|
|
||||||
// String lists what block keeps inside the TUN, or is empty for nothing.
|
// String lists what block keeps inside the TUN, or is empty for nothing.
|
||||||
func (block leakFilters) String() string {
|
func (block leakFilters) String() string {
|
||||||
var blocked []string
|
values := make([]string, len(block))
|
||||||
for _, port := range block.ports {
|
for i, l := range block {
|
||||||
blocked = append(blocked, port.String())
|
values[i] = l.String()
|
||||||
}
|
}
|
||||||
for _, b := range []struct {
|
return strings.Join(values, ", ")
|
||||||
on bool
|
|
||||||
what string
|
|
||||||
}{{block.dnsClient, "windnsclient"}, {block.ipv4, "IPv4"}, {block.ipv6, "IPv6"}} {
|
|
||||||
if b.on {
|
|
||||||
blocked = append(blocked, b.what)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return strings.Join(blocked, ", ")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// systemDNS tells whether block keeps the system's DNS inside the TUN.
|
// systemDNS tells whether block keeps the system's DNS inside the TUN, to at
|
||||||
|
// least some addresses: port 53, the DNS Client service, or everything ("all"),
|
||||||
|
// though not everything but the local network ("allexceptlan"), where a
|
||||||
|
// resolver like the router's may be.
|
||||||
func (block leakFilters) systemDNS() bool {
|
func (block leakFilters) systemDNS() bool {
|
||||||
return block.dnsClient || slices.ContainsFunc(block.ports, func(port leakPort) bool { return port.port == 53 })
|
return slices.ContainsFunc(block, leak.blocksDNS)
|
||||||
|
}
|
||||||
|
|
||||||
|
// prefixes returns the CIDRs of the values of block named name over an IP
|
||||||
|
// version.
|
||||||
|
func (block leakFilters) prefixes(name string, ipv6 bool) []netip.Prefix {
|
||||||
|
var prefixes []netip.Prefix
|
||||||
|
for _, l := range block {
|
||||||
|
if prefix, ok := l.over(ipv6); ok && l.name == name {
|
||||||
|
prefixes = append(prefixes, prefix)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return prefixes
|
||||||
|
}
|
||||||
|
|
||||||
|
// over returns the CIDR of l over an IP version, all its addresses for l
|
||||||
|
// without one, or false for l over the other IP version only.
|
||||||
|
func (l leak) over(ipv6 bool) (netip.Prefix, bool) {
|
||||||
|
if !l.prefix.IsValid() {
|
||||||
|
return allAddresses(ipv6), true
|
||||||
|
}
|
||||||
|
return l.prefix, l.prefix.Addr().Is6() == ipv6
|
||||||
|
}
|
||||||
|
|
||||||
|
// allAddresses is the CIDR of all addresses of an IP version.
|
||||||
|
func allAddresses(ipv6 bool) netip.Prefix {
|
||||||
|
if ipv6 {
|
||||||
|
return netip.PrefixFrom(netip.IPv6Unspecified(), 0)
|
||||||
|
}
|
||||||
|
return netip.PrefixFrom(netip.IPv4Unspecified(), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// lanWithin returns the parts of lanPrefixes that lie in any of prefixes: two
|
||||||
|
// prefixes either share no address, or one holds the other.
|
||||||
|
func lanWithin(prefixes ...netip.Prefix) []netip.Prefix {
|
||||||
|
var parts []netip.Prefix
|
||||||
|
for _, lan := range lanPrefixes {
|
||||||
|
for _, prefix := range prefixes {
|
||||||
|
if !prefix.Overlaps(lan) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
part := lan
|
||||||
|
if prefix.Bits() > lan.Bits() {
|
||||||
|
part = prefix
|
||||||
|
}
|
||||||
|
if !slices.Contains(parts, part) {
|
||||||
|
parts = append(parts, part)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
// dnsClientUsesAnyPort tells whether Windows' DNS Client service may send its
|
// dnsClientUsesAnyPort tells whether Windows' DNS Client service may send its
|
||||||
@@ -229,31 +319,49 @@ func dnsClientUsesAnyPort() bool {
|
|||||||
return build >= 20348
|
return build >= 20348
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The weights of the filters of blockLeaks, the heaviest matching one of which
|
||||||
|
// decides.
|
||||||
|
const (
|
||||||
|
weightAllExceptLAN uint8 = iota // block "allexceptlan"
|
||||||
|
weightLAN // permit its local network
|
||||||
|
weightDNSClient // block "windnsclient"
|
||||||
|
weightLocalLink // permit its mDNS and LLMNR on the local network
|
||||||
|
weightBlock // block the other values
|
||||||
|
weightPermit // permit what always stays allowed, and the TUN
|
||||||
|
weightXray // permit Xray
|
||||||
|
)
|
||||||
|
|
||||||
// blockLeaks keeps traffic from leaving through interfaces other than tun,
|
// blockLeaks keeps traffic from leaving through interfaces other than tun,
|
||||||
// for every program but Xray itself, whose outbounds (DNS included) use the
|
// for every program but Xray itself, whose outbounds (DNS included) use the
|
||||||
// other interfaces on purpose:
|
// other interfaces on purpose, as the values of block say, each to the
|
||||||
|
// addresses of its CIDR, or to all:
|
||||||
//
|
//
|
||||||
// - ports: connections to these TCP or UDP ports may only go through the
|
// - Protocols and ports: connections of these, TCP or UDP to some or all
|
||||||
// TUN, those of DNS (53), DNS over TLS (TCP 853) and DNS over QUIC (UDP
|
// ports, or ICMP, may only go through the TUN, those of DNS (53), DNS
|
||||||
// 853) with "dns". Windows sends a name query to the DNS servers of all
|
// over TLS (TCP 853) and DNS over QUIC (UDP 853) with "dns". Windows
|
||||||
// interfaces, not only to those of the TUN: to the first server of each
|
// sends a name query to the DNS servers of all interfaces, not only to
|
||||||
// interface, then to all of them when no answer arrives within a second or
|
// those of the TUN: to the first server of each interface, then to all
|
||||||
// two. It sends the queries for the servers of an interface out through
|
// of them when no answer arrives within a second or two. It sends the
|
||||||
// that interface, whatever the routes say, and other programs reach an
|
// queries for the servers of an interface out through that interface,
|
||||||
// on-link resolver, like 192.168.1.1 from DHCP, through its LAN route,
|
// whatever the routes say, and other programs reach an on-link resolver,
|
||||||
// which is more specific than the TUN's default route.
|
// like 192.168.1.1 from DHCP, through its LAN route, which is more
|
||||||
// - dnsClient: since Windows 11 and Server 2022, Windows may also send its
|
// specific than the TUN's default route.
|
||||||
// queries over HTTPS or TLS, to any port, so its DNS Client service may not
|
// - "windnsclient": since Windows 11 and Server 2022, Windows may also send
|
||||||
// connect outside the TUN at all, except for name resolution on the local
|
// its queries over HTTPS or TLS, to any port, so its DNS Client service
|
||||||
// link (mDNS, LLMNR).
|
// may not connect outside the TUN at all, except for name resolution on
|
||||||
// - ipv4, ipv6: no IPv4, or no IPv6, at all, in either direction, for a TUN
|
// the local network (mDNS, LLMNR).
|
||||||
// that no route of it leads to, except loopback and what Windows itself
|
// - "all", and "misconfigtun" over an IP version no route of which leads to
|
||||||
// needs on the local link (DHCP, and for IPv6 neighbor and multicast
|
// the TUN: nothing at all outside the TUN, in either direction. The TUN
|
||||||
// listener discovery), none of which can leave it. The TUN carries what
|
// carries what is routed to it even without an address of that IP
|
||||||
// is routed to it even without an address of that IP version in gateway:
|
// version in gateway: Windows gives it link-local ones itself, an IPv6
|
||||||
// Windows gives it link-local ones itself, an IPv6 one at once, an IPv4
|
// one at once, an IPv4 one from 169.254.0.0/16 after some seconds (until
|
||||||
// one from 169.254.0.0/16 after some seconds (until then, IPv4 routed to
|
// then, IPv4 routed to the TUN is unreachable).
|
||||||
// the TUN is unreachable).
|
// - "allexceptlan": the same, but to and from the local network.
|
||||||
|
//
|
||||||
|
// The other values still apply to what "allexceptlan" and "windnsclient" leave
|
||||||
|
// open on the local network. Whatever is blocked, loopback, which cannot leave
|
||||||
|
// the system, and what Windows itself needs on the local link stay allowed:
|
||||||
|
// DHCP, and for IPv6 neighbor and multicast listener discovery.
|
||||||
//
|
//
|
||||||
// The filters live in a dynamic WFP session: closing the returned engine handle
|
// The filters live in a dynamic WFP session: closing the returned engine handle
|
||||||
// with closeWFPEngine deletes them, and so does Windows when the process dies.
|
// with closeWFPEngine deletes them, and so does Windows when the process dies.
|
||||||
@@ -354,33 +462,149 @@ func addLeakFilters(engine windows.Handle, tun winipcfg.LUID, block leakFilters)
|
|||||||
onTUN := func(field *windows.GUID) fwpmFilterCondition0 {
|
onTUN := func(field *windows.GUID) fwpmFilterCondition0 {
|
||||||
return condition(field, fwpUint64, uintptr(unsafe.Pointer(tunLUID)))
|
return condition(field, fwpUint64, uintptr(unsafe.Pointer(tunLUID)))
|
||||||
}
|
}
|
||||||
|
// remote matches the remote addresses in any of prefixes, all of one IP
|
||||||
|
// version: conditions on the same field match when any of them does. With
|
||||||
|
// all addresses among them, no condition is needed.
|
||||||
|
remote := func(prefixes ...netip.Prefix) []fwpmFilterCondition0 {
|
||||||
|
if slices.ContainsFunc(prefixes, func(prefix netip.Prefix) bool { return prefix.Bits() == 0 }) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var conditions []fwpmFilterCondition0
|
||||||
|
for _, prefix := range prefixes {
|
||||||
|
var value uintptr
|
||||||
|
typ := uint32(fwpV4AddrMask)
|
||||||
|
if prefix.Addr().Is6() {
|
||||||
|
addr := &fwpV6AddrAndMask{addr: prefix.Addr().As16(), prefixLength: uint8(prefix.Bits())}
|
||||||
|
pinner.Pin(addr) // the condition only holds it as uintptr
|
||||||
|
value, typ = uintptr(unsafe.Pointer(addr)), fwpV6AddrMask
|
||||||
|
} else {
|
||||||
|
a := prefix.Addr().As4()
|
||||||
|
addr := &fwpV4AddrAndMask{addr: binary.BigEndian.Uint32(a[:]), mask: ^uint32(0) << (32 - prefix.Bits())}
|
||||||
|
pinner.Pin(addr) // the condition only holds it as uintptr
|
||||||
|
value = uintptr(unsafe.Pointer(addr))
|
||||||
|
}
|
||||||
|
conditions = append(conditions, condition(&fwpmConditionIPRemoteAddress, typ, value))
|
||||||
|
}
|
||||||
|
return conditions
|
||||||
|
}
|
||||||
|
// toPorts matches the ports of traffic, if not all of them.
|
||||||
|
toPorts := func(traffic leak) []fwpmFilterCondition0 {
|
||||||
|
switch {
|
||||||
|
case traffic.low == 0:
|
||||||
|
return nil
|
||||||
|
case traffic.low == traffic.high:
|
||||||
|
return []fwpmFilterCondition0{condition(&fwpmConditionIPRemotePort, fwpUint16, uintptr(traffic.low))}
|
||||||
|
}
|
||||||
|
ports := &fwpRange0{
|
||||||
|
low: fwpValue0{typ: fwpUint16, value: uintptr(traffic.low)},
|
||||||
|
high: fwpValue0{typ: fwpUint16, value: uintptr(traffic.high)},
|
||||||
|
}
|
||||||
|
pinner.Pin(ports) // the condition only holds it as uintptr
|
||||||
|
return []fwpmFilterCondition0{{
|
||||||
|
fieldKey: fwpmConditionIPRemotePort,
|
||||||
|
matchType: fwpMatchRange,
|
||||||
|
conditionValue: fwpValue0{typ: fwpRangeType, value: uintptr(unsafe.Pointer(ports))},
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// What stays allowed whatever is blocked, in both directions: replies to
|
||||||
|
// a connection accepted from outside would leave through the physical
|
||||||
|
// link as well.
|
||||||
|
type permit struct {
|
||||||
|
name string
|
||||||
|
conditions []fwpmFilterCondition0
|
||||||
|
}
|
||||||
|
loopback := permit{"loopback", []fwpmFilterCondition0{{
|
||||||
|
fieldKey: fwpmConditionFlags,
|
||||||
|
matchType: fwpMatchFlagsAllSet,
|
||||||
|
conditionValue: fwpValue0{typ: fwpUint32, value: fwpConditionFlagIsLoopback},
|
||||||
|
}}}
|
||||||
|
// DHCP keeps the addresses of the other interfaces, which Xray's own
|
||||||
|
// connections use.
|
||||||
|
dhcp := permit{"DHCP", []fwpmFilterCondition0{
|
||||||
|
condition(&fwpmConditionIPProtocol, fwpUint8, windows.IPPROTO_UDP),
|
||||||
|
condition(&fwpmConditionIPLocalPort, fwpUint16, 68),
|
||||||
|
condition(&fwpmConditionIPRemotePort, fwpUint16, 67),
|
||||||
|
}}
|
||||||
|
// Neighbor and multicast listener discovery, ICMPv6 130-137 and 143,
|
||||||
|
// whose type and code sit where the local and remote port are.
|
||||||
|
discovery := permit{"IPv6 neighbor and multicast listener discovery", []fwpmFilterCondition0{condition(&fwpmConditionIPProtocol, fwpUint8, windows.IPPROTO_ICMPV6)}}
|
||||||
|
for _, typ := range []uintptr{130, 131, 132, 133, 134, 135, 136, 137, 143} {
|
||||||
|
discovery.conditions = append(discovery.conditions, condition(&fwpmConditionIPLocalPort, fwpUint16, typ))
|
||||||
|
}
|
||||||
|
discovery.conditions = append(discovery.conditions, condition(&fwpmConditionIPRemotePort, fwpUint16, 0))
|
||||||
|
dhcpv6 := []fwpmFilterCondition0{
|
||||||
|
condition(&fwpmConditionIPProtocol, fwpUint8, windows.IPPROTO_UDP),
|
||||||
|
condition(&fwpmConditionIPLocalPort, fwpUint16, 546),
|
||||||
|
condition(&fwpmConditionIPRemotePort, fwpUint16, 547),
|
||||||
|
}
|
||||||
|
// The DHCPv6 client sends to the servers' multicast address, and they
|
||||||
|
// answer from their own.
|
||||||
|
dhcpv6Out := permit{"DHCPv6", slices.Concat(dhcpv6, []fwpmFilterCondition0{condition(&fwpmConditionIPRemoteAddress, fwpByteArray16Type, uintptr(unsafe.Pointer(&ipv6AllDHCPv6Servers)))})}
|
||||||
|
dhcpv6In := permit{"DHCPv6", dhcpv6}
|
||||||
|
|
||||||
for _, layer := range []struct {
|
for _, layer := range []struct {
|
||||||
key *windows.GUID
|
key *windows.GUID
|
||||||
selfFlags uint32
|
selfFlags uint32
|
||||||
via *windows.GUID // the interface that has to be the TUN as well
|
via *windows.GUID // the interface that has to be the TUN as well
|
||||||
|
ipv6 bool
|
||||||
|
permits []permit
|
||||||
}{
|
}{
|
||||||
{&fwpmLayerALEAuthConnectV4, fwpmFilterFlagClearActionRight, &fwpmConditionIPNexthopInterface},
|
{&fwpmLayerALEAuthConnectV4, fwpmFilterFlagClearActionRight, &fwpmConditionIPNexthopInterface, false, []permit{loopback, dhcp}},
|
||||||
{&fwpmLayerALEAuthRecvAcceptV4, 0, &fwpmConditionIPArrivalInterface},
|
{&fwpmLayerALEAuthRecvAcceptV4, 0, &fwpmConditionIPArrivalInterface, false, []permit{loopback, dhcp}},
|
||||||
{&fwpmLayerALEAuthConnectV6, fwpmFilterFlagClearActionRight, &fwpmConditionIPNexthopInterface},
|
{&fwpmLayerALEAuthConnectV6, fwpmFilterFlagClearActionRight, &fwpmConditionIPNexthopInterface, true, []permit{loopback, discovery, dhcpv6Out}},
|
||||||
{&fwpmLayerALEAuthRecvAcceptV6, 0, &fwpmConditionIPArrivalInterface},
|
{&fwpmLayerALEAuthRecvAcceptV6, 0, &fwpmConditionIPArrivalInterface, true, []permit{loopback, discovery, dhcpv6In}},
|
||||||
} {
|
} {
|
||||||
if err := add(layer.key, "permit Xray", layer.selfFlags, fwpActionPermit, 4, self); err != nil {
|
throughTUN := permit{"through the TUN", []fwpmFilterCondition0{onTUN(&fwpmConditionIPLocalInterface), onTUN(layer.via)}}
|
||||||
|
if err := add(layer.key, "permit Xray", layer.selfFlags, fwpActionPermit, weightXray, self); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, port := range block.ports {
|
for _, p := range append(layer.permits, throughTUN) {
|
||||||
protocol := uintptr(windows.IPPROTO_UDP)
|
if err := add(layer.key, "permit "+p.name, 0, fwpActionPermit, weightPermit, p.conditions...); err != nil {
|
||||||
if port.tcp {
|
|
||||||
protocol = windows.IPPROTO_TCP
|
|
||||||
}
|
|
||||||
toPort := []fwpmFilterCondition0{
|
|
||||||
condition(&fwpmConditionIPProtocol, fwpUint8, protocol),
|
|
||||||
condition(&fwpmConditionIPRemotePort, fwpUint16, uintptr(port.port)),
|
|
||||||
}
|
|
||||||
throughTUN := slices.Concat(toPort, []fwpmFilterCondition0{onTUN(&fwpmConditionIPLocalInterface), onTUN(layer.via)})
|
|
||||||
if err := add(layer.key, "permit "+port.String()+" through the TUN", 0, fwpActionPermit, 3, throughTUN...); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := add(layer.key, "block "+port.String(), 0, fwpActionBlock, 2, toPort...); err != nil {
|
}
|
||||||
|
for _, l := range block {
|
||||||
|
prefix, ok := l.over(layer.ipv6)
|
||||||
|
if !ok {
|
||||||
|
continue // for the other IP version only
|
||||||
|
}
|
||||||
|
var protocols []uintptr
|
||||||
|
switch l.name {
|
||||||
|
case "tcp":
|
||||||
|
protocols = []uintptr{windows.IPPROTO_TCP}
|
||||||
|
case "udp":
|
||||||
|
protocols = []uintptr{windows.IPPROTO_UDP}
|
||||||
|
case "":
|
||||||
|
protocols = []uintptr{windows.IPPROTO_TCP, windows.IPPROTO_UDP}
|
||||||
|
case "icmp":
|
||||||
|
protocols = []uintptr{windows.IPPROTO_ICMP}
|
||||||
|
if layer.ipv6 {
|
||||||
|
protocols = []uintptr{windows.IPPROTO_ICMPV6}
|
||||||
|
}
|
||||||
|
case "all", "misconfigtun":
|
||||||
|
// every protocol
|
||||||
|
default:
|
||||||
|
continue // "allexceptlan" and "windnsclient" have filters of their own
|
||||||
|
}
|
||||||
|
var matches []fwpmFilterCondition0
|
||||||
|
for _, protocol := range protocols {
|
||||||
|
matches = append(matches, condition(&fwpmConditionIPProtocol, fwpUint8, protocol))
|
||||||
|
}
|
||||||
|
matches = slices.Concat(matches, toPorts(l), remote(prefix))
|
||||||
|
if err := add(layer.key, "block "+l.String(), 0, fwpActionBlock, weightBlock, matches...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if allExceptLAN := block.prefixes("allexceptlan", layer.ipv6); len(allExceptLAN) > 0 {
|
||||||
|
// Lighter than the other values, which so still apply on the
|
||||||
|
// local network, DNS with "allexceptlan" among them.
|
||||||
|
if lan := lanWithin(allExceptLAN...); len(lan) > 0 {
|
||||||
|
if err := add(layer.key, "permit the local network", 0, fwpActionPermit, weightLAN, remote(lan...)...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := add(layer.key, "block allexceptlan", 0, fwpActionBlock, weightAllExceptLAN, remote(allExceptLAN...)...); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -389,12 +613,11 @@ func addLeakFilters(engine windows.Handle, tun winipcfg.LUID, block leakFilters)
|
|||||||
// Since Windows 11 and Server 2022, the DNS Client service may also send
|
// Since Windows 11 and Server 2022, the DNS Client service may also send
|
||||||
// the queries for an interface's servers over HTTPS or TLS, out through
|
// the queries for an interface's servers over HTTPS or TLS, out through
|
||||||
// that interface and to any port. So there it may only connect through
|
// that interface and to any port. So there it may only connect through
|
||||||
// the TUN, except for mDNS and LLMNR, which stay on the local link (over
|
// the TUN, except for mDNS and LLMNR on the local network. Like Windows
|
||||||
// an IP version only while it is not blocked altogether). Like Windows
|
|
||||||
// Firewall's rules for it, the filters recognize the service by its SID,
|
// Firewall's rules for it, the filters recognize the service by its SID,
|
||||||
// which Windows puts in the token of its process: the security descriptor
|
// which Windows puts in the token of its process: the security descriptor
|
||||||
// grants that SID the right to match (FWP_ACTRL_MATCH_FILTER, CC in SDDL).
|
// grants that SID the right to match (FWP_ACTRL_MATCH_FILTER, CC in SDDL).
|
||||||
if block.dnsClient {
|
if slices.ContainsFunc(block, func(l leak) bool { return l.name == "windnsclient" }) {
|
||||||
sd, err := windows.SecurityDescriptorFromString("O:SYG:SYD:(A;;CCRC;;;" + dnsClientSID + ")")
|
sd, err := windows.SecurityDescriptorFromString("O:SYG:SYD:(A;;CCRC;;;" + dnsClientSID + ")")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -406,84 +629,19 @@ func addLeakFilters(engine windows.Handle, tun winipcfg.LUID, block leakFilters)
|
|||||||
mdnsLLMNR := []fwpmFilterCondition0{dnsClient, condition(&fwpmConditionIPRemotePort, fwpUint16, 5353), condition(&fwpmConditionIPRemotePort, fwpUint16, 5355)}
|
mdnsLLMNR := []fwpmFilterCondition0{dnsClient, condition(&fwpmConditionIPRemotePort, fwpUint16, 5353), condition(&fwpmConditionIPRemotePort, fwpUint16, 5355)}
|
||||||
for _, layer := range []struct {
|
for _, layer := range []struct {
|
||||||
key *windows.GUID
|
key *windows.GUID
|
||||||
localLink bool
|
ipv6 bool
|
||||||
}{
|
}{
|
||||||
{&fwpmLayerALEAuthConnectV4, !block.ipv4},
|
{&fwpmLayerALEAuthConnectV4, false},
|
||||||
{&fwpmLayerALEAuthConnectV6, !block.ipv6},
|
{&fwpmLayerALEAuthConnectV6, true},
|
||||||
} {
|
} {
|
||||||
if err := add(layer.key, "permit the DNS Client service through the TUN", 0, fwpActionPermit, 3, dnsClient, onTUN(&fwpmConditionIPLocalInterface), onTUN(&fwpmConditionIPNexthopInterface)); err != nil {
|
prefixes := block.prefixes("windnsclient", layer.ipv6)
|
||||||
|
if len(prefixes) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := add(layer.key, "permit the DNS Client service's mDNS and LLMNR", 0, fwpActionPermit, weightLocalLink, slices.Concat(mdnsLLMNR, remote(lanWithin(allAddresses(layer.ipv6))...))...); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if layer.localLink {
|
if err := add(layer.key, "block the DNS Client service", 0, fwpActionBlock, weightDNSClient, slices.Concat([]fwpmFilterCondition0{dnsClient}, remote(prefixes...))...); err != nil {
|
||||||
if err := add(layer.key, "permit the DNS Client service's mDNS and LLMNR", 0, fwpActionPermit, 3, mdnsLLMNR...); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := add(layer.key, "block the DNS Client service", 0, fwpActionBlock, 2, dnsClient); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Both directions: replies to a connection accepted from outside would
|
|
||||||
// leave through the physical link as well.
|
|
||||||
loopback := fwpmFilterCondition0{
|
|
||||||
fieldKey: fwpmConditionFlags,
|
|
||||||
matchType: fwpMatchFlagsAllSet,
|
|
||||||
conditionValue: fwpValue0{typ: fwpUint32, value: fwpConditionFlagIsLoopback},
|
|
||||||
}
|
|
||||||
if block.ipv4 {
|
|
||||||
// DHCP keeps the addresses of the other interfaces, which Xray's own
|
|
||||||
// connections use.
|
|
||||||
dhcp := []fwpmFilterCondition0{
|
|
||||||
condition(&fwpmConditionIPProtocol, fwpUint8, windows.IPPROTO_UDP),
|
|
||||||
condition(&fwpmConditionIPLocalPort, fwpUint16, 68),
|
|
||||||
condition(&fwpmConditionIPRemotePort, fwpUint16, 67),
|
|
||||||
}
|
|
||||||
for _, layer := range []*windows.GUID{&fwpmLayerALEAuthConnectV4, &fwpmLayerALEAuthRecvAcceptV4} {
|
|
||||||
if err := add(layer, "permit IPv4 loopback", 0, fwpActionPermit, 1, loopback); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := add(layer, "permit DHCP", 0, fwpActionPermit, 1, dhcp...); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := add(layer, "block IPv4", 0, fwpActionBlock, 0); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if block.ipv6 {
|
|
||||||
// Neighbor and multicast listener discovery, ICMPv6 130-137 and 143,
|
|
||||||
// whose type and code sit where the local and remote port are.
|
|
||||||
discovery := []fwpmFilterCondition0{condition(&fwpmConditionIPProtocol, fwpUint8, windows.IPPROTO_ICMPV6)}
|
|
||||||
for _, typ := range []uintptr{130, 131, 132, 133, 134, 135, 136, 137, 143} {
|
|
||||||
discovery = append(discovery, condition(&fwpmConditionIPLocalPort, fwpUint16, typ))
|
|
||||||
}
|
|
||||||
discovery = append(discovery, condition(&fwpmConditionIPRemotePort, fwpUint16, 0))
|
|
||||||
dhcpv6 := []fwpmFilterCondition0{
|
|
||||||
condition(&fwpmConditionIPProtocol, fwpUint8, windows.IPPROTO_UDP),
|
|
||||||
condition(&fwpmConditionIPLocalPort, fwpUint16, 546),
|
|
||||||
condition(&fwpmConditionIPRemotePort, fwpUint16, 547),
|
|
||||||
}
|
|
||||||
for _, direction := range []struct {
|
|
||||||
layer *windows.GUID
|
|
||||||
dhcpv6 []fwpmFilterCondition0
|
|
||||||
}{
|
|
||||||
// The client sends to the servers' multicast address, and they
|
|
||||||
// answer from their own.
|
|
||||||
{&fwpmLayerALEAuthConnectV6, slices.Concat(dhcpv6, []fwpmFilterCondition0{condition(&fwpmConditionIPRemoteAddress, fwpByteArray16Type, uintptr(unsafe.Pointer(&ipv6AllDHCPv6Servers)))})},
|
|
||||||
{&fwpmLayerALEAuthRecvAcceptV6, dhcpv6},
|
|
||||||
} {
|
|
||||||
if err := add(direction.layer, "permit IPv6 loopback", 0, fwpActionPermit, 1, loopback); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := add(direction.layer, "permit IPv6 neighbor and multicast listener discovery", 0, fwpActionPermit, 1, discovery...); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := add(direction.layer, "permit DHCPv6", 0, fwpActionPermit, 1, direction.dhcpv6...); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := add(direction.layer, "block IPv6", 0, fwpActionBlock, 0); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -510,13 +668,22 @@ func addFilter(engine windows.Handle, sublayer, layer *windows.GUID, name string
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// dnsOutsideTUN returns the servers outside all of prefixes, the TUN's own
|
// dnsOutsideTUN returns the servers whose queries block blocks: those outside
|
||||||
// subnets and routes: queries to them cannot go through the TUN.
|
// all of prefixes, the TUN's own subnets and routes, as queries to them cannot
|
||||||
func dnsOutsideTUN(servers []netip.Addr, prefixes []netip.Prefix) []netip.Addr {
|
// go through the TUN, and inside the CIDR of a value that keeps DNS inside the
|
||||||
|
// TUN, or of "misconfigtun". Loopback ones, local resolvers, are not among
|
||||||
|
// them, as loopback stays allowed.
|
||||||
|
func dnsOutsideTUN(servers []netip.Addr, prefixes []netip.Prefix, block leakFilters) []netip.Addr {
|
||||||
var outside []netip.Addr
|
var outside []netip.Addr
|
||||||
for _, server := range servers {
|
for _, server := range servers {
|
||||||
server = server.Unmap()
|
server = server.Unmap()
|
||||||
if !slices.ContainsFunc(prefixes, func(p netip.Prefix) bool { return p.Contains(server) }) {
|
if server.IsLoopback() || slices.ContainsFunc(prefixes, func(p netip.Prefix) bool { return p.Contains(server) }) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if slices.ContainsFunc(block, func(l leak) bool {
|
||||||
|
prefix, ok := l.over(server.Is6())
|
||||||
|
return ok && prefix.Contains(server) && (l.blocksDNS() || l.name == "misconfigtun")
|
||||||
|
}) {
|
||||||
outside = append(outside, server)
|
outside = append(outside, server)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,21 @@ func TestWFPStructLayout(t *testing.T) {
|
|||||||
[]uintptr{unsafe.Sizeof(value), unsafe.Offsetof(value.value)},
|
[]uintptr{unsafe.Sizeof(value), unsafe.Offsetof(value.value)},
|
||||||
[]uintptr{16, 8}, []uintptr{8, 4})
|
[]uintptr{16, 8}, []uintptr{8, 4})
|
||||||
|
|
||||||
|
var ports fwpRange0
|
||||||
|
check("FWP_RANGE0",
|
||||||
|
[]uintptr{unsafe.Sizeof(ports), unsafe.Offsetof(ports.high)},
|
||||||
|
[]uintptr{32, 16}, []uintptr{16, 8})
|
||||||
|
|
||||||
|
var v4 fwpV4AddrAndMask
|
||||||
|
check("FWP_V4_ADDR_AND_MASK",
|
||||||
|
[]uintptr{unsafe.Sizeof(v4), unsafe.Offsetof(v4.mask)},
|
||||||
|
[]uintptr{8, 4}, []uintptr{8, 4})
|
||||||
|
|
||||||
|
var v6 fwpV6AddrAndMask
|
||||||
|
check("FWP_V6_ADDR_AND_MASK",
|
||||||
|
[]uintptr{unsafe.Sizeof(v6), unsafe.Offsetof(v6.prefixLength)},
|
||||||
|
[]uintptr{17, 16}, []uintptr{17, 16})
|
||||||
|
|
||||||
var display fwpmDisplayData0
|
var display fwpmDisplayData0
|
||||||
check("FWPM_DISPLAY_DATA0",
|
check("FWPM_DISPLAY_DATA0",
|
||||||
[]uintptr{unsafe.Sizeof(display), unsafe.Offsetof(display.description)},
|
[]uintptr{unsafe.Sizeof(display), unsafe.Offsetof(display.description)},
|
||||||
@@ -114,35 +129,101 @@ func TestLeakFiltersAccepted(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
leaks, err := ExpandWfpBlockLeak([]string{"dns", "misconfigtun", "tcp/443"})
|
// Each with a sublayer of its own.
|
||||||
|
for _, c := range []struct {
|
||||||
|
values []string
|
||||||
|
route4, route6 bool
|
||||||
|
}{
|
||||||
|
{[]string{"dns", "misconfigtun", "all", "tcp/443", "udp/1000-2000", "tcp", "icmp", "10-20", "1-65535"}, false, false},
|
||||||
|
// CIDRs, and the local network's addresses.
|
||||||
|
{[]string{"1.1.1.0/24:tcp/80", "[2001:db8::/32]:udp/5000-6000", "[::/0]:icmp", "8.8.8.8/32:all", "[2000::/3]:misconfigtun", "9.9.9.9/32:dns"}, true, false},
|
||||||
|
{[]string{"allexceptlan", "udp/1000-2000", "icmp", "192.168.1.5/32:all"}, true, false},
|
||||||
|
{[]string{"0.0.0.0/0:allexceptlan", "[::/0]:all", "[::/0]:windnsclient", "1.0.0.0/8:windnsclient"}, true, true},
|
||||||
|
{[]string{"[::/0]:allexceptlan", "0.0.0.0/0:misconfigtun", "10.0.0.0/8:allexceptlan", "1.0.0.0/8:allexceptlan"}, false, true},
|
||||||
|
} {
|
||||||
|
leaks, err := ExpandWfpBlockLeak(c.values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
block := newLeakFilters(leaks, false, false)
|
if err := addLeakFilters(engine, loopback, newLeakFilters(leaks, c.route4, c.route6)); err != nil {
|
||||||
block.dnsClient = true // whatever the Windows version
|
|
||||||
if err := addLeakFilters(engine, loopback, block); err != nil {
|
|
||||||
skipUnlessElevated(err)
|
skipUnlessElevated(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewLeakFilters(t *testing.T) {
|
func TestNewLeakFilters(t *testing.T) {
|
||||||
leaks, err := ExpandWfpBlockLeak([]string{"dns", "misconfigtun"})
|
for _, c := range []struct {
|
||||||
|
values []string
|
||||||
|
route4, route6 bool
|
||||||
|
blocked string
|
||||||
|
systemDNS bool
|
||||||
|
}{
|
||||||
|
{[]string{"dns", "misconfigtun"}, true, false, "53, 853, windnsclient, [::/0]:misconfigtun", true},
|
||||||
|
{[]string{"tcp/853", "udp/853", "misconfigtun"}, true, true, "tcp/853, udp/853", false},
|
||||||
|
{[]string{"all"}, true, true, "all", true},
|
||||||
|
{[]string{"all", "misconfigtun"}, true, true, "all", true},
|
||||||
|
{[]string{"misconfigtun"}, true, false, "[::/0]:misconfigtun", false},
|
||||||
|
{[]string{"misconfigtun"}, false, true, "0.0.0.0/0:misconfigtun", false},
|
||||||
|
{[]string{"misconfigtun"}, false, false, "misconfigtun", false},
|
||||||
|
{[]string{"tcp/10-20", "udp", "icmp"}, true, true, "tcp/10-20, udp, icmp", true},
|
||||||
|
{[]string{"tcp/54-60", "icmp", "54-60"}, true, true, "tcp/54-60, icmp, 54-60", false},
|
||||||
|
{[]string{"allexceptlan"}, true, true, "allexceptlan, 53, 853, windnsclient", true},
|
||||||
|
{[]string{"allexceptlan", "all"}, true, true, "allexceptlan, 53, 853, windnsclient, all", true},
|
||||||
|
{[]string{"misconfigtun", "allexceptlan"}, true, false, "[::/0]:misconfigtun, allexceptlan, 53, 853, windnsclient", true},
|
||||||
|
// Limited to the addresses of a CIDR.
|
||||||
|
{[]string{"0.0.0.0/0:TCP/10-20", "[::/0]:udp", "0.0.0.0/0:icmp"}, true, true, "0.0.0.0/0:tcp/10-20, [::/0]:udp, 0.0.0.0/0:icmp", true},
|
||||||
|
{[]string{"[::/0]:tcp/54-60", "[::/0]:icmp"}, true, true, "[::/0]:tcp/54-60, [::/0]:icmp", false},
|
||||||
|
{[]string{"0.0.0.0/0:windnsclient"}, true, true, "0.0.0.0/0:windnsclient", true},
|
||||||
|
{[]string{"1.1.1.0/24:53"}, true, true, "1.1.1.0/24:53", true},
|
||||||
|
{[]string{"[::/0]:all"}, true, false, "[::/0]:all", true},
|
||||||
|
{[]string{"0.0.0.0/0:allexceptlan", "[::/0]:all"}, true, true, "0.0.0.0/0:allexceptlan, 0.0.0.0/0:53, 0.0.0.0/0:853, 0.0.0.0/0:windnsclient, [::/0]:all", true},
|
||||||
|
{[]string{"0.0.0.0/0:misconfigtun"}, true, false, "", false},
|
||||||
|
{[]string{"[::/0]:misconfigtun"}, true, false, "[::/0]:misconfigtun", false},
|
||||||
|
{[]string{"[2000::/3]:misconfigtun", "1.0.0.0/8:misconfigtun"}, true, false, "[2000::/3]:misconfigtun", false},
|
||||||
|
{[]string{"misconfigtun", "[::/0]:misconfigtun"}, true, false, "[::/0]:misconfigtun", false},
|
||||||
|
{[]string{"0.0.0.0/0:misconfigtun", "[::/0]:allexceptlan"}, false, true, "0.0.0.0/0:misconfigtun, [::/0]:allexceptlan, [::/0]:53, [::/0]:853, [::/0]:windnsclient", true},
|
||||||
|
} {
|
||||||
|
leaks, err := ExpandWfpBlockLeak(c.values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
block := newLeakFilters(leaks, true, false)
|
block := newLeakFilters(leaks, c.route4, c.route6)
|
||||||
want := "udp/53, tcp/53, tcp/853, udp/853, IPv6"
|
if got := block.String(); got != c.blocked {
|
||||||
if dnsClientUsesAnyPort() {
|
t.Errorf("%v: String() = %q, want %q", c.values, got, c.blocked)
|
||||||
want = "udp/53, tcp/53, tcp/853, udp/853, windnsclient, IPv6"
|
|
||||||
}
|
}
|
||||||
if got := block.String(); got != want {
|
if got := block.systemDNS(); got != c.systemDNS {
|
||||||
t.Errorf("String() = %q, want %q", got, want)
|
t.Errorf("%v: systemDNS() = %v", c.values, got)
|
||||||
}
|
}
|
||||||
if !block.systemDNS() {
|
|
||||||
t.Error("systemDNS() = false with dns")
|
|
||||||
}
|
}
|
||||||
if block := newLeakFilters([]string{"tcp/853", "udp/853", "misconfigtun"}, true, true); block.String() != "tcp/853, udp/853" || block.systemDNS() {
|
// Without the port 53 values "allexceptlan" brings along, a resolver on
|
||||||
t.Errorf("tcp/853, udp/853: %q, systemDNS() = %v", block.String(), block.systemDNS())
|
// the local network, like the router's, stays reachable.
|
||||||
|
if (leakFilters{{name: "allexceptlan"}}).systemDNS() {
|
||||||
|
t.Error("systemDNS() = true with the local network open")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLanWithin(t *testing.T) {
|
||||||
|
prefixes := func(cidrs ...string) []netip.Prefix {
|
||||||
|
var prefixes []netip.Prefix
|
||||||
|
for _, cidr := range cidrs {
|
||||||
|
prefixes = append(prefixes, netip.MustParsePrefix(cidr))
|
||||||
|
}
|
||||||
|
return prefixes
|
||||||
|
}
|
||||||
|
for _, c := range []struct {
|
||||||
|
within, lan []netip.Prefix
|
||||||
|
}{
|
||||||
|
{nil, nil},
|
||||||
|
{prefixes("0.0.0.0/0"), prefixes("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "169.254.0.0/16", "224.0.0.0/4", "255.255.255.255/32")},
|
||||||
|
{prefixes("::/0"), prefixes("fc00::/7", "fe80::/10", "ff00::/8")},
|
||||||
|
{prefixes("1.0.0.0/8", "10.1.0.0/16"), prefixes("10.1.0.0/16")},
|
||||||
|
{prefixes("192.0.0.0/2"), prefixes("192.168.0.0/16", "224.0.0.0/4", "255.255.255.255/32")},
|
||||||
|
{prefixes("2000::/3", "fe80::/64", "fe80::/10"), prefixes("fe80::/64", "fe80::/10")},
|
||||||
|
{prefixes("8.8.8.8/32", "2001:db8::/32"), nil},
|
||||||
|
} {
|
||||||
|
if got := lanWithin(c.within...); !slices.Equal(got, c.lan) {
|
||||||
|
t.Errorf("%v: got %v, want %v", c.within, got, c.lan)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,10 +248,38 @@ func TestDNSOutsideTUN(t *testing.T) {
|
|||||||
netip.MustParseAddr("::ffff:203.0.113.54"),
|
netip.MustParseAddr("::ffff:203.0.113.54"),
|
||||||
netip.MustParseAddr("8.8.8.8"),
|
netip.MustParseAddr("8.8.8.8"),
|
||||||
netip.MustParseAddr("2001:db8::53"),
|
netip.MustParseAddr("2001:db8::53"),
|
||||||
|
// Local resolvers, reachable over loopback whatever is blocked.
|
||||||
|
netip.MustParseAddr("127.0.0.1"),
|
||||||
|
netip.MustParseAddr("::ffff:127.0.0.53"),
|
||||||
|
netip.MustParseAddr("::1"),
|
||||||
|
}
|
||||||
|
// Only to the addresses of their CIDRs, if any, and "misconfigtun" over
|
||||||
|
// an IP version without routes to the TUN blocks DNS as well.
|
||||||
|
for _, c := range []struct {
|
||||||
|
values []string
|
||||||
|
route4, route6 bool
|
||||||
|
want []string
|
||||||
|
}{
|
||||||
|
{[]string{"dns"}, true, true, []string{"8.8.8.8", "2001:db8::53"}},
|
||||||
|
{[]string{"0.0.0.0/0:53"}, true, true, []string{"8.8.8.8"}},
|
||||||
|
{[]string{"8.8.8.0/24:windnsclient", "[2001:db8::/32]:tcp/853"}, true, true, []string{"8.8.8.8"}},
|
||||||
|
{[]string{"[2001:db8::53/128]:all", "9.9.9.9/32:53"}, true, true, []string{"2001:db8::53"}},
|
||||||
|
{[]string{"misconfigtun"}, true, false, []string{"2001:db8::53"}},
|
||||||
|
{[]string{"misconfigtun"}, true, true, nil},
|
||||||
|
{[]string{"tcp/853", "udp/5353", "icmp", "10.0.0.0/8:all"}, true, true, nil},
|
||||||
|
{[]string{"[::/0]:allexceptlan"}, true, true, []string{"2001:db8::53"}},
|
||||||
|
} {
|
||||||
|
leaks, err := ExpandWfpBlockLeak(c.values)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var want []netip.Addr
|
||||||
|
for _, server := range c.want {
|
||||||
|
want = append(want, netip.MustParseAddr(server))
|
||||||
|
}
|
||||||
|
if got := dnsOutsideTUN(servers, prefixes, newLeakFilters(leaks, c.route4, c.route6)); !slices.Equal(got, want) {
|
||||||
|
t.Errorf("%v: got %v, want %v", c.values, got, want)
|
||||||
}
|
}
|
||||||
want := []netip.Addr{netip.MustParseAddr("8.8.8.8"), netip.MustParseAddr("2001:db8::53")}
|
|
||||||
if got := dnsOutsideTUN(servers, prefixes); !slices.Equal(got, want) {
|
|
||||||
t.Errorf("got %v, want %v", got, want)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ type udpConnectionHandler struct {
|
|||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
|
||||||
udpConns map[net.Destination]*udpConn
|
udpConns map[net.Destination]*udpConn
|
||||||
|
// closed is set by closeAll; a packet that arrives after it opens no flow
|
||||||
|
closed bool
|
||||||
|
|
||||||
handleConnection func(conn net.Conn, dest net.Destination)
|
handleConnection func(conn net.Conn, dest net.Destination)
|
||||||
writePacket func(data []byte, src net.Destination, dst net.Destination) error
|
writePacket func(data []byte, src net.Destination, dst net.Destination) error
|
||||||
@@ -51,6 +53,10 @@ func (u *udpConnectionHandler) HandlePacket(src net.Destination, dst net.Destina
|
|||||||
u.Lock()
|
u.Lock()
|
||||||
defer u.Unlock()
|
defer u.Unlock()
|
||||||
|
|
||||||
|
if u.closed {
|
||||||
|
data.Release()
|
||||||
|
return
|
||||||
|
}
|
||||||
conn, found = u.udpConns[src]
|
conn, found = u.udpConns[src]
|
||||||
if !found {
|
if !found {
|
||||||
conn = &udpConn{handler: u, queue: newPacketQueue(udpQueueLimit), src: src, dst: dst}
|
conn = &udpConn{handler: u, queue: newPacketQueue(udpQueueLimit), src: src, dst: dst}
|
||||||
@@ -66,6 +72,23 @@ func (u *udpConnectionHandler) HandlePacket(src net.Destination, dst net.Destina
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// closeAll ends every UDP flow and takes no new ones: the readers get EOF, so the dispatch of each flow
|
||||||
|
// returns and lets go of its outbound. Called when the stack closes; without it an inbound's UDP flows,
|
||||||
|
// and whatever carries them, outlive the instance.
|
||||||
|
func (u *udpConnectionHandler) closeAll() {
|
||||||
|
u.Lock()
|
||||||
|
u.closed = true
|
||||||
|
conns := make([]*udpConn, 0, len(u.udpConns))
|
||||||
|
for _, c := range u.udpConns {
|
||||||
|
conns = append(conns, c)
|
||||||
|
}
|
||||||
|
u.udpConns = make(map[net.Destination]*udpConn)
|
||||||
|
u.Unlock()
|
||||||
|
for _, c := range conns {
|
||||||
|
c.queue.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (u *udpConnectionHandler) connectionFinished(conn *udpConn) {
|
func (u *udpConnectionHandler) connectionFinished(conn *udpConn) {
|
||||||
u.Lock()
|
u.Lock()
|
||||||
// Close runs twice per flow; a newer conn may already own this src.
|
// Close runs twice per flow; a newer conn may already own this src.
|
||||||
|
|||||||
@@ -89,3 +89,39 @@ func TestPacketQueueDropsDrainedStorage(t *testing.T) {
|
|||||||
t.Fatalf("drained queue still holds %d slots", cap(q.items))
|
t.Fatalf("drained queue still holds %d slots", cap(q.items))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A closing stack must end its UDP flows: the dispatch reading a flow gets EOF and returns, instead of
|
||||||
|
// waiting on the queue forever and keeping its outbound alive past the instance; a packet that arrives
|
||||||
|
// afterwards opens no flow.
|
||||||
|
func TestUDPHandlerCloseAllEndsFlows(t *testing.T) {
|
||||||
|
done := make(chan struct{}, 2)
|
||||||
|
handler := newUdpConnectionHandler(func(conn net.Conn, dest net.Destination) {
|
||||||
|
b := make([]byte, 2048)
|
||||||
|
for {
|
||||||
|
if _, err := conn.Read(b); err != nil {
|
||||||
|
done <- struct{}{}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, func(data []byte, src net.Destination, dst net.Destination) error { return nil })
|
||||||
|
dst := net.UDPDestination(net.IPAddress([]byte{10, 6, 0, 2}), 53)
|
||||||
|
for _, port := range []net.Port{40000, 40001} {
|
||||||
|
src := net.UDPDestination(net.IPAddress([]byte{10, 255, 0, 2}), port)
|
||||||
|
handler.HandlePacket(src, dst, buf.FromBytes([]byte("query")))
|
||||||
|
}
|
||||||
|
handler.closeAll()
|
||||||
|
for i := 0; i < 2; i++ {
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
case <-time.After(2 * time.Second):
|
||||||
|
t.Fatalf("flow %d still running after closeAll", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
handler.HandlePacket(net.UDPDestination(net.IPAddress([]byte{10, 255, 0, 2}), 40002), dst, buf.FromBytes([]byte("late")))
|
||||||
|
handler.RLock()
|
||||||
|
n := len(handler.udpConns)
|
||||||
|
handler.RUnlock()
|
||||||
|
if n != 0 {
|
||||||
|
t.Fatalf("%d flows in the table after closeAll", n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+124
-43
@@ -1,6 +1,7 @@
|
|||||||
package tun
|
package tun
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/netip"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -8,72 +9,152 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// dnsLeaks is what "dns" in autoSystemWfpBlockLeak stands for: DNS over UDP and
|
// dnsLeaks is what "dns" in autoSystemWfpBlockLeak stands for: DNS over TCP
|
||||||
// TCP, Windows' DNS Client service, which may also use other protocols and
|
// and UDP, DNS over TLS and QUIC, and Windows' DNS Client service, which may
|
||||||
// ports, DNS over TLS, and DNS over QUIC.
|
// also use other protocols and ports.
|
||||||
var dnsLeaks = []string{"udp/53", "tcp/53", "windnsclient", "tcp/853", "udp/853"}
|
var dnsLeaks = []string{"53", "853", "windnsclient"}
|
||||||
|
|
||||||
// leakPort is a "tcp/<port>" or "udp/<port>" value of autoSystemWfpBlockLeak:
|
// leak is a value of autoSystemWfpBlockLeak: "dns", "windnsclient",
|
||||||
// connections to that port may only go through the TUN.
|
// "misconfigtun", "all", "allexceptlan", "icmp", or "tcp" or "udp", the latter
|
||||||
type leakPort struct {
|
// two with "/<port>" or "/<low>-<high>" for some ports only, such as "tcp/853"
|
||||||
tcp bool
|
// or "udp/10-20", or such ports alone for TCP and UDP, such as "53". A CIDR in
|
||||||
port uint16
|
// front limits any of them to its addresses, an IPv6 one in brackets, such as
|
||||||
|
// "1.1.1.0/24:53" or "[::/0]:all".
|
||||||
|
type leak struct {
|
||||||
|
prefix netip.Prefix // all addresses of both IP versions if not valid
|
||||||
|
name string // empty for TCP and UDP to some ports
|
||||||
|
low, high uint16 // the ports of TCP and UDP, both 0 for all
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p leakPort) String() string {
|
func (l leak) String() string {
|
||||||
if p.tcp {
|
s := l.name
|
||||||
return "tcp/" + strconv.Itoa(int(p.port))
|
if l.low != 0 {
|
||||||
|
if s != "" {
|
||||||
|
s += "/"
|
||||||
|
}
|
||||||
|
s += strconv.Itoa(int(l.low))
|
||||||
|
if l.high != l.low {
|
||||||
|
s += "-" + strconv.Itoa(int(l.high))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case !l.prefix.IsValid():
|
||||||
|
return s
|
||||||
|
case l.prefix.Addr().Is6():
|
||||||
|
return "[" + l.prefix.String() + "]:" + s
|
||||||
|
default:
|
||||||
|
return l.prefix.String() + ":" + s
|
||||||
}
|
}
|
||||||
return "udp/" + strconv.Itoa(int(p.port))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseLeakPort parses a lower case "tcp/<port>" or "udp/<port>" value.
|
// covers tells whether l includes connections of protocol, "tcp" or "udp", to
|
||||||
func parseLeakPort(value string) (leakPort, bool) {
|
// port, to at least some addresses.
|
||||||
protocol, port, ok := strings.Cut(value, "/")
|
func (l leak) covers(protocol string, port uint16) bool {
|
||||||
if !ok || protocol != "tcp" && protocol != "udp" {
|
switch l.name {
|
||||||
return leakPort{}, false
|
case "all":
|
||||||
|
return true
|
||||||
|
case "", protocol:
|
||||||
|
return l.low == 0 || l.low <= port && port <= l.high
|
||||||
}
|
}
|
||||||
n, err := strconv.ParseUint(port, 10, 16)
|
return false
|
||||||
if err != nil || n == 0 {
|
}
|
||||||
return leakPort{}, false
|
|
||||||
|
// blocksDNS tells whether l keeps the system's DNS, TCP or UDP port 53 or
|
||||||
|
// Windows' DNS Client service, inside the TUN, to at least some addresses.
|
||||||
|
func (l leak) blocksDNS() bool {
|
||||||
|
return l.name == "windnsclient" || l.covers("udp", 53) || l.covers("tcp", 53)
|
||||||
|
}
|
||||||
|
|
||||||
|
// parseLeak parses a lower case value of autoSystemWfpBlockLeak. Ports go from
|
||||||
|
// 1 to 65535, low not above high, and "tcp/1-65535" stands for all of them, as
|
||||||
|
// does "tcp".
|
||||||
|
func parseLeak(value string) (leak, bool) {
|
||||||
|
var l leak
|
||||||
|
cidr, rest, hasCIDR := strings.Cut(value, ":")
|
||||||
|
ipv6 := strings.HasPrefix(value, "[")
|
||||||
|
if ipv6 {
|
||||||
|
cidr, rest, hasCIDR = strings.Cut(value[1:], "]:")
|
||||||
}
|
}
|
||||||
return leakPort{tcp: protocol == "tcp", port: uint16(n)}, true
|
if hasCIDR {
|
||||||
|
// IPv4-mapped IPv6 ones would not match: Windows checks such
|
||||||
|
// connections as IPv4.
|
||||||
|
prefix, err := netip.ParsePrefix(cidr)
|
||||||
|
if err != nil || prefix.Addr().Is6() != ipv6 || prefix.Addr().Is4In6() {
|
||||||
|
return leak{}, false
|
||||||
|
}
|
||||||
|
l.prefix, value = prefix.Masked(), rest
|
||||||
|
}
|
||||||
|
name, ports, hasPorts := strings.Cut(value, "/")
|
||||||
|
switch name {
|
||||||
|
case "tcp", "udp":
|
||||||
|
l.name = name
|
||||||
|
if !hasPorts {
|
||||||
|
return l, true
|
||||||
|
}
|
||||||
|
case "dns", "windnsclient", "misconfigtun", "all", "allexceptlan", "icmp":
|
||||||
|
l.name = name
|
||||||
|
return l, !hasPorts
|
||||||
|
default:
|
||||||
|
if hasPorts {
|
||||||
|
return leak{}, false
|
||||||
|
}
|
||||||
|
ports = name // for TCP and UDP
|
||||||
|
}
|
||||||
|
lowText, highText, isRange := strings.Cut(ports, "-")
|
||||||
|
low, err := strconv.ParseUint(lowText, 10, 16)
|
||||||
|
if err != nil || low == 0 {
|
||||||
|
return leak{}, false
|
||||||
|
}
|
||||||
|
high := low
|
||||||
|
if isRange {
|
||||||
|
if high, err = strconv.ParseUint(highText, 10, 16); err != nil || high < low {
|
||||||
|
return leak{}, false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if l.name == "" || low != 1 || high != 65535 {
|
||||||
|
l.low, l.high = uint16(low), uint16(high)
|
||||||
|
}
|
||||||
|
return l, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExpandWfpBlockLeak checks the values of autoSystemWfpBlockLeak and returns
|
// ExpandWfpBlockLeak checks the values of autoSystemWfpBlockLeak and returns
|
||||||
// them in lower case, in order and without duplicates, with "dns" replaced by
|
// them in lower case, in order and each once, with "dns" replaced by what it
|
||||||
// what it stands for.
|
// stands for, "allexceptlan" followed by that, CIDRs masked, and ports written
|
||||||
|
// the same way, "tcp/1-65535" as "tcp" say.
|
||||||
func ExpandWfpBlockLeak(values []string) ([]string, error) {
|
func ExpandWfpBlockLeak(values []string) ([]string, error) {
|
||||||
var leaks []string
|
var expanded []string
|
||||||
add := func(leak string) {
|
add := func(l leak) {
|
||||||
if !slices.Contains(leaks, leak) {
|
if value := l.String(); !slices.Contains(expanded, value) {
|
||||||
leaks = append(leaks, leak)
|
expanded = append(expanded, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
switch value = strings.ToLower(value); value {
|
l, ok := parseLeak(strings.ToLower(value))
|
||||||
case "dns":
|
|
||||||
for _, leak := range dnsLeaks {
|
|
||||||
add(leak)
|
|
||||||
}
|
|
||||||
case "windnsclient", "misconfigtun":
|
|
||||||
add(value)
|
|
||||||
default:
|
|
||||||
port, ok := parseLeakPort(value)
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("unknown autoSystemWfpBlockLeak value: ", value)
|
return nil, errors.New("unknown autoSystemWfpBlockLeak value: ", value)
|
||||||
}
|
}
|
||||||
add(port.String())
|
if l.name != "dns" {
|
||||||
|
add(l)
|
||||||
|
}
|
||||||
|
// The local network is no way out for DNS with "allexceptlan", as a
|
||||||
|
// resolver there, like the router, would forward outside the TUN.
|
||||||
|
if l.name == "dns" || l.name == "allexceptlan" {
|
||||||
|
for _, dnsLeak := range dnsLeaks {
|
||||||
|
dns, _ := parseLeak(dnsLeak)
|
||||||
|
dns.prefix = l.prefix
|
||||||
|
add(dns)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return leaks, nil
|
}
|
||||||
|
return expanded, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlocksSystemDNS tells whether expanded autoSystemWfpBlockLeak values keep the
|
// BlocksSystemDNS tells whether expanded autoSystemWfpBlockLeak values keep the
|
||||||
// system's DNS (port 53, or Windows' DNS Client service) inside the TUN, which
|
// system's DNS (TCP or UDP port 53, or Windows' DNS Client service) inside the
|
||||||
// then needs DNS servers of its own.
|
// TUN, to at least some addresses, which then needs DNS servers of its own.
|
||||||
func BlocksSystemDNS(leaks []string) bool {
|
func BlocksSystemDNS(leaks []string) bool {
|
||||||
return slices.ContainsFunc(leaks, func(leak string) bool {
|
return slices.ContainsFunc(leaks, func(value string) bool {
|
||||||
return leak == "udp/53" || leak == "tcp/53" || leak == "windnsclient"
|
l, _ := parseLeak(value)
|
||||||
|
return l.blocksDNS()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,39 @@ func TestExpandWfpBlockLeak(t *testing.T) {
|
|||||||
systemDNS bool
|
systemDNS bool
|
||||||
}{
|
}{
|
||||||
{nil, nil, false},
|
{nil, nil, false},
|
||||||
{[]string{"dns"}, []string{"udp/53", "tcp/53", "windnsclient", "tcp/853", "udp/853"}, true},
|
{[]string{"dns"}, []string{"53", "853", "windnsclient"}, true},
|
||||||
{[]string{"DNS", "MisconfigTUN"}, []string{"udp/53", "tcp/53", "windnsclient", "tcp/853", "udp/853", "misconfigtun"}, true},
|
{[]string{"DNS", "MisconfigTUN"}, []string{"53", "853", "windnsclient", "misconfigtun"}, true},
|
||||||
{[]string{"tcp/853", "dns", "TCP/0853"}, []string{"tcp/853", "udp/53", "tcp/53", "windnsclient", "udp/853"}, true},
|
{[]string{"tcp/853", "dns", "TCP/0853"}, []string{"tcp/853", "53", "853", "windnsclient"}, true},
|
||||||
{[]string{"tcp/853", "udp/853", "misconfigtun"}, []string{"tcp/853", "udp/853", "misconfigtun"}, false},
|
{[]string{"tcp/853", "udp/853", "misconfigtun"}, []string{"tcp/853", "udp/853", "misconfigtun"}, false},
|
||||||
{[]string{"udp/65535", "tcp/1"}, []string{"udp/65535", "tcp/1"}, false},
|
{[]string{"udp/65535", "tcp/1"}, []string{"udp/65535", "tcp/1"}, false},
|
||||||
{[]string{"tcp/53"}, []string{"tcp/53"}, true},
|
{[]string{"tcp/53"}, []string{"tcp/53"}, true},
|
||||||
{[]string{"windnsclient"}, []string{"windnsclient"}, true},
|
{[]string{"windnsclient"}, []string{"windnsclient"}, true},
|
||||||
|
{[]string{"ALL"}, []string{"all"}, true},
|
||||||
|
{[]string{"tcp", "TCP", "UDP"}, []string{"tcp", "udp"}, true},
|
||||||
|
{[]string{"tcp/1-65535", "udp/1-65535"}, []string{"tcp", "udp"}, true},
|
||||||
|
{[]string{"udp/10-20", "udp/53-53", "tcp/50-60"}, []string{"udp/10-20", "udp/53", "tcp/50-60"}, true},
|
||||||
|
{[]string{"tcp/54-60", "udp/1-52"}, []string{"tcp/54-60", "udp/1-52"}, false},
|
||||||
|
{[]string{"ICMP", "icmp"}, []string{"icmp"}, false},
|
||||||
|
{[]string{"AllExceptLAN"}, []string{"allexceptlan", "53", "853", "windnsclient"}, true},
|
||||||
|
{[]string{"dns", "allexceptlan", "all"}, []string{"53", "853", "windnsclient", "allexceptlan", "all"}, true},
|
||||||
|
// Ports alone, for TCP and UDP.
|
||||||
|
{[]string{"53"}, []string{"53"}, true},
|
||||||
|
{[]string{"10-20", "0053", "853-853", "53"}, []string{"10-20", "53", "853"}, true},
|
||||||
|
{[]string{"54-60", "1-52", "65535"}, []string{"54-60", "1-52", "65535"}, false},
|
||||||
|
{[]string{"1-65535"}, []string{"1-65535"}, true},
|
||||||
|
{[]string{"853", "tcp/853"}, []string{"853", "tcp/853"}, false},
|
||||||
|
// Limited to the addresses of a CIDR.
|
||||||
|
{[]string{"1.1.1.0/24:53"}, []string{"1.1.1.0/24:53"}, true},
|
||||||
|
{[]string{"1.1.1.1/24:TCP/853", "[2001:DB8::1/32]:udp/10-20", "[::/0]:ICMP"}, []string{"1.1.1.0/24:tcp/853", "[2001:db8::/32]:udp/10-20", "[::/0]:icmp"}, false},
|
||||||
|
{[]string{"0.0.0.0/0:dns"}, []string{"0.0.0.0/0:53", "0.0.0.0/0:853", "0.0.0.0/0:windnsclient"}, true},
|
||||||
|
{[]string{"[::/0]:all"}, []string{"[::/0]:all"}, true},
|
||||||
|
{[]string{"10.0.0.1/32:windnsclient"}, []string{"10.0.0.1/32:windnsclient"}, true},
|
||||||
|
{[]string{"[2000::/3]:misconfigtun"}, []string{"[2000::/3]:misconfigtun"}, false},
|
||||||
|
{[]string{"1.1.1.0/24:tcp/1-65535", "1.1.1.0/24:udp/53-53"}, []string{"1.1.1.0/24:tcp", "1.1.1.0/24:udp/53"}, true},
|
||||||
|
{[]string{"1.1.1.0/24:20-30", "[::/0]:10-10"}, []string{"1.1.1.0/24:20-30", "[::/0]:10"}, false},
|
||||||
|
{[]string{"0.0.0.0/0:allexceptlan", "[::/0]:all"}, []string{"0.0.0.0/0:allexceptlan", "0.0.0.0/0:53", "0.0.0.0/0:853", "0.0.0.0/0:windnsclient", "[::/0]:all"}, true},
|
||||||
|
{[]string{"1.1.1.1/32:53", "1.1.1.1/32:0053", "1.1.1.1/24:53", "1.1.1.0/24:53", "53"}, []string{"1.1.1.1/32:53", "1.1.1.0/24:53", "53"}, true},
|
||||||
|
{[]string{"1.2.3.4/0:icmp", "[::1/0]:icmp", "icmp"}, []string{"0.0.0.0/0:icmp", "[::/0]:icmp", "icmp"}, false},
|
||||||
} {
|
} {
|
||||||
leaks, err := ExpandWfpBlockLeak(c.values)
|
leaks, err := ExpandWfpBlockLeak(c.values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -32,9 +58,65 @@ func TestExpandWfpBlockLeak(t *testing.T) {
|
|||||||
t.Errorf("%v: BlocksSystemDNS() = %v", c.values, got)
|
t.Errorf("%v: BlocksSystemDNS() = %v", c.values, got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, value := range []string{"", "ip", "tcp", "tcp/", "tcp/0", "udp/65536", "tcp/-1", "tcp/+53", "tcp/53/1", "udp/abc", "icmp/1", "tcp:53", " dns"} {
|
for _, value := range []string{
|
||||||
|
"", "ip", "tcp/", "udp/65536", "tcp/-1", "tcp/+53", "tcp/53/1", "udp/abc", "icmp/0", "icmp/8", "tcp:53", " dns",
|
||||||
|
"tcp/0-10", "tcp/20-10", "tcp/5-", "tcp/-5", "tcp/1-2-3", "tcp/1-65536", "udp/ 53", "all/0", "dns/53", "windnsclient/53",
|
||||||
|
"tcp/0", "udp/0", "tcp/00", "udp/0-0", "udp/65535-1",
|
||||||
|
// Ports alone.
|
||||||
|
"0", "00", "65536", "0-10", "20-10", "5-", "-5", "-", "1-2-3", "1-65536", "+53", " 53", "53 ", "53/1", "53/tcp", "0x35",
|
||||||
|
// IP versions are CIDRs now.
|
||||||
|
"ipv4", "ipv6", "ipv4:udp", "ipv6:all", "ipv4:dns", "tcpv4", "udpv6", "icmpv4", "tcp4", "dnsv4",
|
||||||
|
// CIDRs, IPv6 ones in brackets, but neither single addresses nor
|
||||||
|
// CIDRs on their own.
|
||||||
|
"1.1.1.0/24", "[2001:db8::/32]", "1.1.1.0/24:", "[::/0]:", ":udp", "[]:udp", "[:udp", "[::/0]udp",
|
||||||
|
"1.1.1.1:53", "[::1]:53", "[2001:db8::1]:tcp/53", "2001:db8::/32:53", "::/0:all", "[1.1.1.0/24]:53",
|
||||||
|
"[2001:db8::]/32:53", "1.1.1.0/33:53", "[::/129]:53", "1.1.1.0/24:1.1.1.0/24:53", "[::/0]:[::/0]:53",
|
||||||
|
"1.1.1.0/24 :53", "1.1.1.0/24: 53", " 1.1.1.0/24:53", "1.1.1.0/24::53", "[fe80::%1/64]:53", "geoip:cn:53",
|
||||||
|
"1.1.1.0/24:udp/0", "[::/0]:icmp/8", "1.1.1.0/24:dns/53", "[::/0]:20-10", "1.1.1.0/24:ipv4:53", "1.1.1.0/24:geoip",
|
||||||
|
"[::ffff:1.1.1.0/120]:53", "[::ffff:0:0/96]:all",
|
||||||
|
} {
|
||||||
if _, err := ExpandWfpBlockLeak([]string{value}); err == nil {
|
if _, err := ExpandWfpBlockLeak([]string{value}); err == nil {
|
||||||
t.Errorf("%q was accepted", value)
|
t.Errorf("%q was accepted", value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLeakCovers(t *testing.T) {
|
||||||
|
for _, c := range []struct {
|
||||||
|
value string
|
||||||
|
protocol string
|
||||||
|
port uint16
|
||||||
|
covers bool
|
||||||
|
}{
|
||||||
|
{"tcp", "tcp", 1, true},
|
||||||
|
{"tcp", "udp", 53, false},
|
||||||
|
{"udp/53", "udp", 53, true},
|
||||||
|
{"udp/53", "udp", 54, false},
|
||||||
|
{"tcp/10-20", "tcp", 10, true},
|
||||||
|
{"tcp/10-20", "tcp", 20, true},
|
||||||
|
{"tcp/10-20", "tcp", 21, false},
|
||||||
|
{"tcp/10-20", "tcp", 9, false},
|
||||||
|
{"53", "udp", 53, true},
|
||||||
|
{"53", "tcp", 53, true},
|
||||||
|
{"10-20", "tcp", 15, true},
|
||||||
|
{"10-20", "udp", 21, false},
|
||||||
|
{"1.1.1.0/24:udp/53", "udp", 53, true},
|
||||||
|
{"[::/0]:tcp", "tcp", 443, true},
|
||||||
|
{"[2001:db8::/32]:53", "tcp", 53, true},
|
||||||
|
{"0.0.0.0/0:icmp", "udp", 53, false},
|
||||||
|
{"all", "udp", 53, true},
|
||||||
|
{"1.1.1.1/32:all", "tcp", 1, true},
|
||||||
|
{"allexceptlan", "udp", 53, false},
|
||||||
|
{"misconfigtun", "udp", 53, false},
|
||||||
|
{"windnsclient", "udp", 53, false},
|
||||||
|
} {
|
||||||
|
l, ok := parseLeak(c.value)
|
||||||
|
if !ok {
|
||||||
|
t.Errorf("%q was not parsed", c.value)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if got := l.covers(c.protocol, c.port); got != c.covers {
|
||||||
|
t.Errorf("%q covers %s/%d = %v", c.value, c.protocol, c.port, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ func init() {
|
|||||||
type Handler struct {
|
type Handler struct {
|
||||||
server *protocol.ServerSpec
|
server *protocol.ServerSpec
|
||||||
policyManager policy.Manager
|
policyManager policy.Manager
|
||||||
cone bool
|
|
||||||
encryption *encryption.ClientInstance
|
encryption *encryption.ClientInstance
|
||||||
reverse *Reverse
|
reverse *Reverse
|
||||||
|
|
||||||
@@ -78,7 +77,6 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
|
|||||||
handler := &Handler{
|
handler := &Handler{
|
||||||
server: server,
|
server: server,
|
||||||
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
||||||
cone: ctx.Value("cone").(bool),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
a := handler.server.User.Account.(*vless.MemoryAccount)
|
a := handler.server.User.Account.(*vless.MemoryAccount)
|
||||||
@@ -300,7 +298,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||||||
clientReader := link.Reader // .(*pipe.Reader)
|
clientReader := link.Reader // .(*pipe.Reader)
|
||||||
clientWriter := link.Writer // .(*pipe.Writer)
|
clientWriter := link.Writer // .(*pipe.Writer)
|
||||||
trafficState := proxy.NewTrafficState(account.ID.Bytes())
|
trafficState := proxy.NewTrafficState(account.ID.Bytes())
|
||||||
if request.Command == protocol.RequestCommandUDP && (requestAddons.Flow == vless.XRV || (h.cone && request.Port != 53 && request.Port != 443)) {
|
if request.Command == protocol.RequestCommandUDP && (requestAddons.Flow == vless.XRV || (request.Port != 53 && request.Port != 443)) {
|
||||||
request.Command = protocol.RequestCommandMux
|
request.Command = protocol.RequestCommandMux
|
||||||
request.Address = net.DomainAddress("v1.mux.cool")
|
request.Address = net.DomainAddress("v1.mux.cool")
|
||||||
request.Port = net.Port(666)
|
request.Port = net.Port(666)
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/common/session"
|
"github.com/xtls/xray-core/common/session"
|
||||||
"github.com/xtls/xray-core/common/signal"
|
|
||||||
"github.com/xtls/xray-core/common/task"
|
|
||||||
"github.com/xtls/xray-core/common/uuid"
|
"github.com/xtls/xray-core/common/uuid"
|
||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
feature_inbound "github.com/xtls/xray-core/features/inbound"
|
feature_inbound "github.com/xtls/xray-core/features/inbound"
|
||||||
@@ -23,6 +21,7 @@ import (
|
|||||||
"github.com/xtls/xray-core/features/routing"
|
"github.com/xtls/xray-core/features/routing"
|
||||||
"github.com/xtls/xray-core/proxy/vmess"
|
"github.com/xtls/xray-core/proxy/vmess"
|
||||||
"github.com/xtls/xray-core/proxy/vmess/encoding"
|
"github.com/xtls/xray-core/proxy/vmess/encoding"
|
||||||
|
"github.com/xtls/xray-core/transport"
|
||||||
"github.com/xtls/xray-core/transport/internet/stat"
|
"github.com/xtls/xray-core/transport/internet/stat"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -185,44 +184,6 @@ func (h *Handler) RemoveUser(ctx context.Context, email string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func transferResponse(timer signal.ActivityUpdater, session *encoding.ServerSession, request *protocol.RequestHeader, response *protocol.ResponseHeader, input buf.Reader, output *buf.BufferedWriter) error {
|
|
||||||
session.EncodeResponseHeader(response, output)
|
|
||||||
|
|
||||||
bodyWriter, err := session.EncodeResponseBody(request, output)
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("failed to start decoding response").Base(err)
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// Optimize for small response packet
|
|
||||||
data, err := input.ReadMultiBuffer()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := bodyWriter.WriteMultiBuffer(data); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := output.SetBuffered(false); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := buf.Copy(input, bodyWriter, buf.UpdateActivity(timer)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
account := request.User.Account.(*vmess.MemoryAccount)
|
|
||||||
|
|
||||||
if request.Option.Has(protocol.RequestOptionChunkStream) && !account.NoTerminationSignal {
|
|
||||||
if err := bodyWriter.WriteMultiBuffer(buf.MultiBuffer{}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process implements proxy.Inbound.Process().
|
// Process implements proxy.Inbound.Process().
|
||||||
func (h *Handler) Process(ctx context.Context, network net.Network, connection stat.Connection, dispatcher routing.Dispatcher) error {
|
func (h *Handler) Process(ctx context.Context, network net.Network, connection stat.Connection, dispatcher routing.Dispatcher) error {
|
||||||
sessionPolicy := h.policyManager.ForLevel(0)
|
sessionPolicy := h.policyManager.ForLevel(0)
|
||||||
@@ -273,49 +234,29 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||||||
inbound.CanSpliceCopy = 3
|
inbound.CanSpliceCopy = 3
|
||||||
inbound.User = request.User
|
inbound.User = request.User
|
||||||
|
|
||||||
sessionPolicy = h.policyManager.ForLevel(request.User.Level)
|
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
|
|
||||||
|
|
||||||
ctx = policy.ContextWithBufferPolicy(ctx, sessionPolicy.Buffer)
|
|
||||||
link, err := dispatcher.Dispatch(ctx, request.Destination())
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("failed to dispatch request to ", request.Destination()).Base(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
requestDone := func() error {
|
|
||||||
defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly)
|
|
||||||
|
|
||||||
bodyReader, err := svrSession.DecodeRequestBody(request, reader)
|
bodyReader, err := svrSession.DecodeRequestBody(request, reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("failed to start decoding").Base(err)
|
return errors.New("failed to start decoding").Base(err)
|
||||||
}
|
}
|
||||||
if err := buf.Copy(bodyReader, link.Writer, buf.UpdateActivity(timer)); err != nil {
|
|
||||||
return errors.New("failed to transfer request").Base(err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
responseDone := func() error {
|
|
||||||
defer timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly)
|
|
||||||
|
|
||||||
writer := buf.NewBufferedWriter(buf.NewWriter(connection))
|
writer := buf.NewBufferedWriter(buf.NewWriter(connection))
|
||||||
defer writer.Flush()
|
|
||||||
|
|
||||||
response := &protocol.ResponseHeader{
|
response := &protocol.ResponseHeader{
|
||||||
Command: h.generateCommand(ctx, request),
|
Command: h.generateCommand(ctx, request),
|
||||||
}
|
}
|
||||||
return transferResponse(timer, svrSession, request, response, link.Reader, writer)
|
svrSession.EncodeResponseHeader(response, writer)
|
||||||
|
bodyWriter, err := svrSession.EncodeResponseBody(request, writer)
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("failed to start decoding response").Base(err)
|
||||||
}
|
}
|
||||||
|
writer.SetFlushNext()
|
||||||
|
|
||||||
requestDonePost := task.OnSuccess(requestDone, task.Close(link.Writer))
|
if err := dispatcher.DispatchLink(ctx, request.Destination(), &transport.Link{
|
||||||
if err := task.Run(ctx, requestDonePost, responseDone); err != nil {
|
Reader: bodyReader,
|
||||||
common.Interrupt(link.Reader)
|
Writer: bodyWriter,
|
||||||
common.Interrupt(link.Writer)
|
},
|
||||||
return errors.New("connection ends").Base(err)
|
); err != nil {
|
||||||
|
return errors.New("failed to dispatch request").Base(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import (
|
|||||||
type Handler struct {
|
type Handler struct {
|
||||||
server *protocol.ServerSpec
|
server *protocol.ServerSpec
|
||||||
policyManager policy.Manager
|
policyManager policy.Manager
|
||||||
cone bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new VMess outbound handler.
|
// New creates a new VMess outbound handler.
|
||||||
@@ -49,7 +48,6 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
|
|||||||
handler := &Handler{
|
handler := &Handler{
|
||||||
server: server,
|
server: server,
|
||||||
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
||||||
cone: ctx.Value("cone").(bool),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return handler, nil
|
return handler, nil
|
||||||
@@ -143,7 +141,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||||||
}
|
}
|
||||||
}, sessionPolicy.Timeouts.ConnectionIdle)
|
}, sessionPolicy.Timeouts.ConnectionIdle)
|
||||||
|
|
||||||
if request.Command == protocol.RequestCommandUDP && h.cone && request.Port != 53 && request.Port != 443 {
|
if request.Command == protocol.RequestCommandUDP && request.Port != 53 && request.Port != 443 {
|
||||||
request.Command = protocol.RequestCommandMux
|
request.Command = protocol.RequestCommandMux
|
||||||
request.Address = net.DomainAddress("v1.mux.cool")
|
request.Address = net.DomainAddress("v1.mux.cool")
|
||||||
request.Port = net.Port(666)
|
request.Port = net.Port(666)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
|
|
||||||
type bind struct {
|
type bind struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
resolveFunc func(host string) (net.IP, error)
|
resolveFunc func(ctx context.Context, host string) (net.IP, error)
|
||||||
listenFunc func(ctx context.Context) (net.PacketConn, error)
|
listenFunc func(ctx context.Context) (net.PacketConn, error)
|
||||||
downFunc func() error
|
downFunc func() error
|
||||||
reserved []byte
|
reserved []byte
|
||||||
@@ -143,7 +143,11 @@ func (b *bind) ParseEndpoint(s string) (conn.Endpoint, error) {
|
|||||||
if port < 0 || port > 65535 {
|
if port < 0 || port > 65535 {
|
||||||
return nil, errors.New("invalid port " + sport)
|
return nil, errors.New("invalid port " + sport)
|
||||||
}
|
}
|
||||||
ip, err := b.resolveFunc(host)
|
// up sets the connection's context right before it hands over the endpoint
|
||||||
|
b.mu.Lock()
|
||||||
|
ctx := b.ctx
|
||||||
|
b.mu.Unlock()
|
||||||
|
ip, err := b.resolveFunc(ctx, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -323,12 +323,12 @@ func (h *Handler) up(ctx context.Context) error {
|
|||||||
return h.dev.Up()
|
return h.dev.Up()
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeResolveLocal(d dns.Client, streamSettings *internet.MemoryStreamConfig) func(host string) (net.IP, error) {
|
func MakeResolveLocal(d dns.Client, streamSettings *internet.MemoryStreamConfig) func(ctx context.Context, host string) (net.IP, error) {
|
||||||
return func(host string) (net.IP, error) {
|
return func(ctx context.Context, host string) (net.IP, error) {
|
||||||
if ip := net.ParseIP(host); ip != nil {
|
if ip := net.ParseIP(host); ip != nil {
|
||||||
return ip, nil
|
return ip, nil
|
||||||
}
|
}
|
||||||
ips, _, err := d.LookupIP(host, dns.IPOption{IPv4Enable: true, IPv6Enable: true})
|
ips, err := lookupIPContext(ctx, d, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -368,6 +368,27 @@ func MakeResolveLocal(d dns.Client, streamSettings *internet.MemoryStreamConfig)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func lookupIPContext(ctx context.Context, d dns.Client, host string) ([]net.IP, error) {
|
||||||
|
if err := ctx.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
type result struct {
|
||||||
|
ips []net.IP
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
done := make(chan result, 1)
|
||||||
|
go func() {
|
||||||
|
ips, _, err := d.LookupIP(host, dns.IPOption{IPv4Enable: true, IPv6Enable: true})
|
||||||
|
done <- result{ips, err}
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case r := <-done:
|
||||||
|
return r.ips, r.err
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil, ctx.Err()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type UDPConnClient struct {
|
type UDPConnClient struct {
|
||||||
net.PacketConn
|
net.PacketConn
|
||||||
Dest *net.UDPAddr
|
Dest *net.UDPAddr
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ func TestCommanderListenConfigurationItem(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
Tag: "default-outbound",
|
Tag: "default-outbound",
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}}}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}}}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ func TestCommanderRemoveHandler(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
Tag: "default-outbound",
|
Tag: "default-outbound",
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}}}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}}}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -262,7 +262,7 @@ func TestCommanderListHandlers(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Tag: "default-outbound",
|
Tag: "default-outbound",
|
||||||
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{}),
|
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{}),
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}}}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}}}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -390,7 +390,7 @@ func TestCommanderAddRemoveUser(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -579,7 +579,7 @@ func TestCommanderStats(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build coverage
|
//go:build coverage
|
||||||
// +build coverage
|
|
||||||
|
|
||||||
package scenarios
|
package scenarios
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build !coverage
|
//go:build !coverage
|
||||||
// +build !coverage
|
|
||||||
|
|
||||||
package scenarios
|
package scenarios
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/serial"
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
"github.com/xtls/xray-core/proxy/blackhole"
|
|
||||||
"github.com/xtls/xray-core/proxy/freedom"
|
"github.com/xtls/xray-core/proxy/freedom"
|
||||||
"github.com/xtls/xray-core/proxy/socks"
|
"github.com/xtls/xray-core/proxy/socks"
|
||||||
"github.com/xtls/xray-core/testing/servers/tcp"
|
"github.com/xtls/xray-core/testing/servers/tcp"
|
||||||
@@ -78,7 +77,7 @@ func TestResolveIP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&blackhole.Config{}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Block, Delay: &freedom.Range{}}}}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Tag: "direct",
|
Tag: "direct",
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func TestDokodemoTCP(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -163,7 +163,7 @@ func TestDokodemoUDP(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/serial"
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/common/uuid"
|
"github.com/xtls/xray-core/common/uuid"
|
||||||
core "github.com/xtls/xray-core/core"
|
core "github.com/xtls/xray-core/core"
|
||||||
"github.com/xtls/xray-core/proxy/blackhole"
|
|
||||||
"github.com/xtls/xray-core/proxy/dokodemo"
|
"github.com/xtls/xray-core/proxy/dokodemo"
|
||||||
"github.com/xtls/xray-core/proxy/freedom"
|
"github.com/xtls/xray-core/proxy/freedom"
|
||||||
v2http "github.com/xtls/xray-core/proxy/http"
|
v2http "github.com/xtls/xray-core/proxy/http"
|
||||||
@@ -62,7 +61,7 @@ func TestPassiveConnection(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -123,7 +122,7 @@ func TestDialerProxy(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -152,7 +151,7 @@ func TestDialerProxy(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -254,7 +253,7 @@ func TestDialerProxyOverKCP(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -283,7 +282,7 @@ func TestDialerProxyOverKCP(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
|
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
|
||||||
StreamSettings: &internet.StreamConfig{
|
StreamSettings: &internet.StreamConfig{
|
||||||
@@ -402,11 +401,11 @@ func TestBlackhole(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
Tag: "direct",
|
Tag: "direct",
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}}}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}}}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Tag: "blocked",
|
Tag: "blocked",
|
||||||
ProxySettings: serial.ToTypedMessage(&blackhole.Config{}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Block, Delay: &freedom.Range{}}}}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
@@ -517,7 +516,7 @@ func TestUDPConnection(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -582,7 +581,7 @@ func TestDomainSniffing(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Tag: "direct",
|
Tag: "direct",
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}}}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}}}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
@@ -669,7 +668,7 @@ func TestDialXray(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func TestHttpConformance(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -113,7 +113,7 @@ func TestHttpError(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -163,7 +163,7 @@ func TestHTTPConnectMethod(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -245,7 +245,7 @@ func TestHttpPost(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -317,7 +317,7 @@ func TestHttpBasicAuth(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -405,7 +405,7 @@ func TestHTTPOutboundServerFirst(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -499,7 +499,7 @@ func masqueServerConfig(serverPort net.Port, certificate *tls.Certificate, h2 bo
|
|||||||
Port: uint32(dest.Port),
|
Port: uint32(dest.Port),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func TestMetrics(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
Tag: "default-outbound",
|
Tag: "default-outbound",
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}}}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}}}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ func TestVMessClosing(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -193,7 +193,7 @@ func TestZeroBuffer(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/serial"
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/common/uuid"
|
"github.com/xtls/xray-core/common/uuid"
|
||||||
core "github.com/xtls/xray-core/core"
|
core "github.com/xtls/xray-core/core"
|
||||||
"github.com/xtls/xray-core/proxy/blackhole"
|
|
||||||
"github.com/xtls/xray-core/proxy/dokodemo"
|
"github.com/xtls/xray-core/proxy/dokodemo"
|
||||||
"github.com/xtls/xray-core/proxy/freedom"
|
"github.com/xtls/xray-core/proxy/freedom"
|
||||||
"github.com/xtls/xray-core/proxy/vmess"
|
"github.com/xtls/xray-core/proxy/vmess"
|
||||||
@@ -100,7 +99,7 @@ func TestReverseProxy(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&blackhole.Config{}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Block, Delay: &freedom.Range{}}}}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -151,7 +150,7 @@ func TestReverseProxy(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
Tag: "freedom",
|
Tag: "freedom",
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}}}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}}}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Tag: "reverse",
|
Tag: "reverse",
|
||||||
@@ -275,7 +274,7 @@ func TestReverseProxyLongRunning(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&blackhole.Config{}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Block, Delay: &freedom.Range{}}}}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -340,7 +339,7 @@ func TestReverseProxyLongRunning(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
Tag: "freedom",
|
Tag: "freedom",
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}}}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}}}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Tag: "reverse",
|
Tag: "reverse",
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func testShadowsocks2022Tcp(t *testing.T, method string, password string) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -176,7 +176,7 @@ func testShadowsocks2022Udp(t *testing.T, method string, password string) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user