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>
test -e "$pidfile" && pid=`cat "$pidfile"` && pid_exists "$pid" && pid_comm_check $1 $pid
} >/dev/null 2>&1
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
# IP addresses (including IPv6).
echo "ip addr flush dev $dev 2>/dev/null" # Suppresses "Nothing to flush".
# IP addresses (including IPv6).
echo "ip addr flush dev $dev 2>/dev/null" # Suppresses "Nothing to flush".
;;
"$dev"|"$dev:"*)
# Address label string
;;
"$dev"|"$dev:"*)
# Address label string
- addrcmd="$addrcmd label $1"
+ label=`echo $1 | sed "s/$dev/$dst/"`
+ addrcmd="$addrcmd label $label"
- echo ip -f $family addr add $addrcmd dev $dev
+ echo ip -f $family addr add $addrcmd dev $dst
-# 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
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.
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.
*" proto kernel "*) continue ;;
esac
*" proto kernel "*) continue ;;
esac
- echo "ip route add $route dev $dev"
+ echo "ip route add $route dev $dst"
echo ip link set dev $dev $linkcmd
fi
echo ip link set dev $dev $linkcmd
fi
+ move_ip_address $dev $dev
+ move_ip_routes $dev $dev