bbaaef
From 84d337ec6c4a15154de2e8dd7b53d3626814d7a9 Mon Sep 17 00:00:00 2001
bbaaef
Message-Id: <84d337ec6c4a15154de2e8dd7b53d3626814d7a9.1569932887.git.lorenzo.bianconi@redhat.com>
bbaaef
In-Reply-To: <9c04a4b62484895dc301875ad9da7c77c17a99c7.1569932887.git.lorenzo.bianconi@redhat.com>
bbaaef
References: <9c04a4b62484895dc301875ad9da7c77c17a99c7.1569932887.git.lorenzo.bianconi@redhat.com>
bbaaef
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
bbaaef
Date: Tue, 24 Sep 2019 18:39:56 +0200
bbaaef
Subject: [PATCH ovn 3/3] northd: introduce logical flow for localnet egress
bbaaef
 shaping
bbaaef
bbaaef
Add set_queue() action for qos capable localnet port in
bbaaef
S_SWITCH_OUT_PORT_SEC_L2 stage of logical swith pipeline
bbaaef
Introduce build_lswitch_{input,outpur}_port_sec and refactor
bbaaef
lswitch_port_security code in order to remove duplicated code
bbaaef
bbaaef
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
bbaaef
Signed-off-by: Mark Michelson <mmichels@redhat.com>
bbaaef
Acked-by: Mark Michelson <mmichels@redhat.com>
bbaaef
---
bbaaef
 ovn/northd/ovn-northd.8.xml |   7 +-
bbaaef
 ovn/northd/ovn-northd.c     | 231 ++++++++++++++++++++++++----------------
bbaaef
 2 files changed, 143 insertions(+), 95 deletions(-)
bbaaef
bbaaef
--- a/ovn/northd/ovn-northd.8.xml
bbaaef
+++ b/ovn/northd/ovn-northd.8.xml
bbaaef
@@ -1120,10 +1120,15 @@ output;
bbaaef
       eth.dst are always accepted instead of being subject to the
bbaaef
       port security rules; this is implemented through a priority-100 flow that
bbaaef
       matches on eth.mcast with action output;.
bbaaef
-      Finally, to ensure that even broadcast and multicast packets are not
bbaaef
+      Moreover, to ensure that even broadcast and multicast packets are not
bbaaef
       delivered to disabled logical ports, a priority-150 flow for each
bbaaef
       disabled logical outport overrides the priority-100 flow
bbaaef
       with a drop; action.
bbaaef
+      Finally if egress qos has been enabled on a localnet port, the outgoing
bbaaef
+      queue id is set through set_queue action. Please remember to
bbaaef
+      mark the corresponding physical interface with
bbaaef
+      ovn-egress-iface set to true in 
bbaaef
+      table="Interface" db="Open_vSwitch"/>
bbaaef
     

bbaaef
 
bbaaef
     

Logical Router Datapaths

bbaaef
--- a/ovn/northd/ovn-northd.c
bbaaef
+++ b/ovn/northd/ovn-northd.c
bbaaef
@@ -3771,6 +3771,140 @@ has_stateful_acl(struct ovn_datapath *od
bbaaef
 }
bbaaef
 
bbaaef
 static void
