Make attach-bridge iptables rule insertion idempotent
This commit is contained in:
1 parent
2bfc86e7b2
commit
264d5e4828
1 file changed
+10
-1
@@ -403,6 +403,15 @@ add_iptables_rule() {
|
|||||||
fi
|
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 a rule from iptables, if it exist
|
||||||
delete_iptables_rule() {
|
delete_iptables_rule() {
|
||||||
IPTABLES_TABLE="$1"
|
IPTABLES_TABLE="$1"
|
||||||
@@ -1832,7 +1841,7 @@ EOF
|
|||||||
attach-bridge)
|
attach-bridge)
|
||||||
if detect_bridge_type ; then
|
if detect_bridge_type ; then
|
||||||
attach_bridge ${1:-$DOCKER_BRIDGE}
|
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
|
else
|
||||||
echo "Weave bridge not found. Please run 'weave launch' and try again" >&2
|
echo "Weave bridge not found. Please run 'weave launch' and try again" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Reference in new issue
Block a user