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