Learned routes must be bound to a lrp on which the routes where learned.
In case the lrp is deleted for whatever reason no ovn-controller would
clean these routes up, therefor we do this in northd.

Acked-by: Dumitru Ceara <dce...@redhat.com>
Acked-by: Lorenzo Bianconi <lorenzo.bianc...@redhat.com>
Signed-off-by: Felix Huettner <felix.huettner@stackit.cloud>
---
v5->v6:
  * addressed review comments
v4->v5: skipped
v2->v3:
  * A lot of minor review comments.

 northd/en-learned-route-sync.c |  7 ++++++-
 northd/northd.c                | 12 ++++++------
 tests/ovn-northd.at            | 16 ++++++++++++++++
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/northd/en-learned-route-sync.c b/northd/en-learned-route-sync.c
index 49780de39..406f1551f 100644
--- a/northd/en-learned-route-sync.c
+++ b/northd/en-learned-route-sync.c
@@ -193,7 +193,12 @@ routes_table_sync(
     struct hmap *parsed_routes_out)
 {
     const struct sbrec_learned_route *sb_route;
-    SBREC_LEARNED_ROUTE_TABLE_FOR_EACH (sb_route, sbrec_learned_route_table) {
+    SBREC_LEARNED_ROUTE_TABLE_FOR_EACH_SAFE (sb_route,
+                                             sbrec_learned_route_table) {
+        if (!ovn_port_find(lr_ports, sb_route->logical_port->logical_port)) {
+            sbrec_learned_route_delete(sb_route);
+            continue;
+        }
         parse_route_from_sbrec_route(parsed_routes_out, lr_ports,
                                      &lr_datapaths->datapaths,
                                      sb_route);
diff --git a/northd/northd.c b/northd/northd.c
index 87bce7a21..d1a91c8a5 100644
--- a/northd/northd.c
+++ b/northd/northd.c
@@ -1367,6 +1367,12 @@ ovn_port_find(const struct hmap *ports, const char *name)
     return ovn_port_find__(ports, name, false);
 }
 
+static struct ovn_port *
+ovn_port_find_bound(const struct hmap *ports, const char *name)
+{
+    return ovn_port_find__(ports, name, true);
+}
+
 static bool
 lsp_is_clone_to_unknown(const struct nbrec_logical_switch_port *nbsp)
 {
@@ -1381,12 +1387,6 @@ lsp_is_clone_to_unknown(const struct 
nbrec_logical_switch_port *nbsp)
     return false;
 }
 
-static struct ovn_port *
-ovn_port_find_bound(const struct hmap *ports, const char *name)
-{
-    return ovn_port_find__(ports, name, true);
-}
-
 /* Returns true only if the logical switch port 'up' column is set to true.
  * Otherwise, if the column is not set or set to false, returns false. */
 static bool
diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at
index b65d659f4..826989671 100644
--- a/tests/ovn-northd.at
+++ b/tests/ovn-northd.at
@@ -15164,6 +15164,22 @@ AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | 
ovn_strip_lflows], [0], [dnl
   table=??(lr_in_ip_routing   ), priority=518  , match=(ip6.dst == 
2001:db8:ffff::/64), action=(ip.ttl--; reg8[[0..15]] = 0; xxreg0 = ip6.dst; 
xxreg1 = 2001:db8:ffff::1; eth.src = 00:00:00:00:ff:02; outport = "lr0-sw1"; 
flags.loopback = 1; reg9[[9]] = 0; next;)
 ])
 
+# Deleting lr0-sw1 will remove the flows and also the learned route.
+check ovn-nbctl --wait=sb lrp-del lr0-sw1
+check_row_count Advertised_Route 2
+check_row_count Learned_Route 2
+check_row_count Learned_Route 2 logical_port=$sw0
+ovn-sbctl dump-flows lr0 > lr0flows
+AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | ovn_strip_lflows], [0], [dnl
+  table=??(lr_in_ip_routing   ), priority=0    , match=(1), action=(drop;)
+  table=??(lr_in_ip_routing   ), priority=10550, match=(nd_rs || nd_ra), 
action=(drop;)
+  table=??(lr_in_ip_routing   ), priority=194  , match=(reg7 == 0 && ip4.dst 
== 172.16.0.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = 10.0.0.11; reg5 
= 10.0.0.1; eth.src = 00:00:00:00:ff:01; outport = "lr0-sw0"; flags.loopback = 
1; reg9[[9]] = 1; next;)
+  table=??(lr_in_ip_routing   ), priority=196  , match=(reg7 == 0 && ip4.dst 
== 192.168.0.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = 10.0.0.10; reg5 
= 10.0.0.1; eth.src = 00:00:00:00:ff:01; outport = "lr0-sw0"; flags.loopback = 
1; reg9[[9]] = 1; next;)
+  table=??(lr_in_ip_routing   ), priority=198  , match=(ip4.dst == 
10.0.0.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = ip4.dst; reg5 = 
10.0.0.1; eth.src = 00:00:00:00:ff:01; outport = "lr0-sw0"; flags.loopback = 1; 
reg9[[9]] = 1; next;)
+  table=??(lr_in_ip_routing   ), priority=514  , match=(reg7 == 0 && ip6.dst 
== 2001:db8:3::/64), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = 10.0.0.20; 
reg5 = 10.0.0.1; eth.src = 00:00:00:00:ff:01; outport = "lr0-sw0"; 
flags.loopback = 1; reg9[[9]] = 1; next;)
+  table=??(lr_in_ip_routing   ), priority=518  , match=(inport == "lr0-sw0" && 
ip6.dst == fe80::/64), action=(ip.ttl--; reg8[[0..15]] = 0; xxreg0 = ip6.dst; 
xxreg1 = fe80::200:ff:fe00:ff01; eth.src = 00:00:00:00:ff:01; outport = 
"lr0-sw0"; flags.loopback = 1; reg9[[9]] = 0; next;)
+])
+
 AT_CLEANUP
 ])
 
-- 
2.47.1


_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to