From patchwork Fri Sep 18 15:07:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1366993 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cambridgegreys.com Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BtHK96fsGz9sT6 for ; Sat, 19 Sep 2020 01:08:29 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 2EA7B810D0; Fri, 18 Sep 2020 15:08:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Wk3naxMzXM45; Fri, 18 Sep 2020 15:08:25 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 0C4A7873A1; Fri, 18 Sep 2020 15:08:25 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C9F4DC0888; Fri, 18 Sep 2020 15:08:24 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 405BFC0888 for ; Fri, 18 Sep 2020 15:08:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 28BC487269 for ; Fri, 18 Sep 2020 15:08:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bRybv43TYAYT for ; Fri, 18 Sep 2020 15:08:19 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.kot-begemot.co.uk (ivanoab7.miniserver.com [37.128.132.42]) by whitealder.osuosl.org (Postfix) with ESMTPS id 610E884353 for ; Fri, 18 Sep 2020 15:08:19 +0000 (UTC) Received: from tun252.jain.kot-begemot.co.uk ([192.168.18.6] helo=jain.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kJHzl-0004bl-GN; Fri, 18 Sep 2020 15:08:17 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.92) (envelope-from ) id 1kJHzi-0000UP-Pk; Fri, 18 Sep 2020 16:08:16 +0100 From: anton.ivanov@cambridgegreys.com To: dev@openvswitch.org Date: Fri, 18 Sep 2020 16:07:47 +0100 Message-Id: <20200918150756.3414-6-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200918150756.3414-1-anton.ivanov@cambridgegreys.com> References: <20200918150756.3414-1-anton.ivanov@cambridgegreys.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett Cc: i.maximets@ovn.org, Anton Ivanov Subject: [ovs-dev] [PATCH ovn v2 05/14] ovn-northd: replace build_lswitch_input_port_sec with iterators X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Anton Ivanov Replace build_lswitch_input_port_sec with two separate op and od iterators. Reuse the match and actions allocated in build_lswitch_flows to avoid extra allocs and frees. Signed-off-by: Anton Ivanov --- northd/ovn-northd.c | 58 ++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index 838772bee..0f3818890 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -4750,46 +4750,40 @@ has_stateful_acl(struct ovn_datapath *od) } static void -build_lswitch_input_port_sec(struct hmap *ports, struct hmap *datapaths, - struct hmap *lflows) +build_lswitch_input_port_sec_op( + struct ovn_port *op, struct hmap *lflows, + struct ds *match, struct ds *actions) { /* Logical switch ingress table 0: Ingress port security - L2 * (priority 50). * Ingress table 1: Ingress port security - IP (priority 90 and 80) * Ingress table 2: Ingress port security - ND (priority 90 and 80) */ - struct ds actions = DS_EMPTY_INITIALIZER; - struct ds match = DS_EMPTY_INITIALIZER; - struct ovn_port *op; - - HMAP_FOR_EACH (op, key_node, ports) { - if (!op->nbsp) { - continue; - } + if (op->nbsp) { if (!lsp_is_enabled(op->nbsp)) { /* Drop packets from disabled logical ports (since logical flow * tables are default-drop). */ - continue; + return; } if (lsp_is_external(op->nbsp)) { - continue; + return; } - ds_clear(&match); - ds_clear(&actions); - ds_put_format(&match, "inport == %s", op->json_key); + ds_clear(match); + ds_clear(actions); + ds_put_format(match, "inport == %s", op->json_key); build_port_security_l2("eth.src", op->ps_addrs, op->n_ps_addrs, - &match); + match); const char *queue_id = smap_get(&op->sb->options, "qdisc_queue_id"); if (queue_id) { - ds_put_format(&actions, "set_queue(%s); ", queue_id); + ds_put_format(actions, "set_queue(%s); ", queue_id); } - ds_put_cstr(&actions, "next;"); + ds_put_cstr(actions, "next;"); ovn_lflow_add_with_hint(lflows, op->od, S_SWITCH_IN_PORT_SEC_L2, 50, - ds_cstr(&match), ds_cstr(&actions), + ds_cstr(match), ds_cstr(actions), &op->nbsp->header_); if (op->nbsp->n_port_security) { @@ -4797,22 +4791,19 @@ build_lswitch_input_port_sec(struct hmap *ports, struct hmap *datapaths, build_port_security_nd(op, lflows, &op->nbsp->header_); } } +} +static void +build_lswitch_input_port_sec_od( + struct ovn_datapath *od, struct hmap *lflows) +{ /* Ingress table 1 and 2: Port security - IP and ND, by default * goto next. (priority 0) */ - struct ovn_datapath *od; - HMAP_FOR_EACH (od, key_node, datapaths) { - if (!od->nbs) { - continue; - } - + if (od->nbs) { ovn_lflow_add(lflows, od, S_SWITCH_IN_PORT_SEC_ND, 0, "1", "next;"); ovn_lflow_add(lflows, od, S_SWITCH_IN_PORT_SEC_IP, 0, "1", "next;"); } - - ds_destroy(&match); - ds_destroy(&actions); } static void @@ -6775,6 +6766,8 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports, /* Build pre-ACL and ACL tables for both ingress and egress. * Ingress tables 3 through 10. Egress tables 0 through 7. */ struct ovn_datapath *od; + struct ovn_port *op; + HMAP_FOR_EACH (od, key_node, datapaths) { build_lswitch_flows_pre_acl_and_acl(od, lflows, port_groups, meter_groups, lbs); @@ -6789,12 +6782,17 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports, build_lswitch_ingress_admission_control(od, lflows); } - build_lswitch_input_port_sec(ports, datapaths, lflows); + HMAP_FOR_EACH (op, key_node, ports) { + build_lswitch_input_port_sec_op(op, lflows, &match, &actions); + } + + HMAP_FOR_EACH (od, key_node, datapaths) { + build_lswitch_input_port_sec_od(od, lflows); + } /* Ingress table 13: ARP/ND responder, skip requests coming from localnet * and vtep ports. (priority 100); see ovn-northd.8.xml for the * rationale. */ - struct ovn_port *op; HMAP_FOR_EACH (op, key_node, ports) { if (!op->nbsp) { continue;