Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

trojan客户端传输 udp +ipv6 数据时报错 #136

Closed
qiuzi opened this issue Aug 14, 2022 · 28 comments
Closed

trojan客户端传输 udp +ipv6 数据时报错 #136

qiuzi opened this issue Aug 14, 2022 · 28 comments
Assignees
Labels
bug Something isn't working

Comments

@qiuzi
Copy link

qiuzi commented Aug 14, 2022

不管使用socks5或tproxy模式经过的ipv6地址都是错误
socks5: udp://%5B2404:6800:4009:82b::200a%5D:443
tproxy: ERROR TProxy startLoopUDP loop read failed {"error": "unable to obtain original destination: %!s()"}

@qiuzi qiuzi added the bug Something isn't working label Aug 14, 2022
@Leao9203
Copy link

试过在 IPv6 地址前后加上 [] 吗?

@qiuzi
Copy link
Author

qiuzi commented Aug 22, 2022

@Leao9203 使用的是ip2socks方式对接的 主要是UDP全部出问题

@e1732a364fed
Copy link
Owner

收到。

@e1732a364fed
Copy link
Owner

e1732a364fed commented Sep 13, 2022

你这个百分号是怎么出现的?可能不是vs这里的问题。建议手动测试一下,不使用ip2socks

@e1732a364fed e1732a364fed removed the bug Something isn't working label Sep 13, 2022
@e1732a364fed e1732a364fed changed the title [Bug] 代理ipv6地址错误 使用ip2socks 代理ipv6地址错误 Sep 13, 2022
@e1732a364fed
Copy link
Owner

https://github.com/FlowerWrong/ip2socks/blob/1f8417bf5f199c12397a5bb9dc9404126bdee68a/README.md

标着,似乎还没支持ipv6,在todo里有,没勾选上。

@qiuzi
Copy link
Author

qiuzi commented Sep 13, 2022

@e1732a364fed 我使用 https://github.com/zfl9/ipt2socks
况且使用tproxy模式的udp 错误怎么处理?

@e1732a364fed
Copy link
Owner

@e1732a364fed 我使用 https://github.com/zfl9/ipt2socks 况且使用tproxy模式的udp 错误怎么处理?

你配置文件和日志发全一些好吗?

@qiuzi
Copy link
Author

qiuzi commented Sep 13, 2022

@e1732a364fed
`[[listen]]
protocol = "socks5"
host = "[::]"
port = 1080

[[listen]]
protocol = "dokodemo"
network = "udp"
host = "127.0.0.1"
port = 5353
target = "udp://8.8.8.8:53"

[[listen]]
protocol = "tproxy"
ip = "[::]"
port = 60080
[[dial]]
protocol = "trojans"
uuid = "xxxzzzxx"
host = "xxxZsss.eu.org"
port = 443
advancedLayer = "grpc"
path = "shop"
sockopt.mark = 720`
在外面日志暂时给不了你

@e1732a364fed
Copy link
Owner

e1732a364fed commented Sep 13, 2022

我看了。

那个 5B 和 5D 实际上就是 ascii 的 []

也就是说,你的上游 把这个中括号也当作 ip的一部分传送过来了,才导致的识别问题。

tproxy 应该没什么ipv6方面的问题的,因为我们这里的代码 trojan-go 也在用。

@qiuzi
Copy link
Author

qiuzi commented Sep 13, 2022

@e1732a364fed 其实我想去掉上游ipt2,trojan-go在tproxy udp的ipv6也同样出现问题 你可以复现一下nft的规则配置

@qiuzi
Copy link
Author

qiuzi commented Sep 13, 2022

https://github.com/heiher/hev-socks5-tproxy
有规则参考

@e1732a364fed
Copy link
Owner

啊,没想到trojan-go也有同样的问题!怪不得。因为我们两个都使用同样的上游代码。

看来需要好好研究一下了。

@e1732a364fed e1732a364fed reopened this Sep 13, 2022
@e1732a364fed
Copy link
Owner

我稍微改动了一下,你用最新代码重新编译试试看看还有没有问题

@qiuzi
Copy link
Author

qiuzi commented Sep 13, 2022

有空我会试试 现在外地

@qiuzi
Copy link
Author

qiuzi commented Sep 15, 2022

@e1732a364fed
2022-09-15 12:48:18.620 ERROR TProxy startLoopUDP loop read failed {"error": "unable to obtain original destination: <nil >"}
nslookup www.youtube.com 2001:4860:4860::8888
使用tproxy模式还是不行

