When a logical router with a NAT attached is deleted, all logical
flows added through the logical router's lflow_ref are properly
removed.  However, the logical flows added through the corresponding
lr_stateful record's lflow_ref are not.  Since these flows hold a
strong reference to the Datapath_Binding, the SB DB transaction
that deletes the Datapath_Binding row fails with a referential
integrity violation, forcing an unnecessary ovn-northd recompute.

lflow_handle_lr_stateful_changes() only handles the 'crupdated'
lr_stateful records and ignores the 'deleted' ones.  All other
lflow handlers walk the deleted entries and unlink their lflows
first; this was an oversight.  Add the missing loop so that the
lflows owned by a deleted lr_stateful record's lflow_ref are
unlinked and the SB DB transaction succeeds.

Tested with a new test that deletes a logical router with
an SNAT rule and asserts that the SB DB contains no orphaned
logical flows and that ovn-northd logs no referential integrity
violation.

Fixes: 2f297d52746e ("northd: Reapply "northd: Add and delete logical routers 
in en-lflow engine node.".")
Reported-by: Mark Michelson <[email protected]>
Reported-at: https://redhat.atlassian.net/browse/FDP-4765
Co-authored-by: Mark Michelson <[email protected]>
Assisted-by: GLM 5.3, OpenCode
Signed-off-by: Jacob Tanenbaum <[email protected]>
Signed-off-by: Mark Michelson <[email protected]>
---
 northd/northd.c     |  6 ++++++
 tests/ovn-northd.at | 27 +++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/northd/northd.c b/northd/northd.c
index e4acb11ab..3d9b6d825 100644
--- a/northd/northd.c
+++ b/northd/northd.c
@@ -21294,6 +21294,12 @@ lflow_handle_lr_stateful_changes(struct 
lr_stateful_tracked_data *trk_data,
     struct ds match = DS_EMPTY_INITIALIZER;
     struct hmapx_node *hmapx_node;
 
+    HMAPX_FOR_EACH (hmapx_node, &trk_data->deleted) {
+        lr_stateful_rec = hmapx_node->data;
+        lflow_ref_unlink_lflows(lr_stateful_rec->lflow_ref, lflows);
+        hmapx_add(dirty_lflow_refs, lr_stateful_rec->lflow_ref);
+    }
+
     HMAPX_FOR_EACH (hmapx_node, &trk_data->crupdated) {
         lr_stateful_rec = hmapx_node->data;
         /* Unlink old lflows. */
diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at
index f1e88b4bd..06817cce3 100644
--- a/tests/ovn-northd.at
+++ b/tests/ovn-northd.at
@@ -26110,6 +26110,33 @@ OVN_CLEANUP_NORTHD
 AT_CLEANUP
 ])
 
+OVN_FOR_EACH_NORTHD_NO_HV([
+AT_SETUP([Deleting a router with NAT does not leave orphaned lflows])
+ovn_start
+
+check ovn-nbctl lr-add lr1
+check ovn-nbctl lr-nat-add lr1 snat 172.16.1.1 192.168.1.1
+check ovn-nbctl --wait=sb sync
+
+dnl The lr_stateful-owned ARP respond flow for the SNAT external IP
+dnl must be installed before the router is deleted.
+OVS_WAIT_UNTIL([ovn-sbctl lflow-list lr1 | grep 'lr_in_ip_input' | grep -q 
'arp.tpa == 172.16.1.1'])
+
+check ovn-nbctl --wait=sb lr-del lr1
+check ovn-nbctl --wait=sb sync
+
+dnl Deleting the router must remove all its logical flows from the SB
+dnl database without any referential integrity violation.
+AT_CHECK([grep -q "referential integrity violation" northd/ovn-northd.log], 
[1])
+AT_CHECK([ovn-sbctl lflow-list], [0], [dnl
+])
+AT_CHECK([ovn-sbctl --no-heading list datapath_binding], [0], [dnl
+])
+
+OVN_CLEANUP_NORTHD
+AT_CLEANUP
+])
+
 OVN_FOR_EACH_NORTHD_NO_HV([
 AT_SETUP([Load balancer un-DNAT on a router without DGP])
 ovn_start
-- 
2.56.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to