From 906238c891d3f02b4c706457783694e3a01d91ce Mon Sep 17 00:00:00 2001 From: Miloslav Trmac Date: Wed, 10 May 2006 00:08:02 +0000 Subject: Add METRIC= support for default routes (#124045) * ifup-ppp, network-functions: Save all default routes, lose no data. * network-functions: - (find_gateway_dev): Fix - it should find the device while $GATEWAY is not the default route - (add_default_route): Don't use configuration for the device that is being brought down; document function purpose and bugs. --- sysconfig/network-scripts/network-functions | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'sysconfig/network-scripts/network-functions') diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions index d2372d00..aea5f0c9 100644 --- a/sysconfig/network-scripts/network-functions +++ b/sysconfig/network-scripts/network-functions @@ -314,15 +314,19 @@ find_gateway_dev () { . /etc/sysconfig/network if [ -n "${GATEWAY}" -a "${GATEWAY}" != "none" ] ; then - dev=`LC_ALL=C /sbin/ip route | \ - grep ${GATEWAY} | \ - sed -e 's/.* dev \([:alnum:]*\)/\1/'` + dev=$(LC_ALL=C /sbin/ip route get to "${GATEWAY}" 2>/dev/null | \ + sed -n 's/.* dev \([[:alnum:]]*\) .*/\1/p') if [ -n "$dev" ]; then GATEWAYDEV="$dev" fi fi } +# After the device $1 goes away, restore the standard default route; typically +# used for ppp with DEFROUTE temporarily replacing the "standard" default +# route. +# FIXME: This function doesn't support some newer features (GATEWAY in ifcfg, +# $WINDOW, $METRIC) add_default_route () { . /etc/sysconfig/network @@ -332,14 +336,16 @@ add_default_route () "${GATEWAY}" != "none" ]; then if ! check_device_down $1; then if [ "$GATEWAY" = "0.0.0.0" ]; then - /sbin/ip route add default ${WINDOW:+window $WINDOW} dev ${GATEWAYDEV} + /sbin/ip route add default dev ${GATEWAYDEV} else - /sbin/ip route add default ${WINDOW:+window $WINDOW} via ${GATEWAY} + /sbin/ip route add default via ${GATEWAY} fi fi - elif [ -f /etc/default-route ]; then - /sbin/ip route add default ${WINDOW:+window $WINDOW} via `cat /etc/default-route` - rm -f /etc/default-route + elif [ -f /etc/default-routes ]; then + while read spec; do + /sbin/ip route add $spec + done < /etc/default-routes + rm -f /etc/default-routes fi } -- cgit v1.2.1