From patchwork Mon Feb 27 20:03:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1749132 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=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 4PQWfT0CKyz1yWw for ; Tue, 28 Feb 2023 07:04:01 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id C452F81F6E; Mon, 27 Feb 2023 20:03:58 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org C452F81F6E X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9AjJhYrW_4Yi; Mon, 27 Feb 2023 20:03:57 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id F068081EF6; Mon, 27 Feb 2023 20:03:55 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org F068081EF6 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id BD42BC007F; Mon, 27 Feb 2023 20:03:53 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5EC46C002B for ; Mon, 27 Feb 2023 20:03:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 2D23A6107B for ; Mon, 27 Feb 2023 20:03:52 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 2D23A6107B X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j1ASD0P2MT9u for ; Mon, 27 Feb 2023 20:03:51 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 8CE0C61073 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by smtp3.osuosl.org (Postfix) with ESMTPS id 8CE0C61073 for ; Mon, 27 Feb 2023 20:03:50 +0000 (UTC) Received: (Authenticated sender: i.maximets@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id 9FE0CC0009; Mon, 27 Feb 2023 20:03:48 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Mon, 27 Feb 2023 21:03:42 +0100 Message-Id: <20230227200344.1308604-2-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 1/3] treewide: Remove unnecessary strlen() calls. 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" In many cases OVN components are using strlen() to check if the string is not empty. In that case, unnecessary scan of the whole string is performed and the length is calculated, while it's enough to just check the first byte. Some functions also have completely unnecessary strlen() calls where needed functionality can be achieved without them. The most impactful changes in this commit are around extract_addresses() function, and extract_lsp_addresses() in particular. It is called by northd for every logical port and involves 2 unnecessary strlen() calls. Signed-off-by: Ilya Maximets Reviewed-by: Simon Horman Acked-by: Mark Michelson --- controller/chassis.c | 4 ++-- controller/encaps.c | 2 +- controller/physical.c | 2 +- controller/pinctrl.c | 6 +++--- ic/ovn-ic.c | 4 ++-- lib/ovn-util.c | 5 ++--- northd/northd.c | 10 +++++----- utilities/ovn-nbctl.c | 14 +++++++------- 8 files changed, 23 insertions(+), 24 deletions(-) diff --git a/controller/chassis.c b/controller/chassis.c index acde00849..0484e2fb9 100644 --- a/controller/chassis.c +++ b/controller/chassis.c @@ -99,9 +99,9 @@ static const char * get_hostname(const struct smap *ext_ids, const char *chassis_id) { const char *hostname = get_chassis_external_id_value(ext_ids, chassis_id, - "hostname", ""); + "hostname", NULL); - if (strlen(hostname) == 0) { + if (!hostname) { static char hostname_[HOST_NAME_MAX + 1]; if (gethostname(hostname_, sizeof(hostname_))) { diff --git a/controller/encaps.c b/controller/encaps.c index 5d383401d..2662eaf98 100644 --- a/controller/encaps.c +++ b/controller/encaps.c @@ -77,7 +77,7 @@ tunnel_create_name(struct tunnel_ctx *tc, const char *chassis_id) for (int i = 0; i < UINT16_MAX; i++) { const char *idx = get_chassis_idx(tc->ovs_table); char *port_name = xasprintf( - "ovn%s-%.*s-%x", idx, strlen(idx) ? 5 : 6, chassis_id, i); + "ovn%s-%.*s-%x", idx, idx[0] ? 5 : 6, chassis_id, i); if (!sset_contains(&tc->port_names, port_name)) { return port_name; diff --git a/controller/physical.c b/controller/physical.c index e718268ea..ec861f49c 100644 --- a/controller/physical.c +++ b/controller/physical.c @@ -505,7 +505,7 @@ populate_remote_chassis_macs(const struct sbrec_chassis *my_chassis, const char *tokens = get_chassis_mac_mappings(&chassis->other_config, chassis->name); - if (!strlen(tokens)) { + if (!tokens[0]) { continue; } diff --git a/controller/pinctrl.c b/controller/pinctrl.c index 248b1a0e7..795847729 100644 --- a/controller/pinctrl.c +++ b/controller/pinctrl.c @@ -3775,12 +3775,12 @@ ipv6_ra_update_config(const struct sbrec_port_binding *pb) const char *dnssl = smap_get(&pb->options, "ipv6_ra_dnssl"); if (dnssl) { - ds_put_buffer(&config->dnssl, dnssl, strlen(dnssl)); + ds_put_cstr(&config->dnssl, dnssl); } const char *route_info = smap_get(&pb->options, "ipv6_ra_route_info"); if (route_info) { - ds_put_buffer(&config->route_info, route_info, strlen(route_info)); + ds_put_cstr(&config->route_info, route_info); } return config; @@ -5825,7 +5825,7 @@ extract_addresses_with_port(const char *addresses, int ofs; if (!extract_addresses(addresses, laddrs, &ofs)) { return false; - } else if (ofs >= strlen(addresses)) { + } else if (!addresses[ofs]) { return true; } diff --git a/ic/ovn-ic.c b/ic/ovn-ic.c index 9a80a7f68..1d0a062f6 100644 --- a/ic/ovn-ic.c +++ b/ic/ovn-ic.c @@ -1162,7 +1162,7 @@ add_static_to_routes_ad( ipv6_format_addr(&nexthop, &msg); } - ds_put_format(&msg, ", route_table: %s", strlen(nb_route->route_table) + ds_put_format(&msg, ", route_table: %s", nb_route->route_table[0] ? nb_route->route_table : "
"); @@ -1348,7 +1348,7 @@ sync_learned_routes(struct ic_context *ctx, continue; } - if (strlen(isb_route->route_table) && + if (isb_route->route_table[0] && strcmp(isb_route->route_table, ts_route_table)) { if (VLOG_IS_DBG_ENABLED()) { VLOG_DBG("Skip learning static route %s -> %s as either " diff --git a/lib/ovn-util.c b/lib/ovn-util.c index b12c027b9..47484ef01 100644 --- a/lib/ovn-util.c +++ b/lib/ovn-util.c @@ -128,7 +128,6 @@ parse_and_store_addresses(const char *address, struct lport_addresses *laddrs, const char *buf = address; const char *const start = buf; int buf_index = 0; - const char *buf_end = buf + strlen(address); if (extract_eth_addr) { if (!ovs_scan_len(buf, &buf_index, ETH_ADDR_SCAN_FMT, @@ -151,7 +150,7 @@ parse_and_store_addresses(const char *address, struct lport_addresses *laddrs, * and store in the 'laddrs'. Break the loop if invalid data is found. */ buf += buf_index; - while (buf < buf_end) { + while (*buf != '\0') { buf_index = 0; error = ip_parse_cidr_len(buf, &buf_index, &ip4, &plen); if (!error) { @@ -205,7 +204,7 @@ extract_lsp_addresses(const char *address, struct lport_addresses *laddrs) int ofs; bool success = extract_addresses(address, laddrs, &ofs); - if (success && ofs < strlen(address)) { + if (success && address[ofs]) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); VLOG_INFO_RL(&rl, "invalid syntax '%s' in address", address); } diff --git a/northd/northd.c b/northd/northd.c index 770a5b50e..6d37ea713 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -9623,7 +9623,7 @@ route_table_add(struct simap *route_tables, const char *route_table_name) static uint32_t get_route_table_id(struct simap *route_tables, const char *route_table_name) { - if (!route_table_name || !strlen(route_table_name)) { + if (!route_table_name || !route_table_name[0]) { return 0; } @@ -9698,7 +9698,7 @@ parsed_routes_add(struct ovn_datapath *od, const struct hmap *ports, struct in6_addr nexthop; unsigned int plen; bool is_discard_route = !strcmp(route->nexthop, "discard"); - bool valid_nexthop = strlen(route->nexthop) && !is_discard_route; + bool valid_nexthop = route->nexthop[0] && !is_discard_route; if (valid_nexthop) { if (!ip46_parse_cidr(route->nexthop, &nexthop, &plen)) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); @@ -9989,7 +9989,7 @@ find_static_route_outport(struct ovn_datapath *od, const struct hmap *ports, route->output_port, route->ip_prefix); return false; } - if (strlen(route->nexthop)) { + if (route->nexthop[0]) { lrp_addr_s = find_lrp_member_ip(out_port, route->nexthop); } if (!lrp_addr_s) { @@ -10021,7 +10021,7 @@ find_static_route_outport(struct ovn_datapath *od, const struct hmap *ports, continue; } - if (strlen(route->nexthop)) { + if (route->nexthop[0]) { lrp_addr_s = find_lrp_member_ip(out_port, route->nexthop); } if (lrp_addr_s) { @@ -10337,7 +10337,7 @@ add_route(struct hmap *lflows, struct ovn_datapath *od, } else { ds_put_format(&common_actions, REG_ECMP_GROUP_ID" = 0; %s = ", is_ipv4 ? REG_NEXT_HOP_IPV4 : REG_NEXT_HOP_IPV6); - if (gateway && strlen(gateway)) { + if (gateway && gateway[0]) { ds_put_cstr(&common_actions, gateway); } else { ds_put_format(&common_actions, "ip%s.dst", is_ipv4 ? "4" : "6"); diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index ae4d6c403..45572fd30 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -4553,7 +4553,7 @@ nbctl_lr_route_add(struct ctl_context *ctx) } cleanup: - if (next_hop && strlen(next_hop)) { + if (next_hop && next_hop[0]) { free(next_hop); } free(prefix); @@ -6590,12 +6590,12 @@ print_route(const struct nbrec_logical_router_static_route *route, if (!strcmp(route->nexthop, "discard")) { next_hop = xasprintf("discard"); - } else if (strlen(route->nexthop)) { + } else if (route->nexthop[0]) { next_hop = normalize_prefix_str(route->nexthop); } ds_put_format(s, "%25s %25s", prefix, next_hop); free(prefix); - if (strlen(next_hop)) { + if (next_hop[0]) { free(next_hop); } @@ -6734,8 +6734,8 @@ nbctl_lr_route_list(struct ctl_context *ctx) if (!i || (i > 0 && strcmp(route->route_table, ipv4_routes[i - 1].route->route_table))) { ds_put_format(&ctx->output, "%sRoute Table %s:\n", i ? "\n" : "", - strlen(route->route_table) ? route->route_table - : "
"); + route->route_table[0] ? route->route_table + : "
"); } print_route(ipv4_routes[i].route, &ctx->output, ecmp); @@ -6760,8 +6760,8 @@ nbctl_lr_route_list(struct ctl_context *ctx) if (!i || (i > 0 && strcmp(route->route_table, ipv6_routes[i - 1].route->route_table))) { ds_put_format(&ctx->output, "%sRoute Table %s:\n", i ? "\n" : "", - strlen(route->route_table) ? route->route_table - : "
"); + route->route_table[0] ? route->route_table + : "
"); } print_route(ipv6_routes[i].route, &ctx->output, ecmp); 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 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);