Merge pull request #3747 from weaveworks/iptables1.8

support Iptables 1.8 with legacy and nf_tables support
This commit is contained in:
Bryan Boreham authored and GitHub committed 2020-01-08 10:46:41 +00:00
commit 8bdfcd3042
4 files changed
+62 -1

No files matched your search

+1 -1
View File
@@ -25,7 +25,7 @@ ifeq ($(ARCH),amd64)
WEAVEEXEC_DOCKER_ARCH?=x86_64
# The name of the alpine baseimage to use as the base for weave images
ALPINE_BASEIMAGE?=alpine:3.8
ALPINE_BASEIMAGE?=alpine:3.10
# The extension for the made images
# Specifying none means for example weaveworks/weave:latest
+30
View File
@@ -6,6 +6,34 @@ modprobe_safe() {
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 -s /sbin/iptables-nft /sbin/iptables
ln -s /sbin/iptables-nft-save /sbin/iptables-save
ln -s /sbin/iptables-nft-restore /sbin/iptables-restore
fi
}
# Check whether xt_set actually exists
xt_set_exists() {
# 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)
}
setup_iptables_backend
# Default if not supplied - same as weave net default
IPALLOC_RANGE=${IPALLOC_RANGE:-10.32.0.0/12}
HTTP_ADDR=${WEAVE_HTTP_ADDR:-127.0.0.1:6784}
+30
View File
@@ -2,5 +2,35 @@
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 -s /sbin/iptables-nft /sbin/iptables
ln -s /sbin/iptables-nft-save /sbin/iptables-save
ln -s /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)
exec /usr/bin/weave-npc $EXTRA_ARGS $@
+1
View File
@@ -406,6 +406,7 @@ The list of variables you can set is:
* `NO_MASQ_LOCAL` - set to 1 to preserve the client source IP address when
accessing Service annotated with `service.spec.externalTrafficPolicy=Local`.
The feature works only with Weave IPAM (default).
* `IPTABLES_BACKEND` - set to `nft` to use `nftables` backend for `iptables` (default is `iptables`)
Example:
```