Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
623f0ab
Fix lint errors
nekohasekai Jun 22, 2026
ebb52fb
ping: Fix missing TTL and ICMP error handling
nekohasekai Jun 22, 2026
53208c8
Fix ping
nekohasekai Jun 29, 2026
8f387ab
ping: Fix stale flows kept alive by unrelated ICMP traffic
nekohasekai Jul 9, 2026
f2fb366
Add MAC address include/exclude filtering for nftables auto-redirect
nekohasekai Mar 3, 2026
d47cef7
Make gtcpip public for external use
nekohasekai Apr 2, 2026
6bb5b52
Add compatibility with docker bridge
nekohasekai Apr 24, 2026
712c420
Add read waiter support for gVisor conn
nekohasekai Apr 27, 2026
27a88e9
Add DNS mode
nekohasekai May 2, 2026
f0cdbed
Add flow dispatcher
nekohasekai Jul 6, 2026
b017e6d
Fix gVisor process
nekohasekai Jul 6, 2026
4412996
Drain pending packets in Linux batch read
nekohasekai Jul 6, 2026
321ffec
Add flow tracking
nekohasekai Jul 6, 2026
f456a50
Minor fixes
nekohasekai Jul 7, 2026
95180d1
Fix CalculateInterfaceName on iOS
nekohasekai Jul 7, 2026
0e0b6ec
Add UDPTimeout option for flow
nekohasekai Jul 7, 2026
127c941
Fix android GSO
nekohasekai Jul 8, 2026
4fb6a79
Add flow PortWithSelectorRange
nekohasekai Jul 8, 2026
f14624c
Reject flows on selector range exhaustion
nekohasekai Jul 8, 2026
467c206
Fix flow close reasons
nekohasekai Jul 8, 2026
1b35243
Improve darwin forwarding
nekohasekai Jul 8, 2026
f6c89a8
ping: Fix stale flows kept alive by unrelated ICMP traffic
nekohasekai Jul 9, 2026
8a2ff73
Fix logger check
nekohasekai Jul 9, 2026
9432f47
Avoid Docker firewall policy bypass
nekohasekai Jul 11, 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
41 changes: 38 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,56 @@ on:

jobs:
build:
name: Build
name: Lint ${{ matrix.goos }}/${{ matrix.goarch }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- goos: windows
goarch: amd64
- goos: windows
goarch: '386'
- goos: windows
goarch: arm64
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: linux
goarch: arm
- goos: linux
goarch: '386'
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: android
goarch: arm64
- goos: freebsd
goarch: amd64
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ^1.25
- name: Cache go module
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
key: go-${{ hashFiles('**/go.sum') }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
with:
version: latest
args: --timeout=30m
install-mode: binary
verify: false
verify: false
27 changes: 6 additions & 21 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
version: "2"
run:
go: "1.25"
go: "1.24"
linters:
default: none
enable:
- govet
- ineffassign
- paralleltest
- staticcheck
- modernize
settings:
staticcheck:
checks:
- all
- -S1000
- -S1008
- -S1017
- -ST1003
- -QF1001
- -QF1003
- -QF1008
- -QF1008 # could remove embedded field "<interface>" from selector
- -ST1003 # should not use ALL_CAPS in Go names; use CamelCase instead
- -QF1001 # could apply De Morgan's law
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gci
Expand All @@ -42,8 +31,4 @@ formatters:
- default
custom-order: true
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
generated: lax
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ fmt_install:
go install -v github.com/daixiang0/gci@latest

lint:
GOOS=linux golangci-lint run .
GOOS=android golangci-lint run .
GOOS=windows golangci-lint run .
GOOS=darwin golangci-lint run .
GOOS=freebsd golangci-lint run .
GOOS=linux golangci-lint --max-same-issues=0 --max-issues-per-linter=0 run ./...
GOOS=android golangci-lint --max-same-issues=0 --max-issues-per-linter=0 run ./...
GOOS=windows golangci-lint --max-same-issues=0 --max-issues-per-linter=0 run ./...
GOOS=darwin golangci-lint --max-same-issues=0 --max-issues-per-linter=0 run ./...

lint_install:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
Expand Down
73 changes: 73 additions & 0 deletions flow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package tun

import (
"net/netip"
"time"
)

type FlowVerdict struct {
Action FlowAction
Port Port
Destination netip.AddrPort
UDPTimeout time.Duration
NewTracker func() FlowTracker
}

type FlowAction uint8

const (
ActionAccept FlowAction = iota
ActionFlow
ActionReject
ActionDrop
ActionBypass
)

type FlowTracker interface {
AttachFlow(handle FlowHandle)
CountForward(n int)
CountReverse(n int)
FlowEstablished()
CloseFlow(reason FlowCloseReason)
}

type FlowHandle interface {
CloseFlow()
}

type FlowCloseReason uint8

const (
FlowCloseReset FlowCloseReason = iota
FlowCloseFinished
FlowCloseTimeout
)

func (r FlowCloseReason) String() string {
switch r {
case FlowCloseFinished:
return "finished"
case FlowCloseTimeout:
return "idle timeout"
default:
return "connection reset"
}
}

type Port interface {
PortAddresses() (v4 netip.Addr, v6 netip.Addr)
PortMTU() uint32
AttachReturn(returnPath Return) error
DetachReturn(returnPath Return) error
WritePackets(packets [][]byte) error
}

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

type Return interface {
ReturnHeadroom() int
ReturnPackets(packets [][]byte) [][]byte
}
Loading