From: Saverio Proto Date: Tue, 19 Feb 2013 17:01:38 +0000 (+0000) Subject: [packages] olsrd: init: cleanup an expensive/forky call X-Git-Url: http://git.openwrt.org/?p=feed%2Frouting.git;a=commitdiff_plain;h=cfa9769cd6775b9ae961f91b1a8b53d996209288;hp=cb75e9bf4c44cd54be79afd7a396fcbfe30a432a [packages] olsrd: init: cleanup an expensive/forky call for determining all gateways in all routing tables 1) write out the ip-call, never ever abbreviate in scripts 2) avoid forks: sorting/uniq is not needed, if we only append yet unappended words 3) use an extra function() for this, better readable 4) check for installed ip-command Signed-off-by: Bastian Bittorf git-svn-id: svn://svn.openwrt.org/openwrt/packages/net/olsrd@35680 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- diff --git a/files/olsrd.init b/files/olsrd.init index 6d08b69..18cd42f 100644 --- a/files/olsrd.init +++ b/files/olsrd.init @@ -558,6 +558,37 @@ olsrd_write_config() { return 0 } +get_wan_ifnames() +{ + local wanifnames word catch_next + + which ip >/dev/null || return 1 + + set -- $( ip route list exact 0.0.0.0/0 table all ) + for word in $*; do + case "$word" in + dev) + catch_next="true" + ;; + *) + [ -n "$catch_next" ] && { + case "$wanifnames" in + *" $word "*) + ;; + *) + wanifnames="$wanifnames $word " + ;; + esac + + catch_next= + } + ;; + esac + done + + echo "$wanifnames" +} + olsrd_setup_smartgw_rules() { local funcname="olsrd_setup_smartgw_rules" # Check if ipip is installed @@ -566,10 +597,12 @@ olsrd_setup_smartgw_rules() { return 1 } - wanifnames=$(ip r l e 0/0 t all | sed -e 's/^.* dev //' |cut -d " " -f 1 | sort | uniq) - nowan=0 + local wanifnames="$( get_wan_ifnames )" + if [ -z "$wanifnames" ]; then nowan=1 + else + nowan=0 fi IP4T=$(which iptables)