From 516c1363e3a1e2421b20ff057eedcab29c560f29 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 22 Aug 2014 18:14:17 +0100 Subject: [PATCH] eliminate dependency on pipework ...and docker-ns (though we still leave the script around since it's handy for debugging), and arping (as I have yet to encounter a situation where it was required) --- README.md | 22 ++++++---------------- weaver/.gitignore | 1 - weaver/Makefile | 4 ---- weaver/weave | 34 +++++++++++++++++++++++++++++++--- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 9497467f..4c814c86 100644 --- a/README.md +++ b/README.md @@ -8,24 +8,14 @@ multiple containers, running anywhere. ## Installation -Each host needs to have the following installed +Each host needs to have `weave` from the `weaver` sub-directory +installed in the root user's path, e.g. -- `weave` and `docker-ns` from the `weaver` sub-directory. Install - these somewhere in the root user's path, e.g. `/usr/local/bin`. -- [pipework][], by Jérôme Petazzoni. Install this in the same place as - the aforementioned scripts. + host# curl https://raw.githubusercontent.com/zettio/weave/master/weaver/weave \ + > /usr/local/bin/weave; chmod a+x /usr/local/bin/weave -[pipework]: https://raw.githubusercontent.com/jpetazzo/pipework/master/pipework - -e.g. - - host# cp -a weaver/weave weaver/docker-ns /usr/local/bin - host# curl https://raw.githubusercontent.com/jpetazzo/pipework/master/pipework \ - > /usr/local/bin/pipework; chmod a+x /usr/local/bin/pipework - -We also need `ethtool` and `arping`. On most systems these are -installed already; if not then grab them via your favourite package -manager. +We also need `ethtool`. On most systems that is installed already; if +not then grab it via your favourite package manager. ## Example diff --git a/weaver/.gitignore b/weaver/.gitignore index 766b4578..ffe05437 100644 --- a/weaver/.gitignore +++ b/weaver/.gitignore @@ -1,2 +1 @@ weaver -pipework diff --git a/weaver/Makefile b/weaver/Makefile index ca51ed4c..7c0ea882 100644 --- a/weaver/Makefile +++ b/weaver/Makefile @@ -13,10 +13,6 @@ docker-image: /tmp/weave.tar sudo docker build -t zettio/weave . sudo docker save zettio/weave > /tmp/weave.tar -pipework: - wget --no-check-certificate -nv https://raw.github.com/jpetazzo/pipework/master/pipework - chmod +x pipework - clean: -sudo docker rmi zettio/weave rm -f weaver pipework /tmp/weave.tar diff --git a/weaver/weave b/weaver/weave index a325bf7c..0d3f4304 100755 --- a/weaver/weave +++ b/weaver/weave @@ -12,7 +12,7 @@ shift 2 # pre-create bridge so we can set the MTU [ ! -d /sys/class/net/$BRIDGE ] && { - ip link add dev $BRIDGE type bridge > /dev/null 2>&1 + ip link add dev $BRIDGE type bridge ip link set dev $BRIDGE address 7a:$(od -txC -An -N5 /dev/random | tr \ : | tail -c+2) # attempting to set the bridge MTU to a high value directly # fails. Bridges take the lowest MTU of their interfaces. So @@ -42,8 +42,36 @@ case "$COMMAND" in ;; esac -${SCRIPT_DIR}/pipework $BRIDGE -i $CONTAINER_IFNAME $CONTAINER $IPADDR 1>&2 +# the following borrows from https://github.com/jpetazzo/pipework -${SCRIPT_DIR}/docker-ns $CONTAINER ethtool -K $IFACE tx off > /dev/null +DOCKERPID=$(docker inspect --format='{{ .State.Pid }}' $CONTAINER) +[ "$DOCKERPID" = 0 ] && { + echo "Docker inspect returned invalid PID 0" + exit 1 +} +[ "$DOCKERPID" = "" ] && { + echo "Container $CONTAINER unknown to Docker." + exit 1 +} + +NSPID=$DOCKERPID + +[ ! -d /var/run/netns ] && mkdir -p /var/run/netns +[ -f /var/run/netns/$NSPID ] && rm -f /var/run/netns/$NSPID +ln -s /proc/$NSPID/ns/net /var/run/netns/$NSPID + +LOCAL_IFNAME="v${CONTAINER_IFNAME}pl${NSPID}" +GUEST_IFNAME="v${CONTAINER_IFNAME}pg${NSPID}" +ip link add name $LOCAL_IFNAME mtu $MTU type veth peer name $GUEST_IFNAME mtu $MTU +ip link set $LOCAL_IFNAME master $BRIDGE +ip link set $LOCAL_IFNAME up +ip link set $GUEST_IFNAME netns $NSPID +ip netns exec $NSPID ip link set $GUEST_IFNAME name $CONTAINER_IFNAME +ip netns exec $NSPID ip addr add $IPADDR dev $CONTAINER_IFNAME +ip netns exec $NSPID ip link set $CONTAINER_IFNAME up + +ip netns exec $NSPID ethtool -K $IFACE tx off > /dev/null + +[ -f /var/run/netns/$NSPID ] && rm -f /var/run/netns/$NSPID echo $CONTAINER