5f9769
From 685d26ba45965b2268fbbc36d167115419321f25 Mon Sep 17 00:00:00 2001
5f9769
Message-Id: <685d26ba45965b2268fbbc36d167115419321f25.1610458802.git.lorenzo.bianconi@redhat.com>
5f9769
In-Reply-To: <f21c1b7a467a691847b5552d4570af706fcc5bb0.1610458802.git.lorenzo.bianconi@redhat.com>
5f9769
References: <f21c1b7a467a691847b5552d4570af706fcc5bb0.1610458802.git.lorenzo.bianconi@redhat.com>
5f9769
From: Anton Ivanov <anton.ivanov@cambridgegreys.com>
5f9769
Date: Tue, 5 Jan 2021 17:49:30 +0000
5f9769
Subject: [PATCH 03/16] ovn-northd: Move lswitch DNS lookup and response to a
5f9769
 function.
5f9769
5f9769
Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
5f9769
Signed-off-by: Numan Siddique <numans@ovn.org>
5f9769
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
5f9769
---
5f9769
 northd/ovn-northd.c | 50 ++++++++++++++++++++++++---------------------
5f9769
 1 file changed, 27 insertions(+), 23 deletions(-)
5f9769
5f9769
diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
5f9769
index a5b28584f..be98a6013 100644
5f9769
--- a/northd/ovn-northd.c
5f9769
+++ b/northd/ovn-northd.c
5f9769
@@ -6780,29 +6780,6 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
5f9769
     struct ovn_datapath *od;
5f9769
     struct ovn_port *op;
5f9769
 
5f9769
-    /* Logical switch ingress table 17 and 18: DNS lookup and response
5f9769
-     * priority 100 flows.
5f9769
-     */
5f9769
-    HMAP_FOR_EACH (od, key_node, datapaths) {
5f9769
-        if (!od->nbs || !ls_has_dns_records(od->nbs)) {
5f9769
-           continue;
5f9769
-        }
5f9769
-
5f9769
-        ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_LOOKUP, 100,
5f9769
-                      "udp.dst == 53",
5f9769
-                      REGBIT_DNS_LOOKUP_RESULT" = dns_lookup(); next;");
5f9769
-        const char *dns_action = "eth.dst <-> eth.src; ip4.src <-> ip4.dst; "
5f9769
-                      "udp.dst = udp.src; udp.src = 53; outport = inport; "
5f9769
-                      "flags.loopback = 1; output;";
5f9769
-        const char *dns_match = "udp.dst == 53 && "REGBIT_DNS_LOOKUP_RESULT;
5f9769
-        ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
5f9769
-                      dns_match, dns_action);
5f9769
-        dns_action = "eth.dst <-> eth.src; ip6.src <-> ip6.dst; "
5f9769
-                      "udp.dst = udp.src; udp.src = 53; outport = inport; "
5f9769
-                      "flags.loopback = 1; output;";
5f9769
-        ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
5f9769
-                      dns_match, dns_action);
5f9769
-    }
5f9769
 
5f9769
     /* Ingress table 14 and 15: DHCP options and response, by default goto
5f9769
      * next. (priority 0).
5f9769
@@ -7484,6 +7461,32 @@ build_lswitch_dhcp_options_and_response(struct ovn_port *op,
5f9769
     }
5f9769
 }
5f9769
 
5f9769
+/* Logical switch ingress table 17 and 18: DNS lookup and response
5f9769
+* priority 100 flows.
5f9769
+*/
5f9769
+static void
5f9769
+build_lswitch_dns_lookup_and_response(struct ovn_datapath *od,
5f9769
+                                      struct hmap *lflows)
5f9769
+{
5f9769
+    if (od->nbs && ls_has_dns_records(od->nbs)) {
5f9769
+
5f9769
+        ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_LOOKUP, 100,
5f9769
+                      "udp.dst == 53",
5f9769
+                      REGBIT_DNS_LOOKUP_RESULT" = dns_lookup(); next;");
5f9769
+        const char *dns_action = "eth.dst <-> eth.src; ip4.src <-> ip4.dst; "
5f9769
+                      "udp.dst = udp.src; udp.src = 53; outport = inport; "
5f9769
+                      "flags.loopback = 1; output;";
5f9769
+        const char *dns_match = "udp.dst == 53 && "REGBIT_DNS_LOOKUP_RESULT;
5f9769
+        ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
5f9769
+                      dns_match, dns_action);
5f9769
+        dns_action = "eth.dst <-> eth.src; ip6.src <-> ip6.dst; "
5f9769
+                      "udp.dst = udp.src; udp.src = 53; outport = inport; "
5f9769
+                      "flags.loopback = 1; output;";
5f9769
+        ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
5f9769
+                      dns_match, dns_action);
5f9769
+    }
5f9769
+}
5f9769
+
5f9769
 /* Returns a string of the IP address of the router port 'op' that
5f9769
  * overlaps with 'ip_s".  If one is not found, returns NULL.
5f9769
  *
5f9769
@@ -11335,6 +11338,7 @@ build_lswitch_and_lrouter_iterate_by_od(struct ovn_datapath *od,
5f9769
     build_lswitch_lflows_admission_control(od, lsi->lflows);
5f9769
     build_lswitch_input_port_sec_od(od, lsi->lflows);
5f9769
     build_lswitch_arp_nd_responder_default(od, lsi->lflows);
5f9769
+    build_lswitch_dns_lookup_and_response(od, lsi->lflows);
5f9769
 
5f9769
     /* Build Logical Router Flows. */
5f9769
     build_adm_ctrl_flows_for_lrouter(od, lsi->lflows);
5f9769
-- 
5f9769
2.29.2
5f9769