You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ya...@apache.org on 2013/07/11 00:54:21 UTC

git commit: updated refs/heads/4.2 to 2ea61e7

Updated Branches:
  refs/heads/4.2 f8e45c2d7 -> 2ea61e7f2


CLOUDSTACK-3436: Fix inconsistent ip routing table between redundant virtual routers


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/2ea61e7f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/2ea61e7f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/2ea61e7f

Branch: refs/heads/4.2
Commit: 2ea61e7f2259978589df829f8168dcc673b4d40b
Parents: f8e45c2
Author: Sheng Yang <sh...@citrix.com>
Authored: Wed Jul 10 15:53:31 2013 -0700
Committer: Sheng Yang <sh...@citrix.com>
Committed: Wed Jul 10 15:54:14 2013 -0700

----------------------------------------------------------------------
 .../debian/config/opt/cloud/bin/ipassoc.sh      |  8 +++----
 patches/systemvm/debian/config/root/func.sh     | 23 ++++++++++++++++++++
 2 files changed, 27 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2ea61e7f/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh
----------------------------------------------------------------------
diff --git a/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh b/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh
index d23ec00..9efae26 100755
--- a/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh
+++ b/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh
@@ -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

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2ea61e7f/patches/systemvm/debian/config/root/func.sh
----------------------------------------------------------------------
diff --git a/patches/systemvm/debian/config/root/func.sh b/patches/systemvm/debian/config/root/func.sh
index 8cc9608..9c7c494 100644
--- a/patches/systemvm/debian/config/root/func.sh
+++ b/patches/systemvm/debian/config/root/func.sh
@@ -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
+}