Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--dev 参数 无效的问题 #266

Open
someonebw opened this issue Oct 16, 2024 · 5 comments
Open

--dev 参数 无效的问题 #266

someonebw opened this issue Oct 16, 2024 · 5 comments

Comments

@someonebw
Copy link

本项目是基于Linux/macOS的,请确认您遇到的问题是否在Linux或macOS上存在。

Openwrt
Linux F85E3C5FA22C 5.4.255 #0 SMP Fri May 17 11:49:10 2024 aarch64 GNU/Linux
2 个wan的出口 usb0(默认)usb1(第2个出口)

usb0 Link encap:Ethernet HWaddr 1E:98:AB:E2:28:23
inet addr:192.168.42.2 Bcast:192.168.42.255 Mask:255.255.255.0
inet6 addr: fe80::1c98:abff:fee2:2823/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2042419 errors:0 dropped:967 overruns:0 frame:0
TX packets:1271530 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2305110354 (2.1 GiB) TX bytes:465878851 (444.2 MiB)

usb1 Link encap:Ethernet HWaddr 32:29:A9:42:A6:A6
inet addr:192.168.52.2 Bcast:192.168.52.255 Mask:255.255.255.0
inet6 addr: fe80::3029:a9ff:fe42:a6a6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2559603 errors:0 dropped:0 overruns:0 frame:0
TX packets:3073517 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2836038976 (2.6 GiB) TX bytes:2474963081 (2.3 GiB)

root@F85E3C5FA22C:~# ip route
default via 192.168.42.1 dev usb0 proto static src 192.168.42.2 metric 30
default via 192.168.52.1 dev usb1 proto static src 192.168.52.2 metric 40
192.168.42.0/24 dev usb0 proto static scope link metric 30
192.168.48.0/24 dev br-lan proto kernel scope link src 192.168.48.1
192.168.52.0/24 dev usb1 proto static scope link metric 40

你正在使用哪个版本的 nexttrace?

NextTrace v1.3.5 2024-10-16T03:16:40Z 4ae9d8e
linux_arm64的版本

你看到的异常现象是什么?

没有走指定的网卡usb1,走的默认网卡usb0(192.168.42.1)

你期待看到的正常表现是怎样的?

走usb1网卡(192.168.52.1)

请附上你的命令

./nexttrace_linux_arm64 -d ipinfo 223.5.5.5 --dev usb1
root@F85E3C5FA22C:~# ./nexttrace_linux_arm64 -d ipinfo 223.5.5.5 --dev usb1
NextTrace v1.3.5 2024-10-16T03:16:40Z 4ae9d8e
IP Geo Data Provider: ipinfo
traceroute to 223.5.5.5, 30 hops max, 52 bytes payload
1 192.168.42.1 * RFC1918
2.97 ms / 3.10 ms / 2.31 ms
2 192.168.30.254 * RFC1918
30.16 ms / 25.09 ms / 25.16 ms
3 10.3.0.17 * RFC1918
24.01 ms / 25.53 ms / 24.73 ms
4 *
5 *
6 124.73.164.29 AS4134 China Shanghai Shanghai CHINANET-BACKBONE
29.164.73.124.broad.dynamic.hf.ah.cndata.com 80.11 ms / 71.03 ms / * ms
7 *
8 *
9 *
10 *
11 *
12 116.251.116.93 AS45102 China Shanghai Shanghai Alibaba (US) Technology Co., Ltd.
33.10 ms / 37.73 ms / 32.58 ms
13 *
14 *
15 223.5.5.5 AS45102 ANYCAST ANYCAST Alibaba (US) Technology Co., Ltd.
public1.alidns.com 36.43 ms / 40.46 ms / 35.27 ms
MapTrace URL: https://assets.nxtrace.org/tracemap/5cde2dd2-abdc-5f84-9d12-d2ef516a2d6d.html

请附上出错时软件输出的错误信息

是否查询过本仓库wiki有没有类似错误

是否没有绑定到指定的接口?
是否可用linux下的SO_BINDTODEVICE方式来实现?
之前有用过此软件,改版后,实现了对interface的绑定。
//供参考。
MagnaboscoL/speedtest-cli@1651a82

@tsosunchia
Copy link
Member

我刚刚测试了一下,v1.3.5 版本的--dev参数在Linux下工作是正常的。

Linux 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

@tsosunchia
Copy link
Member

建议检查您本地策略路由设置

@someonebw
Copy link
Author

@tsosunchia tsosunchia
感谢你的解答

################
因为路由器是openwrt,用到了mwan3的策略路由管理。
usb0是主出口,usb1是备出口。

是不是--dev用到的模式,在此场景下,不够可靠?
建议:针对linux环境下,是否可用更可靠的方式,例如:socket option SO_BINDTODEVICE 来实现对interface的bind?

之前此环境,也用到了librespeed的工具,之前也是不支持此类型的环境,bind address的方式也是不行,后来我找到一个改版的版本。用到了SO_BINDTODEVICE ,就支持对接口的bind了,优先级,高于策略路由。
似乎此做法,适应更多的场景。意见供参考。
//供参考。
MagnaboscoL/speedtest-cli@1651a82

