refactor: extract basic container/bridge connection establishment

Note that we do not mark the interface in the container as 'up' here
since some callers, in particular 'attach', add CIDRs to the
interface, and some programs rely on 'up' implying 'has IP address'.
This commit is contained in:
Matthias Radestock committed 2014-10-26 12:13:28 +00:00
1 parent de82adce46
commit fad5846946
1 file changed
+8 -16
+8 -16
View File
@@ -175,7 +175,7 @@ with_container_netns () {
return $STATUS
}
launch() {
connect_container_to_bridge() {
if ! ip link add name $LOCAL_IFNAME mtu $MTU type veth peer name $GUEST_IFNAME mtu $MTU ; then
return 1
fi
@@ -188,7 +188,12 @@ launch() {
ip link set $LOCAL_IFNAME master $BRIDGE &&
ip link set $LOCAL_IFNAME up &&
ip netns exec $NETNS ip link set $GUEST_IFNAME name $CONTAINER_IFNAME &&
ip netns exec $NETNS ip link set $GUEST_IFNAME name $CONTAINER_IFNAME
}
launch() {
connect_container_to_bridge &&
ip netns exec $NETNS ip link set $CONTAINER_IFNAME up &&
check_command_and_run ethtool ip netns exec $NETNS ethtool -K eth0 tx off >/dev/null
}
@@ -209,20 +214,7 @@ attach() {
return 0
fi
if ! ip link add name $LOCAL_IFNAME mtu $MTU type veth peer name $GUEST_IFNAME mtu $MTU ; then
return 1
fi
if ! ip link set $GUEST_IFNAME netns $NETNS ; then
# failed before we assigned the veth to the container's
# namespace - delete it
ip link del $LOCAL_IFNAME type veth || true
return 1
fi
if ! ip link set $LOCAL_IFNAME master $BRIDGE ||
! ip link set $LOCAL_IFNAME up ||
! ip netns exec $NETNS ip link set $GUEST_IFNAME name $CONTAINER_IFNAME ||
if ! connect_container_to_bridge ||
! ip netns exec $NETNS ip addr add $1 dev $CONTAINER_IFNAME ||
! ip netns exec $NETNS ip link set $CONTAINER_IFNAME up ||
! check_command_and_run ethtool ip netns exec $NETNS ethtool -K $CONTAINER_IFNAME tx off >/dev/null ; then