ovs-lib: Ability to move ip address and routes.
authorGurucharan Shetty <gshetty@nicira.com>
Sun, 21 Jun 2015 15:39:04 +0000 (08:39 -0700)
committerGurucharan Shetty <gshetty@nicira.com>
Wed, 1 Jul 2015 16:00:27 +0000 (09:00 -0700)
The ability to move IP address and routes between two interfaces
is useful when we want to make a physical interface (say eth0)
as a port of OVS bridge (say breth0) with all its IP address and route
information transferred to OVS bridge. An upcoming commit
uses the new ability.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
utilities/ovs-lib.in
utilities/ovs-save

index 32d621e..7cde6e4 100644 (file)
@@ -251,9 +251,14 @@ daemon_is_running () {
     test -e "$pidfile" && pid=`cat "$pidfile"` && pid_exists "$pid" && pid_comm_check $1 $pid
 } >/dev/null 2>&1
 
-# Prints commands needed to restore the ip address of an interface.
-save_ip_address () {
+# Prints commands needed to move the ip address from interface $1 to interface
+# $2
+move_ip_address () {
+    if [ -z "$1" ] || [ -z "$2" ]; then
+        return
+    fi
     dev="$1"
+    dst="$2"
 
     # IP addresses (including IPv6).
     echo "ip addr flush dev $dev 2>/dev/null" # Suppresses "Nothing to flush".
@@ -286,7 +291,8 @@ save_ip_address () {
                     ;;
                 "$dev"|"$dev:"*)
                     # Address label string
-                    addrcmd="$addrcmd label $1"
+                    label=`echo $1 | sed "s/$dev/$dst/"`
+                    addrcmd="$addrcmd label $label"
                     shift
                     continue
                     ;;
@@ -298,13 +304,17 @@ save_ip_address () {
             addrcmd="$addrcmd $1"
         fi
 
-        echo ip -f $family addr add $addrcmd dev $dev
+        echo ip -f $family addr add $addrcmd dev $dst
     done
 }
 
-# Prints commands needed to restore the ip route of an interface.
-save_ip_routes () {
+# Prints commands needed to move the ip route of interface $1 to interface $2
+move_ip_routes () {
+    if [ -z "$1" ] || [ -z "$2" ]; then
+        return
+    fi
     dev="$1"
+    dst="$2"
     echo "ip route flush dev $dev proto boot 2>/dev/null" # Suppresses "Nothing to flush".
     ip route show dev $dev | while read route; do
         # "proto kernel" routes are installed by the kernel automatically.
@@ -312,6 +322,6 @@ save_ip_routes () {
             *" proto kernel "*) continue ;;
         esac
 
-        echo "ip route add $route dev $dev"
+        echo "ip route add $route dev $dst"
     done
 }
index 33faa9c..bcaf27c 100755 (executable)
@@ -84,9 +84,9 @@ save_interfaces () {
             echo ip link set dev $dev $linkcmd
         fi
 
-        save_ip_address $dev
+        move_ip_address $dev $dev
 
-        save_ip_routes $dev
+        move_ip_routes $dev $dev
 
         echo
     done