fix openwrt network script bug

On my router there are some interfaces in /etc/config/network. The wan interface is configured as a PPPOE netowrk to connect my ISP. There is also a pptp-vpn connected named zvpn. I found it is very slow to run “/etc/init.d/network reload”, taking about 2 miniutes. If I comment out the zvpn interface, it runs fast.

Obviously, the vpn connection depends on my main connection — the wan interface which works in PPPOE mode. So this should be the key point. I spent many hours before to find how to config the dependency, including asking this question in the openwrt forum, but with no luck.  Today I wrote some debug statements in the network scripts and almost brick my router to find what is wrong, finaly I got it.

I thought it is because the vpn interface is inited before wan, so I named my vpn interface as zvpn to make it as the last one,  but I’m wrong.  I don’t need to care its name.  The network scripts load each interface in the order of what it is in the configration file — /etc/config/network. However, there is a problem: the network scripts also unload each interface in this order.

We know, the unload order should be the reverse of the load order. This can be changed by patch /sbin/ifdown.

This is the patch:

--- /rom/sbin/ifdown        2012-01-21 22:21:29.000000000 +0800
+++ ifdown      2012-01-23 17:23:46.000000000 +0800
@@ -7,10 +7,17 @@
 case "$1" in
        "-a")
                [ -e "/tmp/resolv.conf.auto" ] && rm /tmp/resolv.conf.auto
+               TODO=
                config_cb() {
-                       [ interface != "$1" -o -z "$2" ] || eval "$0 -w $2"
+                       [ interface != "$1" -o -z "$2" ] || TODO="$2 $TODO"
                }
                config_load network
+               for i in $TODO ; do
+                       $0 -w $i
+               done
                exit 0
        ;;
        "-w") shift ;;

Openwrt has a recovery mode that helps me to unbrick my router after I made some bad modifications to the config files. To enter this mode, power off the router, hold reset button, power on, keep holding reset button until 192.168.1.1 replying ping requests. Then just telnet 192.168.1.1, mount -t jffs2 /dev/mtdblock3 /overlay/, and fix problems there.

此条目发表在linux分类目录,贴了标签。将固定链接加入收藏夹。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

*