OpenWRT 交叉编译 traceroute

OpenWRT 交叉编译 traceroute

最近 (2014.10)需要在路由器上运行完整版的 traceroute (路由器自带的 traceroute 是精简版, 不支持很多功能, 如 --fwmark= 设置 icmp 包标记), 于是自己编译.

下载对应路由器架构 OpenWrt toolchain 最新版 (brcm47xx 最新版 OpenWrt toolchain), 设置相应的环境变量 (参考 OpenWrt cross compile 文档)

下载 traceroute 源代码: http://sourceforge.net/projects/traceroute/

解压缩, 修改 Make.rules, 搜索含有 "CROSS" 和 "LDFLAGS" 的两行, 改成下面的:

$(call set, CROSS, mipsel-openwrt-linux-uclibc-)
$(call set, LDFLAGS, -s -L../libsupp)

然后 make 即可. 生成的 bin 位于 traceroute/traceroute

PS. 编译完后放到路由器上运行出错, 上网搜索下找到了解决方法:

# traceroute 10.0.0.1
10.0.0.1: Bad value for ai_flags
Cannot handle "host" cmdline arg `10.0.0.1' on position 1 (argc 1)

# traceroute www.yahoo.com
www.yahoo.com: Bad value for ai_flags
Cannot handle "host" cmdline arg `www.yahoo.com' on position 1 (argc 1)

The solution was simply to comment out the line that sets ai_flags to
AI_IDN.  Here is the patch:

diff -Naur traceroute-2.0.12.org/traceroute/traceroute.c
traceroute-2.0.12/traceroute/traceroute.c
--- traceroute-2.0.12.org/traceroute/traceroute.c       2008-09-17
07:30:22.000000000 -0600
+++ traceroute-2.0.12/traceroute/traceroute.c   2010-06-14
20:32:19.000000000 -0600
@@ -176,7 +176,6 @@

PS2. linux 的 ping 和 traceroute 工具都可以设置 mark 标记 (用于 ip rule 做策略路由)

ping -m 0xa 8.8.8.8
traceroute --fwmark=0xa 8.8.8.8

但是 mtr 好像不支持 mark 标记, 文档里没找到相应参数.


comments powered by Disqus