diff mbox series

[ovs-dev,2/5] northd: move nat_flows_for_lb for force_nat in a dedicated routine

Message ID 2dd8656fd1739cd5d37d43b2060eefc5de8f6fd7.1651605343.git.lorenzo.bianconi@redhat.com
State Superseded
Headers show
Series optimize lb lflow generation for gw router | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test fail github build: failed
ovsrobot/github-robot-_ovn-kubernetes fail github build: failed

Commit Message

Lorenzo Bianconi May 3, 2022, 7:20 p.m. UTC
Similar to skip_snat counterpart, move force_nat gw router where a
given lb is installed in a dedicated routine.
This is a preliminary patch to reduce load balancer logical flows
computation cost.

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
 northd/northd.c | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/northd/northd.c b/northd/northd.c
index d90879eeb..27be74ea7 100644
--- a/northd/northd.c
+++ b/northd/northd.c
@@ -9987,12 +9987,18 @@  build_lrouter_nat_flows_for_lb(struct ovn_lb_vip *lb_vip,
             skip_snat_new_action, est_match,
             skip_snat_est_action, lflows, prio, meter_groups);
 
+    char *new_actions = xasprintf("flags.force_snat_for_lb = 1; %s",
+                                  ds_cstr(action));
+    build_gw_lrouter_nat_flows_for_lb(lb, gw_router_force_snat,
+            n_gw_router_force_snat, reject, new_match,
+            new_actions, est_match,
+            "flags.force_snat_for_lb = 1; next;",
+            lflows, prio, meter_groups);
 
     for (size_t i = 0; i < lb->n_nb_lr; i++) {
         struct ovn_datapath *od = lb->nb_lr[i];
         char *new_match_p = new_match;
         char *est_match_p = est_match;
-        char *est_actions = NULL;
         const char *meter = NULL;
 
         if (reject) {
@@ -10036,19 +10042,16 @@  build_lrouter_nat_flows_for_lb(struct ovn_lb_vip *lb_vip,
                                         &lb->nlb->header_);
             }
         } else if (snat_type == FORCE_SNAT) {
-            char *new_actions = xasprintf("flags.force_snat_for_lb = 1; %s",
-                                          ds_cstr(action));
-            ovn_lflow_add_with_hint__(lflows, od, S_ROUTER_IN_DNAT, prio,
-                                      new_match_p, new_actions, NULL,
-                                      meter, &lb->nlb->header_);
-            free(new_actions);
-
-            est_actions = xasprintf("flags.force_snat_for_lb = 1; "
-                                    "next;");
-            ovn_lflow_add_with_hint(lflows, od, S_ROUTER_IN_DNAT, prio,
-                                    est_match_p, est_actions,
-                                    &lb->nlb->header_);
-        } else {
+            if (od->n_l3dgw_ports) {
+                ovn_lflow_add_with_hint__(lflows, od, S_ROUTER_IN_DNAT, prio,
+                                          new_match_p, new_actions, NULL,
+                                          meter, &lb->nlb->header_);
+                ovn_lflow_add_with_hint(lflows, od, S_ROUTER_IN_DNAT, prio,
+                                        est_match_p,
+                                        "flags.force_snat_for_lb = 1; next;",
+                                        &lb->nlb->header_);
+            }
+        } else if (snat_type == NO_FORCE_SNAT) {
             ovn_lflow_add_with_hint__(lflows, od, S_ROUTER_IN_DNAT, prio,
                                       new_match_p, ds_cstr(action), NULL,
                                       meter, &lb->nlb->header_);
@@ -10065,7 +10068,7 @@  build_lrouter_nat_flows_for_lb(struct ovn_lb_vip *lb_vip,
         }
 
         if (!od->n_l3dgw_ports || !lb_vip->n_backends) {
-            goto next;
+            continue;
         }
 
         char *undnat_match_p = xasprintf(
@@ -10079,7 +10082,8 @@  build_lrouter_nat_flows_for_lb(struct ovn_lb_vip *lb_vip,
                                     &lb->nlb->header_);
         } else if (snat_type == FORCE_SNAT) {
             ovn_lflow_add_with_hint(lflows, od, S_ROUTER_OUT_UNDNAT, 120,
-                                    undnat_match_p, est_actions,
+                                    undnat_match_p,
+                                    "flags.force_snat_for_lb = 1; next;",
                                     &lb->nlb->header_);
         } else {
             ovn_lflow_add_with_hint(
@@ -10088,8 +10092,6 @@  build_lrouter_nat_flows_for_lb(struct ovn_lb_vip *lb_vip,
                 &lb->nlb->header_);
         }
         free(undnat_match_p);
-next:
-        free(est_actions);
     }
 
     ds_destroy(&unsnat_match);
@@ -10099,6 +10101,7 @@  next:
     free(skip_snat_est_action);
     free(est_match);
     free(new_match);
+    free(new_actions);
 
     free(gw_router_force_snat);
     free(gw_router_skip_snat);