Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
e94b31c
Implement fully functional auto redirect for Android
nekohasekai Sep 1, 2026
7fcc863
Fix lint errors
nekohasekai Sep 1, 2026
33f5bb5
Add NEON checksum for arm64
nekohasekai Sep 7, 2026
f513215
Keep the forward packet network header as a byte slice
nekohasekai Sep 7, 2026
8f3b714
Drop IPv6 packets carrying extension headers from the forward dispatcher
nekohasekai Sep 7, 2026
aea036a
Raise the utun receive buffer and derive the pending packet limit fro…
nekohasekai Sep 7, 2026
11691fa
Add go stack
nekohasekai Sep 7, 2026
143e23d
Fix go stack
nekohasekai Sep 14, 2026
00116b8
Mark Android bypass routes as static to keep them out of NetworkStack
nekohasekai Sep 15, 2026
92529ee
Rework go conn concurrency
nekohasekai Sep 15, 2026
616db1c
Add userspace API and improve qdisc for stack
nekohasekai Sep 15, 2026
2cacccb
Fix iptables DNS hijack skipped by input connmark
nekohasekai Sep 17, 2026
d94ecd6
Refactor go stack memory
nekohasekai Sep 17, 2026
44c4e5c
Fix Android VPNService kernel bypass
nekohasekai Sep 19, 2026
e8dfbfc
Exit go stack engine on unrecoverable read errors
nekohasekai Sep 19, 2026
e02d80e
Add ICMP error builder and IP transport protocol helper
nekohasekai Sep 22, 2026
27bc4fa
Fix auto-redirect interfering with bridge
nekohasekai Sep 24, 2026
2005a26
Add per-destination outbound queues to memory tun
nekohasekai Sep 25, 2026
1ab5dcc
Fix zero UDP checksum in checksum completion
nekohasekai Sep 28, 2026
5490f40
Avoid allocations in checksum paths
nekohasekai Sep 28, 2026
5f06bf9
Optimize header and NAT checksums
nekohasekai Sep 28, 2026
6d73652
Fix packet splice reads on darwin
nekohasekai Sep 29, 2026
f0eaee5
Fix protocol input validation
nekohasekai Sep 29, 2026
c6a3d9b
Add Options.AutoRedirectOutputMarkOrDefault
nekohasekai Oct 2, 2026
0396173
Rework forward NAT with UDP mapping and fragment support
nekohasekai Oct 6, 2026
4e1d58e
Batch loopback hairpin writes in go stack
nekohasekai Oct 13, 2026
2ee5c13
Add blocking inbound write to memory tun
nekohasekai Oct 18, 2026
e0fddf9
Judge flows without blocking packet processing
nekohasekai Oct 18, 2026
fbb935c
Fix redirect port reject for TPROXY connections
nekohasekai Oct 19, 2026
7207970
Fix packets dropped after closing forward flows
nekohasekai Oct 19, 2026
c791b11
Add routed port support
nekohasekai Oct 28, 2026
aad70fc
Fix go stack UDP replies sharing a single IPv4 ID
nekohasekai Nov 8, 2026
3ef6193
Fix auto redirect capturing flows to local addresses with iptables
nekohasekai Nov 7, 2026
fa3644b
Fix auto redirect not routing replies of tun flows back into tun
nekohasekai Nov 7, 2026
795c059
Fix redirected connections hanging after auto-redirect close
nekohasekai Nov 8, 2026
a0014b4
Fix go stack resetting connections on tun write ENOBUFS
nekohasekai Nov 9, 2026
17e8de1
Fix Android kernel bypass NAT skipped after vendor mark rewrite
nekohasekai Nov 14, 2026
2d0ad11
Fix auto-redirect overwriting marks of other programs
nekohasekai Nov 14, 2026
cf12c56
Fix auto-redirect reject on Linux before 5.9
nekohasekai Nov 3, 2026
395563c
Fix strict route rejecting own ICMPv6 with auto-redirect
nekohasekai Nov 14, 2026
6515f57
Fall back to iptables when nftables lacks inet nat
nekohasekai Nov 14, 2026
e678f04
Fix auto-redirect failing without nft_fib or nft_queue modules
nekohasekai Nov 14, 2026
506ea00
Fix uid rules silently ignored on Linux before 4.10
nekohasekai Nov 14, 2026
03010f0
Fix auto-redirect not capturing traffic marked by other programs
nekohasekai Nov 16, 2026
e157fc5
Fix auto-redirect routing replies of tun flows out directly
nekohasekai Nov 16, 2026
4d8313a
Fix auto-redirect not hijacking DNS from link-local sources
nekohasekai Nov 17, 2026
ddd4a9a
Fix splice scratch vectors pointing into unmapped slabs
nekohasekai Nov 19, 2026
b790aed
Add native socket poller, Ethernet framing, and virtio offload to mem…
nekohasekai Nov 22, 2026
766f99e
Apply BufferProfile to engine, ring, and NAT capacities
nekohasekai Nov 23, 2026
466c614
Fix system stack UDP writer ignoring headroom of downstream buffers
nekohasekai Nov 24, 2026
a00043a
Fix go stack publishing UDP tracker before attaching flow
nekohasekai Nov 24, 2026
ba1e075
Fix go stack reassembling fragments of forwarded flows
nekohasekai Nov 24, 2026
cbad00e
Fix go stack keeping references into released read and arena buffers
nekohasekai Nov 24, 2026
23346e0
Fix go stack engine sleeping on recoverable read errors
nekohasekai Nov 24, 2026
e466484
Fix go stack resetting connections on tun write ENOMEM
nekohasekai Nov 24, 2026
ae71e9c
Fix auto-redirect marks clashing with other programs
nekohasekai Nov 24, 2026
9674021
Fix iptables auto-redirect keeping foreign mark bits on Linux
nekohasekai Nov 24, 2026
6fc3a55
Fix auto-redirect DNS hijack loop and link-local DNS redirect
nekohasekai Nov 24, 2026
49ae692
Fix strict_route rejecting local traffic of the disabled family
nekohasekai Nov 24, 2026
e44e451
Fix ICMP forwarder answering pings it cannot forward
nekohasekai Nov 25, 2026
fcd6b5d
Fix auto-redirect resetting bypassed TCP connections picked up mid-st…
nekohasekai Nov 25, 2026
3bba2a0
Refresh UDP NAT sessions on replies
nekohasekai Nov 25, 2026
9e5ad41
Fix iptables strict route rejecting the disabled family with port unr…
nekohasekai Nov 25, 2026
d24de35
Fix keepalive test tripping Linux out-of-window ACK rate limit
polaris-arch Nov 7, 2026
f6169f2
Fix Windows packet mapping test blocked by inbound firewall
nekohasekai Nov 25, 2026
1a13df1
Fix darwin packet tests assuming IPv6 fragment ordering and default r…
nekohasekai Nov 25, 2026
3768c12
Test that LinkEndpointFilter.Attach forwards a nil dispatcher
arpitjain099 Nov 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 30 additions & 77 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,28 @@ on:
- '**.md'
- '.github/**'
- '!.github/workflows/debug.yml'
- '!.github/workflows/test.yml'
pull_request:
branches:
- main
- dev

