--- rc-scripts-1.6.14.orig/lib/rcscripts/net.modules.d/helpers.d/udhcpc-iproute2 2006-03-21 17:40:09.528606500 +0300 +++ rc-scripts-1.6.14/lib/rcscripts/net.modules.d/helpers.d/udhcpc-iproute2 2006-03-21 18:31:19.872491000 +0300 @@ -62,14 +62,50 @@ eval dhcp=\" \$\{dhcp_${interface}\} \" if [[ ${dhcp} != *' nogateway '* ]]; then # Configure our default route - x=$(ip route show | awk '{ if ($1 == "default") {print $3} }') for r in ${router}; do # We can only have one default route! - if [[ -z ${x} ]]; then - ip route add default via ${r} dev ${interface} 2>/dev/null && break - elif [[ ${x} != ${r} ]]; then - ip route change default via ${r} dev ${interface} 2>/dev/null && break - fi + ip route replace default via ${r} dev ${interface} 2>/dev/null && break + done +fi + +# Configure static routes +if [[ "${cidrroute}" ]]; then + cidrroute="${cidrroute} " + # Work while cidrroute not empty + while true; do + # First go number of bits in mask + bits=${cidrroute%% *} + [[ -z ${bits} ]] && break + cidrroute=${cidrroute#* } + pref="" + if [[ ${bits} == 0 ]]; then + # We got 0/0 here + pref="default" + else + # Calc how many bytes we need to get from cidrroute + # And get them in prefix + bytes=$(( (${bits} - 1) / 8 + 1 )) + while [[ ${bytes} > 0 ]]; do + byte=${cidrroute%% *} + cidrroute=${cidrroute#* } + pref="${pref}.${byte}" + bytes=$(( ${bytes} - 1 )) + done + pref=${pref#.} + pref="${pref}/${bits}" + fi + # We have subnet prefix now and need to get gateway same way + bytes=4 + gw="" + while [[ ${bytes} > 0 ]]; do + byte=${cidrroute%% *} + cidrroute=${cidrroute#* } + gw="${gw}.${byte}" + bytes=$(( ${bytes} - 1 )) + done + gw=${gw#.} + # And add the next route finally + ip route replace ${pref} via ${gw} dev ${interface} 2>/dev/null done fi