set iptables backend to use if specified explicitly or auto-detect
This commit is contained in:
1 parent
4b30d97d4e
commit
4f48670345
2 files changed
+60
No files matched your search
@@ -6,6 +6,34 @@ modprobe_safe() {
|
|||||||
modprobe $1 || echo "Ignore the error if \"$1\" is built-in in the kernel" >&2
|
modprobe $1 || echo "Ignore the error if \"$1\" is built-in in the kernel" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Setup iptables backend to be legacy or nftable
|
||||||
|
setup_iptables_backend() {
|
||||||
|
if [ -n "${IPTABLES_BACKEND}" ]; then
|
||||||
|
mode=$IPTABLES_BACKEND
|
||||||
|
else
|
||||||
|
# auto-detect if iptables backend mode to use if not specified explicitly
|
||||||
|
num_legacy_lines=$( (iptables-legacy-save || true) 2>/dev/null | grep '^-' | wc -l)
|
||||||
|
num_nft_lines=$( (iptables-nft-save || true) 2>/dev/null | grep '^-' | wc -l)
|
||||||
|
if [ "${num_legacy_lines}" -ge 10 ]; then
|
||||||
|
mode="legacy"
|
||||||
|
else
|
||||||
|
if [ "${num_legacy_lines}" -ge "${num_nft_lines}" ]; then
|
||||||
|
mode="legacy"
|
||||||
|
else
|
||||||
|
mode="nft"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [ $mode = "nft" ]; then
|
||||||
|
rm /sbin/iptables
|
||||||
|
rm /sbin/iptables-save
|
||||||
|
rm /sbin/iptables-restore
|
||||||
|
ln /sbin/iptables-nft /sbin/iptables
|
||||||
|
ln /sbin/iptables-nft-save /sbin/iptables-save
|
||||||
|
ln /sbin/iptables-nft-restore /sbin/iptables-restore
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Check whether xt_set actually exists
|
# Check whether xt_set actually exists
|
||||||
xt_set_exists() {
|
xt_set_exists() {
|
||||||
# Clean everything up in advance, in case there's leftovers
|
# Clean everything up in advance, in case there's leftovers
|
||||||
@@ -24,6 +52,8 @@ xt_set_exists() {
|
|||||||
[ -z "$NOT_EXIST" ] || (echo "\"xt_set\" does not exist" >&2 && return 1)
|
[ -z "$NOT_EXIST" ] || (echo "\"xt_set\" does not exist" >&2 && return 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setup_iptables_backend
|
||||||
|
|
||||||
# Default if not supplied - same as weave net default
|
# Default if not supplied - same as weave net default
|
||||||
IPALLOC_RANGE=${IPALLOC_RANGE:-10.32.0.0/12}
|
IPALLOC_RANGE=${IPALLOC_RANGE:-10.32.0.0/12}
|
||||||
HTTP_ADDR=${WEAVE_HTTP_ADDR:-127.0.0.1:6784}
|
HTTP_ADDR=${WEAVE_HTTP_ADDR:-127.0.0.1:6784}
|
||||||
|
|||||||
@@ -2,5 +2,35 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# Setup iptables backend to be legacy or nftable
|
||||||
|
setup_iptables_backend() {
|
||||||
|
if [ -n "${IPTABLES_BACKEND}" ]; then
|
||||||
|
mode=$IPTABLES_BACKEND
|
||||||
|
else
|
||||||
|
# auto-detect if iptables backend mode to use if not specified explicitly
|
||||||
|
num_legacy_lines=$( (iptables-legacy-save || true) 2>/dev/null | grep '^-' | wc -l)
|
||||||
|
num_nft_lines=$( (iptables-nft-save || true) 2>/dev/null | grep '^-' | wc -l)
|
||||||
|
if [ "${num_legacy_lines}" -ge 10 ]; then
|
||||||
|
mode="legacy"
|
||||||
|
else
|
||||||
|
if [ "${num_legacy_lines}" -ge "${num_nft_lines}" ]; then
|
||||||
|
mode="legacy"
|
||||||
|
else
|
||||||
|
mode="nft"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [ $mode = "nft" ]; then
|
||||||
|
rm /sbin/iptables
|
||||||
|
rm /sbin/iptables-save
|
||||||
|
rm /sbin/iptables-restore
|
||||||
|
ln /sbin/iptables-nft /sbin/iptables
|
||||||
|
ln /sbin/iptables-nft-save /sbin/iptables-save
|
||||||
|
ln /sbin/iptables-nft-restore /sbin/iptables-restore
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_iptables_backend
|
||||||
|
|
||||||
# Start weave-npc with any flags specified in $EXTRA_ARGS as well as any flags passed to this container (for backwards compatibility)
|
# Start weave-npc with any flags specified in $EXTRA_ARGS as well as any flags passed to this container (for backwards compatibility)
|
||||||
exec /usr/bin/weave-npc $EXTRA_ARGS $@
|
exec /usr/bin/weave-npc $EXTRA_ARGS $@
|
||||||
Reference in new issue
Block a user