SagerNet / sing-box

The universal proxy platform
https://sing-box.sagernet.org/
Other
20.03k stars 2.38k forks source link

gRPC(gun-lite) 连接中转服务器时不通过 #168

Closed Gzxhwq closed 2 years ago

Gzxhwq commented 2 years ago

Welcome

Description of the problem

客户端A(out: gRPC) -> 中转服务器B(in:gRPC / out:任意tcp协议)-> 终点服务器C (in:任意tcp协议) 以上情况不通过。

此时把中转服务器B的出口协议更换为udp的协议,就没问题,例如下面这样: 客户端A(out: gRPC) -> 中转服务器B(in:gRPC / out: Hysieria)-> 终点服务器C (in:Hysieria)

附注: 1、与gRPC内层包裹的协议无关,经测试trojan和vmess均会在中转服务器B产生invalid argument错误 2、没有编译标准gRPC,不确定使用标准gRPC是否有此异常。

Version of sing-box

```console $ sing-box version sing-box version v1.1-beta10 Environment: go1.19.2 linux/amd64 Tags: with_quic,with_wireguard,with_utls,with_acme,with_clash_api Revision: 7e0958b4ac57f972d0f8baf9ea1cf670bdae576f CGO: disabled ```

Server and client configuration file

客户端A

```json { "dns": { "servers": [ { "tag": "google", "address": "tls://8.8.8.8" }, { "tag": "local", "address": "tls://1.12.12.12", "detour": "direct" } ], "rules": [ { "domain": "mydomain.com", "geosite": "cn", "server": "local" } ], "strategy": "ipv4_only" }, "inbounds": [ { "type": "tun", "inet4_address": "172.19.0.1/30", "auto_route": true, "endpoint_independent_nat": true, "stack": "system", "sniff": true } ], "outbounds": [ { "type": "trojan", "tag": "TR-GRPC-out", "server": "***.***.***.***", "server_port": 12345, "password": "*****", "transport": { "type": "grpc", "service_name": "*****" }, "tls": { "enabled": true, "server_name": "**********" } }, { "type": "direct", "tag": "direct" }, { "type": "block", "tag": "block" }, { "type": "dns", "tag": "dns-out" } ], "route": { "rules": [ { "protocol": "dns", "outbound": "dns-out" }, { "geosite": "category-ads-all", "outbound": "block" }, { "geosite": "cn", "geoip": [ "cn", "private" ], "outbound": "direct" }, { "protocol": "quic", "outbound": "block" } ], "auto_detect_interface": true } } ```

中转服务器B

```json { "inbounds": [ { "type": "trojan", "listen": "::", "listen_port": 12345, "proxy_protocol": false, "users": [ { "name": "TEST", "password": "*********" } ], "tls": { "enabled": true, "server_name": "***********", "alpn": [ "http/1.1", "h2" ], "min_version": "1.2", "max_version": "1.3", "certificate_path": "******.crt", "key_path": "*****.key" }, "transport": { "type": "grpc", "service_name": "********" } } ], "outbounds": [ { "type": "vmess", "tag": "VMESS-out", "server": "**********", "server_port": 54321, "uuid": "**********", "security": "auto", "alter_id": 0, "global_padding": false, "authenticated_length": true, "packet_encoding": "xudp" }, { "type": "hysteria", "tag": "HY-out", "server": "**********", "server_port": 55555, "up_mbps": 35, "down_mbps": 35, "obfs": "*****", "auth_str": "*****", "tls": { "enabled": true, "disable_sni": true, "server_name": "****************", "alpn": [ "h3" ] } } ] } ```

Server and client log file

客户端A上日志无异常

中转服务器B上日志有异常

``` +0000 2022-10-20 01:56:18 INFO inbound/trojan[0]: tcp server started at [::]:12345 +0000 2022-10-20 01:56:18 INFO sing-box started (0.00s) +0000 2022-10-20 01:56:24 INFO [2503396838] inbound/trojan[0]: inbound connection from **********:52792 +0000 2022-10-20 01:56:24 INFO [2767936057] inbound/trojan[0]: [TEST] inbound connection to 172.67.75.172:80 +0000 2022-10-20 01:56:24 INFO [2767936057] outbound/vmess[VMESS-out]: outbound connection to 172.67.75.172:80 +0000 2022-10-20 01:56:24 ERROR [2503396838] inbound/trojan[0]: process connection from **********:52792: invalid argument +0000 2022-10-20 01:56:27 INFO [4114087625] inbound/trojan[0]: inbound connection from **********:52792 +0000 2022-10-20 01:56:27 INFO [1209777204] inbound/trojan[0]: [TEST] inbound connection to 172.67.75.172:80 +0000 2022-10-20 01:56:27 INFO [1209777204] outbound/vmess[VMESS-out]: outbound connection to 172.67.75.172:80 +0000 2022-10-20 01:56:27 ERROR [4114087625] inbound/trojan[0]: process connection from **********:52792: invalid argument +0000 2022-10-20 01:56:27 INFO [76375507] inbound/trojan[0]: inbound connection from **********:52792 +0000 2022-10-20 01:56:27 INFO [787955418] inbound/trojan[0]: [TEST] inbound connection to 172.67.75.172:80 +0000 2022-10-20 01:56:27 INFO [787955418] outbound/vmess[VMESS-out]: outbound connection to 172.67.75.172:80 +0000 2022-10-20 01:56:27 ERROR [76375507] inbound/trojan[0]: process connection from **********:52792: invalid argument ```
nekohasekai commented 2 years ago

Try 95c03c9373d84977f2c99d60cf6b7f8a16a743a8

Gzxhwq commented 2 years ago

Fixed. https://github.com/SagerNet/sing-box/commit/95c03c9373d84977f2c99d60cf6b7f8a16a743a8