From a1d5e459917a65263c70e9d56d74643a006aef54 Mon Sep 17 00:00:00 2001 From: Gurucharan Shetty Date: Sun, 21 Jun 2015 08:39:04 -0700 Subject: [PATCH] ovs-lib: Ability to move ip address and routes. 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 Acked-by: Ben Pfaff --- utilities/ovs-lib.in | 24 +++++++++++++++++------- utilities/ovs-save | 4 ++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/utilities/ovs-lib.in b/utilities/ovs-lib.in index 32d621eb2..7cde6e426 100644 --- a/utilities/ovs-lib.in +++ b/utilities/ovs-lib.in @@ -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 } diff --git a/utilities/ovs-save b/utilities/ovs-save index 33faa9cb5..bcaf27cf6 100755 --- a/utilities/ovs-save +++ b/utilities/ovs-save @@ -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 -- 2.20.1