Update lwip to fork

This commit is contained in:
世界 2022-08-18 10:08:10 +08:00
parent 85c649d9a3
commit 9c905191f6
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
6 changed files with 15 additions and 109 deletions

View file

@ -41,6 +41,4 @@ jobs:
continue-on-error: true continue-on-error: true
- name: Build - name: Build
run: | run: |
make test go build -v .
make lint_install
make lint

View file

@ -6,15 +6,3 @@ fmt:
fmt_install: fmt_install:
go install -v mvdan.cc/gofumpt@latest go install -v mvdan.cc/gofumpt@latest
go install -v github.com/daixiang0/gci@v0.4.0 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 .

4
go.mod
View file

@ -3,10 +3,10 @@ module github.com/sagernet/sing-tun
go 1.18 go 1.18
require ( require (
github.com/eycorsican/go-tun2socks v1.16.11
github.com/fsnotify/fsnotify v1.5.4 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/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/net v0.0.0-20220812174116-3211cb980234
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab
gvisor.dev/gvisor v0.0.0-20220801010827-addd1f7b3e97 gvisor.dev/gvisor v0.0.0-20220801010827-addd1f7b3e97

15
go.sum
View file

@ -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 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= 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 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= 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 h1:iNtsfGMenajBUGZ/1yAzl1v3p+t/7IJ/ilQXq9haRZ8=
github.com/sagernet/netlink v0.0.0-20220816152750-7a75378bd31a/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM= 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-20220817130738-ce854cda8522 h1:CtHJzJbaZ7icl+yL15NHiXf9Bbm84Wep0P61lQiAFsY=
github.com/sagernet/sing v0.0.0-20220816094748-fb82be7f3f08/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY= github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
github.com/songgao/water v0.0.0-20190725173103-fd331bda3f4b/go.mod h1:P5HUIBuIWKbyjl083/loAegFkfbFNx5i2qEP4CNbm7E=
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 h1:gga7acRE695APm9hlsSMoOoE65U4/TcqNj90mc69Rlg= 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= 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 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E=
golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= 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-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-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 h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 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 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 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= gvisor.dev/gvisor v0.0.0-20220801010827-addd1f7b3e97 h1:zncudP85ZlJelPsgxZXN00Rl5M5j7QuDK27L35Ez01M=

17
lwip.go
View file

@ -9,13 +9,12 @@ import (
"os" "os"
"runtime" "runtime"
lwip "github.com/sagernet/go-tun2socks/core"
"github.com/sagernet/sing/common" "github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/buf" "github.com/sagernet/sing/common/buf"
M "github.com/sagernet/sing/common/metadata" M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network" N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/udpnat" "github.com/sagernet/sing/common/udpnat"
lwip "github.com/eycorsican/go-tun2socks/core"
) )
type LWIP struct { type LWIP struct {
@ -114,7 +113,7 @@ func (l *LWIP) Close() error {
return l.stack.Close() 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() lAddr := conn.LocalAddr()
rAddr := conn.RemoteAddr() rAddr := conn.RemoteAddr()
if lAddr == nil || rAddr == nil { if lAddr == nil || rAddr == nil {
@ -133,14 +132,10 @@ func (l *LWIP) Handle(conn net.Conn, target *net.TCPAddr) error {
return nil return nil
} }
func (l *LWIP) Connect(conn lwip.UDPConn, target *net.UDPAddr) error { func (l *LWIP) ReceiveTo(conn lwip.UDPConn, data []byte, addr M.Socksaddr) error {
return nil
}
func (l *LWIP) ReceiveTo(conn lwip.UDPConn, data []byte, addr *net.UDPAddr) error {
var upstreamMetadata M.Metadata var upstreamMetadata M.Metadata
upstreamMetadata.Source = M.SocksaddrFromNet(conn.LocalAddr()) upstreamMetadata.Source = conn.LocalAddr()
upstreamMetadata.Destination = M.SocksaddrFromNet(addr) upstreamMetadata.Destination = addr
l.udpNat.NewPacket( l.udpNat.NewPacket(
l.ctx, l.ctx,
@ -160,7 +155,7 @@ type LWIPUDPBackWriter struct {
func (w *LWIPUDPBackWriter) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error { func (w *LWIPUDPBackWriter) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error {
defer buffer.Release() 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 { func (w *LWIPUDPBackWriter) Close() error {

View file

@ -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)
}
}
}