From a31d8c4d8001ab05210c7f6716f288f6819a7f4f Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 30 Sep 2014 15:23:23 +0100 Subject: [PATCH] Refactor add_nat_rule into add_iptables_rule that is more general --- weaver/weave | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/weaver/weave b/weaver/weave index fe83ad52..4f2e6d6d 100755 --- a/weaver/weave +++ b/weaver/weave @@ -82,13 +82,20 @@ run_iptables() { iptables $IPTABLES_W "$@" } -add_nat_rule() { - if ! run_iptables -t nat -C "$@" >/dev/null 2>&1 +# 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 nat -A "$@" >/dev/null + 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