From 69d5672dd695d9492c939f2eb91e1f8a1e01fcf3 Mon Sep 17 00:00:00 2001 From: omengye Date: Thu, 16 Nov 2023 14:41:28 +0800 Subject: [PATCH] update go mod version from remote main branch; remove wireguard --- go.mod | 10 +- go.sum | 17 -- infra/conf/transport_authenticators.go | 7 - infra/conf/transport_internet.go | 1 - main/distro/all/all.go | 1 - proxy/wireguard/config.go | 25 -- proxy/wireguard/tun_default.go | 42 ---- proxy/wireguard/tun_linux.go | 223 ------------------ transport/internet/header_test.go | 5 - .../internet/headers/wireguard/config.pb.go | 145 ------------ .../internet/headers/wireguard/config.proto | 9 - .../internet/headers/wireguard/wireguard.go | 30 --- transport/internet/quic/quic_test.go | 8 +- 13 files changed, 3 insertions(+), 520 deletions(-) delete mode 100644 proxy/wireguard/config.go delete mode 100644 proxy/wireguard/tun_default.go delete mode 100644 proxy/wireguard/tun_linux.go delete mode 100644 transport/internet/headers/wireguard/config.pb.go delete mode 100644 transport/internet/headers/wireguard/config.proto delete mode 100644 transport/internet/headers/wireguard/wireguard.go diff --git a/go.mod b/go.mod index bd71b937e229..f82210f7517e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/xtls/xray-core -go 1.21 +go 1.21.4 require ( github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344 @@ -15,8 +15,6 @@ require ( github.com/sagernet/sing v0.2.17 github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb github.com/stretchr/testify v1.8.4 - github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e - github.com/vishvananda/netlink v1.2.1-beta.2.0.20230316163032-ced5aaba43e3 github.com/xtls/reality v0.0.0-20231112171332-de1173cf2b19 go4.org/netipx v0.0.0-20230824141953-6213f710f925 golang.org/x/crypto v0.15.0 @@ -38,24 +36,18 @@ require ( github.com/gaukas/godicttls v0.0.4 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/google/btree v1.1.2 // indirect github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a // indirect github.com/klauspost/compress v1.17.2 // indirect github.com/klauspost/cpuid/v2 v2.2.6 // indirect github.com/onsi/ginkgo/v2 v2.13.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/quic-go/qtls-go1-20 v0.4.1 // indirect - github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect - github.com/vishvananda/netns v0.0.4 // indirect go.uber.org/mock v0.3.0 // indirect golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect golang.org/x/mod v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/time v0.4.0 // indirect golang.org/x/tools v0.15.0 // indirect - golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - gvisor.dev/gvisor v0.0.0-20231104011432-48a6d7d5bd0b // indirect ) diff --git a/go.sum b/go.sum index c72455233cc9..c58d3f7d04a5 100644 --- a/go.sum +++ b/go.sum @@ -123,8 +123,6 @@ github.com/refraction-networking/utls v1.5.4/go.mod h1:SPuDbBmgLGp8s+HLNc83Fuavw github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/sagernet/sing v0.2.17 h1:vMPKb3MV0Aa5ws4dCJkRI8XEjrsUcDn810czd0FwmzI= github.com/sagernet/sing v0.2.17/go.mod h1:OL6k2F0vHmEzXz2KW19qQzu172FDgSbUSODylighuVo= -github.com/sagernet/sing-shadowsocks v0.2.5 h1:qxIttos4xu6ii7MTVJYA8EFQR7Q3KG6xMqmLJIFtBaY= -github.com/sagernet/sing-shadowsocks v0.2.5/go.mod h1:MGWGkcU2xW2G2mfArT9/QqpVLOGU+dBaahZCtPHdt7A= github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb h1:XfLJSPIOUX+osiMraVgIrMR27uMXnRJWGm1+GL8/63U= github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb/go.mod h1:bR6DqgcAl1zTcOX8/pE2Qkj9XO00eCNqmKb7lXP8EAg= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= @@ -160,11 +158,6 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU= github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM= -github.com/vishvananda/netlink v1.2.1-beta.2.0.20230316163032-ced5aaba43e3 h1:tkMT5pTye+1NlKIXETU78NXw0fyjnaNHmJyyLyzw8+U= -github.com/vishvananda/netlink v1.2.1-beta.2.0.20230316163032-ced5aaba43e3/go.mod h1:cAAsePK2e15YDAMJNyOpGYEWNe4sIghTY7gpz4cX/Ik= -github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= -github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8= -github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM= github.com/xtls/reality v0.0.0-20231112171332-de1173cf2b19 h1:capMfFYRgH9BCLd6A3Er/cH3A9Nz3CU2KwxwOQZIePI= github.com/xtls/reality v0.0.0-20231112171332-de1173cf2b19/go.mod h1:dm4y/1QwzjGaK17ofi0Vs6NpKAHegZky8qk6J2JJZAE= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= @@ -222,11 +215,9 @@ golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190316082340-a2f829d7f35f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220804214406-8e32c043e418/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= @@ -238,8 +229,6 @@ golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.4.0 h1:Z81tqI5ddIoXDPvVQ7/7CC9TnLM7ubaFG2qXYd5BbYY= -golang.org/x/time v0.4.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -253,10 +242,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 h1:B82qJJgjvYKsXS9jeunTOisW56dUokqW/FOteYJJ/yg= -golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2/go.mod h1:deeaetjYA+DHMHg+sMSMI58GrEteJUUzzw7en6TJQcI= -golang.zx2c4.com/wireguard v0.0.0-20231022001213-2e0774f246fb h1:c5tyN8sSp8jSDxdCCDXVOpJwYXXhmTkNMt+g0zTSOic= -golang.zx2c4.com/wireguard v0.0.0-20231022001213-2e0774f246fb/go.mod h1:tkCQ4FQXmpAgYVh++1cq16/dH4QJtmvpRv19DWGAHSA= google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.1.0/go.mod h1:UGEZY7KEX120AnNLIHFMKIo4obdJhkp2tPbaPlQx13Y= @@ -294,8 +279,6 @@ gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= -gvisor.dev/gvisor v0.0.0-20231104011432-48a6d7d5bd0b h1:yqkg3pTifuKukuWanp8spDsL4irJkHF5WI0J47hU87o= -gvisor.dev/gvisor v0.0.0-20231104011432-48a6d7d5bd0b/go.mod h1:10sU+Uh5KKNv1+2x2A0Gvzt8FjD3ASIhorV3YsauXhk= h12.io/socks v1.0.3 h1:Ka3qaQewws4j4/eDQnOdpr4wXsC//dXtWvftlIcCQUo= h12.io/socks v1.0.3/go.mod h1:AIhxy1jOId/XCz9BO+EIgNL2rQiPTBNnOfnVnQ+3Eck= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/infra/conf/transport_authenticators.go b/infra/conf/transport_authenticators.go index db9f4a726e45..aad5818d48f0 100644 --- a/infra/conf/transport_authenticators.go +++ b/infra/conf/transport_authenticators.go @@ -10,7 +10,6 @@ import ( "github.com/xtls/xray-core/transport/internet/headers/tls" "github.com/xtls/xray-core/transport/internet/headers/utp" "github.com/xtls/xray-core/transport/internet/headers/wechat" - "github.com/xtls/xray-core/transport/internet/headers/wireguard" "google.golang.org/protobuf/proto" ) @@ -44,12 +43,6 @@ func (WechatVideoAuthenticator) Build() (proto.Message, error) { return new(wechat.VideoConfig), nil } -type WireguardAuthenticator struct{} - -func (WireguardAuthenticator) Build() (proto.Message, error) { - return new(wireguard.WireguardConfig), nil -} - type DNSAuthenticator struct { Domain string `json:"domain"` } diff --git a/infra/conf/transport_internet.go b/infra/conf/transport_internet.go index e1471bde1ffc..e2eaec20a603 100644 --- a/infra/conf/transport_internet.go +++ b/infra/conf/transport_internet.go @@ -35,7 +35,6 @@ var ( "utp": func() interface{} { return new(UTPAuthenticator) }, "wechat-video": func() interface{} { return new(WechatVideoAuthenticator) }, "dtls": func() interface{} { return new(DTLSAuthenticator) }, - "wireguard": func() interface{} { return new(WireguardAuthenticator) }, "dns": func() interface{} { return new(DNSAuthenticator) }, }, "type", "") diff --git a/main/distro/all/all.go b/main/distro/all/all.go index 40e1f81366a9..11025f806a8c 100644 --- a/main/distro/all/all.go +++ b/main/distro/all/all.go @@ -66,7 +66,6 @@ import ( _ "github.com/xtls/xray-core/transport/internet/headers/tls" _ "github.com/xtls/xray-core/transport/internet/headers/utp" _ "github.com/xtls/xray-core/transport/internet/headers/wechat" - _ "github.com/xtls/xray-core/transport/internet/headers/wireguard" // JSON & TOML & YAML _ "github.com/xtls/xray-core/main/json" diff --git a/proxy/wireguard/config.go b/proxy/wireguard/config.go deleted file mode 100644 index 756227539991..000000000000 --- a/proxy/wireguard/config.go +++ /dev/null @@ -1,25 +0,0 @@ -package wireguard - -func (c *DeviceConfig) preferIP4() bool { - return c.DomainStrategy == DeviceConfig_FORCE_IP || - c.DomainStrategy == DeviceConfig_FORCE_IP4 || - c.DomainStrategy == DeviceConfig_FORCE_IP46 -} - -func (c *DeviceConfig) preferIP6() bool { - return c.DomainStrategy == DeviceConfig_FORCE_IP || - c.DomainStrategy == DeviceConfig_FORCE_IP6 || - c.DomainStrategy == DeviceConfig_FORCE_IP64 -} - -func (c *DeviceConfig) hasFallback() bool { - return c.DomainStrategy == DeviceConfig_FORCE_IP46 || c.DomainStrategy == DeviceConfig_FORCE_IP64 -} - -func (c *DeviceConfig) fallbackIP4() bool { - return c.DomainStrategy == DeviceConfig_FORCE_IP64 -} - -func (c *DeviceConfig) fallbackIP6() bool { - return c.DomainStrategy == DeviceConfig_FORCE_IP46 -} diff --git a/proxy/wireguard/tun_default.go b/proxy/wireguard/tun_default.go deleted file mode 100644 index 07f212722385..000000000000 --- a/proxy/wireguard/tun_default.go +++ /dev/null @@ -1,42 +0,0 @@ -//go:build !linux - -package wireguard - -import ( - "context" - "net" - "net/netip" - - "golang.zx2c4.com/wireguard/tun/netstack" -) - -var _ Tunnel = (*gvisorNet)(nil) - -type gvisorNet struct { - tunnel - net *netstack.Net -} - -func (g *gvisorNet) Close() error { - return g.tunnel.Close() -} - -func (g *gvisorNet) DialContextTCPAddrPort(ctx context.Context, addr netip.AddrPort) ( - net.Conn, error, -) { - return g.net.DialContextTCPAddrPort(ctx, addr) -} - -func (g *gvisorNet) DialUDPAddrPort(laddr, raddr netip.AddrPort) (net.Conn, error) { - return g.net.DialUDPAddrPort(laddr, raddr) -} - -func CreateTun(localAddresses []netip.Addr, mtu int) (Tunnel, error) { - out := &gvisorNet{} - tun, n, err := netstack.CreateNetTUN(localAddresses, nil, mtu) - if err != nil { - return nil, err - } - out.tun, out.net = tun, n - return out, nil -} diff --git a/proxy/wireguard/tun_linux.go b/proxy/wireguard/tun_linux.go deleted file mode 100644 index ec940c56d009..000000000000 --- a/proxy/wireguard/tun_linux.go +++ /dev/null @@ -1,223 +0,0 @@ -package wireguard - -import ( - "context" - "errors" - "fmt" - "net" - "net/netip" - "os" - - "golang.org/x/sys/unix" - - "github.com/sagernet/sing/common/control" - "github.com/vishvananda/netlink" - wgtun "golang.zx2c4.com/wireguard/tun" -) - -type deviceNet struct { - tunnel - dialer net.Dialer - - handle *netlink.Handle - linkAddrs []netlink.Addr - routes []*netlink.Route - rules []*netlink.Rule -} - -func newDeviceNet(interfaceName string) *deviceNet { - var dialer net.Dialer - bindControl := control.BindToInterface(control.DefaultInterfaceFinder(), interfaceName, -1) - dialer.Control = control.Append(dialer.Control, bindControl) - return &deviceNet{dialer: dialer} -} - -func (d *deviceNet) DialContextTCPAddrPort(ctx context.Context, addr netip.AddrPort) ( - net.Conn, error, -) { - return d.dialer.DialContext(ctx, "tcp", addr.String()) -} - -func (d *deviceNet) DialUDPAddrPort(laddr, raddr netip.AddrPort) (net.Conn, error) { - dialer := d.dialer - dialer.LocalAddr = &net.UDPAddr{IP: laddr.Addr().AsSlice(), Port: int(laddr.Port())} - return dialer.DialContext(context.Background(), "udp", raddr.String()) -} - -func (d *deviceNet) Close() (err error) { - var errs []error - for _, rule := range d.rules { - if err = d.handle.RuleDel(rule); err != nil { - errs = append(errs, fmt.Errorf("failed to delete rule: %w", err)) - } - } - for _, route := range d.routes { - if err = d.handle.RouteDel(route); err != nil { - errs = append(errs, fmt.Errorf("failed to delete route: %w", err)) - } - } - if err = d.tunnel.Close(); err != nil { - errs = append(errs, fmt.Errorf("failed to close tunnel: %w", err)) - } - if d.handle != nil { - d.handle.Close() - d.handle = nil - } - if len(errs) == 0 { - return nil - } - return errors.Join(errs...) -} - -func CreateTun(localAddresses []netip.Addr, mtu int) (t Tunnel, err error) { - var v4, v6 *netip.Addr - for _, prefixes := range localAddresses { - if v4 == nil && prefixes.Is4() { - x := prefixes - v4 = &x - } - if v6 == nil && prefixes.Is6() { - x := prefixes - v6 = &x - } - } - - writeSysctlZero := func(path string) error { - _, err := os.Stat(path) - if os.IsNotExist(err) { - return nil - } - if err != nil { - return err - } - return os.WriteFile(path, []byte("0"), 0o644) - } - - // system configs. - if v4 != nil { - if err = writeSysctlZero("/proc/sys/net/ipv4/conf/all/rp_filter"); err != nil { - return nil, fmt.Errorf("failed to disable ipv4 rp_filter for all: %w", err) - } - } - if v6 != nil { - if err = writeSysctlZero("/proc/sys/net/ipv6/conf/all/disable_ipv6"); err != nil { - return nil, fmt.Errorf("failed to enable ipv6: %w", err) - } - if err = writeSysctlZero("/proc/sys/net/ipv6/conf/all/rp_filter"); err != nil { - return nil, fmt.Errorf("failed to disable ipv6 rp_filter for all: %w", err) - } - } - - n := CalculateInterfaceName("wg") - wgt, err := wgtun.CreateTUN(n, mtu) - if err != nil { - return nil, err - } - defer func() { - if err != nil { - _ = wgt.Close() - } - }() - - // disable linux rp_filter for tunnel device to avoid packet drop. - // the operation require root privilege on container require '--privileged' flag. - if v4 != nil { - if err = writeSysctlZero("/proc/sys/net/ipv4/conf/" + n + "/rp_filter"); err != nil { - return nil, fmt.Errorf("failed to disable ipv4 rp_filter for tunnel: %w", err) - } - } - if v6 != nil { - if err = writeSysctlZero("/proc/sys/net/ipv6/conf/" + n + "/rp_filter"); err != nil { - return nil, fmt.Errorf("failed to disable ipv6 rp_filter for tunnel: %w", err) - } - } - - ipv6TableIndex := 1023 - if v6 != nil { - r := &netlink.Route{Table: ipv6TableIndex} - for { - routeList, fErr := netlink.RouteListFiltered(netlink.FAMILY_V6, r, netlink.RT_FILTER_TABLE) - if len(routeList) == 0 || fErr != nil { - break - } - ipv6TableIndex-- - if ipv6TableIndex < 0 { - return nil, fmt.Errorf("failed to find available ipv6 table index") - } - } - } - - out := newDeviceNet(n) - out.handle, err = netlink.NewHandle() - if err != nil { - return nil, err - } - defer func() { - if err != nil { - _ = out.Close() - } - }() - - l, err := netlink.LinkByName(n) - if err != nil { - return nil, err - } - - if v4 != nil { - addr := netlink.Addr{ - IPNet: &net.IPNet{ - IP: v4.AsSlice(), - Mask: net.CIDRMask(v4.BitLen(), v4.BitLen()), - }, - } - out.linkAddrs = append(out.linkAddrs, addr) - } - if v6 != nil { - addr := netlink.Addr{ - IPNet: &net.IPNet{ - IP: v6.AsSlice(), - Mask: net.CIDRMask(v6.BitLen(), v6.BitLen()), - }, - } - out.linkAddrs = append(out.linkAddrs, addr) - - rt := &netlink.Route{ - LinkIndex: l.Attrs().Index, - Dst: &net.IPNet{ - IP: net.IPv6zero, - Mask: net.CIDRMask(0, 128), - }, - Table: ipv6TableIndex, - } - out.routes = append(out.routes, rt) - - r := netlink.NewRule() - r.Table, r.Family, r.Src = ipv6TableIndex, unix.AF_INET6, addr.IPNet - out.rules = append(out.rules, r) - } - - for _, addr := range out.linkAddrs { - if err = out.handle.AddrAdd(l, &addr); err != nil { - return nil, fmt.Errorf("failed to add address %s to %s: %w", addr, n, err) - } - } - if err = out.handle.LinkSetMTU(l, mtu); err != nil { - return nil, err - } - if err = out.handle.LinkSetUp(l); err != nil { - return nil, err - } - - for _, route := range out.routes { - if err = out.handle.RouteAdd(route); err != nil { - return nil, fmt.Errorf("failed to add route %s: %w", route, err) - } - } - for _, rule := range out.rules { - if err = out.handle.RuleAdd(rule); err != nil { - return nil, fmt.Errorf("failed to add rule %s: %w", rule, err) - } - } - out.tun = wgt - return out, nil -} diff --git a/transport/internet/header_test.go b/transport/internet/header_test.go index e87ee78438ca..908748daf5c5 100644 --- a/transport/internet/header_test.go +++ b/transport/internet/header_test.go @@ -9,7 +9,6 @@ import ( "github.com/xtls/xray-core/transport/internet/headers/srtp" "github.com/xtls/xray-core/transport/internet/headers/utp" "github.com/xtls/xray-core/transport/internet/headers/wechat" - "github.com/xtls/xray-core/transport/internet/headers/wireguard" ) func TestAllHeadersLoadable(t *testing.T) { @@ -33,10 +32,6 @@ func TestAllHeadersLoadable(t *testing.T) { Input: new(wechat.VideoConfig), Size: 13, }, - { - Input: new(wireguard.WireguardConfig), - Size: 4, - }, } for _, testCase := range testCases { diff --git a/transport/internet/headers/wireguard/config.pb.go b/transport/internet/headers/wireguard/config.pb.go deleted file mode 100644 index 4274198c2f80..000000000000 --- a/transport/internet/headers/wireguard/config.pb.go +++ /dev/null @@ -1,145 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.31.0 -// protoc v4.23.1 -// source: transport/internet/headers/wireguard/config.proto - -package wireguard - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -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 WireguardConfig struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *WireguardConfig) Reset() { - *x = WireguardConfig{} - if protoimpl.UnsafeEnabled { - mi := &file_transport_internet_headers_wireguard_config_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *WireguardConfig) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*WireguardConfig) ProtoMessage() {} - -func (x *WireguardConfig) ProtoReflect() protoreflect.Message { - mi := &file_transport_internet_headers_wireguard_config_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use WireguardConfig.ProtoReflect.Descriptor instead. -func (*WireguardConfig) Descriptor() ([]byte, []int) { - return file_transport_internet_headers_wireguard_config_proto_rawDescGZIP(), []int{0} -} - -var File_transport_internet_headers_wireguard_config_proto protoreflect.FileDescriptor - -var file_transport_internet_headers_wireguard_config_proto_rawDesc = []byte{ - 0x0a, 0x31, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, - 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x77, 0x69, 0x72, - 0x65, 0x67, 0x75, 0x61, 0x72, 0x64, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x12, 0x29, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, - 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, - 0x64, 0x65, 0x72, 0x73, 0x2e, 0x77, 0x69, 0x72, 0x65, 0x67, 0x75, 0x61, 0x72, 0x64, 0x22, 0x11, - 0x0a, 0x0f, 0x57, 0x69, 0x72, 0x65, 0x67, 0x75, 0x61, 0x72, 0x64, 0x43, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x42, 0x9d, 0x01, 0x0a, 0x2d, 0x63, 0x6f, 0x6d, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, - 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, - 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x77, 0x69, 0x72, 0x65, 0x67, 0x75, - 0x61, 0x72, 0x64, 0x50, 0x01, 0x5a, 0x3e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x78, 0x74, 0x6c, 0x73, 0x2f, 0x78, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, - 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, - 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x77, 0x69, 0x72, 0x65, - 0x67, 0x75, 0x61, 0x72, 0x64, 0xaa, 0x02, 0x29, 0x58, 0x72, 0x61, 0x79, 0x2e, 0x54, 0x72, 0x61, - 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, - 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x57, 0x69, 0x72, 0x65, 0x67, 0x75, 0x61, 0x72, - 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_transport_internet_headers_wireguard_config_proto_rawDescOnce sync.Once - file_transport_internet_headers_wireguard_config_proto_rawDescData = file_transport_internet_headers_wireguard_config_proto_rawDesc -) - -func file_transport_internet_headers_wireguard_config_proto_rawDescGZIP() []byte { - file_transport_internet_headers_wireguard_config_proto_rawDescOnce.Do(func() { - file_transport_internet_headers_wireguard_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_headers_wireguard_config_proto_rawDescData) - }) - return file_transport_internet_headers_wireguard_config_proto_rawDescData -} - -var file_transport_internet_headers_wireguard_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_transport_internet_headers_wireguard_config_proto_goTypes = []interface{}{ - (*WireguardConfig)(nil), // 0: xray.transport.internet.headers.wireguard.WireguardConfig -} -var file_transport_internet_headers_wireguard_config_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_transport_internet_headers_wireguard_config_proto_init() } -func file_transport_internet_headers_wireguard_config_proto_init() { - if File_transport_internet_headers_wireguard_config_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_transport_internet_headers_wireguard_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*WireguardConfig); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_transport_internet_headers_wireguard_config_proto_rawDesc, - NumEnums: 0, - NumMessages: 1, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_transport_internet_headers_wireguard_config_proto_goTypes, - DependencyIndexes: file_transport_internet_headers_wireguard_config_proto_depIdxs, - MessageInfos: file_transport_internet_headers_wireguard_config_proto_msgTypes, - }.Build() - File_transport_internet_headers_wireguard_config_proto = out.File - file_transport_internet_headers_wireguard_config_proto_rawDesc = nil - file_transport_internet_headers_wireguard_config_proto_goTypes = nil - file_transport_internet_headers_wireguard_config_proto_depIdxs = nil -} diff --git a/transport/internet/headers/wireguard/config.proto b/transport/internet/headers/wireguard/config.proto deleted file mode 100644 index a115797a5c04..000000000000 --- a/transport/internet/headers/wireguard/config.proto +++ /dev/null @@ -1,9 +0,0 @@ -syntax = "proto3"; - -package xray.transport.internet.headers.wireguard; -option csharp_namespace = "Xray.Transport.Internet.Headers.Wireguard"; -option go_package = "github.com/xtls/xray-core/transport/internet/headers/wireguard"; -option java_package = "com.xray.transport.internet.headers.wireguard"; -option java_multiple_files = true; - -message WireguardConfig {} diff --git a/transport/internet/headers/wireguard/wireguard.go b/transport/internet/headers/wireguard/wireguard.go deleted file mode 100644 index 4ced1bc32aea..000000000000 --- a/transport/internet/headers/wireguard/wireguard.go +++ /dev/null @@ -1,30 +0,0 @@ -package wireguard - -import ( - "context" - - "github.com/xtls/xray-core/common" -) - -type Wireguard struct{} - -func (Wireguard) Size() int32 { - return 4 -} - -// Serialize implements PacketHeader. -func (Wireguard) Serialize(b []byte) { - b[0] = 0x04 - b[1] = 0x00 - b[2] = 0x00 - b[3] = 0x00 -} - -// NewWireguard returns a new VideoChat instance based on given config. -func NewWireguard(ctx context.Context, config interface{}) (interface{}, error) { - return Wireguard{}, nil -} - -func init() { - common.Must(common.RegisterConfig((*WireguardConfig)(nil), NewWireguard)) -} diff --git a/transport/internet/quic/quic_test.go b/transport/internet/quic/quic_test.go index ab07105895a0..a96d8aa4b580 100644 --- a/transport/internet/quic/quic_test.go +++ b/transport/internet/quic/quic_test.go @@ -12,10 +12,8 @@ import ( "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/protocol" "github.com/xtls/xray-core/common/protocol/tls/cert" - "github.com/xtls/xray-core/common/serial" "github.com/xtls/xray-core/testing/servers/udp" "github.com/xtls/xray-core/transport/internet" - "github.com/xtls/xray-core/transport/internet/headers/wireguard" "github.com/xtls/xray-core/transport/internet/quic" "github.com/xtls/xray-core/transport/internet/stat" "github.com/xtls/xray-core/transport/internet/tls" @@ -158,8 +156,7 @@ func TestQuicConnectionAuthHeader(t *testing.T) { listener, err := quic.Listen(context.Background(), net.LocalHostIP, port, &internet.MemoryStreamConfig{ ProtocolName: "quic", ProtocolSettings: &quic.Config{ - Header: serial.ToTypedMessage(&wireguard.WireguardConfig{}), - Key: "abcd", + Key: "abcd", Security: &protocol.SecurityConfig{ Type: protocol.SecurityType_AES128_GCM, }, @@ -190,8 +187,7 @@ func TestQuicConnectionAuthHeader(t *testing.T) { conn, err := quic.Dial(dctx, net.TCPDestination(net.LocalHostIP, port), &internet.MemoryStreamConfig{ ProtocolName: "quic", ProtocolSettings: &quic.Config{ - Header: serial.ToTypedMessage(&wireguard.WireguardConfig{}), - Key: "abcd", + Key: "abcd", Security: &protocol.SecurityConfig{ Type: protocol.SecurityType_AES128_GCM, },