From 264d5e482838973bf2ac350753ddd702be45ec3e Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 9 Feb 2016 17:13:20 +0000 Subject: [PATCH] Make attach-bridge iptables rule insertion idempotent --- weave | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/weave b/weave index 721a2347..b2c7e124 100755 --- a/weave +++ b/weave @@ -403,6 +403,15 @@ add_iptables_rule() { fi } +# Insert a rule in iptables, if it doesn't exist already +insert_iptables_rule() { + IPTABLES_TABLE="$1" + shift 1 + if ! run_iptables -t $IPTABLES_TABLE -C "$@" >/dev/null 2>&1 ; then + run_iptables -t $IPTABLES_TABLE -I "$@" >/dev/null + fi +} + # Delete a rule from iptables, if it exist delete_iptables_rule() { IPTABLES_TABLE="$1" @@ -1832,7 +1841,7 @@ EOF attach-bridge) if detect_bridge_type ; then attach_bridge ${1:-$DOCKER_BRIDGE} - run_iptables -t nat -I POSTROUTING -o $BRIDGE -j ACCEPT + insert_iptables_rule nat POSTROUTING -o $BRIDGE -j ACCEPT else echo "Weave bridge not found. Please run 'weave launch' and try again" >&2 exit 1