#策略路由相关的情况。
Software-Version

OpenWrt - ImmortalWrt 21.02-SNAPSHOT r20548-7bedfa1424
LuCI - git-23.098.38725-847bd6b

Output of "ip a show"

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 7a:56:ef:44:32:ab brd ff:ff:ff:ff:ff:ff
inet6 fe80::7856:efff:fe44:32ab/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
link/ether f8:5e:3c:5f:a2:2d brd ff:ff:ff:ff:ff:ff
4: lan1@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br-lan state LOWERLAYERDOWN group default qlen 1000
link/ether f8:5e:3c:5f:a2:2c brd ff:ff:ff:ff:ff:ff
5: lan2@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br-lan state LOWERLAYERDOWN group default qlen 1000
link/ether f8:5e:3c:5f:a2:2c brd ff:ff:ff:ff:ff:ff
6: lan3@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br-lan state LOWERLAYERDOWN group default qlen 1000
link/ether f8:5e:3c:5f:a2:2c brd ff:ff:ff:ff:ff:ff
7: lan4@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br-lan state LOWERLAYERDOWN group default qlen 1000
link/ether f8:5e:3c:5f:a2:2c brd ff:ff:ff:ff:ff:ff
8: sit0@NONE: mtu 1480 qdisc noop state DOWN group default qlen 1000
link/sit 0.0.0.0 brd 0.0.0.0
9: ra0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br-lan state UNKNOWN group default qlen 1000
link/ether f8:5e:3c:5f:a2:2d brd ff:ff:ff:ff:ff:ff
10: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 1e:98:ab:e2:28:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.42.2/24 brd 192.168.42.255 scope global usb0
valid_lft forever preferred_lft forever
inet6 fe80::1c98:abff:fee2:2823/64 scope link
valid_lft forever preferred_lft forever
11: br-lan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether f8:5e:3c:5f:a2:2c brd ff:ff:ff:ff:ff:ff
inet 192.168.48.1/24 brd 192.168.48.255 scope global br-lan
valid_lft forever preferred_lft forever
inet6 fe80::fa5e:3cff:fe5f:a22c/64 scope link
valid_lft forever preferred_lft forever
12: rax0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br-lan state UNKNOWN group default qlen 1000
link/ether f8:5e:3c:5f:a2:2e brd ff:ff:ff:ff:ff:ff
13: apcli0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether fe:5e:3c:5f:a2:2d brd ff:ff:ff:ff:ff:ff
14: apclix0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether f2:5e:3c:5f:a2:2d brd ff:ff:ff:ff:ff:ff
17: usb1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 32:29:a9:42:a6:a6 brd ff:ff:ff:ff:ff:ff
inet 192.168.52.2/24 brd 192.168.52.255 scope global usb1
valid_lft forever preferred_lft forever
inet6 fe80::3029:a9ff:fe42:a6a6/64 scope link
valid_lft forever preferred_lft forever

Output of "ip route show"

default via 192.168.42.1 dev usb0 proto static src 192.168.42.2 metric 30
default via 192.168.52.1 dev usb1 proto static src 192.168.52.2 metric 40
192.168.42.0/24 dev usb0 proto static scope link metric 30
192.168.48.0/24 dev br-lan proto kernel scope link src 192.168.48.1
192.168.52.0/24 dev usb1 proto static scope link metric 40

Output of "ip rule show"

0: from all lookup local
1002: from all iif usb0 lookup 2
1003: from all iif usb1 lookup 3
2002: from all fwmark 0x200/0x3f00 lookup 2
2003: from all fwmark 0x300/0x3f00 lookup 3
2061: from all fwmark 0x3d00/0x3f00 blackhole
2062: from all fwmark 0x3e00/0x3f00 unreachable
32766: from all lookup main
32767: from all lookup default

Output of "ip route list table 1-250"

Table 2: default via 192.168.42.1 dev usb0 metric 30
192.168.42.0/24 dev usb0 proto static scope link metric 30
192.168.48.0/24 dev br-lan proto kernel scope link src 192.168.48.1
192.168.52.0/24 dev usb1 proto static scope link metric 40
Table 3: default via 192.168.52.1 dev usb1 metric 40
192.168.42.0/24 dev usb0 proto static scope link metric 30
192.168.48.0/24 dev br-lan proto kernel scope link src 192.168.48.1
192.168.52.0/24 dev usb1 proto static scope link metric 40

Output of "iptables -L -t mangle -v -n"

Chain PREROUTING (policy ACCEPT 614K packets, 306M bytes)
pkts bytes target prot opt in out source destination
5382K 5581M mwan3_hook all -- * * 0.0.0.0/0 0.0.0.0/0

Chain INPUT (policy ACCEPT 614K packets, 306M bytes)
pkts bytes target prot opt in out source destination

