From 9c905191f63d5429c413c9f73aa2192f1873748e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 18 Aug 2022 10:08:10 +0800 Subject: [PATCH] Update lwip to fork --- .github/workflows/debug.yml | 4 +-- Makefile | 14 +------- go.mod | 4 +-- go.sum | 15 +++----- lwip.go | 17 ++++----- tun_test.go | 70 ------------------------------------- 6 files changed, 15 insertions(+), 109 deletions(-) delete mode 100644 tun_test.go diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 8a4a8e5..53a252f 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -41,6 +41,4 @@ jobs: continue-on-error: true - name: Build run: | - make test - make lint_install - make lint \ No newline at end of file + go build -v . \ No newline at end of file diff --git a/Makefile b/Makefile index dddccee..db33160 100644 --- a/Makefile +++ b/Makefile @@ -5,16 +5,4 @@ fmt: fmt_install: go install -v mvdan.cc/gofumpt@latest - go install -v github.com/daixiang0/gci@v0.4.0 - -lint: - GOOS=linux golangci-lint run . - GOOS=windows golangci-lint run . - GOOS=darwin golangci-lint run . - GOOS=freebsd golangci-lint run . - -lint_install: - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest - -test: - go test -v . \ No newline at end of file + go install -v github.com/daixiang0/gci@v0.4.0 \ No newline at end of file diff --git a/go.mod b/go.mod index f8e2c0d..7cba465 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/sagernet/sing-tun go 1.18 require ( - github.com/eycorsican/go-tun2socks v1.16.11 github.com/fsnotify/fsnotify v1.5.4 + github.com/sagernet/go-tun2socks v1.16.12-0.20220818015926-16cb67876a61 github.com/sagernet/netlink v0.0.0-20220816152750-7a75378bd31a - github.com/sagernet/sing v0.0.0-20220816094748-fb82be7f3f08 + github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522 golang.org/x/net v0.0.0-20220812174116-3211cb980234 golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab gvisor.dev/gvisor v0.0.0-20220801010827-addd1f7b3e97 diff --git a/go.sum b/go.sum index 16c8498..d9e9e2c 100644 --- a/go.sum +++ b/go.sum @@ -1,27 +1,22 @@ -github.com/eycorsican/go-tun2socks v1.16.11 h1:+hJDNgisrYaGEqoSxhdikMgMJ4Ilfwm/IZDrWRrbaH8= -github.com/eycorsican/go-tun2socks v1.16.11/go.mod h1:wgB2BFT8ZaPKyKOQ/5dljMG/YIow+AIXyq4KBwJ5sGQ= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= +github.com/sagernet/go-tun2socks v1.16.12-0.20220818015926-16cb67876a61 h1:5+m7c6AkmAylhauulqN/c5dnh8/KssrE9c93TQrXldA= +github.com/sagernet/go-tun2socks v1.16.12-0.20220818015926-16cb67876a61/go.mod h1:QUQ4RRHD6hGGHdFMEtR8T2P6GS6R3D/CXKdaYHKKXms= github.com/sagernet/netlink v0.0.0-20220816152750-7a75378bd31a h1:iNtsfGMenajBUGZ/1yAzl1v3p+t/7IJ/ilQXq9haRZ8= github.com/sagernet/netlink v0.0.0-20220816152750-7a75378bd31a/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM= -github.com/sagernet/sing v0.0.0-20220816094748-fb82be7f3f08 h1:Z5UMSxFO+c2GtJqDlU7SF4OqzEV76KNYktTyzhofL9o= -github.com/sagernet/sing v0.0.0-20220816094748-fb82be7f3f08/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY= -github.com/songgao/water v0.0.0-20190725173103-fd331bda3f4b/go.mod h1:P5HUIBuIWKbyjl083/loAegFkfbFNx5i2qEP4CNbm7E= +github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522 h1:CtHJzJbaZ7icl+yL15NHiXf9Bbm84Wep0P61lQiAFsY= +github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY= github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 h1:gga7acRE695APm9hlsSMoOoE65U4/TcqNj90mc69Rlg= github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20191021144547-ec77196f6094/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E= golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= gvisor.dev/gvisor v0.0.0-20220801010827-addd1f7b3e97 h1:zncudP85ZlJelPsgxZXN00Rl5M5j7QuDK27L35Ez01M= diff --git a/lwip.go b/lwip.go index c3a47b3..21de9d0 100644 --- a/lwip.go +++ b/lwip.go @@ -9,13 +9,12 @@ import ( "os" "runtime" + lwip "github.com/sagernet/go-tun2socks/core" "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/buf" M "github.com/sagernet/sing/common/metadata" N "github.com/sagernet/sing/common/network" "github.com/sagernet/sing/common/udpnat" - - lwip "github.com/eycorsican/go-tun2socks/core" ) type LWIP struct { @@ -114,7 +113,7 @@ func (l *LWIP) Close() error { return l.stack.Close() } -func (l *LWIP) Handle(conn net.Conn, target *net.TCPAddr) error { +func (l *LWIP) Handle(conn net.Conn) error { lAddr := conn.LocalAddr() rAddr := conn.RemoteAddr() if lAddr == nil || rAddr == nil { @@ -133,14 +132,10 @@ func (l *LWIP) Handle(conn net.Conn, target *net.TCPAddr) error { return nil } -func (l *LWIP) Connect(conn lwip.UDPConn, target *net.UDPAddr) error { - return nil -} - -func (l *LWIP) ReceiveTo(conn lwip.UDPConn, data []byte, addr *net.UDPAddr) error { +func (l *LWIP) ReceiveTo(conn lwip.UDPConn, data []byte, addr M.Socksaddr) error { var upstreamMetadata M.Metadata - upstreamMetadata.Source = M.SocksaddrFromNet(conn.LocalAddr()) - upstreamMetadata.Destination = M.SocksaddrFromNet(addr) + upstreamMetadata.Source = conn.LocalAddr() + upstreamMetadata.Destination = addr l.udpNat.NewPacket( l.ctx, @@ -160,7 +155,7 @@ type LWIPUDPBackWriter struct { func (w *LWIPUDPBackWriter) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error { defer buffer.Release() - return common.Error(w.conn.WriteFrom(buffer.Bytes(), destination.UDPAddr())) + return common.Error(w.conn.WriteFrom(buffer.Bytes(), destination)) } func (w *LWIPUDPBackWriter) Close() error { diff --git a/tun_test.go b/tun_test.go deleted file mode 100644 index ee120c6..0000000 --- a/tun_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package tun - -import ( - "reflect" - "testing" - - "github.com/sagernet/sing/common/ranges" -) - -func TestUIDRanges(t *testing.T) { - for _, testRange := range []struct { - include []ranges.Range[uint32] - exclude []ranges.Range[uint32] - androidUser []int - expected []ranges.Range[uint32] - }{ - {}, - { - include: []ranges.Range[uint32]{ - ranges.NewSingle[uint32](0), - ranges.NewSingle[uint32](1000), - }, - expected: []ranges.Range[uint32]{ - {Start: 1, End: 999}, - {Start: 1001, End: userEnd}, - }, - }, - { - androidUser: []int{0}, - expected: []ranges.Range[uint32]{ - {Start: androidUserRange, End: userEnd}, - }, - }, - { - androidUser: []int{0}, - expected: []ranges.Range[uint32]{ - {Start: 100000, End: userEnd}, - }, - }, - { - androidUser: []int{10}, - include: []ranges.Range[uint32]{ - ranges.NewSingle[uint32](0), - }, - expected: []ranges.Range[uint32]{ - {Start: 1, End: androidUserRange*10 - 1}, - {Start: androidUserRange * 11, End: userEnd}, - }, - }, - { - include: []ranges.Range[uint32]{ - {Start: 123456, End: 123456}, - }, - exclude: []ranges.Range[uint32]{ - {Start: 1000, End: 1000}, - }, - androidUser: []int{0}, - expected: []ranges.Range[uint32]{ - {Start: 1000, End: 1000}, - {Start: 100000, End: 123455}, - {Start: 123457, End: userEnd}, - }, - }, - } { - result := buildExcludedRanges(testRange.include, testRange.exclude, testRange.androidUser) - if !reflect.DeepEqual(result, testRange.expected) { - t.Fatal("input", testRange.include, testRange.exclude, testRange.androidUser, "\nexpected", testRange.expected, "\ngot", result) - } - } -}