mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2025-12-24 13:27:56 +08:00
修复tproxy bug, 已经可用!
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
|
||||
下面给出安装到 ubuntu amd64服务器 所需要的命令, 大家总结一下即可得到一个简单的一键脚本
|
||||
下面给出安装到 ubuntu amd64服务器 所需要的步骤和命令, 大家总结一下即可得到一个简单的一键脚本
|
||||
|
||||
本指导默认不使用root账户。我是不建议用一键的。大家分段分步骤学习更加科学。
|
||||
本指导默认不使用root账户,且不建议用一键脚本。分步骤学习、安装 更加科学。
|
||||
|
||||
如果你用root账户运行的话,不要在前面加 "sudo".
|
||||
|
||||
下面的命令也不要整个一大段拷贝,而要分条拷贝到vps并运行。
|
||||
|
||||
## 第0步,准备阶段
|
||||
## 第〇步,准备阶段
|
||||
|
||||
首先确保自己服务器相应端口都是打开状态,防火墙要处理一下。然后安装一些BBR之类的加速组件。
|
||||
|
||||
@@ -26,7 +26,7 @@ sudo mkdir -p /usr/local/etc/verysimple
|
||||
|
||||
sudo apt-get update
|
||||
|
||||
sudo apt-get -y install jq curl
|
||||
sudo apt-get -y install jq curl wget
|
||||
|
||||
tag=`curl -sL https://api.github.com/repos/hahahrfool/v2ray_simple/releases/latest | jq -r ".tag_name"`
|
||||
|
||||
@@ -45,7 +45,7 @@ sudo cp examples/vlesss.server.toml server.toml
|
||||
然后修改 `/usr/local/etc/verysimple/server.toml` ,使配置达到你想要的效果,注意里面证书路径要改为完整路径
|
||||
|
||||
|
||||
## 第二部,证书部分
|
||||
## 第二步,证书部分
|
||||
|
||||
如果你没有证书,想要先用自签名证书试试,可以运行 `verysimple -i` 进入交互模式,然后根据提示自行生成自签名ssl证书
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ port = 12345
|
||||
protocol = "vlesss"
|
||||
uuid = "a684455c-b14f-11ea-bf0d-42010aaa0003"
|
||||
host = "127.0.0.1"
|
||||
port = 4434
|
||||
port = 4433
|
||||
version = 0
|
||||
insecure = true
|
||||
utls = true
|
||||
|
||||
2
main.go
2
main.go
@@ -1075,7 +1075,7 @@ func passToOutClient(iics incomingInserverConnState, isfallback bool, wlc net.Co
|
||||
|
||||
//实测 grpc.Conn 被调用了Close 也不会实际关闭连接,而是会卡住,阻塞,直到底层tcp连接被关闭后才会返回
|
||||
// 但是我们还是 直接避免这种情况
|
||||
if !inServer.IsMux() {
|
||||
if inServer != nil && !inServer.IsMux() {
|
||||
iics.shouldCloseInSerBaseConnWhenFinish = true
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package netLayer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/hahahrfool/v2ray_simple/utils"
|
||||
@@ -131,3 +133,24 @@ func ListenAndAccept(network, addr string, sockopt *Sockopt, acceptFunc func(net
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (addr Addr) ListenUDP_withOpt(sockopt *Sockopt) (net.PacketConn, error) {
|
||||
var lc net.ListenConfig
|
||||
lc.Control = func(network, address string, c syscall.RawConn) error {
|
||||
return c.Control(func(fd uintptr) {
|
||||
if sockopt != nil {
|
||||
|
||||
if sockopt.Somark != 0 {
|
||||
SetSomark(int(fd), sockopt.Somark)
|
||||
}
|
||||
|
||||
if sockopt.TProxy {
|
||||
SetTproxy(int(fd))
|
||||
SetTproxy_udp(int(fd))
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
return lc.ListenPacket(context.Background(), "udp", addr.String())
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@ func SetTproxy(fd int) error {
|
||||
return syscall.SetsockoptInt(fd, syscall.SOL_IP, syscall.IP_TRANSPARENT, 1)
|
||||
}
|
||||
|
||||
func SetTproxy_udp(fd int) error {
|
||||
return syscall.SetsockoptInt(fd, syscall.SOL_IP, syscall.IP_RECVORIGDSTADDR, 1)
|
||||
}
|
||||
|
||||
func SetSomark(fd int, somark int) error {
|
||||
return syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_MARK, somark)
|
||||
}
|
||||
|
||||
@@ -22,3 +22,6 @@ func SetTproxy(fd int) error {
|
||||
func SetSomark(fd int, somark int) error {
|
||||
return nil
|
||||
}
|
||||
func SetTproxy_udp(fd int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func listenTproxy(addr string) {
|
||||
utils.Info("Start running Tproxy ")
|
||||
utils.Info("Start running Tproxy")
|
||||
|
||||
ad, err := netLayer.NewAddr(addr)
|
||||
if err != nil {
|
||||
@@ -43,7 +43,8 @@ func (tp TProxy) StartLoopTCP() {
|
||||
}
|
||||
|
||||
passToOutClient(incomingInserverConnState{
|
||||
wrappedConn: tcpconn,
|
||||
wrappedConn: tcpconn,
|
||||
defaultClient: defaultOutClient,
|
||||
}, false, tcpconn, nil, targetAddr)
|
||||
})
|
||||
|
||||
@@ -52,7 +53,7 @@ func (tp TProxy) StartLoopTCP() {
|
||||
func (tp TProxy) StartLoopUDP() {
|
||||
ad := netLayer.Addr(tp)
|
||||
ad.Network = "udp"
|
||||
conn, err := ad.DialWithOpt(&netLayer.Sockopt{TProxy: true})
|
||||
conn, err := ad.ListenUDP_withOpt(&netLayer.Sockopt{TProxy: true})
|
||||
if err != nil {
|
||||
if ce := utils.CanLogErr("TProxy StartLoopUDP DialWithOpt failed"); ce != nil {
|
||||
ce.Write(zap.Error(err))
|
||||
@@ -73,6 +74,8 @@ func (tp TProxy) StartLoopUDP() {
|
||||
}
|
||||
}
|
||||
|
||||
go passToOutClient(incomingInserverConnState{}, false, nil, msgConn, raddr)
|
||||
go passToOutClient(incomingInserverConnState{
|
||||
defaultClient: defaultOutClient,
|
||||
}, false, nil, msgConn, raddr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user