From fad584694629ef553f845c13ed159b97f2797a3c Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sun, 26 Oct 2014 12:13:28 +0000 Subject: [PATCH] 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'. --- weave | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/weave b/weave index a4994867..8a1bbcf0 100755 --- a/weave +++ b/weave @@ -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