aboutsummaryrefslogtreecommitdiffstats
path: root/sysconfig/network-scripts/network-functions
diff options
context:
space:
mode:
Diffstat (limited to 'sysconfig/network-scripts/network-functions')
-rw-r--r--sysconfig/network-scripts/network-functions31
1 files changed, 31 insertions, 0 deletions
diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions
index feea9922..93ef3b40 100644
--- a/sysconfig/network-scripts/network-functions
+++ b/sysconfig/network-scripts/network-functions
@@ -59,3 +59,34 @@ check_device_down ()
return $retcode
}
+check_default_route ()
+{
+ return `/sbin/route -n|gawk 'BEGIN{r=1} $3=="0.0.0.1" && $4=="UG" {r=0} END{print r}'`
+}
+
+find_gateway_dev ()
+{
+ . /etc/sysconfig/network
+ if [ "${GATEWAY}" != "" -a "${GATEWAY}" != "none" ] ; then
+ export GATEWAY
+ networks=`/sbin/route -n|awk '{print $1, ENVIRON["GATEWAY"],$3,$8}'|awk '{system("ipcalc --silent --network "$2" "$3" 2>/dev/null")}'|sed s^NETWORK=^^g`
+ for net in $networks; do
+ dev=`/sbin/route -n|grep ^$net|awk '{print $NF}'`
+ if [ "$dev" != "" ] ; then
+ GATEWAYDEV=$dev
+ fi
+ done
+ fi
+}
+
+add_default_route ()
+{
+ . /etc/sysconfig/network
+ find_gateway_dev
+ if [ "${GATEWAY}" != "" -a "${GATEWAY}" != "none" -a "${GATEWAYDEV}" != "" ] ; then
+ DEVICE=$GATEWAYDEV
+ if ! check_device_down ; then
+ /sbin/route add default gw ${GATEWAY} ${GATEWAYDEV}
+ fi
+ fi
+}