diff mbox series

[ovs-dev,ovn,RFC,v3,07/29] Move out multicast lookup into a function

Message ID 20200716131927.3943-8-anton.ivanov@cambridgegreys.com
State RFC
Headers show
Series [ovs-dev,ovn,RFC,v3,01/29] Move out Table 0 operations to functions | expand

Commit Message

Anton Ivanov July 16, 2020, 1:19 p.m. UTC
From: Anton Ivanov <anton.ivanov@cambridgegreys.com>

Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
---
 northd/ovn-northd.c | 128 ++++++++++++++++++++++++--------------------
 1 file changed, 69 insertions(+), 59 deletions(-)

Comments

Dumitru Ceara Aug. 13, 2020, 12:20 p.m. UTC | #1
On 7/16/20 3:19 PM, anton.ivanov@cambridgegreys.com wrote:
> From: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> 
> Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> ---
>  northd/ovn-northd.c | 128 ++++++++++++++++++++++++--------------------
>  1 file changed, 69 insertions(+), 59 deletions(-)
> 
> diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
> index c6e58576a..61f9b4ab8 100644
> --- a/northd/ovn-northd.c
> +++ b/northd/ovn-northd.c
> @@ -9843,6 +9843,74 @@ build_lrouter_flows_step_80_od(
>      }
>  }
>  
> +static void
> +build_lrouter_flows_step_90_od(struct ovn_datapath *od, struct hmap *lflows)
> +{
> +    struct ds match = DS_EMPTY_INITIALIZER;
> +    struct ds actions = DS_EMPTY_INITIALIZER;
> +
> +    /* IP Multicast lookup. Here we set the output port, adjust TTL and
> +     * advance to next table (priority 500).
> +     */
> +    if (od->nbr) {
> +
> +        /* Drop IPv6 multicast traffic that shouldn't be forwarded,
> +         * i.e., router solicitation and router advertisement.
> +         */
> +        ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 550,
> +                      "nd_rs || nd_ra", "drop;");
> +
> +        if (!od->mcast_info.rtr.relay) {
> +            return;
> +        }
> +
> +        struct ovn_igmp_group *igmp_group;
> +
> +        LIST_FOR_EACH (igmp_group, list_node, &od->mcast_info.groups) {
> +            ds_clear(&match);
> +            ds_clear(&actions);
> +            if (IN6_IS_ADDR_V4MAPPED(&igmp_group->address)) {
> +                ds_put_format(&match, "ip4 && ip4.dst == %s ",
> +                            igmp_group->mcgroup.name);

Nit: indentation was wrong before your change but we could probably fix
it now that we're refactoring this part.

> +            } else {
> +                ds_put_format(&match, "ip6 && ip6.dst == %s ",
> +                            igmp_group->mcgroup.name);

Same here.

Thanks,
Dumitru

> +            }
> +            if (od->mcast_info.rtr.flood_static) {
> +                ds_put_cstr(&actions,
> +                            "clone { "
> +                                "outport = \""MC_STATIC"\"; "
> +                                "ip.ttl--; "
> +                                "next; "
> +                            "};");
> +            }
> +            ds_put_format(&actions, "outport = \"%s\"; ip.ttl--; next;",
> +                          igmp_group->mcgroup.name);
> +            ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 500,
> +                          ds_cstr(&match), ds_cstr(&actions));
> +        }
> +
> +        /* If needed, flood unregistered multicast on statically configured
> +         * ports. Otherwise drop any multicast traffic.
> +         */
> +        if (od->mcast_info.rtr.flood_static) {
> +            ds_clear(&actions);
> +            ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 450,
> +                          "ip4.mcast || ip6.mcast",
> +                          "clone { "
> +                                "outport = \""MC_STATIC"\"; "
> +                                "ip.ttl--; "
> +                                "next; "
> +                          "};");
> +        } else {
> +            ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 450,
> +                          "ip4.mcast || ip6.mcast", "drop;");
> +        }
> +    }
> +    ds_destroy(&match);
> +    ds_destroy(&actions);
> +}
> +
>  static void
>  build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>                      struct hmap *lflows, struct shash *meter_groups,
> @@ -9908,66 +9976,8 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>          build_lrouter_flows_step_80_od(od, lflows, ports);
>      }
>  
> -    /* IP Multicast lookup. Here we set the output port, adjust TTL and
> -     * advance to next table (priority 500).
> -     */
>      HMAP_FOR_EACH (od, key_node, datapaths) {
> -        if (!od->nbr) {
> -            continue;
> -        }
> -
> -        /* Drop IPv6 multicast traffic that shouldn't be forwarded,
> -         * i.e., router solicitation and router advertisement.
> -         */
> -        ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 550,
> -                      "nd_rs || nd_ra", "drop;");
> -
> -        if (!od->mcast_info.rtr.relay) {
> -            continue;
> -        }
> -
> -        struct ovn_igmp_group *igmp_group;
> -
> -        LIST_FOR_EACH (igmp_group, list_node, &od->mcast_info.groups) {
> -            ds_clear(&match);
> -            ds_clear(&actions);
> -            if (IN6_IS_ADDR_V4MAPPED(&igmp_group->address)) {
> -                ds_put_format(&match, "ip4 && ip4.dst == %s ",
> -                            igmp_group->mcgroup.name);
> -            } else {
> -                ds_put_format(&match, "ip6 && ip6.dst == %s ",
> -                            igmp_group->mcgroup.name);
> -            }
> -            if (od->mcast_info.rtr.flood_static) {
> -                ds_put_cstr(&actions,
> -                            "clone { "
> -                                "outport = \""MC_STATIC"\"; "
> -                                "ip.ttl--; "
> -                                "next; "
> -                            "};");
> -            }
> -            ds_put_format(&actions, "outport = \"%s\"; ip.ttl--; next;",
> -                          igmp_group->mcgroup.name);
> -            ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 500,
> -                          ds_cstr(&match), ds_cstr(&actions));
> -        }
> -
> -        /* If needed, flood unregistered multicast on statically configured
> -         * ports. Otherwise drop any multicast traffic.
> -         */
> -        if (od->mcast_info.rtr.flood_static) {
> -            ds_clear(&actions);
> -            ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 450,
> -                          "ip4.mcast || ip6.mcast",
> -                          "clone { "
> -                                "outport = \""MC_STATIC"\"; "
> -                                "ip.ttl--; "
> -                                "next; "
> -                          "};");
> -        } else {
> -            ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 450,
> -                          "ip4.mcast || ip6.mcast", "drop;");
> -        }
> +        build_lrouter_flows_step_90_od(od, lflows);
>      }
>  
>      /* Logical router ingress table POLICY: Policy.
>
diff mbox series

Patch

diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
index c6e58576a..61f9b4ab8 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -9843,6 +9843,74 @@  build_lrouter_flows_step_80_od(
     }
 }
 
+static void
+build_lrouter_flows_step_90_od(struct ovn_datapath *od, struct hmap *lflows)
+{
+    struct ds match = DS_EMPTY_INITIALIZER;
+    struct ds actions = DS_EMPTY_INITIALIZER;
+
+    /* IP Multicast lookup. Here we set the output port, adjust TTL and
+     * advance to next table (priority 500).
+     */
+    if (od->nbr) {
+
+        /* Drop IPv6 multicast traffic that shouldn't be forwarded,
+         * i.e., router solicitation and router advertisement.
+         */
+        ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 550,
+                      "nd_rs || nd_ra", "drop;");
+
+        if (!od->mcast_info.rtr.relay) {
+            return;
+        }
+
+        struct ovn_igmp_group *igmp_group;
+
+        LIST_FOR_EACH (igmp_group, list_node, &od->mcast_info.groups) {
+            ds_clear(&match);
+            ds_clear(&actions);
+            if (IN6_IS_ADDR_V4MAPPED(&igmp_group->address)) {
+                ds_put_format(&match, "ip4 && ip4.dst == %s ",
+                            igmp_group->mcgroup.name);
+            } else {
+                ds_put_format(&match, "ip6 && ip6.dst == %s ",
+                            igmp_group->mcgroup.name);
+            }
+            if (od->mcast_info.rtr.flood_static) {
+                ds_put_cstr(&actions,
+                            "clone { "
+                                "outport = \""MC_STATIC"\"; "
+                                "ip.ttl--; "
+                                "next; "
+                            "};");
+            }
+            ds_put_format(&actions, "outport = \"%s\"; ip.ttl--; next;",
+                          igmp_group->mcgroup.name);
+            ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 500,
+                          ds_cstr(&match), ds_cstr(&actions));
+        }
+
+        /* If needed, flood unregistered multicast on statically configured
+         * ports. Otherwise drop any multicast traffic.
+         */
+        if (od->mcast_info.rtr.flood_static) {
+            ds_clear(&actions);
+            ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 450,
+                          "ip4.mcast || ip6.mcast",
+                          "clone { "
+                                "outport = \""MC_STATIC"\"; "
+                                "ip.ttl--; "
+                                "next; "
+                          "};");
+        } else {
+            ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 450,
+                          "ip4.mcast || ip6.mcast", "drop;");
+        }
+    }
+    ds_destroy(&match);
+    ds_destroy(&actions);
+}
+
 static void
 build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
                     struct hmap *lflows, struct shash *meter_groups,