Chain FORWARD (policy ACCEPT 4 packets, 264 bytes)
pkts bytes target prot opt in out source destination
0 0 TCPMSS tcp -- * eth1 0.0.0.0/0 0.0.0.0/0 tcp flags:0x06/0x02 /* !fw3: Zone wan MTU fixing / TCPMSS clamp to PMTU
0 0 TCPMSS tcp -- eth1 * 0.0.0.0/0 0.0.0.0/0 tcp flags:0x06/0x02 /
!fw3: Zone wan MTU fixing / TCPMSS clamp to PMTU
0 0 TCPMSS tcp -- * usb0 0.0.0.0/0 0.0.0.0/0 tcp flags:0x06/0x02 /
!fw3: Zone wan MTU fixing / TCPMSS clamp to PMTU
0 0 TCPMSS tcp -- usb0 * 0.0.0.0/0 0.0.0.0/0 tcp flags:0x06/0x02 /
!fw3: Zone wan MTU fixing / TCPMSS clamp to PMTU
0 0 TCPMSS tcp -- * usb1 0.0.0.0/0 0.0.0.0/0 tcp flags:0x06/0x02 /
!fw3: Zone wan MTU fixing / TCPMSS clamp to PMTU
0 0 TCPMSS tcp -- usb1 * 0.0.0.0/0 0.0.0.0/0 tcp flags:0x06/0x02 /
!fw3: Zone wan MTU fixing */ TCPMSS clamp to PMTU

Chain OUTPUT (policy ACCEPT 657K packets, 154M bytes)
pkts bytes target prot opt in out source destination
3856K 3302M mwan3_hook all -- * * 0.0.0.0/0 0.0.0.0/0

Chain POSTROUTING (policy ACCEPT 657K packets, 154M bytes)
pkts bytes target prot opt in out source destination

Chain mwan3_connected (2 references)
pkts bytes target prot opt in out source destination
4999K 5514M MARK all -- * * 0.0.0.0/0 0.0.0.0/0 match-set mwan3_connected dst MARK or 0x3f00

Chain mwan3_hook (2 references)
pkts bytes target prot opt in out source destination
9238K 8883M CONNMARK all -- * * 0.0.0.0/0 0.0.0.0/0 CONNMARK restore mask 0x3f00
127K 32M mwan3_ifaces_in all -- * * 0.0.0.0/0 0.0.0.0/0 mark match 0x0/0x3f00
110K 8668K mwan3_connected all -- * * 0.0.0.0/0 0.0.0.0/0 mark match 0x0/0x3f00
97708 7875K mwan3_rules all -- * * 0.0.0.0/0 0.0.0.0/0 mark match 0x0/0x3f00
9238K 8883M CONNMARK all -- * * 0.0.0.0/0 0.0.0.0/0 CONNMARK save mask 0x3f00
8271K 8711M mwan3_connected all -- * * 0.0.0.0/0 0.0.0.0/0 mark match ! 0x3f00/0x3f00

Chain mwan3_iface_in_wan_5g1 (1 references)
pkts bytes target prot opt in out source destination
0 0 MARK all -- usb0 * 0.0.0.0/0 0.0.0.0/0 match-set mwan3_connected src mark match 0x0/0x3f00 /* default / MARK or 0x3f00
0 0 MARK all -- usb0 * 0.0.0.0/0 0.0.0.0/0 mark match 0x0/0x3f00 /
wan_5g1 */ MARK xset 0x200/0x3f00

Chain mwan3_iface_in_wan_5g2 (1 references)
pkts bytes target prot opt in out source destination
0 0 MARK all -- usb1 * 0.0.0.0/0 0.0.0.0/0 match-set mwan3_connected src mark match 0x0/0x3f00 /* default / MARK or 0x3f00
1 52 MARK all -- usb1 * 0.0.0.0/0 0.0.0.0/0 mark match 0x0/0x3f00 /
wan_5g2 */ MARK xset 0x300/0x3f00

Chain mwan3_ifaces_in (1 references)
pkts bytes target prot opt in out source destination
92043 16M mwan3_iface_in_wan_5g1 all -- * * 0.0.0.0/0 0.0.0.0/0 mark match 0x0/0x3f00
39675 3133K mwan3_iface_in_wan_5g2 all -- * * 0.0.0.0/0 0.0.0.0/0 mark match 0x0/0x3f00

Chain mwan3_policy_default_poli (1 references)
pkts bytes target prot opt in out source destination
35323 2852K MARK all -- * * 0.0.0.0/0 0.0.0.0/0 mark match 0x0/0x3f00 /* wan_5g1 3 3 */ MARK xset 0x200/0x3f00

Chain mwan3_rules (1 references)
pkts bytes target prot opt in out source destination
35323 2852K mwan3_policy_default_poli all -- * * 0.0.0.0/0 0.0.0.0/0 mark match 0x0/0x3f00

@someonebw
Copy link
Author

使用SO_BINDTODEVICE的时候,好像可以直接bypassing the routing table

@someonebw
Copy link
Author

traceroute 的bind interface 就是SO_BINDTODEVICE模式的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants