Skip to content

Commit

Permalink
auto select iptables mode
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTheElder committed Mar 16, 2020
1 parent 49eba13 commit 3f5de46
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion images/base/files/usr/local/bin/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set -o nounset
set -o pipefail

fix_mount() {
echo 'INFO: ensuring we can execute /bin/mount even with userns-remap'
echo 'INFO: ensuring we can execute /bin/mount even with userns-remap'
# necessary only when userns-remap is enabled on the host, but harmless
# The binary /bin/mount should be owned by root and have the setuid bit
chown root:root /bin/mount
Expand Down Expand Up @@ -136,6 +136,24 @@ DefaultEnvironment="HTTP_PROXY=${HTTP_PROXY:-}" "HTTPS_PROXY=${HTTPS_PROXY:-}" "
EOF
}

select_iptables() {
# based on: https://github.com/kubernetes/kubernetes/blob/ffe93b3979486feb41a0f85191bdd189cbd56ccc/build/debian-iptables/iptables-wrapper
local mode=nft
num_legacy_lines=$( (iptables-legacy-save || true; ip6tables-legacy-save || true) 2>/dev/null | grep '^-' | wc -l || true)
if [ "${num_legacy_lines}" -ge 10 ]; then
mode=legacy
else
num_nft_lines=$( (timeout 5 sh -c "iptables-nft-save; ip6tables-nft-save" || true) 2>/dev/null | grep '^-' | wc -l || true)
if [ "${num_legacy_lines}" -ge "${num_nft_lines}" ]; then
mode=legacy
fi
fi

echo "INFO: setting iptables to detected mode: ${mode}"
update-alternatives --set iptables "/usr/sbin/iptables-${mode}" > /dev/null
update-alternatives --set ip6tables "/usr/sbin/ip6tables-${mode}" > /dev/null
}

# run pre-init fixups
fix_kmsg
fix_mount
Expand All @@ -144,6 +162,7 @@ fix_machine_id
fix_product_name
fix_product_uuid
configure_proxy
select_iptables

# we want the command (expected to be systemd) to be PID1, so exec to it
exec "$@"

0 comments on commit 3f5de46

Please sign in to comment.