bbaaef
+build_lswitch_input_port_sec(struct hmap *ports, struct hmap *datapaths,
bbaaef
+                             struct hmap *lflows)
bbaaef
+{
bbaaef
+    /* Logical switch ingress table 0: Ingress port security - L2
bbaaef
+     *  (priority 50).
bbaaef
+     *  Ingress table 1: Ingress port security - IP (priority 90 and 80)
bbaaef
+     *  Ingress table 2: Ingress port security - ND (priority 90 and 80)
bbaaef
+     */
bbaaef
+    struct ds actions = DS_EMPTY_INITIALIZER;
bbaaef
+    struct ds match = DS_EMPTY_INITIALIZER;
bbaaef
+    struct ovn_port *op;
bbaaef
+
bbaaef
+    HMAP_FOR_EACH (op, key_node, ports) {
bbaaef
+        if (!op->nbsp) {
bbaaef
+            continue;
bbaaef
+        }
bbaaef
+
bbaaef
+        if (!lsp_is_enabled(op->nbsp)) {
bbaaef
+            /* Drop packets from disabled logical ports (since logical flow
bbaaef
+             * tables are default-drop). */
bbaaef
+            continue;
bbaaef
+        }
bbaaef
+
bbaaef
+        if (lsp_is_external(op->nbsp)) {
bbaaef
+            continue;
bbaaef
+        }
bbaaef
+
bbaaef
+        ds_clear(&match);
bbaaef
+        ds_clear(&actions);
bbaaef
+        ds_put_format(&match, "inport == %s", op->json_key);
bbaaef
+        build_port_security_l2("eth.src", op->ps_addrs, op->n_ps_addrs,
bbaaef
+                               &match);
bbaaef
+
bbaaef
+        const char *queue_id = smap_get(&op->sb->options, "qdisc_queue_id");
bbaaef
+        if (queue_id) {
bbaaef
+            ds_put_format(&actions, "set_queue(%s); ", queue_id);
bbaaef
+        }
bbaaef
+        ds_put_cstr(&actions, "next;");
bbaaef
+        ovn_lflow_add(lflows, op->od, S_SWITCH_IN_PORT_SEC_L2, 50,
bbaaef
+                      ds_cstr(&match), ds_cstr(&actions));
bbaaef
+
bbaaef
+        if (op->nbsp->n_port_security) {
bbaaef
+            build_port_security_ip(P_IN, op, lflows);
bbaaef
+            build_port_security_nd(op, lflows);
bbaaef
+        }
bbaaef
+    }
bbaaef
+
bbaaef
+    /* Ingress table 1 and 2: Port security - IP and ND, by default
bbaaef
+     * goto next. (priority 0)
bbaaef
+     */
bbaaef
+    struct ovn_datapath *od;
bbaaef
+    HMAP_FOR_EACH (od, key_node, datapaths) {
bbaaef
+        if (!od->nbs) {
bbaaef
+            continue;
bbaaef
+        }
bbaaef
+
bbaaef
+        ovn_lflow_add(lflows, od, S_SWITCH_IN_PORT_SEC_ND, 0, "1", "next;");
bbaaef
+        ovn_lflow_add(lflows, od, S_SWITCH_IN_PORT_SEC_IP, 0, "1", "next;");
bbaaef
+    }
bbaaef
+
bbaaef
+    ds_destroy(&match);
bbaaef
+    ds_destroy(&actions);
bbaaef
+}
bbaaef
+
bbaaef
+static void
bbaaef
+build_lswitch_output_port_sec(struct hmap *ports, struct hmap *datapaths,
bbaaef
+                              struct hmap *lflows)
bbaaef
+{
bbaaef
+    struct ds actions = DS_EMPTY_INITIALIZER;
bbaaef
+    struct ds match = DS_EMPTY_INITIALIZER;
bbaaef
+    struct ovn_port *op;
bbaaef
+
bbaaef
+    /* Egress table 8: Egress port security - IP (priorities 90 and 80)
bbaaef
+     * if port security enabled.
bbaaef
+     *
bbaaef
+     * Egress table 9: Egress port security - L2 (priorities 50 and 150).
bbaaef
+     *
bbaaef
+     * Priority 50 rules implement port security for enabled logical port.
bbaaef
+     *
bbaaef
+     * Priority 150 rules drop packets to disabled logical ports, so that
bbaaef
+     * they don't even receive multicast or broadcast packets.
bbaaef
+     */
bbaaef
+    HMAP_FOR_EACH (op, key_node, ports) {
bbaaef
+        if (!op->nbsp || lsp_is_external(op->nbsp)) {
bbaaef
+            continue;
bbaaef
+        }
bbaaef
+
bbaaef
+        ds_clear(&actions);
bbaaef
+        ds_clear(&match);
bbaaef
+
bbaaef
+        ds_put_format(&match, "outport == %s", op->json_key);
bbaaef
+        if (lsp_is_enabled(op->nbsp)) {
bbaaef
+            build_port_security_l2("eth.dst", op->ps_addrs, op->n_ps_addrs,
bbaaef
+                                   &match);
bbaaef
+
bbaaef
+            if (!strcmp(op->nbsp->type, "localnet")) {
bbaaef
+                const char *queue_id = smap_get(&op->sb->options,
bbaaef
+                                                "qdisc_queue_id");
bbaaef
+                if (queue_id) {
bbaaef
+                    ds_put_format(&actions, "set_queue(%s); ", queue_id);
bbaaef
+                }
bbaaef
+            }
bbaaef
+            ds_put_cstr(&actions, "output;");
bbaaef
+            ovn_lflow_add(lflows, op->od, S_SWITCH_OUT_PORT_SEC_L2, 50,
bbaaef
+                              ds_cstr(&match), ds_cstr(&actions));
bbaaef
+        } else {
bbaaef
+            ovn_lflow_add(lflows, op->od, S_SWITCH_OUT_PORT_SEC_L2, 150,
bbaaef
+                          ds_cstr(&match), "drop;");
bbaaef
+        }
bbaaef
+
bbaaef
+        if (op->nbsp->n_port_security) {
bbaaef
+            build_port_security_ip(P_OUT, op, lflows);
bbaaef
+        }
bbaaef
+    }
bbaaef
+
bbaaef
+    /* Egress tables 8: Egress port security - IP (priority 0)
bbaaef
+     * Egress table 9: Egress port security L2 - multicast/broadcast
bbaaef
+     *                 (priority 100). */
bbaaef
+    struct ovn_datapath *od;
bbaaef
+    HMAP_FOR_EACH (od, key_node, datapaths) {
bbaaef
+        if (!od->nbs) {
bbaaef
+            continue;
bbaaef
+        }
bbaaef
+
bbaaef
+        ovn_lflow_add(lflows, od, S_SWITCH_OUT_PORT_SEC_IP, 0, "1", "next;");
bbaaef
+        ovn_lflow_add(lflows, od, S_SWITCH_OUT_PORT_SEC_L2, 100, "eth.mcast",
bbaaef
+                      "output;");
bbaaef
+    }
bbaaef
+
bbaaef
+    ds_destroy(&match);
bbaaef
+    ds_destroy(&actions);
bbaaef
+}
bbaaef
+
bbaaef
+static void
bbaaef
 build_pre_acls(struct ovn_datapath *od, struct hmap *lflows)
