diff options
Diffstat (limited to 'main/busybox-initscripts/default.script')
-rw-r--r-- | main/busybox-initscripts/default.script | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/main/busybox-initscripts/default.script b/main/busybox-initscripts/default.script index c6cfbc5be1..5447080ec9 100644 --- a/main/busybox-initscripts/default.script +++ b/main/busybox-initscripts/default.script @@ -34,16 +34,35 @@ deconfig() { ip addr flush dev $interface } +is_wifi() { + test -e /sys/class/net/$interface/phy80211 +} + +if_index() { + cat /sys/class/net/$interface/ifindex +} + +calc_metric() { + local base= + if is_wifi; then + base=300 + else + base=200 + fi + echo $(( $base + $(if_index) )) +} + routes() { [ -z "$router" ] && return - local gw metric + local gw= num= while ip route del default via dev $interface 2>/dev/null; do : done - metric=0 + num=0 for gw in $router; do - route add default gw $gw dev $interface metric $metric - metric=$(( $metric + 1 )) + ip route add 0.0.0.0/0 via $gw dev $interface \ + metric $(( $num + ${IF_METRIC:-$(calc_metric)} )) + num=$(( $num + 1 )) done } |