From 4d5faafd0cae360cb1ad190389ccfebc9304450f Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Tue, 30 Sep 2014 16:09:56 +0100 Subject: [PATCH] refactor: order functions by dependency --- weaver/weave | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/weaver/weave b/weaver/weave index f9452dfd..d50ee277 100755 --- a/weaver/weave +++ b/weaver/weave @@ -47,6 +47,32 @@ check_command_and_run() { fi } +run_iptables() { + # -w is recent addition to iptables + if [ -z "$CHECKED_IPTABLES_W" ] ; then + if iptables -S -w >/dev/null 2>&1 ; then + IPTABLES_W=-w + fi + CHECKED_IPTABLES_W=1 + fi + + iptables $IPTABLES_W "$@" +} + +# Add a rule to iptables, if it doesn't exist already +add_iptables_rule() { + IPTABLES_TABLE="$1" + shift 1 + if ! run_iptables -t $IPTABLES_TABLE -C "$@" >/dev/null 2>&1 + then + run_iptables -t $IPTABLES_TABLE -A "$@" >/dev/null + fi +} + +add_nat_rule() { + add_iptables_rule nat "$@" +} + create_bridge() { [ ! -d /sys/class/net/$BRIDGE ] && { ip link add dev $BRIDGE type bridge @@ -74,32 +100,6 @@ destroy_bridge() { run_iptables -t filter -D FORWARD -i weave -o weave -j ACCEPT 2>/dev/null || true } -run_iptables() { - # -w is recent addition to iptables - if [ -z "$CHECKED_IPTABLES_W" ] ; then - if iptables -S -w >/dev/null 2>&1 ; then - IPTABLES_W=-w - fi - CHECKED_IPTABLES_W=1 - fi - - iptables $IPTABLES_W "$@" -} - -# Add a rule to iptables, if it doesn't exist already -add_iptables_rule() { - IPTABLES_TABLE="$1" - shift 1 - if ! run_iptables -t $IPTABLES_TABLE -C "$@" >/dev/null 2>&1 - then - run_iptables -t $IPTABLES_TABLE -A "$@" >/dev/null - fi -} - -add_nat_rule() { - add_iptables_rule nat "$@" -} - setup_masquerading() { run_iptables -t nat -N WEAVE >/dev/null 2>&1 || true add_nat_rule POSTROUTING -j WEAVE