@e1732a364fed
Copy link
Owner

😭

@e1732a364fed
Copy link
Owner

socks5 错误具体是什么错误?vs的完整日志输出是什么?

另外,你只给了udp的情况,tcp呢?

@qiuzi
Copy link
Author

qiuzi commented Dec 2, 2022

tcp正常

@e1732a364fed
Copy link
Owner

客户端和服务端都是用的vs吗,还是只有客户端用的是vs

@qiuzi
Copy link
Author

qiuzi commented Dec 2, 2022

服务端是 https://github.com/XrayR-project/XrayR

@e1732a364fed
Copy link
Owner

有对比过使用v2ray或者xray替换vs吗?

@qiuzi
Copy link
Author

qiuzi commented Dec 2, 2022

客户端换过这两种和trojan全系列都能正常 服务端没法更改,用的他人服务

@qiuzi
Copy link
Author

qiuzi commented Dec 3, 2022

socks5用的是ipt2socks做转换,这个跟服务端没啥关系,貌似是编码方式不兼容

@e1732a364fed
Copy link
Owner

e1732a364fed commented Dec 3, 2022

经过真机测试,ipv6确实存在问题,正在解决当中。

经过测试,udp的ipv4传输没问题,ipv6出错,错误报错在trojan服务端。

报错类似下面:

	ERROR	Failed in reading first udp payload, not because of timeout, will hung up	{"connid": 629766, "target": "[\u0003 ..... ]:1", "error": " [ trojan GetAddrFrom err , Detail: invalid data, Data: 120 ] "}

下面提供测试方案:

用golang编写一个udp发送程序,然后构建三个vs配置,第一个配置为 dokodemo -> socks5
第二个配置为 socks5 -> trojan
第三个配置为 trojan -> direct

同时要有一个ipv6机,用nc监听,比如监听4444端口,命令为 nc -v -u -l 4444

分别记为 “udp发送程序”,v1,v2,v3, ipv6机

udp发送程序给 v1 发送 udp数据,v1通过 dokodemo将该udp数据指定 目标为 ipv6机, 经过socks5 发送到 v2

v2将socks5数据转化成 trojan数据,发送给 v3, v3trojan接受到数据,解析出目标为 ipv6机后,向该 ipv6机发送 “udp发送程序” 逐级传来的 那个数据。

发送程序代码如下,用 go run main.go 执行

package main

import (
	"fmt"
	"net"
	"os"
)

func main() {
	udpServer, err := net.ResolveUDPAddr("udp", "127.0.0.1:63782")

	if err != nil {
		println("ResolveUDPAddr failed:", err.Error())
		os.Exit(1)
	}

	conn, err := net.DialUDP("udp", nil, udpServer)
	if err != nil {
		println("Listen failed:", err.Error())
		os.Exit(1)
	}

	fmt.Println("ready to input")

	defer conn.Close()
	var str string
	for {
		_, err = fmt.Scanln(&str)
		if err != nil {
			println("Scanln failed:", err.Error())
			os.Exit(1)
		}
		conn.Write([]byte(str))
	}

}

不用nc作为数据发送来源,是因为,nc在拨号udp时,会重试多次,而且会预先发送 类似 XXXX 的数据头,这会干扰测试

e1732a364fed added a commit that referenced this issue Dec 3, 2022
这是一个愚蠢的错误,将v2ray类型的定义用在了trojan上
@e1732a364fed e1732a364fed self-assigned this Dec 3, 2022
@e1732a364fed e1732a364fed added the bug Something isn't working label Dec 3, 2022
@e1732a364fed e1732a364fed changed the title 使用ip2socks 代理ipv6地址错误 trojan客户端传输 udp +ipv6 数据时报错 Dec 3, 2022
@e1732a364fed
Copy link
Owner

e1732a364fed commented Dec 3, 2022

你测一下吧,该问题socks5和tproxy无关。是vs的trojan客户端的错误,最新代码已经解决了

@e1732a364fed
Copy link
Owner

e1732a364fed commented Dec 3, 2022

关于tproxy的问题,我新开一个issue, #178

@e1732a364fed
Copy link
Owner

那个tproxy的问题在最新代码应该也解决了,你测一下吧

@qiuzi
Copy link
Author

qiuzi commented Dec 3, 2022

下星期我回家试试 谢谢你的一直维护

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants