Move fix-net logic from hooks to if-up
authorDimitris Aragiorgis <dimara@grnet.gr>
Mon, 13 Jan 2014 09:03:34 +0000 (11:03 +0200)
committerDimitris Aragiorgis <dimara@grnet.gr>
Mon, 13 Jan 2014 09:03:34 +0000 (11:03 +0200)
In target node we used to run arping and ndsend. Move these
commands to if-up script.

Introduce helper function to get eui64 and uplink.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>

common.sh
dnshook
fix-net

index 73a13ca..c89cc2a 100755 (executable)
--- a/common.sh
+++ b/common.sh
@@ -66,26 +66,38 @@ function routed_setup_ipv4 {
 
        # Enable proxy ARP
        echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp
+
+  # Send GARP from host to upstream router
+  get_uplink $TABLE
+  echo 1 > /proc/sys/net/ipv4/ip_nonlocal_bind
+  hooks-log $0 "arping  -c3 -I $UPLINK -U $IP"
+  arping  -c3 -I $UPLINK -U $IP
+  echo 0 > /proc/sys/net/ipv4/ip_nonlocal_bind
+
 }
 
 function routed_setup_ipv6 {
        # Add a routing entry for the eui-64
-       prefix=$NETWORK_SUBNET6
-       uplink=$(ip -6 route list table $TABLE | grep "default via" | awk '{print $5}')
-       eui64=$($MAC2EUI64 $MAC $prefix)
+  get_uplink $TABLE "-6"
+  get_eui64 $MAC $NETWORK_SUBNET6
 
-  if [ -z "$eui64" -o -z "$TABLE" -o -z "$INTERFACE" -o -z "$uplink" ]
+  if [ -z "$EUI64" -o -z "$TABLE" -o -z "$INTERFACE" -o -z "$UPLINK" ]
   then
     return
   fi
 
        ip -6 rule add dev $INTERFACE table $TABLE
-       ip -6 ro replace $eui64/128 dev $INTERFACE table $TABLE
-       ip -6 neigh add proxy $eui64 dev $uplink
+       ip -6 ro replace $EUI64/128 dev $INTERFACE table $TABLE
+       ip -6 neigh add proxy $EUI64 dev $UPLINK
 
        # disable proxy NDP since we're handling this on userspace
        # this should be the default, but better safe than sorry
        echo 0 > /proc/sys/net/ipv6/conf/$INTERFACE/proxy_ndp
+
+  # Send Unsolicited Neighbor Advertisement
+  hooks-log $0 "ndsend $EUI64 $UPLINK"
+  ndsend $EUI64 $UPLINK
+
 }
 
 # pick a firewall profile per NIC, based on tags (and apply it)
@@ -171,3 +183,27 @@ EOF
 
 }
 
+function get_uplink {
+
+  local table=$1
+  local version=$2
+  UPLINK=$(ip "$version" route list table "$table" | grep "default via" | awk '{print $5}')
+
+}
+
+# Because we do not have IPv6 value in our environment
+# we caclulate it based on the NIC's MAC and the IPv6 subnet (if any)
+# first argument MAC second IPv6 subnet
+# Changes global value EUI64
+get_eui64 () {
+
+  local mac=$1
+  local prefix=$2
+
+  if [ -z "$prefix" ]; then
+    EUI64=
+  else
+    EUI64=$($MAC2EUI64 $mac $prefix)
+  fi
+
+}
diff --git a/dnshook b/dnshook
index f93ae58..2cbb01a 100755 (executable)
--- a/dnshook
+++ b/dnshook
@@ -13,6 +13,7 @@ KEYFILE=""
 MAC2EUI64="/usr/bin/mac2eui64"
 
 source /etc/default/snf-network
+source /usr/lib/snf-network/common.sh
 
 if [ -z "$SERVER" -o -z "$FZONE" -o ! -e "$KEYFILE" ]; then
   exit 0
@@ -211,24 +212,6 @@ reset_dns () {
 }
 
 
-# Because we do not have IPv6 value in our environment
-# we caclulate it based on the NIC's MAC and the IPv6 subnet (if any)
-# first argument MAC second IPv6 subnet
-# Changes global value EUI64
-get_eui64 () {
-
-  local mac=$1
-  local prefix=$2
-
-  if [ -z "$prefix" ]; then
-    EUI64=
-  else
-    EUI64=$($MAC2EUI64 $MAC $SUBNET6)
-  fi
-
-}
-
-
 # Main starts here
 
 
diff --git a/fix-net b/fix-net
index 655beb8..50bb092 100755 (executable)
--- a/fix-net
+++ b/fix-net
@@ -28,23 +28,14 @@ for idx in $(seq $FIRST $LAST); do
   for tag in $TAGS; do
     case $tag in
     $IP_LESS_ROUTED_TAG)
-      uplink=$(ip route list table $LINK | grep "default via" | awk '{print $5}')
-      uplink6=$(ip -6 route list table $LINK | grep "default via" | awk '{print $5}')
-      eui64=$($MAC2EUI64 $MAC $SUBNET6 2>/dev/null)
       if [ "$GANETI_INSTANCE_OLD_PRIMARY" == "$host.$domain" ]; then
         # This runs on the source node
-        hooks-log $0 "ip -6 neigh del proxy $eui64 dev $uplink6"
-        ip -6 neigh del proxy $eui64 dev $uplink6 >/dev/null 2>&1
+        get_uplink $LINK "-6"
+        get_eui64 $MAC $SUBNET6
+        hooks-log $0 "ip -6 neigh del proxy $EUI64 dev $UPLINK"
+        ip -6 neigh del proxy $EUI64 dev $UPLINK >/dev/null 2>&1
       elif [ "$GANETI_INSTANCE_NEW_PRIMARY" == "$host.$domain" ]; then
-        # This runs on the target node
-        # Send GARP from host to upstream router to speed up mac change for the VMs IP
-        hooks-log $0 "arping  -c3 -I $uplink -U $IP"
-        echo 1 > /proc/sys/net/ipv4/ip_nonlocal_bind
-        arping  -c3 -I $uplink -U $IP
-        echo 0 > /proc/sys/net/ipv4/ip_nonlocal_bind
-        # Send Unsolicited Neighbor Advertisement to speed up nd change for the VMs IP
-        hooks-log $0 "ndsend $eui64 $uplink6"
-        ndsend $eui64 $uplink6
+        hooks-log $0 "Do nothing in new primary. All done by if-up script"
       fi
     ;;
     esac