2014-07-03 20:27:58 +00:00
|
|
|
#!/bin/bash
|
2011-04-07 17:42:48 +00:00
|
|
|
# IBM(c) 2011EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#=head1 routeop
|
|
|
|
#=head2 routeop is called by makeroutes command and setuproutes postscript to
|
|
|
|
# setup a route on a node.
|
|
|
|
# The syntax is:
|
2014-11-25 17:41:13 +00:00
|
|
|
# routeop add/delete net mask gateway ifname #NOTE: the add/delete will be
|
2014-07-03 20:27:58 +00:00
|
|
|
# obsoleted, using 'replace' is recommended.
|
2014-06-11 11:13:42 +00:00
|
|
|
# routeop replace net mask gateway ifname #NOTE: it only works for sles so far
|
|
|
|
# net - IP of net like 192.168.1.0. The keyword
|
|
|
|
# 'default' is used to set the default route.
|
2014-07-09 12:40:54 +00:00
|
|
|
# mask - The length of the netmask (CIDR) like 8,16,24 OR
|
|
|
|
# the dotted-decimal format like 255.255.0.0
|
2014-07-03 20:27:58 +00:00
|
|
|
# gateway - The next hop. It could be set to 0.0.0.0 for omitting
|
2014-06-11 11:13:42 +00:00
|
|
|
# ifname - The interface to route to the next hop
|
2014-07-03 20:27:58 +00:00
|
|
|
#=head3 example
|
|
|
|
# routeop replace default 0 10.1.0.209 eth0
|
|
|
|
# routeop replace 50.1.0.0 16 10.1.0.210 eth0
|
|
|
|
# routeop replace 60.1.1.0 24 0.0.0.0 eth0
|
|
|
|
# routeop replace 70.1.1.0 24 10.1.0.211 #NOTE: this is NOT supported for redhat
|
2011-04-07 17:42:48 +00:00
|
|
|
#=cut
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
2014-07-23 06:16:48 +00:00
|
|
|
|
|
|
|
if [ "$(uname -s|tr 'A-Z' 'a-z')" = "linux" ];then
|
|
|
|
str_dir_name=`dirname $0`
|
|
|
|
. $str_dir_name/xcatlib.sh
|
|
|
|
fi
|
2014-07-09 12:40:54 +00:00
|
|
|
|
2011-04-07 17:42:48 +00:00
|
|
|
op=$1
|
|
|
|
|
|
|
|
net=$2
|
|
|
|
mask=$3
|
2011-04-07 19:04:05 +00:00
|
|
|
gw=$4
|
2011-08-22 01:08:40 +00:00
|
|
|
if [ -n "$5" ]; then
|
2011-04-07 17:42:48 +00:00
|
|
|
ifname=$5
|
|
|
|
fi
|
|
|
|
|
2014-07-03 20:27:58 +00:00
|
|
|
# use nummask to know whether the netmask format is 255.255.255.0 or CIDR (a number)
|
2014-06-11 11:13:42 +00:00
|
|
|
nummask=0
|
2014-07-03 20:27:58 +00:00
|
|
|
echo $mask | egrep "^[.0123456789]+$" > /dev/null
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2014-07-03 20:27:58 +00:00
|
|
|
echo "Error: invalid format of netmask $mask."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo $mask | egrep "^[0123456789]+$" > /dev/null
|
|
|
|
if [ $? -eq 0 ]; then # only has digital
|
|
|
|
nummask=1 # the netmask is the length of network mask.
|
|
|
|
if [ $mask -ge 128 ]; then
|
|
|
|
echo "Error: invalid format of netmask $mask."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2014-07-03 20:27:58 +00:00
|
|
|
|
2013-05-24 08:37:11 +00:00
|
|
|
function debianpreconf(){
|
|
|
|
#create the config sub dir
|
|
|
|
if [ ! -d "/etc/network/interfaces.d" ];then
|
|
|
|
mkdir -p "/etc/network/interfaces.d"
|
|
|
|
fi
|
|
|
|
#search xcat flag
|
|
|
|
XCATFLAG=`grep "#XCAT_CONFIG" /etc/network/interfaces`
|
|
|
|
if [ -n "$XCATFLAG" ];then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
#back up the old interface configure
|
|
|
|
if [ ! -e "/etc/network/interfaces.bak" ];then
|
|
|
|
mv /etc/network/interfaces /etc/network/interfaces.bak
|
|
|
|
fi
|
|
|
|
|
|
|
|
#create the new config file
|
|
|
|
echo "#XCAT_CONFIG" > /etc/network/interfaces
|
|
|
|
echo "source /etc/network/interfaces.d/*" >> /etc/network/interfaces
|
|
|
|
|
|
|
|
CONFFILE=''
|
|
|
|
|
|
|
|
#read the backfile
|
|
|
|
cat /etc/network/interfaces.bak | while read LINE
|
|
|
|
do
|
|
|
|
if [ ! "$LINE" ];then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
FIRSTCHAR=${LINE:0:1}
|
|
|
|
if [ $FIRSTCHAR = '#' ];then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
CONFTYPE=`echo $LINE | cut -d" " -f1`
|
|
|
|
if [ $CONFTYPE = 'auto' -o $CONFTYPE = 'allow-hotplug' ];then
|
|
|
|
LINE=${LINE#$CONFTYPE}
|
|
|
|
for NICNAME in $LINE; do
|
|
|
|
echo "$CONFTYPE $NICNAME" > "/etc/network/interfaces.d/$NICNAME"
|
|
|
|
done
|
|
|
|
elif [ $CONFTYPE = 'iface' -o $CONFTYPE = 'mapping' ];then
|
|
|
|
#find out the nic name, should think about the eth0:1
|
|
|
|
NICNAME=`echo $LINE | cut -d" " -f 2 | cut -d":" -f 1`
|
|
|
|
CONFFILE="/etc/network/interfaces.d/$NICNAME"
|
|
|
|
if [ ! -e $CONFFILE ];then
|
|
|
|
echo "auto $NICNAME" > $CONFFILE
|
|
|
|
fi
|
|
|
|
|
|
|
|
#write lines into the conffile
|
|
|
|
echo $LINE >> $CONFFILE
|
|
|
|
else
|
|
|
|
echo $LINE >> $CONFFILE
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
|
|
|
}
|
2011-04-07 17:42:48 +00:00
|
|
|
|
|
|
|
route_exists()
|
|
|
|
{
|
|
|
|
net=$1
|
|
|
|
mask=$2
|
|
|
|
gw=$3
|
|
|
|
ret=0
|
|
|
|
|
2011-08-22 01:08:40 +00:00
|
|
|
if [ -n "$4" ]; then
|
2013-05-24 08:37:11 +00:00
|
|
|
ifname=$4
|
2011-04-07 17:42:48 +00:00
|
|
|
fi
|
|
|
|
|
2011-08-22 01:08:40 +00:00
|
|
|
os_type=$(uname -s)
|
|
|
|
|
2013-02-28 02:32:24 +00:00
|
|
|
# ipv6
|
|
|
|
if echo $net | grep : 2>&1 1>/dev/null
|
|
|
|
then
|
|
|
|
result=`ip -6 route show $net/$mask`
|
|
|
|
if [ $? -ne 0 ] || [ -z "$result" ]
|
|
|
|
then
|
|
|
|
ret=0
|
|
|
|
else
|
|
|
|
ret=1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
result=`netstat -nr|grep $net`;
|
|
|
|
if [ $? -eq 0 ] && [ -n "$result" ]; then
|
2013-05-24 06:20:34 +00:00
|
|
|
for x in `echo "$result"|tr -s " " ","`
|
|
|
|
do
|
|
|
|
if [ "$os_type" = "Linux" ]; then
|
|
|
|
net1=`echo $x|cut -d',' -f1`
|
|
|
|
gw1=`echo $x|cut -d',' -f2`
|
|
|
|
mask1=`echo $x|cut -d',' -f3`
|
2014-04-01 15:16:14 +00:00
|
|
|
ifname1=`echo $x|cut -d',' -f8`
|
|
|
|
if [ "$net" = "$net1" ] && [ "$mask" = "$mask1" ] && [ "$gw" = "$gw1" ] && [ "$ifname" = "$ifname1" ]; then
|
2013-05-24 06:20:34 +00:00
|
|
|
ret=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
tmp1=`echo $x|cut -d',' -f1`
|
|
|
|
gw1=`echo $x|cut -d',' -f2`
|
2011-04-07 17:42:48 +00:00
|
|
|
|
2013-05-24 06:20:34 +00:00
|
|
|
n1=`echo $net |cut -d'.' -f1`
|
|
|
|
n2=`echo $net |cut -d'.' -f2`
|
|
|
|
n3=`echo $net |cut -d'.' -f3`
|
2013-02-28 02:32:24 +00:00
|
|
|
n4=`echo $net |cut -d'.' -f4`
|
2011-04-07 17:42:48 +00:00
|
|
|
|
2013-05-24 06:20:34 +00:00
|
|
|
netnum="$(( ($n1 << 24) + ($n2 << 16) + ($n3 << 8) + $n4 ))"
|
2013-02-28 02:32:24 +00:00
|
|
|
bits=32
|
2013-05-24 06:20:34 +00:00
|
|
|
while [ `expr $netnum % 2` -eq 0 ]
|
|
|
|
do
|
|
|
|
bits="$(( $bits - 1 ))"
|
|
|
|
netnum="$(( $netnum >> 1 ))"
|
|
|
|
done
|
2011-04-07 17:42:48 +00:00
|
|
|
|
2013-02-28 02:32:24 +00:00
|
|
|
tmp2="$net/$bits";
|
2013-05-24 06:20:34 +00:00
|
|
|
#echo "$tmp2=$tmp2"
|
|
|
|
if [ "$tmp1" = "$tmp2" ] && [ "$gw" = "$gw1" ]; then
|
|
|
|
ret=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2013-02-28 02:32:24 +00:00
|
|
|
fi
|
2011-04-07 17:42:48 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo $ret
|
|
|
|
}
|
|
|
|
|
2014-07-03 20:27:58 +00:00
|
|
|
# handle the route replace operation that adding the setting to configuration file
|
|
|
|
replace_persistent_route()
|
|
|
|
{
|
|
|
|
net=$1;
|
|
|
|
mask=$2;
|
|
|
|
gw=$3;
|
|
|
|
if [ -n "$4" ]; then
|
|
|
|
ifname=$4
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$(uname -s)" = "Linux" ]; then
|
|
|
|
#determine the os name
|
|
|
|
OS_name="something"
|
|
|
|
if [ -f /etc/redhat-release ]
|
|
|
|
then
|
|
|
|
OS_name="redhat" #it can be RedHatFerdora or CentOS
|
|
|
|
elif [ -f /etc/SuSE-release ]
|
|
|
|
then
|
|
|
|
OS_name="sles"
|
|
|
|
else
|
|
|
|
OS_name="debian"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# set the destination of the route for searching in the route configuration file
|
|
|
|
if [ "$net" = "default" ]; then
|
|
|
|
routedest="default"
|
|
|
|
routedest1="default"
|
|
|
|
else
|
|
|
|
routedest="$net/$mask"
|
|
|
|
routedest1="$net\/$mask"
|
|
|
|
fi
|
|
|
|
|
|
|
|
case $OS_name in
|
|
|
|
sles)
|
2014-11-25 17:41:13 +00:00
|
|
|
filename="/etc/sysconfig/network/routes";
|
|
|
|
if echo $net | grep : 2>&1 1>/dev/null
|
|
|
|
then
|
|
|
|
# for ipv6
|
|
|
|
if [ "$gw" = "" -o "$gw" = "::" ] ; then
|
|
|
|
route="$net/$mask :: - $ifname"
|
|
|
|
route1="$net\/$mask :: - $ifname";
|
2014-07-03 20:27:58 +00:00
|
|
|
else
|
2014-11-25 17:41:13 +00:00
|
|
|
route="$net/$mask $gw - -"
|
|
|
|
route1="$net\/$mask $gw - -";
|
2014-07-03 20:27:58 +00:00
|
|
|
fi
|
|
|
|
else
|
2014-11-25 17:41:13 +00:00
|
|
|
# for ipv4
|
|
|
|
if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then
|
|
|
|
if [ "$net" = "default" ]; then
|
|
|
|
route="default - - $ifname";
|
|
|
|
route1="default - - $ifname";
|
|
|
|
else
|
|
|
|
route="$net/$mask - - $ifname";
|
|
|
|
route1="$net\/$mask - - $ifname";
|
|
|
|
fi
|
2014-07-03 20:27:58 +00:00
|
|
|
else
|
2014-11-25 17:41:13 +00:00
|
|
|
if [ "$net" = "default" ]; then
|
|
|
|
route="default $gw - $ifname";
|
|
|
|
route1="default $gw - $ifname";
|
|
|
|
else
|
|
|
|
route="$net/$mask $gw - $ifname";
|
|
|
|
route1="$net\/$mask $gw - $ifname";
|
|
|
|
fi
|
2014-07-03 20:27:58 +00:00
|
|
|
fi
|
|
|
|
fi
|
2014-11-25 17:41:13 +00:00
|
|
|
if [ -f $filename ]; then
|
|
|
|
egrep "^$routedest" $filename 2>&1 1>/dev/null
|
|
|
|
if [ $? -ne 0 ]; then #route does not exist
|
|
|
|
echo $route >> $filename
|
|
|
|
echo "Persistent route \"$route\" has been added in $filename."
|
|
|
|
else
|
|
|
|
# replace it
|
|
|
|
sed -i -e "s/$routedest1.*/$route1/g" $filename
|
|
|
|
echo "Persistent route \"$route\" has been replaced in $filename."
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "$route" > $filename
|
2014-07-03 20:27:58 +00:00
|
|
|
echo "Persistent route \"$route\" has been added in $filename."
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
redhat)
|
2014-11-25 17:41:13 +00:00
|
|
|
#echo "rh/fedora/centos"
|
|
|
|
if [ -z "$ifname" ]; then
|
|
|
|
echo "Error: the device name is necessary to configure static route."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
if echo $net | grep : 2>&1 1>/dev/null
|
|
|
|
then
|
|
|
|
# ipv6
|
|
|
|
filename="/etc/sysconfig/network-scripts/route6-$ifname"
|
|
|
|
if [ "$gw" = "" -o "$gw" = "::" ] ; then
|
|
|
|
route="$net/$mask dev $ifname"
|
|
|
|
route1="$net\/$mask dev $ifname"
|
|
|
|
else
|
|
|
|
route="$net/$mask via $gw"
|
|
|
|
route1="$net\/$mask via $gw"
|
|
|
|
fi
|
2014-07-03 20:27:58 +00:00
|
|
|
else
|
2014-11-25 17:41:13 +00:00
|
|
|
# ipv4
|
|
|
|
filename="/etc/sysconfig/network-scripts/route-$ifname"
|
|
|
|
if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then
|
|
|
|
route="$net/$mask dev $ifname"
|
|
|
|
route1="$net\/$mask dev $ifname"
|
|
|
|
else
|
|
|
|
route="$net/$mask via $gw"
|
|
|
|
route1="$net\/$mask via $gw"
|
|
|
|
fi
|
2014-07-03 20:27:58 +00:00
|
|
|
fi
|
2014-11-25 17:41:13 +00:00
|
|
|
if [ -f $filename ]; then
|
|
|
|
egrep "^$routedest" $filename 2>&1 1>/dev/null
|
|
|
|
if [ $? -ne 0 ]; then #route does not exist
|
|
|
|
echo $route >> $filename
|
|
|
|
echo "Persistent route \"$route\" has been added in $filename."
|
|
|
|
else
|
|
|
|
# replace it
|
|
|
|
sed -i -e "s/$routedest1.*/$route1/g" $filename
|
|
|
|
echo "Persistent route \"$route\" has been replaced in $filename."
|
|
|
|
fi
|
2014-07-03 20:27:58 +00:00
|
|
|
else
|
2014-11-25 17:41:13 +00:00
|
|
|
echo "$route" > $filename
|
2014-07-03 20:27:58 +00:00
|
|
|
echo "Persistent route \"$route\" has been added in $filename."
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
debian)
|
|
|
|
debianpreconf
|
|
|
|
matchstr=""
|
|
|
|
v6flag=0
|
2014-11-25 17:41:13 +00:00
|
|
|
# on debian/ubuntu need the network device name
|
|
|
|
if [ -z "$ifname" ]; then
|
|
|
|
echo "Error: the device name is necessary to configure static route."
|
|
|
|
return
|
2014-07-03 20:27:58 +00:00
|
|
|
fi
|
|
|
|
filename="/etc/network/interfaces.d/$ifname"
|
|
|
|
|
|
|
|
if [ ! -f $filename ];then
|
|
|
|
echo "auto $ifname" > $filename
|
|
|
|
echo "iface $ifname inet dhcp" >> $filename
|
|
|
|
fi
|
|
|
|
|
2014-11-25 17:41:13 +00:00
|
|
|
# if the route entry for a target net has been added in the if cfg file, just replace it
|
|
|
|
cmd="post-up $cmd"
|
|
|
|
#cmd1=${cmd//\//\\\/}
|
|
|
|
#sed -i -e "s/.*$routedest1.*/$cmd1/g" $filename
|
|
|
|
|
|
|
|
# for the case to add a new cmd for certain interface
|
|
|
|
foundflag=0
|
|
|
|
setflag=0
|
|
|
|
tempfile="/etc/network/interfaces.d/tmp"
|
|
|
|
>$tempfile
|
|
|
|
|
|
|
|
while read LINE
|
|
|
|
do
|
|
|
|
# replace the existed setting
|
|
|
|
echo $LINE | grep "$routedest1" 2>&1 1>/dev/null
|
|
|
|
if [ $? -eq 0 -a $foundflag -eq 1 ];then
|
|
|
|
LINE=$cmd
|
|
|
|
setflag=1
|
2014-07-03 20:27:58 +00:00
|
|
|
fi
|
|
|
|
|
2014-11-25 17:41:13 +00:00
|
|
|
echo $LINE | grep "iface" 2>&1 1>/dev/null
|
|
|
|
if [ $? -eq 0 -a $foundflag -eq 1 -a $setflag -eq 0 ];then
|
|
|
|
foundflag=0
|
|
|
|
echo "$cmd" >> $tempfile
|
2014-07-03 20:27:58 +00:00
|
|
|
fi
|
2014-11-25 17:41:13 +00:00
|
|
|
echo $LINE | grep "iface $ifname " 2>&1 1>/dev/null
|
|
|
|
#this is the last line of the device
|
|
|
|
if [ $? -eq 0 ];then
|
|
|
|
foundflag=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo $LINE >> $tempfile
|
|
|
|
done < $filename
|
|
|
|
|
|
|
|
#the insert place is the last line of the config file
|
|
|
|
if [ $foundflag -eq 1 -a $setflag -eq 0 ];then
|
|
|
|
echo "$cmd" >> $tempfile
|
2014-07-03 20:27:58 +00:00
|
|
|
fi
|
2014-11-25 17:41:13 +00:00
|
|
|
mv -f $tempfile $filename
|
|
|
|
echo "Persistent route \"$cmd\" is added in $filename.; "
|
2014-07-03 20:27:58 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
else #AIX
|
|
|
|
echo "Adding persistent route on AIX is not supported yet."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# handle the route add operation that adding the setting to configuration file
|
2013-01-23 18:36:42 +00:00
|
|
|
add_persistent_route()
|
|
|
|
{
|
|
|
|
net=$1;
|
|
|
|
mask=$2;
|
|
|
|
gw=$3;
|
|
|
|
if [ -n "$4" ]; then
|
2013-05-24 08:37:11 +00:00
|
|
|
ifname=$4
|
2013-01-23 18:36:42 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
xcat_config_start="# xCAT_CONFIG_START";
|
|
|
|
xcat_config_end="# xCAT_CONFIG_END";
|
|
|
|
|
|
|
|
if [ "$(uname -s)" = "Linux" ]; then
|
2013-05-24 06:20:34 +00:00
|
|
|
#determine the os name
|
|
|
|
OS_name="something"
|
|
|
|
if [ -f /etc/redhat-release ]
|
|
|
|
then
|
2013-05-24 08:37:11 +00:00
|
|
|
OS_name="redhat" #it can be RedHatFerdora or CentOS
|
2013-05-24 06:20:34 +00:00
|
|
|
elif [ -f /etc/SuSE-release ]
|
|
|
|
then
|
2013-05-24 08:37:11 +00:00
|
|
|
OS_name="sles"
|
|
|
|
else
|
|
|
|
OS_name="debian"
|
2013-05-24 06:20:34 +00:00
|
|
|
fi
|
2013-01-23 18:36:42 +00:00
|
|
|
|
2014-06-11 11:13:42 +00:00
|
|
|
# The replace operation does not support redhat and debain so far
|
|
|
|
if [ "$op" = "replace" ]; then
|
|
|
|
if [ "$OS_name" = "redhat" -o "$OS_name" = "debain" ]; then
|
|
|
|
echo "Warning: replace operation only supports to add persistent route for sles by now."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-05-24 06:20:34 +00:00
|
|
|
case $OS_name in
|
|
|
|
sles)
|
|
|
|
#echo "sles"
|
2013-02-28 02:32:24 +00:00
|
|
|
# ipv6 net
|
2013-05-24 06:20:34 +00:00
|
|
|
filename="/etc/sysconfig/network/routes";
|
2013-02-28 02:32:24 +00:00
|
|
|
if echo $net | grep : 2>&1 1>/dev/null
|
|
|
|
then
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "::" ] ; then
|
2014-04-01 15:16:14 +00:00
|
|
|
route="$net/$mask :: - $ifname"
|
|
|
|
route1="$net\/$mask :: - $ifname";
|
2014-06-11 11:13:42 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
route="$net/$mask $gw - -"
|
|
|
|
route1="$net\/$mask $gw - -";
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-02-28 02:32:24 +00:00
|
|
|
else
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then
|
|
|
|
if [ $nummask -eq 1 ]; then
|
|
|
|
if [ "$net" = "default" ]; then
|
|
|
|
route="default - - $ifname";
|
|
|
|
route1="default - - $ifname";
|
|
|
|
else
|
|
|
|
route="$net/$mask - - $ifname";
|
|
|
|
route1="$net\/$mask - - $ifname";
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
route="$net 0.0.0.0 $mask $ifname";
|
|
|
|
route1="$net 0.0.0.0 $mask $ifname";
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ $nummask -eq 1 ]; then
|
|
|
|
if [ "$net" = "default" ]; then
|
|
|
|
route="default $gw - $ifname";
|
|
|
|
route1="default $gw - $ifname";
|
|
|
|
else
|
|
|
|
route="$net/$mask $gw - $ifname";
|
|
|
|
route1="$net\/$mask $gw - $ifname";
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
route="$net $gw $mask $ifname";
|
|
|
|
route1="$net $gw $mask $ifname";
|
|
|
|
fi
|
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
fi
|
|
|
|
if [ -f $filename ]; then
|
|
|
|
grep "$route" $filename 2>&1 1>/dev/null
|
|
|
|
if [ $? -ne 0 ]; then #route does not exist
|
2014-06-11 11:13:42 +00:00
|
|
|
grep "$xcat_config_start" $filename 2>&1 1>/dev/null
|
|
|
|
if [ $? -ne 0 ]; then #no xCAT section
|
|
|
|
echo $xcat_config_start >> $filename
|
|
|
|
echo $route >> $filename
|
|
|
|
echo $xcat_config_end >> $filename
|
|
|
|
else
|
|
|
|
sed -i -e s/"$xcat_config_end"/"$route1\n$xcat_config_end"/g $filename
|
|
|
|
fi
|
|
|
|
echo "Persistent route \"$route\" added in $filename."
|
2013-05-24 06:20:34 +00:00
|
|
|
else
|
2014-06-11 11:13:42 +00:00
|
|
|
echo "Persistent route \"$route\" already exists in $filename."
|
2013-05-24 06:20:34 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
#echo "got here"
|
|
|
|
echo "$xcat_config_start" > $filename
|
|
|
|
echo "$route" >> $filename
|
|
|
|
echo "$xcat_config_end" >> $filename
|
|
|
|
echo "Route \"$route\" added in $filename."
|
2013-02-28 02:32:24 +00:00
|
|
|
fi
|
2013-01-23 18:36:42 +00:00
|
|
|
|
2013-05-24 06:20:34 +00:00
|
|
|
;;
|
2013-05-24 08:37:11 +00:00
|
|
|
debian)
|
|
|
|
debianpreconf
|
|
|
|
matchstr=""
|
|
|
|
v6flag=0
|
|
|
|
#on debian/ubuntu need the network device name
|
|
|
|
if [ ! $ifname ];then
|
2013-06-14 07:24:59 +00:00
|
|
|
ifname=`netstat -nr | grep "$net" | awk '{print $8}' | head -1`
|
2013-05-24 08:37:11 +00:00
|
|
|
fi
|
|
|
|
filename="/etc/network/interfaces.d/$ifname"
|
|
|
|
|
2013-06-14 07:01:59 +00:00
|
|
|
if [ ! -f $filename ];then
|
|
|
|
echo "auto $ifname" > $filename
|
|
|
|
echo "iface $ifname inet dhcp" >> $filename
|
|
|
|
fi
|
2013-05-24 08:37:11 +00:00
|
|
|
echo $net | grep : 2>&1 1>/dev/null
|
|
|
|
#ipv6
|
|
|
|
if [ $? -eq 0 ];then
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "::" ] ; then
|
2014-04-01 15:16:14 +00:00
|
|
|
matchstr="$net/$mask dev $ifname"
|
2014-06-11 11:13:42 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
matchstr="$net/$mask gw $gw"
|
|
|
|
fi
|
2013-05-24 08:37:11 +00:00
|
|
|
v6flag=1
|
|
|
|
else
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then
|
2014-04-01 15:16:14 +00:00
|
|
|
matchstr="net $net netmask $mask dev $ifname"
|
2014-06-11 11:13:42 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
matchstr="net $net netmask $mask gw $gw"
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-05-24 08:37:11 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
grep "$matchstr" $filename 2>&1 1>/dev/null
|
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
foundflag=0
|
|
|
|
tempfile="/etc/network/interfaces.d/tmp"
|
|
|
|
while read LINE
|
|
|
|
do
|
|
|
|
echo $LINE | grep "iface" 2>&1 1>/dev/null
|
|
|
|
if [ $? -eq 0 -a $foundflag -eq 1 ];then
|
|
|
|
foundflag=0
|
|
|
|
if [ $v6flag -eq 1 ];then
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "::" ] ; then
|
2014-04-01 15:16:14 +00:00
|
|
|
echo " up route -A inet6 add $net/$mask dev $ifname" >> $tempfile
|
|
|
|
echo " down route -A inet6 del $net/$mask dev $ifname" >> $tempfile
|
2014-06-11 11:13:42 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
echo " up route -A inet6 add $net/$mask gw $gw" >> $tempfile
|
|
|
|
echo " down route -A inet6 del $net/$mask gw $gw" >> $tempfile
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-05-24 08:37:11 +00:00
|
|
|
else
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then
|
|
|
|
echo " up route add -net $net netmask $mask dev $ifname" >> $tempfile
|
|
|
|
echo " down route del -net $net netmask $mask dev $ifname" >> $tempfile
|
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
echo " up route add -net $net netmask $mask gw $gw" >> $tempfile
|
|
|
|
echo " down route del -net $net netmask $mask gw $gw" >> $tempfile
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-05-24 08:37:11 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo $LINE | grep "iface $ifname " 2>&1 1>/dev/null
|
|
|
|
#this is the last line of the device
|
|
|
|
if [ $? -eq 0 ];then
|
|
|
|
foundflag=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo $LINE >> $tempfile
|
|
|
|
done < $filename
|
|
|
|
#the insert place is the last line of the config file
|
|
|
|
if [ $foundflag -eq 1 ];then
|
|
|
|
if [ $v6flag -eq 1 ];then
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "::" ] ; then
|
2014-04-01 15:16:14 +00:00
|
|
|
echo " up route -A inet6 add $net/$mask dev $ifname" >> $tempfile
|
|
|
|
echo " down route -A inet6 del $net/$mask dev $ifname" >> $tempfile
|
2014-06-11 11:13:42 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
echo " up route -A inet6 add $net/$mask gw $gw" >> $tempfile
|
|
|
|
echo " down route -A inet6 del $net/$mask gw $gw" >> $tempfile
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-05-24 08:37:11 +00:00
|
|
|
else
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then
|
|
|
|
echo " up route add -net $net netmask $mask dev $ifname" >> $tempfile
|
|
|
|
echo " down route del -net $net netmask $mask dev $ifname" >> $tempfile
|
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
echo " up route add -net $net netmask $mask gw $gw" >> $tempfile
|
|
|
|
echo " down route del -net $net netmask $mask gw $gw" >> $tempfile
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-05-24 08:37:11 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
mv -f $tempfile $filename
|
|
|
|
echo "Persistent route \"$matchstr\" added in $filename."
|
|
|
|
else
|
|
|
|
echo "Persisten route \"$match\" already exists in $filename"
|
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
;;
|
|
|
|
redhat)
|
|
|
|
#echo "rh/fedora/centos"
|
2013-02-28 02:32:24 +00:00
|
|
|
# ipv6 net
|
|
|
|
if echo $net | grep : 2>&1 1>/dev/null
|
|
|
|
then
|
2014-04-01 15:16:14 +00:00
|
|
|
if [ "$gw" = "" ] ; then
|
2014-06-11 11:13:42 +00:00
|
|
|
$gw = "::";
|
2014-04-01 15:16:14 +00:00
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
filename="/etc/sysconfig/static-routes-ipv6";
|
|
|
|
route="$ifname $net/$mask $gw";
|
2013-02-28 02:32:24 +00:00
|
|
|
# $net/mask does not work with sed cmd
|
2013-05-24 06:20:34 +00:00
|
|
|
route1="$ifname $net\/$mask $gw";
|
2013-02-28 02:32:24 +00:00
|
|
|
else
|
2013-05-24 06:20:34 +00:00
|
|
|
filename="/etc/sysconfig/static-routes";
|
2014-04-01 15:16:14 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then
|
|
|
|
route="any net $net netmask $mask dev $ifname";
|
|
|
|
route1="any net $net netmask $mask dev $ifname";
|
2014-06-11 11:13:42 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
route="any net $net netmask $mask gw $gw $ifname";
|
|
|
|
route1="any net $net netmask $mask gw $gw $ifname";
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-02-28 02:32:24 +00:00
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
if [ -f $filename ]; then
|
|
|
|
grep "$route" $filename 2>&1 1>/dev/null
|
|
|
|
if [ $? -ne 0 ]; then #route does not exist
|
|
|
|
grep "$xcat_config_start" $filename 2>&1 1>/dev/null
|
|
|
|
if [ $? -ne 0 ]; then #no xCAT section
|
|
|
|
echo $xcat_config_start >> $filename
|
|
|
|
echo $route >> $filename
|
|
|
|
echo $xcat_config_end >> $filename
|
|
|
|
else
|
|
|
|
sed -i -e s/"$xcat_config_end"/"$route1\n$xcat_config_end"/g $filename
|
|
|
|
fi
|
|
|
|
echo "Persistent route \"$route\" added in $filename."
|
|
|
|
else
|
|
|
|
echo "Persistent route \"$route\" already exists in $filename."
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
#echo "got here"
|
|
|
|
echo "$xcat_config_start" > $filename
|
|
|
|
echo "$route" >> $filename
|
|
|
|
echo "$xcat_config_end" >> $filename
|
|
|
|
echo "Persistent route \"$route\" added in $filename."
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2013-01-23 18:36:42 +00:00
|
|
|
else #AIX
|
2013-05-24 06:20:34 +00:00
|
|
|
echo "Adding persistent route on AIX is not supported yet."
|
2013-01-23 18:36:42 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
rm_persistent_route()
|
|
|
|
{
|
|
|
|
net=$1;
|
|
|
|
mask=$2;
|
|
|
|
gw=$3;
|
|
|
|
if [ -n "$4" ]; then
|
2013-05-24 08:37:11 +00:00
|
|
|
ifname=$4
|
2013-01-23 18:36:42 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$(uname -s)" = "Linux" ]; then
|
2013-05-24 06:20:34 +00:00
|
|
|
#determine the os name
|
|
|
|
OS_name="something"
|
|
|
|
if [ -f /etc/redhat-release ]
|
|
|
|
then
|
2013-05-24 08:37:11 +00:00
|
|
|
OS_name="redhat" #it can be RedHatFerdora or CentOS
|
2013-05-24 06:20:34 +00:00
|
|
|
elif [ -f /etc/SuSE-release ]
|
|
|
|
then
|
2013-05-24 08:37:11 +00:00
|
|
|
OS_name="sles"
|
|
|
|
else
|
|
|
|
OS_name="debian"
|
2013-05-24 06:20:34 +00:00
|
|
|
fi
|
2013-01-23 18:36:42 +00:00
|
|
|
|
2013-05-24 06:20:34 +00:00
|
|
|
case $OS_name in
|
|
|
|
sles)
|
|
|
|
#echo "sles"
|
|
|
|
filename="/etc/sysconfig/network/routes";
|
2013-02-28 02:32:24 +00:00
|
|
|
# ipv6 net
|
|
|
|
if echo $net | grep : 2>&1 1>/dev/null
|
|
|
|
then
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ $gw = "" -o $gw = "::" ] ; then
|
2014-04-01 15:16:14 +00:00
|
|
|
route="$net/$mask :: - $ifname";
|
|
|
|
route1="$net\/$mask :: - $ifname";
|
2014-06-11 11:13:42 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
route="$net/$mask $gw - -";
|
|
|
|
route1="$net\/$mask $gw - -";
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-02-28 02:32:24 +00:00
|
|
|
else
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ $gw = "" ] ; then
|
|
|
|
$gw = "0.0.0.0";
|
2014-04-01 15:16:14 +00:00
|
|
|
fi
|
2013-04-08 07:28:55 +00:00
|
|
|
if [ -n "$ifname" ]; then
|
2013-05-24 06:20:34 +00:00
|
|
|
route="$net $gw $mask $ifname";
|
|
|
|
route1="$net $gw $mask $ifname";
|
2013-04-08 07:28:55 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
route="$net $gw $mask -";
|
|
|
|
route1="$net $gw $mask -";
|
2013-04-08 07:28:55 +00:00
|
|
|
fi
|
2013-02-28 02:32:24 +00:00
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
if [ -f $filename ]; then
|
2013-04-08 07:12:02 +00:00
|
|
|
grep "$route" $filename 2>&1 1>/dev/null
|
|
|
|
if [ $? -ne 0 ]; then # Does not exist in file
|
|
|
|
echo "Persistent route \"$route\" does not exist in $filename."
|
|
|
|
else
|
2013-05-24 06:20:34 +00:00
|
|
|
sed -i -e s/"$route1"//g $filename
|
2013-04-08 07:12:02 +00:00
|
|
|
echo "Persistent route \"$route\" removed from $filename."
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Persistent route file $filename does not exist."
|
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
;;
|
2013-05-24 08:37:11 +00:00
|
|
|
debian)
|
|
|
|
debianpreconf
|
|
|
|
matchstr=""
|
|
|
|
v6flag=0
|
|
|
|
#on debian/ubuntu need the network device name
|
|
|
|
if [ ! $ifname ];then
|
|
|
|
ifname=`netstat -nr | grep "$net" | awk '{print $8}'`
|
|
|
|
fi
|
|
|
|
filename="/etc/network/interfaces.d/$ifname"
|
|
|
|
|
|
|
|
echo $net | grep : 2>&1 1>/dev/null
|
|
|
|
#ipv6
|
|
|
|
if [ $? -eq 0 ];then
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ $gw = "" -o $gw = "::" ] ; then
|
2014-04-01 15:16:14 +00:00
|
|
|
matchstr="$net/$mask dev $ifname"
|
2014-06-11 11:13:42 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
matchstr="$net/$mask gw $gw"
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-05-24 08:37:11 +00:00
|
|
|
v6flag=1
|
|
|
|
else
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ $gw = "" -o $gw = "0.0.0.0" ] ; then
|
2014-04-01 15:16:14 +00:00
|
|
|
matchstr="net $net netmask $mask dev $ifname"
|
2014-06-11 11:13:42 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
matchstr="net $net netmask $mask gw $gw"
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-05-24 08:37:11 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
grep "$matchstr" $filename
|
|
|
|
if [ $? -eq 0 ];then
|
|
|
|
sed -i -e "/$matchstr/d" $filename
|
|
|
|
echo "Persistent route \"$matchstr\" removed from $filename."
|
|
|
|
else
|
|
|
|
echo "Persistent route \"$matchstr\" does not exist in $filename."
|
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
;;
|
|
|
|
redhat)
|
|
|
|
#echo "rh/fedora/centos"
|
2013-02-28 02:32:24 +00:00
|
|
|
#ipv6
|
|
|
|
if echo $net | grep : 2>&1 1>/dev/null
|
|
|
|
then
|
|
|
|
filename="/etc/sysconfig/static-routes-ipv6";
|
|
|
|
# $net/$mask does not work with sed
|
2014-04-01 15:16:14 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "::" ] ; then
|
|
|
|
route="$ifname $net\/$mask ::"
|
|
|
|
route1="$ifname $net/$mask ::"
|
2014-06-11 11:13:42 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
route="$ifname $net\/$mask $gw"
|
|
|
|
route1="$ifname $net/$mask $gw"
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-02-28 02:32:24 +00:00
|
|
|
else
|
2013-05-24 06:20:34 +00:00
|
|
|
filename="/etc/sysconfig/static-routes";
|
2014-04-01 15:16:14 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then
|
|
|
|
route="any net $net netmask $mask dev $ifname";
|
|
|
|
route1="any net $net netmask $mask dev $ifname";
|
|
|
|
else
|
|
|
|
route="any net $net netmask $mask gw $gw $ifname";
|
|
|
|
route1="any net $net netmask $mask gw $gw $ifname";
|
|
|
|
fi
|
2013-02-28 02:32:24 +00:00
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
if [ -f $filename ]; then
|
2013-04-08 07:12:02 +00:00
|
|
|
grep "$route" $filename 2>&1 1>/dev/null
|
|
|
|
if [ $? -ne 0 ]; then # Does not exist in file
|
|
|
|
echo "Persistent route \"$route1\" does not exist in $filename."
|
|
|
|
else
|
2013-05-24 06:20:34 +00:00
|
|
|
sed -i -e s/"$route"//g $filename
|
2013-04-08 07:12:02 +00:00
|
|
|
echo "Persistent route \"$route1\" removed from $filename."
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Persistent route file $filename does not exist."
|
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
;;
|
|
|
|
esac
|
2013-01-23 18:36:42 +00:00
|
|
|
else #AIX
|
2013-05-24 06:20:34 +00:00
|
|
|
echo "Removing persistent route on AIX is not supported yet."
|
2013-01-23 18:36:42 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$op" = "add" ]; then
|
|
|
|
result=$(route_exists $net $mask $gw)
|
|
|
|
if [ "$result" = "0" ]; then
|
2013-02-28 02:32:24 +00:00
|
|
|
#ipv6
|
|
|
|
if echo $net | grep : 2>&1 1>/dev/null
|
|
|
|
then
|
2013-05-24 06:20:34 +00:00
|
|
|
if [ "$(uname -s)" = "Linux" ]; then
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "::" ] ; then
|
2014-04-01 15:16:14 +00:00
|
|
|
cmd="ip -6 route add $net/$mask dev $ifname"
|
2014-06-11 11:13:42 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
cmd="ip -6 route add $net/$mask via $gw"
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
else
|
2013-02-28 02:32:24 +00:00
|
|
|
# AIX TODO
|
2013-05-24 06:20:34 +00:00
|
|
|
cmd="ip -6 route add $net/$mask via $gw"
|
|
|
|
fi
|
2013-02-28 02:32:24 +00:00
|
|
|
else
|
2013-05-24 06:20:34 +00:00
|
|
|
if [ "$(uname -s)" = "Linux" ]; then
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then
|
2014-04-01 15:16:14 +00:00
|
|
|
cmd="route add -net $net netmask $mask dev $ifname"
|
2014-06-11 11:13:42 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
cmd="route add -net $net netmask $mask gw $gw"
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
else
|
|
|
|
cmd="route add -net $net -netmask $mask $gw"
|
2013-02-28 02:32:24 +00:00
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
fi
|
|
|
|
echo "Adding temporary route: $cmd"
|
|
|
|
result=`$cmd 2>&1`
|
|
|
|
code=$?
|
|
|
|
if [ $code -ne 0 ]; then
|
|
|
|
logger -t xCAT -p local4.err "$cmd\nerror code=$code, result=$result."
|
|
|
|
echo " error code=$code, result=$result."
|
2013-06-14 07:01:59 +00:00
|
|
|
if [ -f "/etc/debian_version" ];then
|
|
|
|
exit 1;
|
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
fi
|
2011-04-07 19:04:05 +00:00
|
|
|
else
|
2013-02-28 02:32:24 +00:00
|
|
|
#ipv6
|
|
|
|
if echo $net | grep : 2>&1 1>/dev/null
|
|
|
|
then
|
|
|
|
echo "The temporary route ($net/$mask $gw) already exists."
|
|
|
|
else
|
2013-05-24 06:20:34 +00:00
|
|
|
echo "The temporary route ($net $mask $gw) already exists."
|
2013-02-28 02:32:24 +00:00
|
|
|
fi
|
2013-01-23 18:36:42 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
#add persistent route
|
|
|
|
add_persistent_route $net $mask $gw $ifname
|
|
|
|
elif [ "$op" = "delete" ]; then
|
|
|
|
result=$(route_exists $net $mask $gw)
|
|
|
|
if [ "$result" = "1" ]; then
|
2013-05-24 06:20:34 +00:00
|
|
|
# ipv6
|
|
|
|
if echo $net | grep : 2>&1 1>/dev/null
|
|
|
|
then
|
|
|
|
if [ "$(uname -s)" = "Linux" ]; then
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "::" ] ; then
|
2014-04-01 15:16:14 +00:00
|
|
|
cmd="ip -6 route delete $net/$mask dev $ifname"
|
2014-06-11 11:13:42 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
cmd="ip -6 route delete $net/$mask via $gw"
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
else
|
|
|
|
# AIX TODO
|
|
|
|
cmd="ip -6 route delete $net/$mask via $gw"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ "$(uname -s)" = "Linux" ]; then
|
2014-06-11 11:13:42 +00:00
|
|
|
if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then
|
2014-04-01 15:16:14 +00:00
|
|
|
cmd="route delete -net $net netmask $mask dev $ifname"
|
2014-06-11 11:13:42 +00:00
|
|
|
else
|
2014-04-01 15:16:14 +00:00
|
|
|
cmd="route delete -net $net netmask $mask gw $gw"
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
else
|
|
|
|
cmd="route delete -net $net -netmask $mask $gw"
|
|
|
|
fi
|
|
|
|
fi
|
2013-02-28 02:32:24 +00:00
|
|
|
|
2013-05-24 06:20:34 +00:00
|
|
|
echo "Removing temporary route: $cmd"
|
|
|
|
result=`$cmd 2>&1`
|
|
|
|
code=$?
|
|
|
|
if [ $code -ne 0 ]; then
|
|
|
|
logger -t xCAT -p local4.err "$cmd\nerror code=$code, result=$result."
|
|
|
|
echo " error code=$code, result=$result."
|
|
|
|
fi
|
2011-04-07 19:04:05 +00:00
|
|
|
else
|
2013-05-24 06:20:34 +00:00
|
|
|
echo "The temporary route ($net $mask $gw) does not exist."
|
2011-04-07 17:42:48 +00:00
|
|
|
fi
|
2013-05-24 06:20:34 +00:00
|
|
|
|
2013-01-23 18:36:42 +00:00
|
|
|
#remove the persistent route
|
|
|
|
rm_persistent_route $net $mask $gw $ifname
|
2014-06-11 11:13:42 +00:00
|
|
|
elif [ "$op" = "replace" ]; then
|
2014-07-03 20:27:58 +00:00
|
|
|
if [ $nummask -ne 1 ]; then
|
2014-07-09 12:40:54 +00:00
|
|
|
mask=$(v4mask2prefix $mask)
|
2014-07-03 20:27:58 +00:00
|
|
|
fi
|
|
|
|
|
2014-06-11 11:13:42 +00:00
|
|
|
if echo $net | grep : 2>&1 1>/dev/null
|
|
|
|
then # ipv6
|
|
|
|
if [ "$(uname -s)" = "Linux" ]; then
|
|
|
|
if [ "$gw" = "" -o "$gw" = "::" ] ; then
|
|
|
|
if [ "$net" = "default" ]; then
|
|
|
|
cmd="ip -6 route replace default dev $ifname"
|
|
|
|
else
|
|
|
|
cmd="ip -6 route replace $net/$mask dev $ifname"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ "$net" = "default" ]; then
|
|
|
|
cmd="ip -6 route replace default via $gw"
|
|
|
|
else
|
|
|
|
cmd="ip -6 route replace $net/$mask via $gw"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else #ipv4
|
|
|
|
if [ "$(uname -s)" = "Linux" ]; then
|
|
|
|
if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then
|
|
|
|
if [ "$net" = "default" ]; then
|
|
|
|
cmd="ip route replace default dev $ifname"
|
|
|
|
else
|
|
|
|
cmd="ip route replace $net/$mask dev $ifname"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ "$net" = "default" ]; then
|
|
|
|
cmd="ip route replace default via $gw"
|
|
|
|
else
|
|
|
|
cmd="ip route replace $net/$mask via $gw"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2014-11-25 17:41:13 +00:00
|
|
|
echo "Adding temporary route: $cmd; "
|
2014-06-11 11:13:42 +00:00
|
|
|
result=`$cmd 2>&1`
|
|
|
|
code=$?
|
|
|
|
if [ $code -ne 0 ]; then
|
2014-07-03 20:27:58 +00:00
|
|
|
logger -t xCAT -p local4.err "Error: $cmd [error code=$code, result=$result]"
|
|
|
|
echo "Error: $cmd [error code=$code, result=$result]"
|
|
|
|
exit 1;
|
2014-06-11 11:13:42 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
#replace the persistent route
|
2014-11-25 17:41:13 +00:00
|
|
|
# the $cmd param is used for Ubuntu since it needs to run the specific cmd to enable
|
|
|
|
# the route during the up of the device
|
|
|
|
replace_persistent_route $net $mask $gw $ifname
|
2011-04-07 17:42:48 +00:00
|
|
|
fi
|
2014-07-03 20:27:58 +00:00
|
|
|
|
2011-04-07 17:42:48 +00:00
|
|
|
exit 0
|