From eb172cc05b2e610e48f637cb3588a8871c28038e Mon Sep 17 00:00:00 2001 From: ssonigra Date: Mon, 7 Sep 2026 14:57:00 +0530 Subject: [PATCH] fix(ovnkube): prevent duplicate NOTRACK iptables rules on container restart Check whether each NOTRACK rule already exists (iptables -C) before appending it. Without this guard, every ovnkube-controller container restart blindly appends duplicate rules for the Geneve and hybrid overlay VXLAN ports. Because NOTRACK is a non-terminating target, duplicates are all evaluated sequentially, inflating packet counters and wasting CPU. Signed-off-by: Saurab Sonigra --- .../ovn-kubernetes/common/008-script-lib.yaml | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/bindata/network/ovn-kubernetes/common/008-script-lib.yaml b/bindata/network/ovn-kubernetes/common/008-script-lib.yaml index 63b7c2f52c..b6342a3b04 100644 --- a/bindata/network/ovn-kubernetes/common/008-script-lib.yaml +++ b/bindata/network/ovn-kubernetes/common/008-script-lib.yaml @@ -487,6 +487,26 @@ data: cp -f "/usr/libexec/cni/ovn-k8s-cni-overlay" /cni-bin-dir/ } + # ensure-notrack-rule ensures exactly one NOTRACK rule exists for the given + # iptables command, chain, and port. Adds the rule if missing, removes only + # duplicates if present, and does nothing if a single rule already exists. + ensure-notrack-rule() + { + local cmd=$1 + local chain=$2 + local port=$3 + local count + count=$($cmd -t raw -S $chain 2>/dev/null | grep -c "\-\-dport $port -j NOTRACK" || true) + if [ "$count" -eq 0 ]; then + $cmd -t raw -A $chain -p udp --dport $port -j NOTRACK + elif [ "$count" -gt 1 ]; then + local to_delete=$((count - 1)) + for ((i=0; i