Modify attach/detach helpers to take list of addresses

This commit is contained in:
Adam Harrison committed 2015-03-27 15:36:10 +00:00
1 parent 140ac8939b
commit e3c0807a18
1 file changed
+31 -19
+31 -19
View File
@@ -325,23 +325,33 @@ launch() {
attach() { attach() {
if ip netns exec $NETNS ip link show $CONTAINER_IFNAME >/dev/null 2>&1 ; then if ip netns exec $NETNS ip link show $CONTAINER_IFNAME >/dev/null 2>&1 ; then
# container already has the expected network interface, so assume we set it up already; for addr; do
# just add the IP address. # container already has the expected network interface, so assume we set it up already;
if ip netns exec $NETNS ip addr show dev $CONTAINER_IFNAME | grep -F $1 >/dev/null ; then # just add the IP address.
# address was there already if ip netns exec $NETNS ip addr show dev $CONTAINER_IFNAME | grep -F $addr >/dev/null ; then
return 0 # address was there already
fi continue
fi
if ! ip netns exec $NETNS ip addr add $1 dev $CONTAINER_IFNAME ; then if ! ip netns exec $NETNS ip addr add $addr dev $CONTAINER_IFNAME ; then
return 1 return 1
fi fi
done
return 0 return 0
fi fi
if ! connect_container_to_bridge || if ! connect_container_to_bridge; then
! ip netns exec $NETNS ip addr add $1 dev $CONTAINER_IFNAME || return 1
! ip netns exec $NETNS ip link set $CONTAINER_IFNAME up ; then fi
for addr; do
if ! ip netns exec $NETNS ip addr add $1 dev $CONTAINER_IFNAME; then
return 1
fi
done
if ! ip netns exec $NETNS ip link set $CONTAINER_IFNAME up ; then
return 1 return 1
fi fi
@@ -354,14 +364,16 @@ attach() {
} }
detach() { detach() {
if ! ip netns exec $NETNS ip addr show dev $CONTAINER_IFNAME | grep -F $1 >/dev/null ; then for addr; do
# address is not there, leave the device alone if ! ip netns exec $NETNS ip addr show dev $CONTAINER_IFNAME | grep -F $addr >/dev/null ; then
return 0 # address is not there, leave the device alone
fi continue
fi
if ! ip netns exec $NETNS ip addr del $1 dev $CONTAINER_IFNAME ; then if ! ip netns exec $NETNS ip addr del $addr dev $CONTAINER_IFNAME ; then
return 1 return 1
fi fi
done
if [ -n "$(ip netns exec $NETNS ip -f inet addr show dev $CONTAINER_IFNAME)" ] ; then if [ -n "$(ip netns exec $NETNS ip -f inet addr show dev $CONTAINER_IFNAME)" ] ; then
# other addresses are left, leave the device alone # other addresses are left, leave the device alone