@@ -9908,66 +9976,8 @@  build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
         build_lrouter_flows_step_80_od(od, lflows, ports);
     }
 
-    /* IP Multicast lookup. Here we set the output port, adjust TTL and
-     * advance to next table (priority 500).
-     */
     HMAP_FOR_EACH (od, key_node, datapaths) {
-        if (!od->nbr) {
-            continue;
-        }
-
-        /* Drop IPv6 multicast traffic that shouldn't be forwarded,
-         * i.e., router solicitation and router advertisement.
-         */
-        ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 550,
-                      "nd_rs || nd_ra", "drop;");
-
-        if (!od->mcast_info.rtr.relay) {
-            continue;
-        }
-
-        struct ovn_igmp_group *igmp_group;
-
-        LIST_FOR_EACH (igmp_group, list_node, &od->mcast_info.groups) {
-            ds_clear(&match);
-            ds_clear(&actions);
-            if (IN6_IS_ADDR_V4MAPPED(&igmp_group->address)) {
-                ds_put_format(&match, "ip4 && ip4.dst == %s ",
-                            igmp_group->mcgroup.name);
-            } else {
-                ds_put_format(&match, "ip6 && ip6.dst == %s ",
-                            igmp_group->mcgroup.name);
-            }
-            if (od->mcast_info.rtr.flood_static) {
-                ds_put_cstr(&actions,
-                            "clone { "
-                                "outport = \""MC_STATIC"\"; "
-                                "ip.ttl--; "
-                                "next; "
-                            "};");
-            }
-            ds_put_format(&actions, "outport = \"%s\"; ip.ttl--; next;",
-                          igmp_group->mcgroup.name);
-            ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 500,
-                          ds_cstr(&match), ds_cstr(&actions));
-        }
-
-        /* If needed, flood unregistered multicast on statically configured
-         * ports. Otherwise drop any multicast traffic.
-         */
-        if (od->mcast_info.rtr.flood_static) {
-            ds_clear(&actions);
-            ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 450,
-                          "ip4.mcast || ip6.mcast",
-                          "clone { "
-                                "outport = \""MC_STATIC"\"; "
-                                "ip.ttl--; "
-                                "next; "
-                          "};");
-        } else {
-            ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_ROUTING, 450,
-                          "ip4.mcast || ip6.mcast", "drop;");
-        }
+        build_lrouter_flows_step_90_od(od, lflows);
     }
 
     /* Logical router ingress table POLICY: Policy.