aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiloslav Trmac <mitr@volny.cz>2006-05-10 00:08:02 +0000
committerMiloslav Trmac <mitr@volny.cz>2006-05-10 00:08:02 +0000
commit906238c891d3f02b4c706457783694e3a01d91ce (patch)
tree4e2003e9100435d47a727d23dfdcb3f182b987f7
parent3bd074fd404b4863d811d0a50e9ef484523c6b57 (diff)
downloadinitscripts-906238c891d3f02b4c706457783694e3a01d91ce.tar
initscripts-906238c891d3f02b4c706457783694e3a01d91ce.tar.gz
initscripts-906238c891d3f02b4c706457783694e3a01d91ce.tar.bz2
initscripts-906238c891d3f02b4c706457783694e3a01d91ce.tar.xz
initscripts-906238c891d3f02b4c706457783694e3a01d91ce.zip
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.
-rw-r--r--sysconfig.txt2
-rwxr-xr-xsysconfig/network-scripts/ifdown-post6
-rwxr-xr-xsysconfig/network-scripts/ifup-aliases3
-rwxr-xr-xsysconfig/network-scripts/ifup-ctc2
-rwxr-xr-xsysconfig/network-scripts/ifup-eth8
-rwxr-xr-xsysconfig/network-scripts/ifup-ippp6
-rwxr-xr-xsysconfig/network-scripts/ifup-iucv2
-rwxr-xr-xsysconfig/network-scripts/ifup-plip6
-rwxr-xr-xsysconfig/network-scripts/ifup-plusb2
-rwxr-xr-xsysconfig/network-scripts/ifup-ppp8
-rw-r--r--sysconfig/network-scripts/network-functions22
11 files changed, 42 insertions, 25 deletions
diff --git a/sysconfig.txt b/sysconfig.txt
index b02dc53f..ff136580 100644
--- a/sysconfig.txt
+++ b/sysconfig.txt
@@ -503,6 +503,8 @@ Files in /etc/sysconfig/network-scripts/
IPADDR=
NETMASK=
GATEWAY=
+ METRIC=
+ Metric for the default route using GATEWAY
ONBOOT=yes|no
HOTPLUG=yes|no
USERCTL=yes|no
diff --git a/sysconfig/network-scripts/ifdown-post b/sysconfig/network-scripts/ifdown-post
index ed944950..87f28a16 100755
--- a/sysconfig/network-scripts/ifdown-post
+++ b/sysconfig/network-scripts/ifdown-post
@@ -25,9 +25,11 @@ if ! check_default_route ; then
# ISDN device needs special handling dial on demand
if [ "${DEVICETYPE}" = "ippp" -o "${DEVICETYPE}" = "isdn" ] && [ "$DIALMODE" = "auto" ] ; then
if [ -z "$GATEWAY" ] ; then
- /sbin/ip route add default ${WINDOW:+window $WINDOW} dev ${DEVICE}
+ /sbin/ip route add default ${METRIC:+metric} \
+ ${WINDOW:+window $WINDOW} dev ${DEVICE}
else
- /sbin/ip route add default ${WINDOW:+window $WINDOW} via ${GATEWAY}
+ /sbin/ip route add default ${METRIC:+metric} \
+ ${WINDOW:+window $WINDOW} via ${GATEWAY}
fi
else
add_default_route ${DEVICE}
diff --git a/sysconfig/network-scripts/ifup-aliases b/sysconfig/network-scripts/ifup-aliases
index 6ac5d9a0..0d84ec0a 100755
--- a/sysconfig/network-scripts/ifup-aliases
+++ b/sysconfig/network-scripts/ifup-aliases
@@ -300,7 +300,8 @@ function new_interface ()
\( -z "${GATEWAYDEV}" -o "${GATEWAYDEV}" = "${DEVICE}" \) ]; then
# set up default gateway, if it isn't already there
if ! is_default_gateway "$GATEWAY"; then
- route add default gw ${GATEWAY} ${DEVICE}
+ route add default gw ${GATEWAY} \
+ ${METRIC:+metric $METRIC} ${DEVICE}
fi
fi
diff --git a/sysconfig/network-scripts/ifup-ctc b/sysconfig/network-scripts/ifup-ctc
index 193c11b5..547fe094 100755
--- a/sysconfig/network-scripts/ifup-ctc
+++ b/sysconfig/network-scripts/ifup-ctc
@@ -47,7 +47,7 @@ fi
if [ "${GATEWAY}" != "" ]; then
if [ "${GATEWAYDEV}" = "" -o "${GATEWAYDEV}" = "${DEVICE}" ]; then
# set up default gateway
- route add default gw ${GATEWAY}
+ route add default gw ${GATEWAY} ${METRIC:+metric $METRIC}
fi
fi
diff --git a/sysconfig/network-scripts/ifup-eth b/sysconfig/network-scripts/ifup-eth
index 081c3fd1..5d05c171 100755
--- a/sysconfig/network-scripts/ifup-eth
+++ b/sysconfig/network-scripts/ifup-eth
@@ -258,12 +258,14 @@ else
if [ -z "${GATEWAYDEV}" -o "${GATEWAYDEV}" = "${REALDEVICE}" ]; then
# set up default gateway. replace if one already exists
if [ -n "${GATEWAY}" -a "`ipcalc --network ${GATEWAY} ${NETMASK} 2>/dev/null`" = "NETWORK=${NETWORK}" ]; then
- ip route replace default via ${GATEWAY} ${WINDOW:+window $WINDOW} ${SRC} ${GATEWAYDEV:+dev $GATEWAYDEV}
+ ip route replace default ${METRIC:+metric $METRIC} \
+ via ${GATEWAY} ${WINDOW:+window $WINDOW} ${SRC} \
+ ${GATEWAYDEV:+dev $GATEWAYDEV}
elif [ "${GATEWAYDEV}" = "${DEVICE}" ]; then
- ip route replace default ${SRC} ${WINDOW:+window $WINDOW} dev ${REALDEVICE}
+ ip route replace default ${METRIC:+metric $METRIC} \
+ ${SRC} ${WINDOW:+window $WINDOW} dev ${REALDEVICE}
fi
fi
-
fi
# Bonding initialization part II - for static, enslave the devices. For
diff --git a/sysconfig/network-scripts/ifup-ippp b/sysconfig/network-scripts/ifup-ippp
index 0defdeb6..e53cb36a 100755
--- a/sysconfig/network-scripts/ifup-ippp
+++ b/sysconfig/network-scripts/ifup-ippp
@@ -358,9 +358,11 @@ function addprovider()
if [ "$DEFROUTE" = "yes" ] ; then
route del default >/dev/null 2>&1
if [ "$GATEWAY" = "0.0.0.0" ]; then
- route add default $DEVICE >/dev/null 2>&1
+ route add default ${METRIC:+metric $METRIC} $DEVICE \
+ >/dev/null 2>&1
else
- route add default gw $GATEWAY >/dev/null 2>&1
+ route add default gw $GATEWAY ${METRIC:+metric $METRIC} \
+ >/dev/null 2>&1
fi
fi
fi
diff --git a/sysconfig/network-scripts/ifup-iucv b/sysconfig/network-scripts/ifup-iucv
index 1352eba2..645f6761 100755
--- a/sysconfig/network-scripts/ifup-iucv
+++ b/sysconfig/network-scripts/ifup-iucv
@@ -36,7 +36,7 @@ fi
if [ "${GATEWAY}" != "" ]; then
if [ "${GATEWAYDEV}" = "" -o "${GATEWAYDEV}" = "${DEVICE}" ]; then
# set up default gateway
- route add default gw ${GATEWAY}
+ route add default gw ${GATEWAY} ${METRIC:+metric $METRIC}
fi
fi
diff --git a/sysconfig/network-scripts/ifup-plip b/sysconfig/network-scripts/ifup-plip
index c7c6bb88..dc766aa8 100755
--- a/sysconfig/network-scripts/ifup-plip
+++ b/sysconfig/network-scripts/ifup-plip
@@ -14,10 +14,10 @@ fi
ifconfig ${DEVICE} ${IPADDR} pointopoint ${REMIP}
route add -net ${NETWORK} netmask ${NETMASK} ${DEVICE}
-# this is broken! it's only here to keep compatibility with old RH sytstems
+# this is broken! it's only here to keep compatibility with old RH systems
if [ "${GATEWAY}" != "" -a "${GATEWAY}" != "none" ]
then
- route add default gw ${GATEWAY} metric 1 ${DEVICE}
+ route add default gw ${GATEWAY} metric ${METRIC:-1} ${DEVICE}
fi
. /etc/sysconfig/network
@@ -25,7 +25,7 @@ fi
if [ "${GATEWAY}" != "" ]; then
if [ "${GATEWAYDEV}" = "" -o "${GATEWAYDEV}" = "${DEVICE}" ]; then
# set up default gateway
- route add default gw ${GATEWAY}
+ route add default gw ${GATEWAY} ${METRIC:+metric $METRIC}
fi
fi
diff --git a/sysconfig/network-scripts/ifup-plusb b/sysconfig/network-scripts/ifup-plusb
index bec39d97..a31608ab 100755
--- a/sysconfig/network-scripts/ifup-plusb
+++ b/sysconfig/network-scripts/ifup-plusb
@@ -34,7 +34,7 @@ fi
if [ "${GATEWAY}" != "" ]; then
if [ "${GATEWAYDEV}" = "" -o "${GATEWAYDEV}" = "${DEVICE}" ]; then
# set up default gateway
- route add default gw ${GATEWAY}
+ route add default gw ${GATEWAY} ${METRIC:+metric $METRIC}
fi
fi
diff --git a/sysconfig/network-scripts/ifup-ppp b/sysconfig/network-scripts/ifup-ppp
index ef6c81b9..eb749fc4 100755
--- a/sysconfig/network-scripts/ifup-ppp
+++ b/sysconfig/network-scripts/ifup-ppp
@@ -105,9 +105,11 @@ fi
if [ "${DEFROUTE}" != no ] ; then
# pppd will no longer delete an existing default route
# so we have to help it out a little here.
- DEFRT=`ip route list | awk '/^default / { print $3 }'`
- [ -n "${DEFRT}" ] && echo $DEFRT > /etc/default-route
- route del default >/dev/null 2>&1
+ DEFRT=$(ip route list match 0/0)
+ [ -n "${DEFRT}" ] && echo "$DEFRT" > /etc/default-routes
+ echo "$DEFRT" | while read spec; do
+ ip route del $spec;
+ done
opts="$opts defaultroute"
fi
if [ "${PEERDNS}" != no ] ; then
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
}