Blame | Last modification | View Log | RSS feed
#! /bin/bash## adds static routes which go through device $1if [ -z "$1" ]; thenecho $"usage: ifup-routes <net-device> [<nickname>]"exit 1fiMATCH='^[[:space:]]*(\#.*)?$'handle_file () {. $1routenum=0while [ "x$(eval echo '$'ADDRESS$routenum)x" != "xx" ]; doeval $(ipcalc -p $(eval echo '$'ADDRESS$routenum) $(eval echo '$'NETMASK$routenum))line="$(eval echo '$'ADDRESS$routenum)/$PREFIX"if [ "x$(eval echo '$'GATEWAY$routenum)x" != "xx" ]; thenline="$line via $(eval echo '$'GATEWAY$routenum)"filine="$line dev $2"/sbin/ip route add $lineroutenum=$(($routenum+1))done}handle_ip_file() {local f t type= file=$1 proto="-4"f=${file##*/}t=${f%%-*}type=${t%%6}if [ "$type" != "$t" ]; thenproto="-6"fi{ cat "$file" ; echo ; } | while read line; doif [[ ! "$line" =~ $MATCH ]]; then/sbin/ip $proto $type add $linefidone}FILES="/etc/sysconfig/network-scripts/route-$1 /etc/sysconfig/network-scripts/route6-$1"if [ -n "$2" -a "$2" != "$1" ]; thenFILES="$FILES /etc/sysconfig/network-scripts/route-$2 /etc/sysconfig/network-scripts/route6-$2"fifor file in $FILES; doif [ -f "$file" ]; thenif egrep -q '^[[:space:]]*ADDRESS[0-9]+=' $file ; then# new formathandle_file $file ${1%:*}else# older formathandle_ip_file $filefifidone# Red Hat network configuration formatNICK=${2:-$1}CONFIG="/etc/sysconfig/network-scripts/$NICK.route"[ -f $CONFIG ] && handle_file $CONFIG $1# Routing rulesFILES="/etc/sysconfig/network-scripts/rule-$1 /etc/sysconfig/network-scripts/rule6-$1"if [ -n "$2" -a "$2" != "$1" ]; thenFILES="$FILES /etc/sysconfig/network-scripts/rule-$2 /etc/sysconfig/network-scripts/rule6-$2"fifor file in $FILES; doif [ -f "$file" ]; thenhandle_ip_file $filefidone