From a3d842bf4a0ab3db52686f20221762432ebda89d Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 4 Feb 2016 17:24:57 +0000 Subject: [PATCH] Implement attach-bridge --- weave | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/weave b/weave index 33ba5392..fda1a467 100755 --- a/weave +++ b/weave @@ -492,6 +492,12 @@ detect_bridge_type() { # No bridge/datapath devices configured return 1 fi + + # WEAVE_MTU may have been specified when the bridge was + # created (perhaps implicitly with WEAVE_NO_FASTDP). So take + # the MTU from the bridge unless it is explicitly specified + # for this invocation. + MTU=${WEAVE_MTU:-$(cat /sys/class/net/$BRIDGE/mtu)} } create_bridge() { @@ -559,12 +565,6 @@ EOF return 1 fi fi - - # WEAVE_MTU may have been specified when the bridge was - # created (perhaps implicitly with WEAVE_NO_FASTDP). So take - # the MTU from the bridge unless it is explicitly specified - # for this invocation. - MTU=${WEAVE_MTU:-$(cat /sys/class/net/$BRIDGE/mtu)} fi [ "$1" = "--without-ethtool" ] || ethtool_tx_off_$BRIDGE_TYPE $BRIDGE @@ -797,6 +797,23 @@ add_iface_bridged_fastdp() { add_iface_bridge "$@" } +attach_bridge() { + bridge="$1" + LOCAL_IFNAME=v${CONTAINER_IFNAME}bl$bridge + GUEST_IFNAME=v${CONTAINER_IFNAME}bg$bridge + + ip link show $GUEST_IFNAME >/dev/null 2>&1 && return 0 + if ! ip link add name $LOCAL_IFNAME mtu $MTU type veth peer name $GUEST_IFNAME mtu $MTU || + ! ip link set $LOCAL_IFNAME up || + ! add_iface_$BRIDGE_TYPE $LOCAL_IFNAME || + ! ip link set $GUEST_IFNAME up + ! ip link set $GUEST_IFNAME master $bridge ; then + ip link del $GUEST_IFNAME >/dev/null 2>&1 || true + ip link del $LOCAL_IFNAME >/dev/null 2>&1 || true + return 1 + fi +} + router_opts_fastdp() { echo "--datapath $DATAPATH" } @@ -1795,18 +1812,34 @@ case "$COMMAND" in # intentionally undocumented since it assumes knowledge of weave # internals create-bridge) + cat 1>&2 <&2 <&2 + exit 1 + fi + ;; bridge-type) detect_bridge_type && echo $BRIDGE_TYPE ;;