mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-3436: Fix inconsistent ip routing table between redundant virtual routers
This commit is contained in:
parent
56da71e5b6
commit
9de2034832
|
|
@ -106,8 +106,8 @@ remove_routing() {
|
|||
local tableNo=$(echo $ethDev | awk -F'eth' '{print $2}')
|
||||
|
||||
local tableName="Table_$ethDev"
|
||||
local ethMask=$(ip route list scope link dev $ethDev | awk '{print $1}')
|
||||
if [ "$ethMask" == "" ]
|
||||
local remainip=`ip addr show $ethDev | grep "inet "`
|
||||
if [ "$remainip" == "" ]
|
||||
then
|
||||
# rules and routes will be deleted for the last ip of the interface.
|
||||
sudo ip rule delete fwmark $tableNo table $tableName
|
||||
|
|
@ -125,7 +125,7 @@ copy_routes_from_main() {
|
|||
#get the network masks from the main table
|
||||
local eth0Mask=$(ip route list scope link dev eth0 | awk '{print $1}')
|
||||
local eth1Mask=$(ip route list scope link dev eth1 | awk '{print $1}')
|
||||
local ethMask=$(ip route list scope link dev $ethDev | awk '{print $1}')
|
||||
local ethMask=$(getcidr $ethDev)
|
||||
|
||||
# eth0,eth1 and other know routes will be skipped, so as main routing table will decide the route. This will be useful if the interface is down and up.
|
||||
sudo ip route add throw $eth0Mask table $tableName proto static
|
||||
|
|
@ -164,7 +164,7 @@ add_routing() {
|
|||
sudo ip route add default via $defaultGwIP table $tableName proto static
|
||||
sudo ip route flush cache
|
||||
|
||||
local ethMask=$(ip route list scope link dev $ethDev | awk '{print $1}')
|
||||
local ethMask=$(getcidr $ethDev)
|
||||
local rulePresent=$(ip rule show | grep $ethMask)
|
||||
if [ "$rulePresent" == "" ]
|
||||
then
|
||||
|
|
|
|||
|
|
@ -95,3 +95,26 @@ unlock_exit() {
|
|||
exit $1
|
||||
}
|
||||
|
||||
# calcuate the ip & network mask
|
||||
rangecalc(){
|
||||
local IFS='.'
|
||||
local -a oct mask ip
|
||||
|
||||
read -ra oct <<<"$1"
|
||||
read -ra mask <<<"$2"
|
||||
for i in {0..3}
|
||||
do
|
||||
ip+=( "$(( oct[i] & mask[i] ))" )
|
||||
done
|
||||
echo "${ip[*]}"
|
||||
}
|
||||
|
||||
#get cidr of the nic
|
||||
getcidr(){
|
||||
local dev=$1
|
||||
local mask=`ifconfig $dev|grep "Mask"|cut -d ":" -f 4`
|
||||
local cidrsize=`ip addr show $dev|grep inet|head -n 1|awk '{print $2}'|cut -d '/' -f 2`
|
||||
local ipaddr=`ip addr show $dev|grep inet|head -n 1|awk '{print $2}'|cut -d '/' -f 1`
|
||||
local base=$(rangecalc $ipaddr $mask)
|
||||
echo $base/$cidrsize
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue