5f9769
From 9e60b5574786c0ef8f6403ac61567553c1a7717f Mon Sep 17 00:00:00 2001
5f9769
Message-Id: <9e60b5574786c0ef8f6403ac61567553c1a7717f.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:33 +0000
5f9769
Subject: [PATCH 06/16] ovn-northd: Move broadcast and multicast lookup in
5f9769
 lswitch to a 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 | 169 +++++++++++++++++++++++---------------------
5f9769
 1 file changed, 87 insertions(+), 82 deletions(-)
5f9769
5f9769
diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
5f9769
index 09bfaae5e..f4e248f55 100644
5f9769
--- a/northd/ovn-northd.c
5f9769
+++ b/northd/ovn-northd.c
5f9769
@@ -6780,88 +6780,6 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
5f9769
     struct ovn_datapath *od;
5f9769
     struct ovn_port *op;
5f9769
 
5f9769
-    /* Ingress table 19: Destination lookup, broadcast and multicast handling
5f9769
-     * (priority 70 - 100). */
5f9769
-    HMAP_FOR_EACH (od, key_node, datapaths) {
5f9769
-        if (!od->nbs) {
5f9769
-            continue;
5f9769
-        }
5f9769
-
5f9769
-        ovn_lflow_add(lflows, od, S_SWITCH_IN_L2_LKUP, 110,
5f9769
-                      "eth.dst == $svc_monitor_mac",
5f9769
-                      "handle_svc_check(inport);");
5f9769
-
5f9769
-        struct mcast_switch_info *mcast_sw_info = &od->mcast_info.sw;
5f9769
-
5f9769
-        if (mcast_sw_info->enabled) {
5f9769
-            ds_clear(&actions);
5f9769
-            if (mcast_sw_info->flood_reports) {
5f9769
-                ds_put_cstr(&actions,
5f9769
-                            "clone { "
5f9769
-                                "outport = \""MC_MROUTER_STATIC"\"; "
5f9769
-                                "output; "
5f9769
-                            "};");
5f9769
-            }
5f9769
-            ds_put_cstr(&actions, "igmp;");
5f9769
-            /* Punt IGMP traffic to controller. */
5f9769
-            ovn_lflow_add_unique(lflows, od, S_SWITCH_IN_L2_LKUP, 100,
5f9769
-                                 "ip4 && ip.proto == 2", ds_cstr(&actions));
5f9769
-
5f9769
-            /* Punt MLD traffic to controller. */
5f9769
-            ovn_lflow_add_unique(lflows, od, S_SWITCH_IN_L2_LKUP, 100,
5f9769
-                                 "mldv1 || mldv2", ds_cstr(&actions));
5f9769
-
5f9769
-            /* Flood all IP multicast traffic destined to 224.0.0.X to all
5f9769
-             * ports - RFC 4541, section 2.1.2, item 2.
5f9769
-             */
5f9769
-            ovn_lflow_add_unique(lflows, od, S_SWITCH_IN_L2_LKUP, 85,
5f9769
-                                 "ip4.mcast && ip4.dst == 224.0.0.0/24",
5f9769
-                                 "outport = \""MC_FLOOD"\"; output;");
5f9769
-
5f9769
-            /* Flood all IPv6 multicast traffic destined to reserved
5f9769
-             * multicast IPs (RFC 4291, 2.7.1).
5f9769
-             */
5f9769
-            ovn_lflow_add_unique(lflows, od, S_SWITCH_IN_L2_LKUP, 85,
5f9769
-                                 "ip6.mcast_flood",
5f9769
-                                 "outport = \""MC_FLOOD"\"; output;");
5f9769
-
5f9769
-            /* Forward uregistered IP multicast to routers with relay enabled
5f9769
-             * and to any ports configured to flood IP multicast traffic.
5f9769
-             * If configured to flood unregistered traffic this will be
5f9769
-             * handled by the L2 multicast flow.
5f9769
-             */
5f9769
-            if (!mcast_sw_info->flood_unregistered) {
5f9769
-                ds_clear(&actions);
5f9769
-
5f9769
-                if (mcast_sw_info->flood_relay) {
5f9769
-                    ds_put_cstr(&actions,
5f9769
-                                "clone { "
5f9769
-                                    "outport = \""MC_MROUTER_FLOOD"\"; "
5f9769
-                                    "output; "
5f9769
-                                "}; ");
5f9769
-                }
5f9769
-
5f9769
-                if (mcast_sw_info->flood_static) {
5f9769
-                    ds_put_cstr(&actions, "outport =\""MC_STATIC"\"; output;");
5f9769
-                }
5f9769
-
5f9769
-                /* Explicitly drop the traffic if relay or static flooding
5f9769
-                 * is not configured.
5f9769
-                 */
5f9769
-                if (!mcast_sw_info->flood_relay &&
5f9769
-                        !mcast_sw_info->flood_static) {
5f9769
-                    ds_put_cstr(&actions, "drop;");
5f9769
-                }
5f9769
-
5f9769
-                ovn_lflow_add_unique(lflows, od, S_SWITCH_IN_L2_LKUP, 80,
5f9769
-                                     "ip4.mcast || ip6.mcast",
5f9769
-                                     ds_cstr(&actions));
5f9769
-            }
5f9769
-        }
5f9769
-
5f9769
-        ovn_lflow_add_unique(lflows, od, S_SWITCH_IN_L2_LKUP, 70, "eth.mcast",
5f9769
-                             "outport = \""MC_FLOOD"\"; output;");
5f9769
-    }
5f9769
 
5f9769
     /* Ingress table 19: Add IP multicast flows learnt from IGMP/MLD
5f9769
      * (priority 90). */