bbaaef
 {
bbaaef
     bool has_stateful = has_stateful_acl(od);
bbaaef
@@ -4841,61 +4975,12 @@ build_lswitch_flows(struct hmap *datapat
bbaaef
          * to the next table if packet source is acceptable. */
bbaaef
     }
bbaaef
 
bbaaef
-    /* Logical switch ingress table 0: Ingress port security - L2
bbaaef
-     *  (priority 50).
bbaaef
-     *  Ingress table 1: Ingress port security - IP (priority 90 and 80)
bbaaef
-     *  Ingress table 2: Ingress port security - ND (priority 90 and 80)
bbaaef
-     */
bbaaef
-    struct ovn_port *op;
bbaaef
-    HMAP_FOR_EACH (op, key_node, ports) {
bbaaef
-        if (!op->nbsp) {
bbaaef
-            continue;
bbaaef
-        }
bbaaef
-
bbaaef
-        if (!lsp_is_enabled(op->nbsp)) {
bbaaef
-            /* Drop packets from disabled logical ports (since logical flow
bbaaef
-             * tables are default-drop). */
bbaaef
-            continue;
bbaaef
-        }
bbaaef
-
bbaaef
-        if (lsp_is_external(op->nbsp)) {
bbaaef
-            continue;
bbaaef
-        }
bbaaef
-
bbaaef
-        ds_clear(&match);
bbaaef
-        ds_clear(&actions);
bbaaef
-        ds_put_format(&match, "inport == %s", op->json_key);
bbaaef
-        build_port_security_l2("eth.src", op->ps_addrs, op->n_ps_addrs,
bbaaef
-                               &match);
bbaaef
-
bbaaef
-        const char *queue_id = smap_get(&op->sb->options, "qdisc_queue_id");
bbaaef
-        if (queue_id) {
bbaaef
-            ds_put_format(&actions, "set_queue(%s); ", queue_id);
bbaaef
-        }
bbaaef
-        ds_put_cstr(&actions, "next;");
bbaaef
-        ovn_lflow_add(lflows, op->od, S_SWITCH_IN_PORT_SEC_L2, 50,
bbaaef
-                      ds_cstr(&match), ds_cstr(&actions));
bbaaef
-
bbaaef
-        if (op->nbsp->n_port_security) {
bbaaef
-            build_port_security_ip(P_IN, op, lflows);
bbaaef
-            build_port_security_nd(op, lflows);
bbaaef
-        }
bbaaef
-    }
bbaaef
-
bbaaef
-    /* Ingress table 1 and 2: Port security - IP and ND, by default goto next.
bbaaef
-     * (priority 0)*/
bbaaef
-    HMAP_FOR_EACH (od, key_node, datapaths) {
bbaaef
-        if (!od->nbs) {
bbaaef
-            continue;
bbaaef
-        }
bbaaef
-
bbaaef
-        ovn_lflow_add(lflows, od, S_SWITCH_IN_PORT_SEC_ND, 0, "1", "next;");
bbaaef
-        ovn_lflow_add(lflows, od, S_SWITCH_IN_PORT_SEC_IP, 0, "1", "next;");
bbaaef
-    }
bbaaef
+    build_lswitch_input_port_sec(ports, datapaths, lflows);
bbaaef
 
bbaaef
     /* Ingress table 11: ARP/ND responder, skip requests coming from localnet
bbaaef
      * and vtep ports. (priority 100); see ovn-northd.8.xml for the
bbaaef
      * rationale. */
bbaaef
+    struct ovn_port *op;
bbaaef
     HMAP_FOR_EACH (op, key_node, ports) {
bbaaef
         if (!op->nbsp) {
bbaaef
             continue;
bbaaef
@@ -5501,49 +5586,7 @@ build_lswitch_flows(struct hmap *datapat
bbaaef
         }
bbaaef
     }
bbaaef
 
bbaaef
-    /* Egress tables 8: Egress port security - IP (priority 0)
bbaaef
-     * Egress table 9: Egress port security L2 - multicast/broadcast
bbaaef
-     *                 (priority 100). */
bbaaef
-    HMAP_FOR_EACH (od, key_node, datapaths) {
bbaaef
-        if (!od->nbs) {
bbaaef
-            continue;
bbaaef
-        }
bbaaef
-
bbaaef
-        ovn_lflow_add(lflows, od, S_SWITCH_OUT_PORT_SEC_IP, 0, "1", "next;");
bbaaef
-        ovn_lflow_add(lflows, od, S_SWITCH_OUT_PORT_SEC_L2, 100, "eth.mcast",
bbaaef
-                      "output;");
bbaaef
-    }
bbaaef
-
bbaaef
-    /* Egress table 8: Egress port security - IP (priorities 90 and 80)
bbaaef
-     * if port security enabled.
bbaaef
-     *
bbaaef
-     * Egress table 9: Egress port security - L2 (priorities 50 and 150).
bbaaef
-     *
bbaaef
-     * Priority 50 rules implement port security for enabled logical port.
bbaaef
-     *
bbaaef
-     * Priority 150 rules drop packets to disabled logical ports, so that they
bbaaef
-     * don't even receive multicast or broadcast packets. */
bbaaef
-    HMAP_FOR_EACH (op, key_node, ports) {
bbaaef
-        if (!op->nbsp || lsp_is_external(op->nbsp)) {
bbaaef
-            continue;
bbaaef
-        }
bbaaef
-
bbaaef
-        ds_clear(&match);
bbaaef
-        ds_put_format(&match, "outport == %s", op->json_key);
bbaaef
-        if (lsp_is_enabled(op->nbsp)) {
bbaaef
-            build_port_security_l2("eth.dst", op->ps_addrs, op->n_ps_addrs,
bbaaef
-                                   &match);
bbaaef
-            ovn_lflow_add(lflows, op->od, S_SWITCH_OUT_PORT_SEC_L2, 50,
bbaaef
-                          ds_cstr(&match), "output;");
bbaaef
-        } else {
bbaaef
-            ovn_lflow_add(lflows, op->od, S_SWITCH_OUT_PORT_SEC_L2, 150,
bbaaef
-                          ds_cstr(&match), "drop;");
bbaaef
-        }
bbaaef
-
bbaaef
-        if (op->nbsp->n_port_security) {
bbaaef
-            build_port_security_ip(P_OUT, op, lflows);
bbaaef
-        }
bbaaef
-    }
bbaaef
+    build_lswitch_output_port_sec(ports, datapaths, lflows);
bbaaef
 
bbaaef
     ds_destroy(&match);
bbaaef
     ds_destroy(&actions);