jobs:
build:
name: Linux
runs-on: ubuntu-latest
test:
name: ${{ matrix.os }} (Go ${{ matrix.go }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
go: ['1.25.x', '1.26.x', stable]
include:
- os: windows-latest
go: stable
- os: macos-latest
go: stable
env:
GOTOOLCHAIN: local
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -26,81 +39,21 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ^1.25.0
- name: Build
go-version: ${{ matrix.go }}
- name: Install network test tools
if: runner.os == 'Linux'
run: |
make test
go test -c -o ping_test ./ping
sudo ./ping_test -test.v
build_go124:
name: Linux (Go 1.24)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ~1.24
continue-on-error: true
- name: Build
run: |
make test
go test -c -o ping_test ./ping
sudo ./ping_test -test.v
build_go123:
name: Linux (Go 1.23)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ~1.23
continue-on-error: true
- name: Build
sudo apt-get update
sudo apt-get install -y iproute2
- name: Test
env:
TEST_FLAGS: ${{ runner.os != 'Windows' && '-exec sudo' || '' }}
run: make test
- name: Test unprivileged ping
if: runner.os != 'Linux'
run: go test -v ./ping
- name: Test privileged ping
if: runner.os != 'Windows'
run: |
make test
go test -c -o ping_test ./ping
sudo ./ping_test -test.v
build_windows:
name: Windows
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ^1.23
continue-on-error: true
- name: Build
run: |
make test
go test -v ./ping
build_darwin:
name: macOS
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ^1.23
continue-on-error: true
- name: Build
run: |
make test
go test -v ./ping
go test -c -o ping_test ./ping
sudo ./ping_test -test.v
10 changes: 2 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ build:
GOOS=windows GOARCH=amd64 go build -v -tags with_gvisor .

fmt:
@gofumpt -l -w .
@gofmt -s -w .
@gci write --custom-order -s standard -s "prefix(github.com/sagernet/)" -s "default" .

fmt_install:
go install -v mvdan.cc/gofumpt@latest
go install -v github.com/daixiang0/gci@latest
@golangci-lint fmt

lint:
GOOS=linux golangci-lint --max-same-issues=0 --max-issues-per-linter=0 run ./...
Expand All @@ -29,4 +23,4 @@ lint_install:
test:
go build -v .
#go test -bench=. ./internal/checksum_test
go test -v .
go test -v $(TEST_FLAGS) .
39 changes: 37 additions & 2 deletions flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,44 @@ type Port interface {
WritePackets(packets [][]byte) error
}

type PortWithSelectorRange interface {
type RoutedPort interface {
Port
PortSelectorRange() (start uint16, count uint16)
RoutedPort()
}

type SelectorRange struct {
Start uint16
Count uint16
}

type PortWithSelectorRange interface {
PortSelectorRanges(protocol uint8) []SelectorRange
ExpandSelectorRanges(protocol uint8) bool
}

type PortWithSelectorReservation interface {
ReserveSelector(protocol uint8, address netip.AddrPort) bool
ReleaseSelector(protocol uint8, address netip.AddrPort)
}

type PortWithUpstream interface {
UpstreamPort() any
}

func portCapability[T any](port any) (T, bool) {
for port != nil {
capability, matched := port.(T)
if matched {
return capability, true
}
wrapper, isWrapper := port.(PortWithUpstream)
if !isWrapper {
break
}
port = wrapper.UpstreamPort()
}
var zero T
return zero, false
}

type Return interface {
Expand Down
Loading