5f9769
@@ -7488,6 +7406,92 @@ build_lswitch_external_port(struct ovn_port *op,
5f9769
     }
5f9769
 }
5f9769
 
5f9769
+/* Ingress table 19: Destination lookup, broadcast and multicast handling
5f9769
+ * (priority 70 - 100). */
5f9769
+static void
5f9769
+build_lswitch_destination_lookup_bmcast(struct ovn_datapath *od,
5f9769
+                                        struct hmap *lflows,
5f9769
+                                        struct ds *actions)
5f9769
+{
5f9769
+    if (od->nbs) {
5f9769
+
5f9769
+        ovn_lflow_add(lflows, od, S_SWITCH_IN_L2_LKUP, 110,
5f9769
+                      "eth.dst == $svc_monitor_mac",
5f9769
+                      "handle_svc_check(inport);");
5f9769
+
5f9769
+        struct mcast_switch_info *mcast_sw_info = &od->mcast_info.sw;
5f9769
+
5f9769
+        if (mcast_sw_info->enabled) {
5f9769
+            ds_clear(actions);
5f9769
+            if (mcast_sw_info->flood_reports) {
5f9769
+                ds_put_cstr(actions,
5f9769
+                            "clone { "
5f9769
+                                "outport = \""MC_MROUTER_STATIC"\"; "
5f9769
+                                "output; "
5f9769
+                            "};");
5f9769
+            }
5f9769
+            ds_put_cstr(actions, "igmp;");
5f9769
+            /* Punt IGMP traffic to controller. */
5f9769
+            ovn_lflow_add_unique(lflows, od, S_SWITCH_IN_L2_LKUP, 100,
5f9769
+                                 "ip4 && ip.proto == 2", ds_cstr(actions));
5f9769
+
5f9769
+            /* Punt MLD traffic to controller. */
5f9769
+            ovn_lflow_add_unique(lflows, od, S_SWITCH_IN_L2_LKUP, 100,
5f9769
+                                 "mldv1 || mldv2", ds_cstr(actions));
5f9769
+
5f9769
+            /* Flood all IP multicast traffic destined to 224.0.0.X to all
5f9769
+             * ports - RFC 4541, section 2.1.2, item 2.
5f9769
+             */
5f9769
+            ovn_lflow_add_unique(lflows, od, S_SWITCH_IN_L2_LKUP, 85,
5f9769
+                                 "ip4.mcast && ip4.dst == 224.0.0.0/24",
5f9769
+                                 "outport = \""MC_FLOOD"\"; output;");
5f9769
+
5f9769
+            /* Flood all IPv6 multicast traffic destined to reserved
5f9769
+             * multicast IPs (RFC 4291, 2.7.1).
5f9769
+             */
5f9769
+            ovn_lflow_add_unique(lflows, od, S_SWITCH_IN_L2_LKUP, 85,
5f9769
+                                 "ip6.mcast_flood",
5f9769
+                                 "outport = \""MC_FLOOD"\"; output;");
5f9769
+
5f9769
+            /* Forward uregistered IP multicast to routers with relay enabled
5f9769
+             * and to any ports configured to flood IP multicast traffic.
5f9769
+             * If configured to flood unregistered traffic this will be
5f9769
+             * handled by the L2 multicast flow.
5f9769
+             */
5f9769
+            if (!mcast_sw_info->flood_unregistered) {
5f9769
+                ds_clear(actions);
5f9769
+
5f9769
+                if (mcast_sw_info->flood_relay) {
5f9769
+                    ds_put_cstr(actions,
5f9769
+                                "clone { "
5f9769
+                                    "outport = \""MC_MROUTER_FLOOD"\"; "
5f9769
+                                    "output; "
5f9769
+                                "}; ");
5f9769
+                }
5f9769
+
5f9769
+                if (mcast_sw_info->flood_static) {
5f9769
+                    ds_put_cstr(actions, "outport =\""MC_STATIC"\"; output;");
5f9769
+                }
5f9769
+
5f9769
+                /* Explicitly drop the traffic if relay or static flooding
5f9769
+                 * is not configured.
5f9769
+                 */
5f9769
+                if (!mcast_sw_info->flood_relay &&
5f9769
+                        !mcast_sw_info->flood_static) {
5f9769
+                    ds_put_cstr(actions, "drop;");
5f9769
+                }
5f9769
+
5f9769
+                ovn_lflow_add_unique(lflows, od, S_SWITCH_IN_L2_LKUP, 80,
5f9769
+                                     "ip4.mcast || ip6.mcast",
5f9769
+                                     ds_cstr(actions));
5f9769
+            }
5f9769
+        }
5f9769
+
5f9769
+        ovn_lflow_add_unique(lflows, od, S_SWITCH_IN_L2_LKUP, 70, "eth.mcast",
5f9769
+                             "outport = \""MC_FLOOD"\"; output;");
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
@@ -11341,6 +11345,7 @@ build_lswitch_and_lrouter_iterate_by_od(struct ovn_datapath *od,
5f9769
     build_lswitch_arp_nd_responder_default(od, lsi->lflows);
5f9769
     build_lswitch_dns_lookup_and_response(od, lsi->lflows);
5f9769
     build_lswitch_dhcp_and_dns_defaults(od, lsi->lflows);
5f9769
+    build_lswitch_destination_lookup_bmcast(od, lsi->lflows, &lsi->actions);
5f9769
 
5f9769
     /* Build Logical Router Flows. */
5f9769
     build_adm_ctrl_flows_for_lrouter(od, lsi->lflows);
5f9769
-- 
5f9769
2.29.2
5f9769