diff mbox series

[ovs-dev,v2,30/32] northd: Support active-active bgp redirects.

Message ID 90ba2b325d56d71d191b6d064f87b4677960ca8f.1730713432.git.felix.huettner@stackit.cloud
State Superseded
Headers show
Series OVN Fabric integration | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success

Commit Message

Felix Huettner Nov. 4, 2024, 11:04 a.m. UTC
add support for routing-protocol-redirects in combination with
active-active routing.

Signed-off-by: Felix Huettner <felix.huettner@stackit.cloud>
---
 northd/northd.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 48 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/northd/northd.c b/northd/northd.c
index 6884b7a0e..05edb1cad 100644
--- a/northd/northd.c
+++ b/northd/northd.c
@@ -2343,6 +2343,7 @@  join_logical_ports_lrp(struct hmap *ports,
 
 struct active_active_port {
     const struct nbrec_logical_switch_port *nbsp;
+    const struct nbrec_logical_switch_port *routing_protocol_redirect;
     const struct nbrec_logical_router_port *nbrp;
     struct ovn_datapath *switch_dp;
     struct ovn_datapath *router_dp;
@@ -2410,6 +2411,7 @@  join_logical_ports(const struct sbrec_port_binding_table *sbrec_pb_table,
     ovs_list_init(both);
 
     struct shash active_active_ports = SHASH_INITIALIZER(&active_active_ports);
+    struct shash aa_redirect_targets = SHASH_INITIALIZER(&aa_redirect_targets);
 
     const struct sbrec_port_binding *sb;
     SBREC_PORT_BINDING_TABLE_FOR_EACH (sb, sbrec_pb_table) {
@@ -2438,6 +2440,12 @@  join_logical_ports(const struct sbrec_port_binding_table *sbrec_pb_table,
                 aap->nbrp = nbrp;
                 aap->router_dp = od;
                 shash_add(&active_active_ports, nbrp->name, aap);
+
+                const char *redirect_port_name = smap_get(&nbrp->options,
+                                              "routing-protocol-redirect");
+                if (redirect_port_name) {
+                    shash_add(&aa_redirect_targets, redirect_port_name, aap);
+                }
                 continue;
             }
 
@@ -2468,6 +2476,12 @@  join_logical_ports(const struct sbrec_port_binding_table *sbrec_pb_table,
                 aap->switch_dp = od;
                 continue;
             }
+            struct active_active_port *aap =
+                shash_find_data(&aa_redirect_targets, nbsp->name);
+            if (aap) {
+                aap->routing_protocol_redirect = nbsp;
+                continue;
+            }
             join_logical_ports_lsp(ports, nb_only, both, od, nbsp,
                                    nbsp->name, queue_id_bitmap,
                                    tag_alloc_table);
@@ -2551,6 +2565,8 @@  join_logical_ports(const struct sbrec_port_binding_table *sbrec_pb_table,
     SHASH_FOR_EACH (aa_snode, &active_active_ports) {
         const struct active_active_port *aap = aa_snode->data;
         const struct nbrec_logical_switch_port *nbsp = aap->nbsp;
+        const struct nbrec_logical_switch_port *nbsp_rpr =
+            aap->routing_protocol_redirect;
         const struct nbrec_logical_router_port *nbrp = aap->nbrp;
         ovs_assert(nbrp);
         ovs_assert(aap->switch_dp);
@@ -2637,6 +2653,18 @@  join_logical_ports(const struct sbrec_port_binding_table *sbrec_pb_table,
                 lsp->aa_chassis_name = xstrdup(chassis->name);
                 lrp->aa_chassis_index = j;
                 lsp->aa_chassis_index = j;
+
+                if (nbsp_rpr) {
+                    char *lsp_rpr_name = xasprintf("%s-%s-%"PRIuSIZE,
+                                                     nbsp_rpr->name,
+                                                     chassis->name, j);
+                    join_logical_ports_lsp(ports, nb_only, both,
+                                           aap->switch_dp, nbsp_rpr,
+                                           lsp_rpr_name, queue_id_bitmap,
+                                           tag_alloc_table);
+                    free(lsp_rpr_name);
+                }
+
             }
             free(networks.network_name);
             free(networks.addresses);
@@ -2701,6 +2729,7 @@  join_logical_ports(const struct sbrec_port_binding_table *sbrec_pb_table,
         ipam_add_port_addresses(op->od, op);
     }
 
+    shash_destroy(&aa_redirect_targets);
     shash_destroy_free_data(&active_active_ports);
 }
 
@@ -14379,6 +14408,20 @@  build_arp_resolve_flows_for_lrp(struct ovn_port *op,
     }
 }
 
+static char*
+ovn_port_get_redirect_port_name(struct ovn_port *op) {
+    const char *rpr = smap_get(&op->nbrp->options,
+                               "routing-protocol-redirect");
+    if (!rpr) {
+        return NULL;
+    }
+    if (op->is_active_active) {
+        return xasprintf("%s-%s-%"PRIuSIZE, rpr,
+                         op->aa_chassis_name, op->aa_chassis_index);
+    }
+    return xstrdup(rpr);
+}
+
 static void
 build_routing_protocols_redirect_rule__(
         const char *s_addr, const char *redirect_port_name, int protocol_port,
@@ -14512,8 +14555,7 @@  build_lrouter_routing_protocol_redirect(
     /* Proceed only for LRPs that have 'routing-protocol-redirect' option set.
      * Value of this option is the name of LSP to which the routing protocol
      * traffic will be redirected. */
-    const char *redirect_port_name = smap_get(&op->nbrp->options,
-                                              "routing-protocol-redirect");
+    char *redirect_port_name = ovn_port_get_redirect_port_name(op);
     if (!redirect_port_name) {
         return;
     }
@@ -14529,6 +14571,7 @@  build_lrouter_routing_protocol_redirect(
                           "Switch Port. Routing protocol redirecting won't be "
                           "configured.",
                           op->key);
+        free(redirect_port_name);
         return;
     }
     if (lsp_in_peer->od != op->peer->od) {
@@ -14539,6 +14582,7 @@  build_lrouter_routing_protocol_redirect(
                           "option. Routing protocol redirecting won't be "
                           "configured.",
                           op->key, redirect_port_name);
+        free(redirect_port_name);
         return;
     }
 
@@ -14550,6 +14594,7 @@  build_lrouter_routing_protocol_redirect(
                           "were set via 'routing-protocols' options. This "
                           "configuration has no effect.",
                           op->key);
+        free(redirect_port_name);
         return;
     }
 
@@ -14597,6 +14642,7 @@  build_lrouter_routing_protocol_redirect(
                   ds_cstr(match),
                   REGBIT_PORT_SEC_DROP " = 1; next;",
                   lflow_ref);
+    free(redirect_port_name);
 }
 
 /* This function adds ARP resolve flows related to a LSP. */