From patchwork Fri Jun 19 11:10:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Numan Siddique X-Patchwork-Id: 1312808 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.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49pGMH6mgmz9sSf for ; Fri, 19 Jun 2020 21:11:07 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 60B0788F5F; Fri, 19 Jun 2020 11:11:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Eau3kubm52mr; Fri, 19 Jun 2020 11:11:02 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id C734188EA8; Fri, 19 Jun 2020 11:11:01 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id AACD3C0865; Fri, 19 Jun 2020 11:11:01 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2C776C016E for ; Fri, 19 Jun 2020 11:11:01 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 1C28987A5E for ; Fri, 19 Jun 2020 11:11:01 +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 S3S1YvcInxjp for ; Fri, 19 Jun 2020 11:10:59 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by fraxinus.osuosl.org (Postfix) with ESMTPS id CEA7287AB3 for ; Fri, 19 Jun 2020 11:10:51 +0000 (UTC) X-Originating-IP: 115.99.208.123 Received: from nusiddiq.home.org.com (unknown [115.99.208.123]) (Authenticated sender: numans@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 4F1381C000C; Fri, 19 Jun 2020 11:10:46 +0000 (UTC) From: numans@ovn.org To: dev@openvswitch.org Date: Fri, 19 Jun 2020 16:40:41 +0530 Message-Id: <20200619111041.2356070-1-numans@ovn.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200619110950.2355684-1-numans@ovn.org> References: <20200619110950.2355684-1-numans@ovn.org> MIME-Version: 1.0 Cc: Han Zhou Subject: [ovs-dev] [PATCH ovn v13 6/7] Add an util function get_unique_lport_key() for generating unique lport key. 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: Numan Siddique Suggested-by: Dumitru Ceara Acked-by: Han Zhou Signed-off-by: Numan Siddique --- controller/binding.c | 8 ++++---- controller/lflow.c | 8 ++++---- lib/ovn-util.h | 8 ++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/controller/binding.c b/controller/binding.c index 58e0bf59f..9dbbb34df 100644 --- a/controller/binding.c +++ b/controller/binding.c @@ -521,8 +521,8 @@ update_local_lport_ids(struct binding_ctx_out *b_ctx, const struct sbrec_port_binding *pb) { char buf[16]; - snprintf(buf, sizeof(buf), "%"PRId64"_%"PRId64, - pb->datapath->tunnel_key, pb->tunnel_key); + get_unique_lport_key(pb->datapath->tunnel_key, pb->tunnel_key, + buf, sizeof(buf)); if (sset_add(b_ctx->local_lport_ids, buf) != NULL) { b_ctx->local_lport_ids_changed = true; @@ -541,8 +541,8 @@ remove_local_lport_ids(struct binding_ctx_out *b_ctx, const struct sbrec_port_binding *pb) { char buf[16]; - snprintf(buf, sizeof(buf), "%"PRId64"_%"PRId64, - pb->datapath->tunnel_key, pb->tunnel_key); + get_unique_lport_key(pb->datapath->tunnel_key, pb->tunnel_key, + buf, sizeof(buf)); if (sset_find_and_delete(b_ctx->local_lport_ids, buf)) { b_ctx->local_lport_ids_changed = true; diff --git a/controller/lflow.c b/controller/lflow.c index c76ba4e92..15f1a6acb 100644 --- a/controller/lflow.c +++ b/controller/lflow.c @@ -130,7 +130,7 @@ is_chassis_resident_cb(const void *c_aux_, const char *port_name) /* Store the port_name to lflow reference. */ int64_t dp_id = pb->datapath->tunnel_key; char buf[16]; - snprintf(buf, sizeof(buf), "%"PRId64"_%"PRId64, dp_id, pb->tunnel_key); + get_unique_lport_key(dp_id, pb->tunnel_key, buf, sizeof(buf)); lflow_resource_add(c_aux->lfrr, REF_TYPE_PORTBINDING, buf, &c_aux->lflow->header_.uuid); @@ -664,7 +664,7 @@ consider_logical_flow(const struct sbrec_logical_flow *lflow, if (port_id) { int64_t dp_id = lflow->logical_datapath->tunnel_key; char buf[16]; - snprintf(buf, sizeof(buf), "%"PRId64"_%"PRId64, dp_id, port_id); + get_unique_lport_key(dp_id, port_id, buf, sizeof(buf)); lflow_resource_add(l_ctx_out->lfrr, REF_TYPE_PORTBINDING, buf, &lflow->header_.uuid); if (!sset_contains(l_ctx_in->local_lport_ids, buf)) { @@ -928,8 +928,8 @@ lflow_handle_flows_for_lport(const struct sbrec_port_binding *pb, bool changed; int64_t dp_id = pb->datapath->tunnel_key; char pb_ref_name[16]; - snprintf(pb_ref_name, sizeof(pb_ref_name), "%"PRId64"_%"PRId64, - dp_id, pb->tunnel_key); + get_unique_lport_key(dp_id, pb->tunnel_key, pb_ref_name, + sizeof(pb_ref_name)); return lflow_handle_changed_ref(REF_TYPE_PORTBINDING, pb_ref_name, l_ctx_in, l_ctx_out, &changed); diff --git a/lib/ovn-util.h b/lib/ovn-util.h index e13cf4d78..eba2948ff 100644 --- a/lib/ovn-util.h +++ b/lib/ovn-util.h @@ -114,6 +114,14 @@ bool ovn_tnlid_in_use(const struct hmap *set, uint32_t tnlid); uint32_t ovn_allocate_tnlid(struct hmap *set, const char *name, uint32_t min, uint32_t max, uint32_t *hint); +static inline void +get_unique_lport_key(uint64_t dp_tunnel_key, uint64_t lport_tunnel_key, + char *buf, size_t buf_size) +{ + snprintf(buf, buf_size, "%"PRId64"_%"PRId64, dp_tunnel_key, + lport_tunnel_key); +} + char *ovn_chassis_redirect_name(const char *port_name); void ovn_set_pidfile(const char *name);