From patchwork Mon Feb 27 20:03:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1749134 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::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (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 4PQWfc5qBxz1yWw for ; Tue, 28 Feb 2023 07:04:08 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id C5615417DA; Mon, 27 Feb 2023 20:04:01 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org C5615417DA X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id n8vk-LpKND35; Mon, 27 Feb 2023 20:03:59 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 9E5A9417A1; Mon, 27 Feb 2023 20:03:57 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 9E5A9417A1 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9ADF2C0089; Mon, 27 Feb 2023 20:03:54 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 86202C002B for ; Mon, 27 Feb 2023 20:03:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 46D444049C for ; Mon, 27 Feb 2023 20:03:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 46D444049C X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mcVM3rajYI-W for ; Mon, 27 Feb 2023 20:03:52 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 3B95E4046D Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by smtp4.osuosl.org (Postfix) with ESMTPS id 3B95E4046D for ; Mon, 27 Feb 2023 20:03:52 +0000 (UTC) Received: (Authenticated sender: i.maximets@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id 40657C0003; Mon, 27 Feb 2023 20:03:50 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Mon, 27 Feb 2023 21:03:43 +0100 Message-Id: <20230227200344.1308604-3-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 2/3] ovn-util: Optimize is_dynamic_lsp_address. 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" For non-dynamic address, current version performs 1 strcmp + 4 attempts for ovs_scan. Updated code perfroms 1 strncmp + 1 ovs_scan. Also, for ports with both IPv4 and IPv6 specified, new version doesn't re-parse IPv4 twice. Signed-off-by: Ilya Maximets Reviewed-by: Simon Horman --- lib/ovn-util.c | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/lib/ovn-util.c b/lib/ovn-util.c index 47484ef01..e683abb45 100644 --- a/lib/ovn-util.c +++ b/lib/ovn-util.c @@ -105,18 +105,41 @@ is_dynamic_lsp_address(const char *address) char ipv6_s[IPV6_SCAN_LEN + 1]; struct eth_addr ea; ovs_be32 ip; - int n; - return (!strcmp(address, "dynamic") - || (ovs_scan(address, "dynamic "IP_SCAN_FMT"%n", - IP_SCAN_ARGS(&ip), &n) - && address[n] == '\0') - || (ovs_scan(address, "dynamic "IP_SCAN_FMT" "IPV6_SCAN_FMT"%n", - IP_SCAN_ARGS(&ip), ipv6_s, &n) - && address[n] == '\0') - || (ovs_scan(address, "dynamic "IPV6_SCAN_FMT"%n", - ipv6_s, &n) && address[n] == '\0') - || (ovs_scan(address, ETH_ADDR_SCAN_FMT" dynamic%n", - ETH_ADDR_SCAN_ARGS(ea), &n) && address[n] == '\0')); + int n = 0; + + if (!strncmp(address, "dynamic", 7)) { + n = 7; + if (!address[n]) { + /* "dynamic" */ + return true; + } + if (ovs_scan_len(address, &n, " "IP_SCAN_FMT, IP_SCAN_ARGS(&ip))) { + if (!address[n]) { + /* "dynamic x.x.x.x" */ + return true; + } + if (ovs_scan_len(address, &n, " "IPV6_SCAN_FMT, ipv6_s) + && !address[n]) { + /* "dynamic x.x.x.x xxxx::xxxx" */ + return true; + } + return false; + } + if (ovs_scan_len(address, &n, " "IPV6_SCAN_FMT, ipv6_s) + && !address[n]) { + /* "dynamic xxxx::xxxx" */ + return true; + } + return false; + } + + if (ovs_scan_len(address, &n, ETH_ADDR_SCAN_FMT" dynamic", + ETH_ADDR_SCAN_ARGS(ea)) && !address[n]) { + /* "xx:xx:xx:xx:xx:xx dynamic" */ + return true; + } + + return false; } static bool