From dc611fa0af793002e3f7057f18238754689d5d9e Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 24 Sep 2014 09:39:44 +0100 Subject: [PATCH 1/5] Refactor common code in attach/detach --- weaver/weave | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/weaver/weave b/weaver/weave index 2870314e..f9853fc0 100755 --- a/weaver/weave +++ b/weaver/weave @@ -120,20 +120,30 @@ container_netns_preamble() { ln -s /proc/$NSPID/ns/net /var/run/netns/$NSPID LOCAL_IFNAME="v${CONTAINER_IFNAME}pl${NSPID}" GUEST_IFNAME="v${CONTAINER_IFNAME}pg${NSPID}" + EXITCODE=1 + IP_TMPFILE=/tmp/weave_ip_output_$$ + rm -f $IP_TMPFILE return 0 } -container_netns_cleanup() { +container_netns_postamble() { + if [ "$EXITCODE" -ne 0 ] ; then + if ! ps -p $DOCKERPID >/dev/null 2>&1 ; then + echo "Container $1 died" >&2 + else + echo "Failure during network configuration for container $1:" >&2 + cat $IP_TMPFILE >&2 + fi + fi + + rm -f $IP_TMPFILE rm -f /var/run/netns/$NSPID } # Parameters are container ID, CIDR address configure_container_networking() { container_netns_preamble $1 - EXITCODE=1 - IP_TMPFILE=/tmp/weave_ip_output_$$ - rm -f $IP_TMPFILE # If veth name already exists then assume we set it up already; # just add the IP address, if it's not already there @@ -161,17 +171,7 @@ configure_container_networking() { fi fi - if [ "$EXITCODE" -ne 0 ] ; then - if ! ps -p $DOCKERPID >/dev/null 2>&1 ; then - echo "Container $1 died" >&2 - else - echo "Failure during network configuration for container $1:" >&2 - cat $IP_TMPFILE >&2 - fi - fi - - rm -f $IP_TMPFILE - container_netns_cleanup + container_netns_postamble $1 return $EXITCODE } @@ -180,9 +180,6 @@ configure_container_networking() { detach() { container_netns_preamble $1 - EXITCODE=1 - IP_TMPFILE=/tmp/weave_ip_output_$$ - rm -f $IP_TMPFILE if (ip netns exec $NSPID ip addr list dev $CONTAINER_IFNAME | grep -qF $2) 2>$IP_TMPFILE ; then if ip netns exec $NSPID ip addr del $2 dev $CONTAINER_IFNAME 2>$IP_TMPFILE ; then # if no inet addresses remain then delete the veth @@ -198,17 +195,7 @@ detach() { EXITCODE=0 fi - if [ "$EXITCODE" -ne 0 ] ; then - if ! ps -p $DOCKERPID >/dev/null 2>&1 ; then - echo "Container $1 died" >&2 - else - echo "Failure while detaching address $2 from container $1" >&2 - cat $IP_TMPFILE >&2 - fi - fi - - rm -f $IP_TMPFILE - container_netns_cleanup + container_netns_postamble $1 return $EXITCODE } From d5acb312b432376aabf5632c49964960defa6433 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 24 Sep 2014 10:01:52 +0100 Subject: [PATCH 2/5] Rename 'configure_container_networking' to 'attach' --- weaver/weave | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/weaver/weave b/weaver/weave index f9853fc0..dc6dbc24 100755 --- a/weaver/weave +++ b/weaver/weave @@ -141,8 +141,9 @@ container_netns_postamble() { rm -f /var/run/netns/$NSPID } -# Parameters are container ID, CIDR address -configure_container_networking() { +# Attach Container-ID $1 to the weave network at CIDR address $2, +# creating a virtual ethernet device if necessary. +attach() { container_netns_preamble $1 # If veth name already exists then assume we set it up already; @@ -176,7 +177,8 @@ configure_container_networking() { return $EXITCODE } -# Parameters are container ID, CIDR address, interface-name +# Detach Container-ID $1 at CIDR address $2 from the weave network +# removing the virtual ethernet device if there are no more addresses detach() { container_netns_preamble $1 @@ -232,7 +234,7 @@ case "$COMMAND" in # restarts. MACADDR=`cat /sys/class/net/$BRIDGE/address` CONTAINER=$(docker run --privileged -d --name=weave -p 6783:6783/tcp -p 6783:6783/udp $WEAVE_DOCKER_ARGS zettio/weave -name $MACADDR "$@") - configure_container_networking $CONTAINER $IPADDR eth0 + attach $CONTAINER $IPADDR eth0 echo $CONTAINER ;; status) @@ -269,13 +271,13 @@ case "$COMMAND" in shift 1 create_bridge CONTAINER=$(docker run -d "$@") - configure_container_networking $CONTAINER $IPADDR $CONTAINER_IFNAME + attach $CONTAINER $IPADDR $CONTAINER_IFNAME echo $CONTAINER ;; attach) [ $# -gt 1 ] || usage create_bridge - configure_container_networking $2 $1 $CONTAINER_IFNAME + attach $2 $1 $CONTAINER_IFNAME ;; detach) [ $# -gt 1 ] || usage From a4ffb4e45ac9c599abd453314e92340d5e844788 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 24 Sep 2014 10:07:49 +0100 Subject: [PATCH 3/5] Revert "don't set pcap timeout, to prevent cpu churn" This reverts commit b5df59660fe83fd5a5d4d3ddd23e6b084ef56465. --- pcap.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pcap.go b/pcap.go index 912d0fba..354ec818 100644 --- a/pcap.go +++ b/pcap.go @@ -40,6 +40,9 @@ func newPcapIO(ifName string, promisc bool, snaplen int, bufSz int) (handle *Pca if err = inactive.SetSnapLen(snaplen); err != nil { return } + if err = inactive.SetTimeout(-1); err != nil { + return + } if err = inactive.SetImmediateMode(true); err != nil { return } From ad3a36686f69bf2a90b43c5f6c9bd77f55fb2698 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 24 Sep 2014 10:11:36 +0100 Subject: [PATCH 4/5] Cosmetic --- weaver/weave | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/weaver/weave b/weaver/weave index dc6dbc24..5d45c55e 100755 --- a/weaver/weave +++ b/weaver/weave @@ -118,9 +118,10 @@ container_netns_preamble() { [ ! -d /var/run/netns ] && mkdir -p /var/run/netns rm -f /var/run/netns/$NSPID ln -s /proc/$NSPID/ns/net /var/run/netns/$NSPID + + EXITCODE=1 LOCAL_IFNAME="v${CONTAINER_IFNAME}pl${NSPID}" GUEST_IFNAME="v${CONTAINER_IFNAME}pg${NSPID}" - EXITCODE=1 IP_TMPFILE=/tmp/weave_ip_output_$$ rm -f $IP_TMPFILE From 704c3dad67b6c6f9cbb4faee3e4992c07a32ca00 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 24 Sep 2014 10:17:45 +0100 Subject: [PATCH 5/5] Improved comment --- weaver/weave | 1 + 1 file changed, 1 insertion(+) diff --git a/weaver/weave b/weaver/weave index 5d45c55e..db6756f2 100755 --- a/weaver/weave +++ b/weaver/weave @@ -144,6 +144,7 @@ container_netns_postamble() { # Attach Container-ID $1 to the weave network at CIDR address $2, # creating a virtual ethernet device if necessary. +# Also turn off tx offload on device $3 inside the namespace. attach() { container_netns_preamble $1