mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2024-12-30 02:37:01 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8fcd8fee85 | ||
|
|
e06cce1dd4 | ||
|
|
867cfefa76 | ||
|
|
176324412b | ||
|
|
66e9c6d4e9 | ||
|
|
3928350e57 | ||
|
|
f6ba31f121 | ||
|
|
bf3f4599cc | ||
|
|
dc8e4f1ba1 | ||
|
|
ad53cc7ffe |
@@ -6,6 +6,9 @@ on:
|
||||
- '*'
|
||||
tags-ignore:
|
||||
- '*'
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
- 'docs/**'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
|
||||
@@ -16,25 +16,30 @@ English | [简体中文](README_ZH.md)
|
||||
|
||||
## Features
|
||||
|
||||
- **Fully support:** IPv4/IPv6/ICMP/TCP/UDP
|
||||
- **Proxy protocol:** HTTP/Socks4/Socks5/Shadowsocks
|
||||
- **Game ready:** optimized UDP transmission
|
||||
- **Pure Go:** no CGO required, stability improved
|
||||
- **Router mode:** forwarding packets in LAN
|
||||
- **TCP/IP stack:** powered by **[gVisor](https://github.com/google/gvisor)**
|
||||
- **High performance:** >2.5Gbps throughput
|
||||
|
||||
## Requirements
|
||||
|
||||
| Target | Minimum | Recommended |
|
||||
| :----- | :-----: | :---------: |
|
||||
| System | Linux MacOS Freebsd OpenBSD Windows | Linux or MacOS |
|
||||
| Memory | >20MB | >128MB |
|
||||
| CPU | ANY | AMD64 or ARM64 |
|
||||
- **Network Support**
|
||||
- Dualstack: `IPv4/IPv6`
|
||||
- Forwarder: `TCP/UDP`
|
||||
- Ping Echo: `ICMP`
|
||||
- **Platform Support**
|
||||
- Linux
|
||||
- MacOS
|
||||
- Windows
|
||||
- FreeBSD
|
||||
- OpenBSD
|
||||
- **Proxy Protocol**
|
||||
- HTTP
|
||||
- Socks4
|
||||
- Socks5
|
||||
- Shadowsocks
|
||||
- **Extra Feature**
|
||||
- Improved stability without CGO
|
||||
- Optimized UDP transmission for game
|
||||
- Performed with >2.5Gbps throughput
|
||||
- TCP/IP stack powered by **[gVisor](https://github.com/google/gvisor)**
|
||||
|
||||
## Documentation
|
||||
|
||||
Documentations and quick start guides can be found at [Github Wiki](https://github.com/xjasonlyu/tun2socks/wiki).
|
||||
Docs and quick start guides can be found at [Github Wiki](https://github.com/xjasonlyu/tun2socks/wiki).
|
||||
|
||||
## Community
|
||||
|
||||
@@ -51,3 +56,8 @@ Welcome and feel free to ask any questions at [Github Discussions](https://githu
|
||||
[GPL-3.0](https://github.com/xjasonlyu/tun2socks/blob/main/LICENSE)
|
||||
|
||||
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fxjasonlyu%2Ftun2socks?ref=badge_large)
|
||||
|
||||
|
||||
## Stargazers over time
|
||||
|
||||
[](https://starchart.cc/xjasonlyu/tun2socks)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package fd
|
||||
|
||||
const Driver = "fd"
|
||||
@@ -0,0 +1,41 @@
|
||||
//go:build !windows
|
||||
|
||||
package fd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/core/device"
|
||||
"golang.org/x/sys/unix"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
)
|
||||
|
||||
type FD struct {
|
||||
stack.LinkEndpoint
|
||||
|
||||
fd int
|
||||
mtu uint32
|
||||
}
|
||||
|
||||
func Open(name string, mtu uint32) (device.Device, error) {
|
||||
fd, err := strconv.Atoi(name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot open fd: %s", name)
|
||||
}
|
||||
return open(fd, mtu)
|
||||
}
|
||||
|
||||
func (f *FD) Type() string {
|
||||
return Driver
|
||||
}
|
||||
|
||||
func (f *FD) Name() string {
|
||||
return strconv.Itoa(f.fd)
|
||||
}
|
||||
|
||||
func (f *FD) Close() error {
|
||||
return unix.Close(f.fd)
|
||||
}
|
||||
|
||||
var _ device.Device = (*FD)(nil)
|
||||
@@ -0,0 +1,11 @@
|
||||
package fd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/core/device"
|
||||
)
|
||||
|
||||
func Open(name string, mtu uint32) (device.Device, error) {
|
||||
return nil, errors.New("not supported")
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package fd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/core/device"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/link/fdbased"
|
||||
)
|
||||
|
||||
func open(fd int, mtu uint32) (device.Device, error) {
|
||||
f := &FD{fd: fd, mtu: mtu}
|
||||
|
||||
ep, err := fdbased.New(&fdbased.Options{
|
||||
MTU: mtu,
|
||||
FDs: []int{fd},
|
||||
EthernetHeader: false,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create endpoint: %w", err)
|
||||
}
|
||||
f.LinkEndpoint = ep
|
||||
|
||||
return f, nil
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//go:build !linux && !windows
|
||||
|
||||
package fd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/core/device"
|
||||
"github.com/xjasonlyu/tun2socks/core/device/rwbased"
|
||||
)
|
||||
|
||||
func open(fd int, mtu uint32) (device.Device, error) {
|
||||
f := &FD{fd: fd, mtu: mtu}
|
||||
|
||||
ep, err := rwbased.New(os.NewFile(uintptr(fd), f.Name()), mtu)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create endpoint: %w", err)
|
||||
}
|
||||
f.LinkEndpoint = ep
|
||||
|
||||
return f, nil
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package tun
|
||||
|
||||
type Option func(*TUN)
|
||||
|
||||
func WithName(name string) Option {
|
||||
return func(t *TUN) {
|
||||
t.name = name
|
||||
}
|
||||
}
|
||||
|
||||
func WithMTU(mtu uint32) Option {
|
||||
return func(t *TUN) {
|
||||
t.mtu = mtu
|
||||
}
|
||||
}
|
||||
@@ -23,12 +23,8 @@ type TUN struct {
|
||||
name string
|
||||
}
|
||||
|
||||
func Open(opts ...Option) (device.Device, error) {
|
||||
t := &TUN{}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(t)
|
||||
}
|
||||
func Open(name string, mtu uint32) (device.Device, error) {
|
||||
t := &TUN{name: name, mtu: mtu}
|
||||
|
||||
if len(t.name) >= unix.IFNAMSIZ {
|
||||
return nil, fmt.Errorf("interface name too long: %s", t.name)
|
||||
@@ -46,11 +42,11 @@ func Open(opts ...Option) (device.Device, error) {
|
||||
}
|
||||
}
|
||||
|
||||
mtu, err := rawfile.GetMTU(t.name)
|
||||
_mtu, err := rawfile.GetMTU(t.name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get mtu: %w", err)
|
||||
}
|
||||
t.mtu = mtu
|
||||
t.mtu = _mtu
|
||||
|
||||
ep, err := fdbased.New(&fdbased.Options{
|
||||
MTU: t.mtu,
|
||||
|
||||
@@ -19,12 +19,8 @@ type TUN struct {
|
||||
name string
|
||||
}
|
||||
|
||||
func Open(opts ...Option) (device.Device, error) {
|
||||
t := &TUN{}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(t)
|
||||
}
|
||||
func Open(name string, mtu uint32) (device.Device, error) {
|
||||
t := &TUN{name: name, mtu: mtu}
|
||||
|
||||
forcedMTU := defaultMTU
|
||||
if t.mtu > 0 {
|
||||
@@ -37,11 +33,11 @@ func Open(opts ...Option) (device.Device, error) {
|
||||
}
|
||||
t.nt = nt.(*tun.NativeTun)
|
||||
|
||||
mtu, err := nt.MTU()
|
||||
_mtu, err := nt.MTU()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get mtu: %w", err)
|
||||
}
|
||||
t.mtu = uint32(mtu)
|
||||
t.mtu = uint32(_mtu)
|
||||
|
||||
ep, err := rwbased.New(t, t.mtu)
|
||||
if err != nil {
|
||||
|
||||
+4
-1
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/core/device"
|
||||
"github.com/xjasonlyu/tun2socks/core/device/fd"
|
||||
"github.com/xjasonlyu/tun2socks/core/device/tun"
|
||||
"github.com/xjasonlyu/tun2socks/proxy"
|
||||
"github.com/xjasonlyu/tun2socks/proxy/proto"
|
||||
@@ -26,8 +27,10 @@ func parseDevice(s string, mtu uint32) (device.Device, error) {
|
||||
driver := strings.ToLower(u.Scheme)
|
||||
|
||||
switch driver {
|
||||
case fd.Driver:
|
||||
return fd.Open(name, mtu)
|
||||
case tun.Driver:
|
||||
return tun.Open(tun.WithName(name), tun.WithMTU(mtu))
|
||||
return tun.Open(name, mtu)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported driver: %s", driver)
|
||||
}
|
||||
|
||||
@@ -7,17 +7,17 @@ require (
|
||||
github.com/go-chi/chi v4.1.2+incompatible
|
||||
github.com/go-chi/cors v1.2.0
|
||||
github.com/go-chi/render v1.0.1
|
||||
github.com/gofrs/uuid v4.0.0+incompatible
|
||||
github.com/gofrs/uuid v4.1.0+incompatible
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/stretchr/testify v1.7.0
|
||||
go.uber.org/atomic v1.9.0
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
|
||||
golang.org/x/net v0.0.0-20210929193557-e81a3d93ecf6 // indirect
|
||||
golang.org/x/sys v0.0.0-20211003122950-b1ebd4e1001c
|
||||
golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect
|
||||
golang.org/x/sys v0.0.0-20211031064116-611d5d643895
|
||||
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
|
||||
golang.zx2c4.com/wireguard v0.0.0-20210927201915-bb745b2ea326
|
||||
gvisor.dev/gvisor v0.0.0-20211002000755-82b90506164f
|
||||
golang.zx2c4.com/wireguard v0.0.0-20211030003956-52704c4b9288
|
||||
gvisor.dev/gvisor v0.0.0-20211029210705-806fa5c3235c
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
+1
-1
@@ -104,7 +104,7 @@ func (ss *Socks5) DialUDP(*M.Metadata) (_ net.PacketConn, err error) {
|
||||
|
||||
addr, err := socks5.ClientHandshake(c, targetAddr, socks5.CmdUDPAssociate, user)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("client hanshake: %w", err)
|
||||
return nil, fmt.Errorf("client handshake: %w", err)
|
||||
}
|
||||
|
||||
pc, err := dialer.ListenPacket("udp", "")
|
||||
|
||||
Reference in New Issue
Block a user