| 4 |
- |
1 |
#! /bin/bash
|
|
|
2 |
#
|
|
|
3 |
# adds static routes which go through device $1
|
|
|
4 |
if [ -z "$1" ]; then
|
|
|
5 |
echo $"usage: ifup-routes <net-device> [<nickname>]"
|
|
|
6 |
exit 1
|
|
|
7 |
fi
|
|
|
8 |
|
|
|
9 |
MATCH='^[[:space:]]*(\#.*)?$'
|
|
|
10 |
|
|
|
11 |
handle_file () {
|
|
|
12 |
. $1
|
|
|
13 |
routenum=0
|
|
|
14 |
while [ "x$(eval echo '$'ADDRESS$routenum)x" != "xx" ]; do
|
|
|
15 |
eval $(ipcalc -p $(eval echo '$'ADDRESS$routenum) $(eval echo '$'NETMASK$routenum))
|
|
|
16 |
line="$(eval echo '$'ADDRESS$routenum)/$PREFIX"
|
|
|
17 |
if [ "x$(eval echo '$'GATEWAY$routenum)x" != "xx" ]; then
|
|
|
18 |
line="$line via $(eval echo '$'GATEWAY$routenum)"
|
|
|
19 |
fi
|
|
|
20 |
line="$line dev $2"
|
|
|
21 |
/sbin/ip route add $line
|
|
|
22 |
routenum=$(($routenum+1))
|
|
|
23 |
done
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
handle_ip_file() {
|
|
|
27 |
local f t type= file=$1 proto="-4"
|
|
|
28 |
f=${file##*/}
|
|
|
29 |
t=${f%%-*}
|
|
|
30 |
type=${t%%6}
|
|
|
31 |
if [ "$type" != "$t" ]; then
|
|
|
32 |
proto="-6"
|
|
|
33 |
fi
|
|
|
34 |
{ cat "$file" ; echo ; } | while read line; do
|
|
|
35 |
if [[ ! "$line" =~ $MATCH ]]; then
|
|
|
36 |
/sbin/ip $proto $type add $line
|
|
|
37 |
fi
|
|
|
38 |
done
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
FILES="/etc/sysconfig/network-scripts/route-$1 /etc/sysconfig/network-scripts/route6-$1"
|
|
|
42 |
if [ -n "$2" -a "$2" != "$1" ]; then
|
|
|
43 |
FILES="$FILES /etc/sysconfig/network-scripts/route-$2 /etc/sysconfig/network-scripts/route6-$2"
|
|
|
44 |
fi
|
|
|
45 |
|
|
|
46 |
for file in $FILES; do
|
|
|
47 |
if [ -f "$file" ]; then
|
|
|
48 |
if egrep -q '^[[:space:]]*ADDRESS[0-9]+=' $file ; then
|
|
|
49 |
# new format
|
|
|
50 |
handle_file $file ${1%:*}
|
|
|
51 |
else
|
|
|
52 |
# older format
|
|
|
53 |
handle_ip_file $file
|
|
|
54 |
fi
|
|
|
55 |
fi
|
|
|
56 |
done
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
# Red Hat network configuration format
|
|
|
60 |
NICK=${2:-$1}
|
|
|
61 |
CONFIG="/etc/sysconfig/network-scripts/$NICK.route"
|
|
|
62 |
[ -f $CONFIG ] && handle_file $CONFIG $1
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
# Routing rules
|
|
|
66 |
FILES="/etc/sysconfig/network-scripts/rule-$1 /etc/sysconfig/network-scripts/rule6-$1"
|
|
|
67 |
if [ -n "$2" -a "$2" != "$1" ]; then
|
|
|
68 |
FILES="$FILES /etc/sysconfig/network-scripts/rule-$2 /etc/sysconfig/network-scripts/rule6-$2"
|
|
|
69 |
fi
|
|
|
70 |
|
|
|
71 |
for file in $FILES; do
|
|
|
72 |
if [ -f "$file" ]; then
|
|
|
73 |
handle_ip_file $file
|
|
|
74 |
fi
|
|
|
75 |
done
|