diff --git a/overlay.d/06gcp-routes/usr/sbin/gcp-routes.sh b/overlay.d/06gcp-routes/usr/sbin/gcp-routes.sh index 5876fe56..39fdba5c 100755 --- a/overlay.d/06gcp-routes/usr/sbin/gcp-routes.sh +++ b/overlay.d/06gcp-routes/usr/sbin/gcp-routes.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Update iptables rules based on google cloud load balancer VIPS +# Update nftables rules based on google cloud load balancer VIPS # # This is needed because the GCP L3 load balancer doesn't actually do DNAT; # the destination IP address is still the VIP. Normally, there is an agent that @@ -14,8 +14,6 @@ # # Additionally, clients can write a file to /run/gcp-routes/$IP.down to force # a VIP as down. This is useful for graceful shutdown / upgrade. -# -# ~cdc~ set -e @@ -27,63 +25,41 @@ curler() { curl --silent -L -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/${1}" } -CHAIN_NAME="gcp-vips" +TABLE_NAME="gcp-vips" +EXTERNAL_VIPS_CHAIN="external-vips" RUN_DIR="/run/gcp-routes" -# Create a chan if it doesn't exist -ensure_chain() { - local table="${1}" - local chain="${2}" - - if ! iptables -w -t "${table}" -S "${chain}" &> /dev/null ; then - iptables -w -t "${table}" -N "${chain}"; - fi; -} - -ensure_rule() { - local table="${1}" - local chain="${2}" - shift 2 - - if ! iptables -w -t "${table}" -C "${chain}" "$@" &> /dev/null; then - iptables -w -t "${table}" -A "${chain}" "$@" - fi -} - -# set the chain, ensure entry rules, ensure ESTABLISHED rule +# Set up base table and rules initialize() { - ensure_chain nat "${CHAIN_NAME}" - ensure_rule nat PREROUTING -m comment --comment 'gcp LB vip DNAT' -j ${CHAIN_NAME} - - # Need this so that existing flows (with an entry in conntrack) continue to be - # balanced, even if the DNAT entry is removed - ensure_rule filter INPUT -m comment --comment 'gcp LB vip existing' -m addrtype ! --dst-type LOCAL -m state --state ESTABLISHED,RELATED -j ACCEPT + nft -f - <