From patchwork Wed Sep 2 14:59:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1355860 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 4BhRv32CFBz9sRK for ; Thu, 3 Sep 2020 01:00:15 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id CA39F869C5; Wed, 2 Sep 2020 15:00:12 +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 jcRH7zXz2EPo; Wed, 2 Sep 2020 15:00:10 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id B139A869AB; Wed, 2 Sep 2020 15:00:10 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8FE33C0894; Wed, 2 Sep 2020 15:00:10 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2A9F9C0051 for ; Wed, 2 Sep 2020 15:00:09 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 19987871DF for ; Wed, 2 Sep 2020 15:00:09 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id izyjUHLaHGGF for ; Wed, 2 Sep 2020 15:00:07 +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 hemlock.osuosl.org (Postfix) with ESMTPS id C597A8710A for ; Wed, 2 Sep 2020 15:00:07 +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 1kDUF3-0000sD-OY; Wed, 02 Sep 2020 15:00:06 +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 1kDUEx-0006lF-Ax; Wed, 02 Sep 2020 16:00:01 +0100 From: anton.ivanov@cambridgegreys.com To: dev@openvswitch.org Date: Wed, 2 Sep 2020 15:59:30 +0100 Message-Id: <20200902145950.25875-4-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200902145950.25875-1-anton.ivanov@cambridgegreys.com> References: <20200902145950.25875-1-anton.ivanov@cambridgegreys.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett Cc: Anton Ivanov Subject: [ovs-dev] [PATCH ovn RFC v4 04/24] Move NAT and Load Balancing to a separate function 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 Signed-off-by: Anton Ivanov --- northd/ovn-northd.c | 148 ++++++++++++++++++++++++++------------------ 1 file changed, 89 insertions(+), 59 deletions(-) diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index 10ddf6d0a..7af7ae525 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -9058,6 +9058,8 @@ build_lrouter_flows_table_3_ip_input_op(struct ovn_port *op, struct hmap *lflows * ETH address. */ if (op != op->od->l3dgw_port) { + ds_destroy(&match); + ds_destroy(&actions); return; } @@ -9176,7 +9178,7 @@ build_lrouter_ip_input_chassis_redirect_op( * No ingress packets are accepted on a chassisredirect * port, so no need to program flows for that port. */ - if (op->nbrp && (!op->derived)) { + if (op->nbrp && !op->derived) { if (op->lrp_networks.n_ipv6_addrs) { /* ICMPv6 echo reply. These flows reply to echo requests * received for the router's IP address. */ @@ -9304,57 +9306,15 @@ build_lrouter_ip_input_chassis_redirect_op( } static void -build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, - struct hmap *lflows, struct shash *meter_groups, - struct hmap *lbs) +build_lrouter_flows_NAT_defrag_lb_od( + struct ovn_datapath *od, struct hmap *lflows, + struct hmap *lbs, struct shash *meter_groups) { - /* This flow table structure is documented in ovn-northd(8), so please - * update ovn-northd.8.xml if you change anything. */ - struct ds match = DS_EMPTY_INITIALIZER; struct ds actions = DS_EMPTY_INITIALIZER; - - struct ovn_datapath *od; - HMAP_FOR_EACH (od, key_node, datapaths) { - build_lrouter_flows_ingress_table_0_od(od, lflows); - } - - struct ovn_port *op; - HMAP_FOR_EACH (op, key_node, ports) { - build_lrouter_flows_ingress_table_0_op(op, lflows); - } - - HMAP_FOR_EACH (od, key_node, datapaths) { - build_lrouter_flows_arp_nd_mac_learn_od(od, lflows); - } - - HMAP_FOR_EACH (op, key_node, ports) { - build_lrouter_flows_arp_nd_mac_learn_op(op, lflows); - } - - HMAP_FOR_EACH (op, key_node, ports) { - build_lrouter_flows_table_3_ip_input_op(op, lflows); - } - - HMAP_FOR_EACH (od, key_node, datapaths) { - build_lrouter_flows_table_3_ip_input_od(od, lflows); - } - - HMAP_FOR_EACH (op, key_node, ports) { - build_lrouter_dhcp_reply_op(op, lflows); - } - - HMAP_FOR_EACH (op, key_node, ports) { - build_lrouter_ip_input_chassis_redirect_op(op, lflows); - } - /* NAT, Defrag and load balancing. */ - HMAP_FOR_EACH (od, key_node, datapaths) { - if (!od->nbr) { - continue; - } - + if (od->nbr) { /* Packets are allowed by default. */ ovn_lflow_add(lflows, od, S_ROUTER_IN_DEFRAG, 0, "1", "next;"); ovn_lflow_add(lflows, od, S_ROUTER_IN_UNSNAT, 0, "1", "next;"); @@ -9373,7 +9333,9 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, * l3dgw_port (router has a port with "redirect-chassis" * specified). */ if (!smap_get(&od->nbr->options, "chassis") && !od->l3dgw_port) { - continue; + ds_destroy(&match); + ds_destroy(&actions); + return; } struct sset nat_entries = SSET_INITIALIZER(&nat_entries); @@ -9895,7 +9857,9 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, * Gateway routers or router with gateway port. */ if (!smap_get(&od->nbr->options, "chassis") && !od->l3dgw_port) { sset_destroy(&nat_entries); - continue; + ds_destroy(&match); + ds_destroy(&actions); + return; } /* A set to hold all ips that need defragmentation and tracking. */ @@ -9974,18 +9938,23 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, sset_destroy(&all_ips); sset_destroy(&nat_entries); } + ds_destroy(&match); + ds_destroy(&actions); +} + +static void +build_lrouter_flows_NAT_defrag_lb_op(struct ovn_port *op, struct hmap *lflows) +{ /* Logical router ingress table ND_RA_OPTIONS & ND_RA_RESPONSE: IPv6 Router * Adv (RA) options and response. */ - HMAP_FOR_EACH (op, key_node, ports) { - if (!op->nbrp || op->nbrp->peer || !op->peer) { - continue; - } - - if (!op->lrp_networks.n_ipv6_addrs) { - continue; - } + if (!op->nbrp || op->nbrp->peer || !op->peer) { + return; + } + if (op->lrp_networks.n_ipv6_addrs) { + struct ds match = DS_EMPTY_INITIALIZER; + struct ds actions = DS_EMPTY_INITIALIZER; struct smap options; smap_clone(&options, &op->sb->options); @@ -10014,7 +9983,9 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, &op->nbrp->ipv6_ra_configs, "address_mode"); if (!address_mode) { - continue; + ds_destroy(&match); + ds_destroy(&actions); + return; } if (strcmp(address_mode, "slaac") && strcmp(address_mode, "dhcpv6_stateful") && @@ -10022,7 +9993,9 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); VLOG_WARN_RL(&rl, "Invalid address mode [%s] defined", address_mode); - continue; + ds_destroy(&match); + ds_destroy(&actions); + return; } if (smap_get_bool(&op->nbrp->ipv6_ra_configs, "send_periodic", @@ -10093,6 +10066,63 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, ds_cstr(&match), ds_cstr(&actions), &op->nbrp->header_); } + ds_destroy(&match); + ds_destroy(&actions); + } +} + +static void +build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, + struct hmap *lflows, struct shash *meter_groups, + struct hmap *lbs) +{ + /* This flow table structure is documented in ovn-northd(8), so please + * update ovn-northd.8.xml if you change anything. */ + + struct ds match = DS_EMPTY_INITIALIZER; + struct ds actions = DS_EMPTY_INITIALIZER; + + struct ovn_datapath *od; + HMAP_FOR_EACH (od, key_node, datapaths) { + build_lrouter_flows_ingress_table_0_od(od, lflows); + } + + struct ovn_port *op; + HMAP_FOR_EACH (op, key_node, ports) { + build_lrouter_flows_ingress_table_0_op(op, lflows); + } + + HMAP_FOR_EACH (od, key_node, datapaths) { + build_lrouter_flows_arp_nd_mac_learn_od(od, lflows); + } + + HMAP_FOR_EACH (op, key_node, ports) { + build_lrouter_flows_arp_nd_mac_learn_op(op, lflows); + } + + HMAP_FOR_EACH (op, key_node, ports) { + build_lrouter_flows_table_3_ip_input_op(op, lflows); + } + + HMAP_FOR_EACH (od, key_node, datapaths) { + build_lrouter_flows_table_3_ip_input_od(od, lflows); + } + + HMAP_FOR_EACH (op, key_node, ports) { + build_lrouter_dhcp_reply_op(op, lflows); + } + + HMAP_FOR_EACH (op, key_node, ports) { + build_lrouter_ip_input_chassis_redirect_op(op, lflows); + } + + HMAP_FOR_EACH (od, key_node, datapaths) { + build_lrouter_flows_NAT_defrag_lb_od( + od, lflows, lbs, meter_groups); + } + + HMAP_FOR_EACH (op, key_node, ports) { + build_lrouter_flows_NAT_defrag_lb_op(op, lflows); } /* Logical router ingress table ND_RA_OPTIONS & ND_RA_RESPONSE: RS