From patchwork Wed Jun 24 16:12:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Michelson X-Patchwork-Id: 1316379 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=fail (p=none dis=none) header.from=redhat.com 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=cIdSZfqU; dkim-atps=neutral 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 49sSpq5SCrz9sRR for ; Thu, 25 Jun 2020 02:12:35 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id C865687675; Wed, 24 Jun 2020 16:12:33 +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 Ez4JnY6H99zN; Wed, 24 Jun 2020 16:12:31 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 590C887586; Wed, 24 Jun 2020 16:12:22 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3B693C0888; Wed, 24 Jun 2020 16:12:22 +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 E05E9C016F for ; Wed, 24 Jun 2020 16:12:20 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id D416385640 for ; Wed, 24 Jun 2020 16:12:20 +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 AeEvTAtvg3z8 for ; Wed, 24 Jun 2020 16:12:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 26A568563A for ; Wed, 24 Jun 2020 16:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593015139; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=moPu39VM+ORwShLfDa/bssHEskkGbsvuPZzyj0UKFDY=; b=cIdSZfqU1VdzeNllD7b3uS/EzrQxM9HHHUtfG6KiFO7c/CqzpJLpYYzxU3sU6fS0He16wo 5WEZegKdaA2vy9RN7zffEGc6PHqatsu52lrxRiGpA0Xi7mImlzWQX4iT2ZaJoEULQs5Puo GhNAotYjLz5kWKhQW/tQPp1ceFTfo1s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-335-2Pci4mE4NJOeYSVXbKglWQ-1; Wed, 24 Jun 2020 12:12:17 -0400 X-MC-Unique: 2Pci4mE4NJOeYSVXbKglWQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5BFCFEC1A0 for ; Wed, 24 Jun 2020 16:12:16 +0000 (UTC) Received: from monae.redhat.com (ovpn-117-53.rdu2.redhat.com [10.10.117.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A06F7CCD1 for ; Wed, 24 Jun 2020 16:12:15 +0000 (UTC) From: Mark Michelson To: dev@openvswitch.org Date: Wed, 24 Jun 2020 12:12:07 -0400 Message-Id: <20200624161211.1559878-2-mmichels@redhat.com> In-Reply-To: <20200624161211.1559878-1-mmichels@redhat.com> References: <20200624161211.1559878-1-mmichels@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v3 ovn 2/6] Use normalized IP addresses in `ovn-nbctl lrp-add` 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" Signed-off-by: Mark Michelson --- tests/ovn.at | 6 +++--- utilities/ovn-nbctl.c | 44 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/tests/ovn.at b/tests/ovn.at index 9181b8425..d54a4d707 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -19721,11 +19721,11 @@ AT_CHECK([test 2287 = `ovs-ofctl dump-group-stats br-int | grep -o bucket | wc - OVN_CLEANUP([hv1]) AT_CLEANUP -AT_SETUP([ovn -- case-insensitive lrp-add]) +AT_SETUP([ovn -- normalized lrp-add]) ovn_start ovn-nbctl lr-add r1 -ovn-nbctl lrp-add r1 rp1 CC:DD:EE:EE:DD:CC +ovn-nbctl lrp-add r1 rp1 CC:DD:EE:EE:DD:CC AEF0::1/64 BEF0::1/64 -AT_CHECK([ovn-nbctl --may-exist lrp-add r1 rp1 cc:dd:ee:ee:dd:cc]) +AT_CHECK([ovn-nbctl --may-exist lrp-add r1 rp1 cc:dd:ee:ee:dd:cc bef0:0000:0000:0000::1/64 aef0::1/64]) AT_CLEANUP diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index 638e6f7c0..708ff2e5b 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -4645,6 +4645,23 @@ nbctl_lrp_get_gateway_chassis(struct ctl_context *ctx) free(gcs); } +static struct sset * +lrp_network_sset(const char **networks, int n_networks) +{ + struct sset *network_set = xzalloc(sizeof *network_set); + sset_init(network_set); + for (int i = 0; i < n_networks; i++) { + char *norm = normalize_prefix_str(networks[i]); + if (!norm) { + sset_destroy(network_set); + free(network_set); + return NULL; + } + sset_add_and_free(network_set, norm); + } + return network_set; +} + static void nbctl_lrp_add(struct ctl_context *ctx) { @@ -4718,17 +4735,26 @@ nbctl_lrp_add(struct ctl_context *ctx) return; } - struct sset new_networks = SSET_INITIALIZER(&new_networks); - for (int i = 0; i < n_networks; i++) { - sset_add(&new_networks, networks[i]); + struct sset *new_networks = lrp_network_sset(networks, n_networks); + if (!new_networks) { + ctl_error(ctx, "%s: Invalid networks configured", lrp_name); + return; + } + struct sset *orig_networks = lrp_network_sset((const char **)lrp->networks, + lrp->n_networks); + if (!orig_networks) { + ctl_error(ctx, "%s: Existing port has invalid networks configured", + lrp_name); + sset_destroy(new_networks); + free(new_networks); + return; } - struct sset orig_networks = SSET_INITIALIZER(&orig_networks); - sset_add_array(&orig_networks, lrp->networks, lrp->n_networks); - - bool same_networks = sset_equals(&orig_networks, &new_networks); - sset_destroy(&orig_networks); - sset_destroy(&new_networks); + bool same_networks = sset_equals(orig_networks, new_networks); + sset_destroy(orig_networks); + free(orig_networks); + sset_destroy(new_networks); + free(new_networks); if (!same_networks) { ctl_error(ctx, "%s: port already exists with different network", lrp_name);