diff mbox series

[ovs-dev,RFC,v4,20/24] Pull DNS lookup and response to a separate function

Message ID 20200902145950.25875-20-anton.ivanov@cambridgegreys.com
State Superseded
Headers show
Series [ovs-dev,RFC,v4,01/24] Move out Table 0 (ingress) operations to functions | expand

Commit Message

Anton Ivanov Sept. 2, 2020, 2:59 p.m. UTC
From: Anton Ivanov <anton.ivanov@cambridgegreys.com>

Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
---
 northd/ovn-northd.c | 67 +++++++++++++++++++++++++--------------------
 1 file changed, 38 insertions(+), 29 deletions(-)
diff mbox series

Patch

diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
index 9b96af9e1..46d56c4d2 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -6895,6 +6895,43 @@  build_lswitch_flows_dhcp_options_op(
     }
 }
 
+static void
+build_lswitch_flows_dns_lookup_od(
+        struct ovn_datapath *od, struct hmap *lflows)
+{
+    /* Logical switch ingress table 17 and 18: DNS lookup and response
+     * priority 100 flows.
+     */
+    if (!od->nbs || !ls_has_dns_records(od->nbs)) {
+       return;
+    }
+
+    struct ds action = DS_EMPTY_INITIALIZER;
+    struct ds match = DS_EMPTY_INITIALIZER;
+
+    ds_clear(&match);
+    ds_put_cstr(&match, "udp.dst == 53");
+    ds_put_format(&action,
+                  REGBIT_DNS_LOOKUP_RESULT" = dns_lookup(); next;");
+    ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_LOOKUP, 100,
+                  ds_cstr(&match), ds_cstr(&action));
+    ds_clear(&action);
+    ds_put_cstr(&match, " && "REGBIT_DNS_LOOKUP_RESULT);
+    ds_put_format(&action, "eth.dst <-> eth.src; ip4.src <-> ip4.dst; "
+                  "udp.dst = udp.src; udp.src = 53; outport = inport; "
+                  "flags.loopback = 1; output;");
+    ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
+                  ds_cstr(&match), ds_cstr(&action));
+    ds_clear(&action);
+    ds_put_format(&action, "eth.dst <-> eth.src; ip6.src <-> ip6.dst; "
+                  "udp.dst = udp.src; udp.src = 53; outport = inport; "
+                  "flags.loopback = 1; output;");
+    ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
+                  ds_cstr(&match), ds_cstr(&action));
+    ds_destroy(&action);
+    ds_destroy(&match);
+}
+
 static void
 build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
                     struct hmap *port_groups, struct hmap *lflows,
@@ -6990,36 +7027,8 @@  build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
         build_lswitch_flows_dhcp_options_op(op, lflows);
     }
 
-    /* Logical switch ingress table 17 and 18: DNS lookup and response
-     * priority 100 flows.
-     */
     HMAP_FOR_EACH (od, key_node, datapaths) {
-        if (!od->nbs || !ls_has_dns_records(od->nbs)) {
-           continue;
-        }
-
-        struct ds action = DS_EMPTY_INITIALIZER;
-
-        ds_clear(&match);
-        ds_put_cstr(&match, "udp.dst == 53");
-        ds_put_format(&action,
-                      REGBIT_DNS_LOOKUP_RESULT" = dns_lookup(); next;");
-        ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_LOOKUP, 100,
-                      ds_cstr(&match), ds_cstr(&action));
-        ds_clear(&action);
-        ds_put_cstr(&match, " && "REGBIT_DNS_LOOKUP_RESULT);
-        ds_put_format(&action, "eth.dst <-> eth.src; ip4.src <-> ip4.dst; "
-                      "udp.dst = udp.src; udp.src = 53; outport = inport; "
-                      "flags.loopback = 1; output;");
-        ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
-                      ds_cstr(&match), ds_cstr(&action));
-        ds_clear(&action);
-        ds_put_format(&action, "eth.dst <-> eth.src; ip6.src <-> ip6.dst; "
-                      "udp.dst = udp.src; udp.src = 53; outport = inport; "
-                      "flags.loopback = 1; output;");
-        ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
-                      ds_cstr(&match), ds_cstr(&action));
-        ds_destroy(&action);
+        build_lswitch_flows_dns_lookup_od(od, lflows);
     }
 
     /* Ingress table 14 and 15: DHCP options and response, by default goto