From patchwork Fri Jun 14 12:36:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Numan Siddique X-Patchwork-Id: 1115954 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45QKqB3yDzz9sBp for ; Fri, 14 Jun 2019 22:36:38 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id D0654E7E; Fri, 14 Jun 2019 12:36:28 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 47C72B4B for ; Fri, 14 Jun 2019 12:36:28 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id DDCEEE5 for ; Fri, 14 Jun 2019 12:36:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 70C4E3086206 for ; Fri, 14 Jun 2019 12:36:27 +0000 (UTC) Received: from nusiddiq.mac (unknown [10.74.10.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 570D72CE56 for ; Fri, 14 Jun 2019 12:36:25 +0000 (UTC) From: nusiddiq@redhat.com To: dev@openvswitch.org Date: Fri, 14 Jun 2019 18:06:22 +0530 Message-Id: <20190614123622.13011-1-nusiddiq@redhat.com> In-Reply-To: <20190614123545.12883-1-nusiddiq@redhat.com> References: <20190614123545.12883-1-nusiddiq@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 14 Jun 2019 12:36:27 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v2 1/3] ovn-northd: Refactor the code which sets nat_addresses X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Numan Siddique The present code which sets the Port_Binding.nat_addresses can be simplied. This patch does this. This would help in upcoming commits to set the nat_addresses column with the mac and IPs of distributed logical router ports and logical router ports with 'reside-on-redirect-chassis' set. Signed-off-by: Numan Siddique --- ovn/northd/ovn-northd.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c index 0b0a96a3a..d0a77293a 100644 --- a/ovn/northd/ovn-northd.c +++ b/ovn/northd/ovn-northd.c @@ -2493,23 +2493,12 @@ ovn_port_update_sbrec(struct northd_context *ctx, const char *nat_addresses = smap_get(&op->nbsp->options, "nat-addresses"); + size_t n_nats = 0; + char **nats = NULL; if (nat_addresses && !strcmp(nat_addresses, "router")) { if (op->peer && op->peer->od && (chassis || op->peer->od->l3redirect_port)) { - size_t n_nats; - char **nats = get_nat_addresses(op->peer, &n_nats); - if (n_nats) { - sbrec_port_binding_set_nat_addresses(op->sb, - (const char **) nats, n_nats); - for (size_t i = 0; i < n_nats; i++) { - free(nats[i]); - } - free(nats); - } else { - sbrec_port_binding_set_nat_addresses(op->sb, NULL, 0); - } - } else { - sbrec_port_binding_set_nat_addresses(op->sb, NULL, 0); + nats = get_nat_addresses(op->peer, &n_nats); } /* Only accept manual specification of ethernet address * followed by IPv4 addresses on type "l3gateway" ports. */ @@ -2519,15 +2508,22 @@ ovn_port_update_sbrec(struct northd_context *ctx, static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); VLOG_WARN_RL(&rl, "Error extracting nat-addresses."); - sbrec_port_binding_set_nat_addresses(op->sb, NULL, 0); } else { sbrec_port_binding_set_nat_addresses(op->sb, &nat_addresses, 1); destroy_lport_addresses(&laddrs); + n_nats = 1; + nats = xcalloc(1, sizeof *nats); + nats[0] = xstrdup(nat_addresses); } - } else { - sbrec_port_binding_set_nat_addresses(op->sb, NULL, 0); } + + sbrec_port_binding_set_nat_addresses(op->sb, + (const char **) nats, n_nats); + for (size_t i = 0; i < n_nats; i++) { + free(nats[i]); + } + free(nats); } sbrec_port_binding_set_parent_port(op->sb, op->nbsp->parent_name); sbrec_port_binding_set_tag(op->sb, op->nbsp->tag, op->nbsp->n_tag);