Skip to content

Commit

Permalink
Implement attach-bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
awh committed Feb 8, 2016
1 parent 1d3c80a commit 2981e4f
Showing 1 changed file with 48 additions and 8 deletions.
56 changes: 48 additions & 8 deletions weave
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -797,6 +797,25 @@ 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 del $LOCAL_IFNAME >/dev/null 2>&1 || true
ip link del $GUEST_IFNAME >/dev/null 2>&1 || true

ip link add name $LOCAL_IFNAME mtu $MTU type veth peer name $GUEST_IFNAME mtu $MTU || return 1

if ! ip link set $LOCAL_IFNAME up ||
! ip link set $GUEST_IFNAME up ||
! add_iface_$BRIDGE_TYPE $LOCAL_IFNAME ||
! ip link set $GUEST_IFNAME master $bridge ; then
ip link del $GUEST_IFNAME >/dev/null 2>&1 || true
return 1
fi
}

router_opts_fastdp() {
echo "--datapath $DATAPATH"
}
Expand Down Expand Up @@ -1795,18 +1814,39 @@ case "$COMMAND" in
# intentionally undocumented since it assumes knowledge of weave
# internals
create-bridge)
cat 1>&2 <<EOF
WARNING: 'weave create-bridge' now requires docker to be running, which
means you can no longer use it to create the weave bridge upfront for use
as the docker bridge. Instead:
* Launch docker
* Launch weave
* Execute 'weave attach-bridge' to link the docker and weave bridges
Note that 'weave attach-bridge' is compatible with fast data path!
EOF
# This subcommand may be run without the docker daemon, but
# fastdp needs to run the router container to setup the ODP
# bridge, hence:
if [ -z "$WEAVE_NO_FASTDP" ] ; then
cat 1>&2 <<EOF
'weave create-bridge' is not compatible with fast data path. Please set
the WEAVE_NO_FASTDP environment variable.
ERROR: 'weave create-bridge' is not compatible with fast data path. If you
really want to do this please set the WEAVE_NO_FASTDP environment variable.
EOF
exit 1
fi
create_bridge --without-ethtool
;;
attach-bridge)
if detect_bridge_type ; then
attach_bridge ${1:-$DOCKER_BRIDGE}
run_iptables -t nat -I POSTROUTING -o $BRIDGE -j ACCEPT
else
echo "Weave bridge not found. Please run 'weave launch' and try again" >&2
exit 1
fi
;;
bridge-type)
detect_bridge_type && echo $BRIDGE_TYPE
;;
Expand Down

0 comments on commit 2981e4f

Please sign in to comment.