From patchwork Mon Jul 12 18:18:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1504158 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=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=N8MyrHDc; dkim-atps=neutral Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GNsTr0kZ0z9sWd for ; Tue, 13 Jul 2021 04:18:55 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 158B7608AE; Mon, 12 Jul 2021 18:18:53 +0000 (UTC) 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 tZ6pHDZNXFSM; Mon, 12 Jul 2021 18:18:51 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 05AD26088A; Mon, 12 Jul 2021 18:18:49 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A9FEBC0024; Mon, 12 Jul 2021 18:18:48 +0000 (UTC) X-Original-To: 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 193A1C000E for ; Mon, 12 Jul 2021 18:18:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id C070A401BF for ; Mon, 12 Jul 2021 18:18:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com 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 RI7rTs09u55D for ; Mon, 12 Jul 2021 18:18:44 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id AE98640214 for ; Mon, 12 Jul 2021 18:18:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626113923; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7xrar14fCYY0bR5AQftouWyafgRQu+ILql9MFBiWy6U=; b=N8MyrHDckiv3QwUDXbw5Jt+N8LecgGmz4vCGB9iL15VUxuHeFR+jmViKqU7dhUf5Dl9xVM mcWC4P26AU82WqmfHBJjOB8WWQYIXA2Y6UGqXDfOpwmF2O216z2v4vTuH+QVHXWdEpCNF1 j1ed51IGqCAYsZQHSp7WS+pMmFXmVZg= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-270-jre44OVSNs2t5_TRBMeNYw-1; Mon, 12 Jul 2021 14:18:37 -0400 X-MC-Unique: jre44OVSNs2t5_TRBMeNYw-1 Received: by mail-ed1-f70.google.com with SMTP id n6-20020aa7c4460000b02903a12bbba1ebso7112652edr.6 for ; Mon, 12 Jul 2021 11:18:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7xrar14fCYY0bR5AQftouWyafgRQu+ILql9MFBiWy6U=; b=TRFxZPEZzpsC/6EwvgkrSrjnM2dH+MaH2GEo2JVw0hCagj3dtlmhe8Q7vS+ZwCNcNd uoWvzXBK6/OTatcvM9MM8LRvWJtpR6T8w6gu1BTavBRqZGlxF31voUsznpyCQEVM3fxV aKXtGHi0Mw+UlgpjNVwOGyeUnWhkInLzQVUXcHvFsoZyv6RflmElIYS5BdHLScT+9bcC UQNvJEIH9hHFsYZwi6D9rQabo8456Lc/1PioucVUfjdBWJZ3fJIUFc9o4H/2gjjBlTyk BbyhoM4YP+4cQV1n9mgq/TZ49gWWmAZDkFCn17GC2Q+Kz/U+dJf+1qJiog53kKeB4Ksb svsg== X-Gm-Message-State: AOAM531L+HFDdD0gsEYWBsZhPd0VgCd+0kjWmY12py9+Gz44Dedknr/N x4NNgzFFSa5WF0uGxjCadEpOZk3z0pcWINSfdhVRrI5uSyAKN6fb0LqLuBM6ZBkfpuGPEyJ/tuw 0lzzu6aaLfjPQ6q9AugYsIM2Ufn63jLiqgSq/tEWeIpfShOIxTCDfI44uMA8XY9aGr3rIn3kElf Y= X-Received: by 2002:a17:906:814f:: with SMTP id z15mr430742ejw.178.1626113916014; Mon, 12 Jul 2021 11:18:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOSowRMEjhhWEjXE//OU3ttADZ582VqUGhbFwCVi92ceSy802S/hi6ZHd5b4PwsWoS7iKKYQ== X-Received: by 2002:a17:906:814f:: with SMTP id z15mr430709ejw.178.1626113915741; Mon, 12 Jul 2021 11:18:35 -0700 (PDT) Received: from lore-desk.redhat.com (net-188-216-29-9.cust.vodafonedsl.it. [188.216.29.9]) by smtp.gmail.com with ESMTPSA id s12sm8149339edd.68.2021.07.12.11.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 11:18:35 -0700 (PDT) From: Lorenzo Bianconi To: dev@openvswitch.org Date: Mon, 12 Jul 2021 20:18:30 +0200 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lorenzo.bianconi@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: dceara@redhat.com Subject: [ovs-dev] [PATCH v3 ovn 1/2] controller: incrementally create ipv6 prefix delegation port_binding list 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" Incrementally manage local_active_ports_ipv6_pd map for interfaces where IPv6 prefix-delegation has been enabled. This patch allows to avoid looping over all local interfaces to check if prefix-delegation is running on the current port binding. Acked-by: Mark Michelson Signed-off-by: Lorenzo Bianconi --- controller/binding.c | 32 +++++++++++ controller/binding.h | 1 + controller/ovn-controller.c | 11 +++- controller/ovn-controller.h | 6 ++ controller/pinctrl.c | 107 +++++++++++++++++------------------- controller/pinctrl.h | 4 +- 6 files changed, 103 insertions(+), 58 deletions(-) diff --git a/controller/binding.c b/controller/binding.c index 594babc98..9711ac850 100644 --- a/controller/binding.c +++ b/controller/binding.c @@ -574,6 +574,30 @@ remove_related_lport(const struct sbrec_port_binding *pb, } } +static void +update_active_pb_ras_pd(const struct sbrec_port_binding *pb, + struct hmap *local_datapaths, + struct shash *map, const char *conf) +{ + bool ras_pd_conf = smap_get_bool(&pb->options, conf, false); + struct shash_node *iter = shash_find(map, pb->logical_port); + + if (iter && !ras_pd_conf) { + shash_delete(map, iter); + return; + } + struct pb_ld_binding *ras_pd = NULL; + if (!iter && ras_pd_conf) { + ras_pd = xzalloc(sizeof *ras_pd); + ras_pd->pb = pb; + shash_add(map, pb->logical_port, ras_pd); + } + if (ras_pd) { + ras_pd->ld = get_local_datapath(local_datapaths, + pb->datapath->tunnel_key); + } +} + /* Corresponds to each Port_Binding.type. */ enum en_lport_type { LP_UNKNOWN, @@ -1645,6 +1669,10 @@ binding_run(struct binding_ctx_in *b_ctx_in, struct binding_ctx_out *b_ctx_out) const struct sbrec_port_binding *pb; SBREC_PORT_BINDING_TABLE_FOR_EACH (pb, b_ctx_in->port_binding_table) { + update_active_pb_ras_pd(pb, b_ctx_out->local_datapaths, + b_ctx_out->local_active_ports_ipv6_pd, + "ipv6_prefix_delegation"); + enum en_lport_type lport_type = get_lport_type(pb); switch (lport_type) { @@ -2482,6 +2510,10 @@ delete_done: continue; } + update_active_pb_ras_pd(pb, b_ctx_out->local_datapaths, + b_ctx_out->local_active_ports_ipv6_pd, + "ipv6_prefix_delegation"); + enum en_lport_type lport_type = get_lport_type(pb); struct binding_lport *b_lport = diff --git a/controller/binding.h b/controller/binding.h index a08011ae2..60ad49da0 100644 --- a/controller/binding.h +++ b/controller/binding.h @@ -72,6 +72,7 @@ void related_lports_destroy(struct related_lports *); struct binding_ctx_out { struct hmap *local_datapaths; + struct shash *local_active_ports_ipv6_pd; struct local_binding_data *lbinding_data; /* sset of (potential) local lports. */ diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 6a9c25f28..c4eb54755 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -1029,6 +1029,8 @@ struct ed_type_runtime_data { bool tracked; bool local_lports_changed; struct hmap tracked_dp_bindings; + + struct shash local_active_ports_ipv6_pd; }; /* struct ed_type_runtime_data has the below members for tracking the @@ -1116,6 +1118,7 @@ en_runtime_data_init(struct engine_node *node OVS_UNUSED, sset_init(&data->egress_ifaces); smap_init(&data->local_iface_ids); local_binding_data_init(&data->lbinding_data); + shash_init(&data->local_active_ports_ipv6_pd); /* Init the tracked data. */ hmap_init(&data->tracked_dp_bindings); @@ -1141,6 +1144,7 @@ en_runtime_data_cleanup(void *data) free(cur_node); } hmap_destroy(&rt_data->local_datapaths); + shash_destroy(&rt_data->local_active_ports_ipv6_pd); local_binding_data_destroy(&rt_data->lbinding_data); } @@ -1219,6 +1223,8 @@ init_binding_ctx(struct engine_node *node, b_ctx_in->ovs_table = ovs_table; b_ctx_out->local_datapaths = &rt_data->local_datapaths; + b_ctx_out->local_active_ports_ipv6_pd = + &rt_data->local_active_ports_ipv6_pd; b_ctx_out->local_lports = &rt_data->local_lports; b_ctx_out->local_lports_changed = false; b_ctx_out->related_lports = &rt_data->related_lports; @@ -1236,6 +1242,7 @@ en_runtime_data_run(struct engine_node *node, void *data) { struct ed_type_runtime_data *rt_data = data; struct hmap *local_datapaths = &rt_data->local_datapaths; + struct shash *local_active_ipv6_pd = &rt_data->local_active_ports_ipv6_pd; struct sset *local_lports = &rt_data->local_lports; struct sset *active_tunnels = &rt_data->active_tunnels; @@ -1251,6 +1258,7 @@ en_runtime_data_run(struct engine_node *node, void *data) free(cur_node); } hmap_clear(local_datapaths); + shash_clear(local_active_ipv6_pd); local_binding_data_destroy(&rt_data->lbinding_data); sset_destroy(local_lports); related_lports_destroy(&rt_data->related_lports); @@ -3265,7 +3273,8 @@ main(int argc, char *argv[]) sbrec_bfd_table_get(ovnsb_idl_loop.idl), br_int, chassis, &runtime_data->local_datapaths, - &runtime_data->active_tunnels); + &runtime_data->active_tunnels, + &runtime_data->local_active_ports_ipv6_pd); /* Updating monitor conditions if runtime data or * logical datapath goups changed. */ if (engine_node_changed(&en_runtime_data) diff --git a/controller/ovn-controller.h b/controller/ovn-controller.h index 5d9466880..417c7aacb 100644 --- a/controller/ovn-controller.h +++ b/controller/ovn-controller.h @@ -87,4 +87,10 @@ enum chassis_tunnel_type { uint32_t get_tunnel_type(const char *name); +struct pb_ld_binding { + const struct sbrec_port_binding *pb; + const struct local_datapath *ld; + struct hmap_node hmap_node; +}; + #endif /* controller/ovn-controller.h */ diff --git a/controller/pinctrl.c b/controller/pinctrl.c index 78ecfed84..5f3eca4a0 100644 --- a/controller/pinctrl.c +++ b/controller/pinctrl.c @@ -1249,83 +1249,76 @@ fill_ipv6_prefix_state(struct ovsdb_idl_txn *ovnsb_idl_txn, static void prepare_ipv6_prefixd(struct ovsdb_idl_txn *ovnsb_idl_txn, struct ovsdb_idl_index *sbrec_port_binding_by_name, - const struct hmap *local_datapaths, + const struct shash *local_active_ports_ipv6_pd, const struct sbrec_chassis *chassis, const struct sset *active_tunnels) OVS_REQUIRES(pinctrl_mutex) { - const struct local_datapath *ld; bool changed = false; - HMAP_FOR_EACH (ld, hmap_node, local_datapaths) { - if (datapath_is_switch(ld->datapath)) { - /* logical switch */ + struct shash_node *iter; + SHASH_FOR_EACH (iter, local_active_ports_ipv6_pd) { + const struct pb_ld_binding *pb_ipv6 = iter->data; + const struct sbrec_port_binding *pb = pb_ipv6->pb; + int j; + + if (!pb_ipv6->ld) { continue; } - for (size_t i = 0; i < ld->n_peer_ports; i++) { - const struct sbrec_port_binding *pb = ld->peer_ports[i].local; - int j; + const char *peer_s = smap_get(&pb->options, "peer"); + if (!peer_s) { + continue; + } - if (!smap_get_bool(&pb->options, "ipv6_prefix_delegation", - false)) { - continue; - } + const struct sbrec_port_binding *peer + = lport_lookup_by_name(sbrec_port_binding_by_name, peer_s); + if (!peer) { + continue; + } - const char *peer_s = smap_get(&pb->options, "peer"); - if (!peer_s) { - continue; - } + char *redirect_name = xasprintf("cr-%s", pb->logical_port); + bool resident = lport_is_chassis_resident( + sbrec_port_binding_by_name, chassis, active_tunnels, + redirect_name); + free(redirect_name); + if (!resident && strcmp(pb->type, "l3gateway")) { + continue; + } - const struct sbrec_port_binding *peer - = lport_lookup_by_name(sbrec_port_binding_by_name, peer_s); - if (!peer) { - continue; - } + struct in6_addr ip6_addr; + struct eth_addr ea = eth_addr_zero; + for (j = 0; j < pb->n_mac; j++) { + struct lport_addresses laddrs; - char *redirect_name = xasprintf("cr-%s", pb->logical_port); - bool resident = lport_is_chassis_resident( - sbrec_port_binding_by_name, chassis, active_tunnels, - redirect_name); - free(redirect_name); - if (!resident && strcmp(pb->type, "l3gateway")) { + if (!extract_lsp_addresses(pb->mac[j], &laddrs)) { continue; } - struct in6_addr ip6_addr; - struct eth_addr ea = eth_addr_zero; - for (j = 0; j < pb->n_mac; j++) { - struct lport_addresses laddrs; - - if (!extract_lsp_addresses(pb->mac[j], &laddrs)) { - continue; - } - - ea = laddrs.ea; - if (laddrs.n_ipv6_addrs > 0) { - ip6_addr = laddrs.ipv6_addrs[0].addr; - destroy_lport_addresses(&laddrs); - break; - } + ea = laddrs.ea; + if (laddrs.n_ipv6_addrs > 0) { + ip6_addr = laddrs.ipv6_addrs[0].addr; destroy_lport_addresses(&laddrs); + break; } + destroy_lport_addresses(&laddrs); + } - if (eth_addr_is_zero(ea)) { - continue; - } - - if (j == pb->n_mac) { - in6_generate_lla(ea, &ip6_addr); - } + if (eth_addr_is_zero(ea)) { + continue; + } - changed |= fill_ipv6_prefix_state(ovnsb_idl_txn, ld, - ea, ip6_addr, - peer->tunnel_key, - peer->datapath->tunnel_key); + if (j == pb->n_mac) { + in6_generate_lla(ea, &ip6_addr); } + + changed |= fill_ipv6_prefix_state(ovnsb_idl_txn, pb_ipv6->ld, + ea, ip6_addr, + peer->tunnel_key, + peer->datapath->tunnel_key); } - struct shash_node *iter, *next; + struct shash_node *next; SHASH_FOR_EACH_SAFE (iter, next, &ipv6_prefixd) { struct ipv6_prefixd_state *pfd = iter->data; if (pfd->last_used + IPV6_PREFIXD_STALE_TIMEOUT < time_msec()) { @@ -3411,7 +3404,8 @@ pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, const struct ovsrec_bridge *br_int, const struct sbrec_chassis *chassis, const struct hmap *local_datapaths, - const struct sset *active_tunnels) + const struct sset *active_tunnels, + const struct shash *local_active_ports_ipv6_pd) { ovs_mutex_lock(&pinctrl_mutex); pinctrl_set_br_int_name_(br_int->name); @@ -3426,7 +3420,8 @@ pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, local_datapaths, active_tunnels); prepare_ipv6_ras(local_datapaths); prepare_ipv6_prefixd(ovnsb_idl_txn, sbrec_port_binding_by_name, - local_datapaths, chassis, active_tunnels); + local_active_ports_ipv6_pd, chassis, + active_tunnels); sync_dns_cache(dns_table); controller_event_run(ovnsb_idl_txn, ce_table, chassis); ip_mcast_sync(ovnsb_idl_txn, chassis, local_datapaths, diff --git a/controller/pinctrl.h b/controller/pinctrl.h index cc0a51984..0b9a57bdd 100644 --- a/controller/pinctrl.h +++ b/controller/pinctrl.h @@ -23,6 +23,7 @@ #include "openvswitch/meta-flow.h" struct hmap; +struct shash; struct lport_index; struct ovsdb_idl_index; struct ovsdb_idl_txn; @@ -49,7 +50,8 @@ void pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, const struct sbrec_bfd_table *, const struct ovsrec_bridge *, const struct sbrec_chassis *, const struct hmap *local_datapaths, - const struct sset *active_tunnels); + const struct sset *active_tunnels, + const struct shash *local_active_ports_ipv6_pd); void pinctrl_wait(struct ovsdb_idl_txn *ovnsb_idl_txn); void pinctrl_destroy(void); void pinctrl_set_br_int_name(char *br_int_name);