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
+21 -9
+21 -9
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
for addr; do
# container already has the expected network interface, so assume we set it up already; # container already has the expected network interface, so assume we set it up already;
# just add the IP address. # just add the IP address.
if ip netns exec $NETNS ip addr show dev $CONTAINER_IFNAME | grep -F $1 >/dev/null ; then if ip netns exec $NETNS ip addr show dev $CONTAINER_IFNAME | grep -F $addr >/dev/null ; then
# address was there already # address was there already
continue
fi
if ! ip netns exec $NETNS ip addr add $addr dev $CONTAINER_IFNAME ; then
return 1
fi
done
return 0 return 0
fi fi
if ! ip netns exec $NETNS ip addr add $1 dev $CONTAINER_IFNAME ; then if ! connect_container_to_bridge; then
return 1 return 1
fi fi
return 0 for addr; do
if ! ip netns exec $NETNS ip addr add $1 dev $CONTAINER_IFNAME; then
return 1
fi fi
done
if ! connect_container_to_bridge || if ! ip netns exec $NETNS ip link set $CONTAINER_IFNAME up ; then
! ip netns exec $NETNS ip addr add $1 dev $CONTAINER_IFNAME ||
! 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
if ! ip netns exec $NETNS ip addr show dev $CONTAINER_IFNAME | grep -F $addr >/dev/null ; then
# address is not there, leave the device alone # address is not there, leave the device alone
return 0 continue
fi 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