From patchwork Mon Feb 27 20:03:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1749133 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PQWfY2qppz1yWw for ; Tue, 28 Feb 2023 07:04:05 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 9A01340B55; Mon, 27 Feb 2023 20:04:02 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 9A01340B55 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xZiQkFFhgO8M; Mon, 27 Feb 2023 20:04:00 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id 4EA3F40ACB; Mon, 27 Feb 2023 20:03:59 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 4EA3F40ACB Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 51DDEC0032; Mon, 27 Feb 2023 20:03:58 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8929FC0071 for ; Mon, 27 Feb 2023 20:03:55 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 4E3E3408A3 for ; Mon, 27 Feb 2023 20:03:55 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 4E3E3408A3 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ARGE0RooK0Cb for ; Mon, 27 Feb 2023 20:03:54 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org BCB9740502 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by smtp2.osuosl.org (Postfix) with ESMTPS id BCB9740502 for ; Mon, 27 Feb 2023 20:03:53 +0000 (UTC) Received: (Authenticated sender: i.maximets@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id A7131C0008; Mon, 27 Feb 2023 20:03:51 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Mon, 27 Feb 2023 21:03:44 +0100 Message-Id: <20230227200344.1308604-4-i.maximets@ovn.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230227200344.1308604-1-i.maximets@ovn.org> References: <20230227200344.1308604-1-i.maximets@ovn.org> MIME-Version: 1.0 Cc: Ilya Maximets , Dumitru Ceara Subject: [ovs-dev] [PATCH ovn 3/3] northd: Don't parse LSP addresses twice. 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" At the point of IPAM configuration all the addresses are already parsed. No need to waste time parsing them again. Signed-off-by: Ilya Maximets Reviewed-by: Simon Horman Acked-by: Mark Michelson --- northd/northd.c | 54 ++++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/northd/northd.c b/northd/northd.c index 6d37ea713..868a8c3b8 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -1497,7 +1497,10 @@ struct ovn_port { const struct nbrec_logical_switch_port *nbsp; /* May be NULL. */ struct lport_addresses *lsp_addrs; /* Logical switch port addresses. */ - unsigned int n_lsp_addrs; + unsigned int n_lsp_addrs; /* Total length of lsp_addrs. */ + unsigned int n_lsp_non_router_addrs; /* Number of elements from the + * beginning of 'lsp_addrs' extracted + * directly from LSP 'addresses'. */ struct lport_addresses *ps_addrs; /* Port security addresses. */ unsigned int n_ps_addrs; @@ -1817,35 +1820,21 @@ ipam_insert_ip_for_datapath(struct ovn_datapath *od, uint32_t ip) } static void -ipam_insert_lsp_addresses(struct ovn_datapath *od, struct ovn_port *op, - char *address) +ipam_insert_lsp_addresses(struct ovn_datapath *od, + struct lport_addresses *laddrs) { - if (!od || !op || !address || !strcmp(address, "unknown") - || !strcmp(address, "router") || is_dynamic_lsp_address(address)) { - return; - } - - struct lport_addresses laddrs; - if (!extract_lsp_addresses(address, &laddrs)) { - static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); - VLOG_WARN_RL(&rl, "Extract addresses failed."); - return; - } - ipam_insert_mac(&laddrs.ea, true); + ipam_insert_mac(&laddrs->ea, true); /* IP is only added to IPAM if the switch's subnet option * is set, whereas MAC is always added to MACAM. */ if (!od->ipam_info.allocated_ipv4s) { - destroy_lport_addresses(&laddrs); return; } - for (size_t j = 0; j < laddrs.n_ipv4_addrs; j++) { - uint32_t ip = ntohl(laddrs.ipv4_addrs[j].addr); + for (size_t j = 0; j < laddrs->n_ipv4_addrs; j++) { + uint32_t ip = ntohl(laddrs->ipv4_addrs[j].addr); ipam_insert_ip_for_datapath(od, ip); } - - destroy_lport_addresses(&laddrs); } static void @@ -1855,29 +1844,21 @@ ipam_add_port_addresses(struct ovn_datapath *od, struct ovn_port *op) return; } - if (op->nbsp) { + if (op->n_lsp_non_router_addrs) { /* Add all the port's addresses to address data structures. */ - for (size_t i = 0; i < op->nbsp->n_addresses; i++) { - ipam_insert_lsp_addresses(od, op, op->nbsp->addresses[i]); - } - } else if (op->nbrp) { - struct lport_addresses lrp_networks; - if (!extract_lrp_networks(op->nbrp, &lrp_networks)) { - static struct vlog_rate_limit rl - = VLOG_RATE_LIMIT_INIT(1, 1); - VLOG_WARN_RL(&rl, "Extract addresses failed."); - return; + for (size_t i = 0; i < op->n_lsp_non_router_addrs; i++) { + ipam_insert_lsp_addresses(od, &op->lsp_addrs[i]); } - ipam_insert_mac(&lrp_networks.ea, true); + } else if (op->lrp_networks.ea_s[0]) { + ipam_insert_mac(&op->lrp_networks.ea, true); if (!op->peer || !op->peer->nbsp || !op->peer->od || !op->peer->od->nbs || !smap_get(&op->peer->od->nbs->other_config, "subnet")) { - destroy_lport_addresses(&lrp_networks); return; } - for (size_t i = 0; i < lrp_networks.n_ipv4_addrs; i++) { - uint32_t ip = ntohl(lrp_networks.ipv4_addrs[i].addr); + for (size_t i = 0; i < op->lrp_networks.n_ipv4_addrs; i++) { + uint32_t ip = ntohl(op->lrp_networks.ipv4_addrs[i].addr); /* If the router has the first IP address of the subnet, don't add * it to IPAM. We already added this when we initialized IPAM for * the datapath. This will just result in an erroneous message @@ -1887,8 +1868,6 @@ ipam_add_port_addresses(struct ovn_datapath *od, struct ovn_port *op) ipam_insert_ip_for_datapath(op->peer->od, ip); } } - - destroy_lport_addresses(&lrp_networks); } } @@ -2573,6 +2552,7 @@ join_logical_ports(struct northd_input *input_data, } op->n_lsp_addrs++; } + op->n_lsp_non_router_addrs = op->n_lsp_addrs; op->ps_addrs = xmalloc(sizeof *op->ps_addrs * nbsp->n_port_security);