From patchwork Wed Jun 24 16:12:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Michelson X-Patchwork-Id: 1316378 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.136; helo=silver.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=RNtwwTcR; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49sSpp1mhjz9sRR for ; Thu, 25 Jun 2020 02:12:33 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id B4B622043D; Wed, 24 Jun 2020 16:12:29 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3mj5iGw7zhRy; Wed, 24 Jun 2020 16:12:26 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id C641D203D1; Wed, 24 Jun 2020 16:12:25 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 06889C0894; Wed, 24 Jun 2020 16:12:25 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6CDA4C016F for ; Wed, 24 Jun 2020 16:12:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 581E3203BD for ; Wed, 24 Jun 2020 16:12:24 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0Ras0nr07Tl0 for ; Wed, 24 Jun 2020 16:12:21 +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 silver.osuosl.org (Postfix) with ESMTPS id 6444720386 for ; Wed, 24 Jun 2020 16:12:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593015140; 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; bh=Kn9HLz2dhunWXJTuTbC1IHTX05Tfrl8qRCJiyv7BZc4=; b=RNtwwTcRgSV5tNtQu6vDEjmXAWKU+FwAxWrmlRVki61ebR9tZ0nfxXo12LRrr481Q94z8+ YIWiNX7DHVKNljM3zB5lYJAjhPt7sT8vkfsJzcvJgo6XIX6oRLJ3jctxwnrUKZeJJ9KYIY sT9XdjC2ujQdp/T6Wxd5adAU7zLnwX4= 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-353-JbdyOwlZN1uNWMs2cNvdJA-1; Wed, 24 Jun 2020 12:12:15 -0400 X-MC-Unique: JbdyOwlZN1uNWMs2cNvdJA-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 3F801107ACF4 for ; Wed, 24 Jun 2020 16:12:14 +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 C49C660C1D for ; Wed, 24 Jun 2020 16:12:12 +0000 (UTC) From: Mark Michelson To: dev@openvswitch.org Date: Wed, 24 Jun 2020 12:12:06 -0400 Message-Id: <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 1/6] Avoid case-sensitive MAC address comparisons. 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" Hex digits in MAC addresses can be represented as either capital or lowercase, and they're equal. Using strcmp to compare MAC addresses has the potential to compare MAC addresses as different when they represent the same address. This commit fixes the issue by converting the string representation to the binary representation and comparing that instead. Reported at: https://bugzilla.redhat.com/show_bug.cgi?id=1829059 Signed-off-by: Mark Michelson --- northd/ovn-northd.c | 17 ++++++++--------- tests/ovn.at | 9 +++++++++ utilities/ovn-nbctl.c | 16 +++++++++------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index eb78f317e..cf3cffd67 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -91,6 +91,7 @@ static bool controller_event_en; * defined in Service_Monitor Southbound table. Since these packets * all locally handled, having just one mac is good enough. */ static char svc_monitor_mac[ETH_ADDR_STRLEN + 1]; +static struct eth_addr svc_monitor_mac_ea; /* Default probe interval for NB and SB DB connections. */ #define DEFAULT_PROBE_INTERVAL_MSEC 5000 @@ -3321,8 +3322,10 @@ ovn_lb_create(struct northd_context *ctx, struct hmap *lbs, ovs_assert(mon_info); sbrec_service_monitor_set_options( mon_info->sbrec_mon, &lb_health_check->options); + struct eth_addr ea; if (!mon_info->sbrec_mon->src_mac || - strcmp(mon_info->sbrec_mon->src_mac, svc_monitor_mac)) { + !eth_addr_from_string(mon_info->sbrec_mon->src_mac, &ea) || + !eth_addr_equals(ea, svc_monitor_mac_ea)) { sbrec_service_monitor_set_src_mac(mon_info->sbrec_mon, svc_monitor_mac); } @@ -11061,12 +11064,9 @@ ovnnb_db_run(struct northd_context *ctx, const char *monitor_mac = smap_get(&nb->options, "svc_monitor_mac"); if (monitor_mac) { - struct eth_addr addr; - - memset(&addr, 0, sizeof addr); - if (eth_addr_from_string(monitor_mac, &addr)) { + if (eth_addr_from_string(monitor_mac, &svc_monitor_mac_ea)) { snprintf(svc_monitor_mac, sizeof svc_monitor_mac, - ETH_ADDR_FMT, ETH_ADDR_ARGS(addr)); + ETH_ADDR_FMT, ETH_ADDR_ARGS(svc_monitor_mac_ea)); } else { monitor_mac = NULL; } @@ -11087,10 +11087,9 @@ ovnnb_db_run(struct northd_context *ctx, } if (!monitor_mac) { - struct eth_addr addr; - eth_addr_random(&addr); + eth_addr_random(&svc_monitor_mac_ea); snprintf(svc_monitor_mac, sizeof svc_monitor_mac, - ETH_ADDR_FMT, ETH_ADDR_ARGS(addr)); + ETH_ADDR_FMT, ETH_ADDR_ARGS(svc_monitor_mac_ea)); smap_replace(&options, "svc_monitor_mac", svc_monitor_mac); } diff --git a/tests/ovn.at b/tests/ovn.at index 15b40ca1e..9181b8425 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -19720,3 +19720,12 @@ 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]) +ovn_start + +ovn-nbctl lr-add r1 +ovn-nbctl 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]) +AT_CLEANUP diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index 6ccc7025d..638e6f7c0 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -4678,6 +4678,12 @@ nbctl_lrp_add(struct ctl_context *ctx) char **settings = (char **) &ctx->argv[n_networks + 4]; int n_settings = ctx->argc - 4 - n_networks; + struct eth_addr ea; + if (!eth_addr_from_string(mac, &ea)) { + ctl_error(ctx, "%s: invalid mac address %s", lrp_name, mac); + return; + } + const struct nbrec_logical_router_port *lrp; error = lrp_by_name_or_uuid(ctx, lrp_name, false, &lrp); if (error) { @@ -4704,7 +4710,9 @@ nbctl_lrp_add(struct ctl_context *ctx) return; } - if (strcmp(mac, lrp->mac)) { + struct eth_addr lrp_ea; + eth_addr_from_string(lrp->mac, &lrp_ea); + if (!eth_addr_equals(ea, lrp_ea)) { ctl_error(ctx, "%s: port already exists with mac %s", lrp_name, lrp->mac); return; @@ -4746,12 +4754,6 @@ nbctl_lrp_add(struct ctl_context *ctx) return; } - struct eth_addr ea; - if (!eth_addr_from_string(mac, &ea)) { - ctl_error(ctx, "%s: invalid mac address %s", lrp_name, mac); - return; - } - for (int i = 0; i < n_networks; i++) { ovs_be32 ipv4; unsigned int plen; 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); From patchwork Wed Jun 24 16:12:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Michelson X-Patchwork-Id: 1316380 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.136; helo=silver.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=hL8c/Zx9; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49sSpx48vVz9s1x for ; Thu, 25 Jun 2020 02:12:41 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 1595020506; Wed, 24 Jun 2020 16:12:39 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VbmQ2GWjdLv4; Wed, 24 Jun 2020 16:12:37 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 54F9B20446; Wed, 24 Jun 2020 16:12:29 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id B61CEC016F; Wed, 24 Jun 2020 16:12:29 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id C3AA3C016F for ; Wed, 24 Jun 2020 16:12:26 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 95047203DB for ; Wed, 24 Jun 2020 16:12:26 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0eoZUFvfQqge for ; Wed, 24 Jun 2020 16:12:21 +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 silver.osuosl.org (Postfix) with ESMTPS id 318031FE49 for ; Wed, 24 Jun 2020 16:12:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593015140; 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=FfC1Wi+j/2oi98YBnjkDdbvufZSzM19yrquyLq513gI=; b=hL8c/Zx9u7fAq08GTw/iLgjeClmVjqMT+DdrkRIxt9U2XRNfBGBnfHZ5wGrdFHIRFn1G5j a/9E2KssH/LRPKevfO5xGE6yNkQIztIvJqYjJZNxbjD8lkhIiaox9Xh9cD4gyXBbgVyZ7z IpKEGo+xbTA5dHsGpdT7P0SXnlx4GEU= 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-367-qlEVp5DeNluCdRd2BSaaqw-1; Wed, 24 Jun 2020 12:12:18 -0400 X-MC-Unique: qlEVp5DeNluCdRd2BSaaqw-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 5A6E4107ACF2 for ; Wed, 24 Jun 2020 16:12:17 +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 98B7E7CCD1 for ; Wed, 24 Jun 2020 16:12:16 +0000 (UTC) From: Mark Michelson To: dev@openvswitch.org Date: Wed, 24 Jun 2020 12:12:08 -0400 Message-Id: <20200624161211.1559878-3-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 3/6] Add more IP address normalization functions. 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" Normalization of IP addresses helps to fix common pitfalls when comparing addresses: * Case-sensitivity in IPv6 addresses * Different valid represntations of netmasks This commit adds new normalization functions and cleans up some of the existing ones. The new functions are not used in this commit but will be used in later commits in this series. Signed-off-by: Mark Michelson --- utilities/ovn-nbctl.c | 81 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 12 deletions(-) diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index 708ff2e5b..2e5253d4e 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -3510,28 +3510,85 @@ normalize_ipv6_prefix(struct in6_addr ipv6, unsigned int plen) } } -/* The caller must free the returned string. */ static char * -normalize_prefix_str(const char *orig_prefix) +normalize_ipv4_prefix_str(const char *orig_prefix) { unsigned int plen; ovs_be32 ipv4; char *error; error = ip_parse_cidr(orig_prefix, &ipv4, &plen); - if (!error) { - return normalize_ipv4_prefix(ipv4, plen); - } else { - struct in6_addr ipv6; + if (error) { free(error); + return NULL; + } + return normalize_ipv4_prefix(ipv4, plen); +} - error = ipv6_parse_cidr(orig_prefix, &ipv6, &plen); - if (error) { - free(error); - return NULL; - } - return normalize_ipv6_prefix(ipv6, plen); +static char * +normalize_ipv6_prefix_str(const char *orig_prefix) +{ + unsigned int plen; + struct in6_addr ipv6; + char *error; + + error = ipv6_parse_cidr(orig_prefix, &ipv6, &plen); + if (error) { + free(error); + return NULL; + } + return normalize_ipv6_prefix(ipv6, plen); +} + +/* The caller must free the returned string. */ +static char * +normalize_prefix_str(const char *orig_prefix) +{ + char *ret; + + ret = normalize_ipv4_prefix_str(orig_prefix); + if (!ret) { + ret = normalize_ipv6_prefix_str(orig_prefix); + } + return ret; +} + +static char * +normalize_ipv4_addr_str(const char *orig_addr) +{ + ovs_be32 ipv4; + + if (!ip_parse(orig_addr, &ipv4)) { + return NULL; } + + return normalize_ipv4_prefix(ipv4, 32); +} + +static char * +normalize_ipv6_addr_str(const char *orig_addr) +{ + struct in6_addr ipv6; + + if (!ipv6_parse(orig_addr, &ipv6)) { + return NULL; + } + + return normalize_ipv6_prefix(ipv6, 128); +} + +/* Similar to normalize_prefix_str but must be an un-masked address. + * The caller must free the returned string. */ +OVS_UNUSED static char * +normalize_addr_str(const char *orig_addr) +{ + char *ret; + + ret = normalize_ipv4_addr_str(orig_addr); + if (!ret) { + ret = normalize_ipv6_addr_str(orig_addr); + } + return ret; } static void From patchwork Wed Jun 24 16:12:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Michelson X-Patchwork-Id: 1316381 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=BfbnNDhg; 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 49sSpx5Hzvz9sRR for ; Thu, 25 Jun 2020 02:12:41 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 0E1A48765D; Wed, 24 Jun 2020 16:12:40 +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 TTCsXZY5vE-F; Wed, 24 Jun 2020 16:12:35 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id D4791876C3; Wed, 24 Jun 2020 16:12:31 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id BD1E3C0888; Wed, 24 Jun 2020 16:12:31 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7A3CFC016F for ; Wed, 24 Jun 2020 16:12:31 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 70A652046D for ; Wed, 24 Jun 2020 16:12:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dRn2+48zoBZF for ; Wed, 24 Jun 2020 16:12:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by silver.osuosl.org (Postfix) with ESMTPS id 6CC81203B8 for ; Wed, 24 Jun 2020 16:12:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593015142; 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=KChtUT/XGroWJmo6QUlluFvTI0Nuq3gMk+sRziL40N4=; b=BfbnNDhgd6vQdoGahKJdn1AzYT/UywVRnA08wFJ4CNJGDwsSQayQyowdZ/ouK7AXPEKTMy eZQk9Ga2p03XR5plwf6U2si5xfcSHygF7j5RGBSTpXD3zk8QlKe0s5bilq00bHLmt3kOnW GiITzh/MHWblLZbeuirrkeeicuhQwUc= 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-279-uqi6wm4ZM3uA3zEoA9kw-A-1; Wed, 24 Jun 2020 12:12:20 -0400 X-MC-Unique: uqi6wm4ZM3uA3zEoA9kw-A-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 3588618A8220 for ; Wed, 24 Jun 2020 16:12:19 +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 E8F991C8 for ; Wed, 24 Jun 2020 16:12:17 +0000 (UTC) From: Mark Michelson To: dev@openvswitch.org Date: Wed, 24 Jun 2020 12:12:09 -0400 Message-Id: <20200624161211.1559878-4-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 4/6] Use normalized IP addreses in `ovn-nbctl lr-nat-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 | 11 ++++ utilities/ovn-nbctl.c | 143 +++++++++++++++++++++--------------------- 2 files changed, 82 insertions(+), 72 deletions(-) diff --git a/tests/ovn.at b/tests/ovn.at index d54a4d707..66e6024e1 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -19729,3 +19729,14 @@ 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 bef0:0000:0000:0000::1/64 aef0::1/64]) AT_CLEANUP + +AT_SETUP([ovn -- normalized lr-nat-add]) +ovn_start + +ovn-nbctl lr-add r1 +ovn-nbctl lr-nat-add r1 snat AEF0::1 BEEF::/64 +ovn-nbctl lr-nat-add r1 dnat AEF0::1 BEEF::1 + +AT_CHECK([ovn-nbctl --may-exist lr-nat-add r1 snat aef0:0000::1 beef:0000::/ffff:ffff:ffff:ffff::0]) +AT_CHECK([ovn-nbctl --may-exist lr-nat-add r1 dnat aef0:0000:00::1 beef::0001]) +AT_CLEANUP diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index 2e5253d4e..1b3027d52 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -4138,6 +4138,7 @@ nbctl_lr_nat_add(struct ctl_context *ctx) const char *external_ip = ctx->argv[3]; const char *logical_ip = ctx->argv[4]; char *new_logical_ip = NULL; + char *new_external_ip = NULL; bool is_portrange = shash_find(&ctx->options, "--portrange") != NULL; char *error = lr_by_name_or_uuid(ctx, ctx->argv[1], true, &lr); @@ -4153,55 +4154,41 @@ nbctl_lr_nat_add(struct ctl_context *ctx) return; } - ovs_be32 ipv4 = 0; - unsigned int plen; - struct in6_addr ipv6; bool is_v6 = false; - if (!ip_parse(external_ip, &ipv4)) { - if (ipv6_parse(external_ip, &ipv6)) { - is_v6 = true; - } else { - ctl_error(ctx, "%s: Not a valid IPv4 or IPv6 address.", - external_ip); - return; - } + + new_external_ip = normalize_ipv4_addr_str(external_ip); + if (!new_external_ip) { + new_external_ip = normalize_ipv6_addr_str(external_ip); + is_v6 = true; + } + if (!new_external_ip) { + ctl_error(ctx, "%s: Not a valid IPv4 or IPv6 address.", + external_ip); + return; } if (strcmp("snat", nat_type)) { - if (is_v6) { - if (!ipv6_parse(logical_ip, &ipv6)) { - ctl_error(ctx, "%s: Not a valid IPv6 address.", logical_ip); - return; - } - } else { - if (!ip_parse(logical_ip, &ipv4)) { - ctl_error(ctx, "%s: Not a valid IPv4 address.", logical_ip); - return; - } + new_logical_ip = is_v6 + ? normalize_ipv6_addr_str(logical_ip) + : normalize_ipv4_addr_str(logical_ip); + if (!new_logical_ip) { + ctl_error(ctx, "%s: Not a valid %s address.", logical_ip, + is_v6 ? "IPv6" : "IPv4"); } - new_logical_ip = xstrdup(logical_ip); } else { - if (is_v6) { - error = ipv6_parse_cidr(logical_ip, &ipv6, &plen); - if (error) { - free(error); - ctl_error(ctx, "%s: should be an IPv6 address or network.", - logical_ip); - return; - } - new_logical_ip = normalize_ipv6_prefix(ipv6, plen); - } else { - error = ip_parse_cidr(logical_ip, &ipv4, &plen); - if (error) { - free(error); - ctl_error(ctx, "%s: should be an IPv4 address or network.", - logical_ip); - return; - } - new_logical_ip = normalize_ipv4_prefix(ipv4, plen); + new_logical_ip = is_v6 + ? normalize_ipv6_prefix_str(logical_ip) + : normalize_ipv4_prefix_str(logical_ip); + if (!new_logical_ip) { + ctl_error(ctx, "%s: should be an %s address or network.", + logical_ip, is_v6 ? "IPv6" : "IPv4"); } } + if (!new_logical_ip) { + goto cleanup; + } + const char *logical_port = NULL; const char *external_mac = NULL; const char *port_range = NULL; @@ -4210,29 +4197,25 @@ nbctl_lr_nat_add(struct ctl_context *ctx) if (!is_portrange) { ctl_error(ctx, "lr-nat-add with logical_port " "must also specify external_mac."); - free(new_logical_ip); - return; + goto cleanup; } port_range = ctx->argv[5]; if (!is_valid_port_range(port_range)) { ctl_error(ctx, "invalid port range %s.", port_range); - free(new_logical_ip); - return; + goto cleanup; } } else if (ctx->argc >= 7) { if (strcmp(nat_type, "dnat_and_snat")) { ctl_error(ctx, "logical_port and external_mac are only valid when " "type is \"dnat_and_snat\"."); - free(new_logical_ip); - return; + goto cleanup; } if (ctx->argc == 7 && is_portrange) { ctl_error(ctx, "lr-nat-add with logical_port " "must also specify external_mac."); - free(new_logical_ip); - return; + goto cleanup; } logical_port = ctx->argv[5]; @@ -4240,24 +4223,21 @@ nbctl_lr_nat_add(struct ctl_context *ctx) error = lsp_by_name_or_uuid(ctx, logical_port, true, &lsp); if (error) { ctx->error = error; - free(new_logical_ip); - return; + goto cleanup; } external_mac = ctx->argv[6]; struct eth_addr ea; if (!eth_addr_from_string(external_mac, &ea)) { ctl_error(ctx, "invalid mac address %s.", external_mac); - free(new_logical_ip); - return; + goto cleanup; } if (ctx->argc > 7) { port_range = ctx->argv[7]; if (!is_valid_port_range(port_range)) { ctl_error(ctx, "invalid port range %s.", port_range); - free(new_logical_ip); - return; + goto cleanup; } } @@ -4278,49 +4258,65 @@ nbctl_lr_nat_add(struct ctl_context *ctx) int is_snat = !strcmp("snat", nat_type); for (size_t i = 0; i < lr->n_nat; i++) { const struct nbrec_nat *nat = lr->nat[i]; + + char *old_external_ip; + char *old_logical_ip; + bool should_return = false; + old_external_ip = normalize_prefix_str(nat->external_ip); + if (!old_external_ip) { + continue; + } + old_logical_ip = normalize_prefix_str(nat->logical_ip); + if (!old_logical_ip) { + free(old_external_ip); + continue; + } + if (!strcmp(nat_type, nat->type)) { - if (!strcmp(is_snat ? new_logical_ip : external_ip, - is_snat ? nat->logical_ip : nat->external_ip)) { - if (!strcmp(is_snat ? external_ip : new_logical_ip, - is_snat ? nat->external_ip : nat->logical_ip)) { + if (!strcmp(is_snat ? new_logical_ip : new_external_ip, + is_snat ? old_logical_ip : old_external_ip)) { + if (!strcmp(is_snat ? new_external_ip : new_logical_ip, + is_snat ? old_external_ip : old_logical_ip)) { if (may_exist) { nbrec_nat_verify_logical_port(nat); nbrec_nat_verify_external_mac(nat); nbrec_nat_set_logical_port(nat, logical_port); nbrec_nat_set_external_mac(nat, external_mac); - free(new_logical_ip); - return; + should_return = true; + } else { + ctl_error(ctx, "%s, %s: a NAT with this external_ip " + "and logical_ip already exists", + new_external_ip, new_logical_ip); + should_return = true; } - ctl_error(ctx, "%s, %s: a NAT with this external_ip " - "and logical_ip already exists", - external_ip, new_logical_ip); - free(new_logical_ip); - return; } else { ctl_error(ctx, "a NAT with this type (%s) and %s (%s) " "already exists", nat_type, is_snat ? "logical_ip" : "external_ip", - is_snat ? new_logical_ip : external_ip); - free(new_logical_ip); - return; + is_snat ? new_logical_ip : new_external_ip); + should_return = true; } } - } if (!strcmp(nat_type, "dnat_and_snat") || !strcmp(nat->type, "dnat_and_snat")) { - if (!strcmp(nat->external_ip, external_ip)) { + if (!strcmp(old_external_ip, new_external_ip)) { struct smap nat_options = SMAP_INITIALIZER(&nat_options); if (!strcmp(smap_get(&nat->options, "stateless"), "true") || stateless) { ctl_error(ctx, "%s, %s: External ip cannot be shared " "across stateless and stateful NATs", - external_ip, new_logical_ip); + new_external_ip, new_logical_ip); } } } + free(old_external_ip); + free(old_logical_ip); + if (should_return) { + goto cleanup; + } } /* Create the NAT. */ @@ -4341,7 +4337,6 @@ nbctl_lr_nat_add(struct ctl_context *ctx) smap_add(&nat_options, "stateless", stateless ? "true":"false"); nbrec_nat_set_options(nat, &nat_options); - free(new_logical_ip); smap_destroy(&nat_options); /* Insert the NAT into the logical router. */ @@ -4351,6 +4346,10 @@ nbctl_lr_nat_add(struct ctl_context *ctx) new_nats[lr->n_nat] = nat; nbrec_logical_router_set_nat(lr, new_nats, lr->n_nat + 1); free(new_nats); + +cleanup: + free(new_logical_ip); + free(new_external_ip); } static void From patchwork Wed Jun 24 16:12:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Michelson X-Patchwork-Id: 1316382 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=ekgllDd+; 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 49sSq14yk5z9sRR for ; Thu, 25 Jun 2020 02:12:45 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 098AB878B5; Wed, 24 Jun 2020 16:12:44 +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 bR0uUtnPJPYP; Wed, 24 Jun 2020 16:12:39 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id BEE4D87804; Wed, 24 Jun 2020 16:12:35 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A1C7BC0893; Wed, 24 Jun 2020 16:12:35 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6C2E4C016F for ; Wed, 24 Jun 2020 16:12:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 56DC68773D for ; Wed, 24 Jun 2020 16:12:34 +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 08iLoadqA6O8 for ; Wed, 24 Jun 2020 16:12:31 +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 [205.139.110.120]) by whitealder.osuosl.org (Postfix) with ESMTPS id 3DC8F87647 for ; Wed, 24 Jun 2020 16:12:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593015145; 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=qTYX/f81MFMKdHERQFgUIhth59blxzXrna09GX4ROzw=; b=ekgllDd+LpRJmb2O0+C1U7NKokDlQ/ybYY6IjrkD5BtYx+vIysHuwFLu+it5apUJMTmm9I JLuGxAcepeFRdXUIL3R9Wja+FHkqaQJYh75PtpyzzEmCYFbn0rw778jq+uCQUnUtehuMTY 6ASpHXFl8Qhlielk0NJkpCbRKxFJMzA= 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-428-TivXa4FNPya9jPmf2FiJ4g-1; Wed, 24 Jun 2020 12:12:20 -0400 X-MC-Unique: TivXa4FNPya9jPmf2FiJ4g-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 059C6464 for ; Wed, 24 Jun 2020 16:12:20 +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 908091C8 for ; Wed, 24 Jun 2020 16:12:19 +0000 (UTC) From: Mark Michelson To: dev@openvswitch.org Date: Wed, 24 Jun 2020 12:12:10 -0400 Message-Id: <20200624161211.1559878-5-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 5/6] Use normalized IP addresses in `ovn-nbctl lr-nat-del` 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 | 11 +++++++++++ utilities/ovn-nbctl.c | 27 ++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/tests/ovn.at b/tests/ovn.at index 66e6024e1..1366fa478 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -19740,3 +19740,14 @@ ovn-nbctl lr-nat-add r1 dnat AEF0::1 BEEF::1 AT_CHECK([ovn-nbctl --may-exist lr-nat-add r1 snat aef0:0000::1 beef:0000::/ffff:ffff:ffff:ffff::0]) AT_CHECK([ovn-nbctl --may-exist lr-nat-add r1 dnat aef0:0000:00::1 beef::0001]) AT_CLEANUP + +AT_SETUP([ovn -- normalized lr-nat-del]) +ovn_start + +ovn-nbctl lr-add r1 +ovn-nbctl lr-nat-add r1 snat AEF0::1 BEEF::/64 +ovn-nbctl lr-nat-add r1 dnat AEF0::1 BEEF::1 + +AT_CHECK([ovn-nbctl --if-exists lr-nat-del r1 snat beef:0000::0/ffff:ffff:ffff:ffff::0]) +AT_CHECK([ovn-nbctl --if-exists lr-nat-del r1 dnat aef0:0000:00::1]) +AT_CLEANUP diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index 1b3027d52..410596bcd 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -4395,13 +4395,24 @@ nbctl_lr_nat_del(struct ctl_context *ctx) return; } - const char *nat_ip = ctx->argv[3]; + char *nat_ip = normalize_prefix_str(ctx->argv[3]); + if (!nat_ip) { + ctl_error(ctx, "%s: Invalid IP address or CIDR", ctx->argv[3]); + return; + } + int is_snat = !strcmp("snat", nat_type); /* Remove the matching NAT. */ for (size_t i = 0; i < lr->n_nat; i++) { struct nbrec_nat *nat = lr->nat[i]; - if (!strcmp(nat_type, nat->type) && - !strcmp(nat_ip, is_snat ? nat->logical_ip : nat->external_ip)) { + bool should_return = false; + char *old_ip = normalize_prefix_str(is_snat + ? nat->logical_ip + : nat->external_ip); + if (!old_ip) { + continue; + } + if (!strcmp(nat_type, nat->type) && !strcmp(nat_ip, old_ip)) { struct nbrec_nat **new_nats = xmemdup(lr->nat, sizeof *new_nats * lr->n_nat); new_nats[i] = lr->nat[lr->n_nat - 1]; @@ -4409,15 +4420,21 @@ nbctl_lr_nat_del(struct ctl_context *ctx) nbrec_logical_router_set_nat(lr, new_nats, lr->n_nat - 1); free(new_nats); - return; + should_return = true; + } + free(old_ip); + if (should_return) { + goto cleanup; } } if (must_exist) { ctl_error(ctx, "no matching NAT with the type (%s) and %s (%s)", nat_type, is_snat ? "logical_ip" : "external_ip", nat_ip); - return; } + +cleanup: + free(nat_ip); } static void From patchwork Wed Jun 24 16:12:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Michelson X-Patchwork-Id: 1316377 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.137; helo=fraxinus.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=fACelgec; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49sSpl3Cr7z9s1x for ; Thu, 25 Jun 2020 02:12:31 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id D8DC885C2E; Wed, 24 Jun 2020 16:12:28 +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 YdWE_EYOcdpG; Wed, 24 Jun 2020 16:12:27 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 0D4AE86303; Wed, 24 Jun 2020 16:12:27 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0276BC0894; Wed, 24 Jun 2020 16:12:27 +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 72961C1797 for ; Wed, 24 Jun 2020 16:12:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 3BB6B85A84 for ; Wed, 24 Jun 2020 16:12:25 +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 JsO-AAbg5Bcq for ; Wed, 24 Jun 2020 16:12:24 +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 9AD16858D4 for ; Wed, 24 Jun 2020 16:12:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593015143; 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=K7YZXReO2Vkx5rtgm880Dr49awSExiNrIUZfl9bQNaU=; b=fACelgecZAuUxU0Of0RloTHkO8PlS9TQuGCHumL/CN4oMuuZnIrlySOfOJqFqO9yfIizeK 3/RGacsCPHzbgY+nkB2WdJZBeddIXl1ecXGGLp/JTF+mjqLKXiE/hOdPcj4Wtoy/8jGyNQ aMPA1rZ8RlF/MCvB/cT0a2X2oh9cEhM= 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-45-169slA8lNd2THpBsHBljpw-1; Wed, 24 Jun 2020 12:12:21 -0400 X-MC-Unique: 169slA8lNd2THpBsHBljpw-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 D6287107ACF9 for ; Wed, 24 Jun 2020 16:12:20 +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 644CC1C8 for ; Wed, 24 Jun 2020 16:12:20 +0000 (UTC) From: Mark Michelson To: dev@openvswitch.org Date: Wed, 24 Jun 2020 12:12:11 -0400 Message-Id: <20200624161211.1559878-6-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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mmichels@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v3 ovn 6/6] Cleanup `ovn-nbctl lr-route-add` IP normalization logic. 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" Use newer IP normalization routines to make things much cleaner. Signed-off-by: Mark Michelson --- utilities/ovn-nbctl.c | 47 ++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index 410596bcd..459cd5627 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -3815,7 +3815,7 @@ nbctl_lr_route_add(struct ctl_context *ctx) ctx->error = error; return; } - char *prefix, *next_hop; + char *prefix = NULL, *next_hop = NULL; const char *policy = shash_find_data(&ctx->options, "--policy"); bool is_src_route = false; @@ -3828,35 +3828,24 @@ nbctl_lr_route_add(struct ctl_context *ctx) } } - prefix = normalize_prefix_str(ctx->argv[2]); + bool v6_prefix = false; + prefix = normalize_ipv4_prefix_str(ctx->argv[2]); + if (!prefix) { + prefix = normalize_ipv6_prefix_str(ctx->argv[2]); + v6_prefix = true; + } if (!prefix) { ctl_error(ctx, "bad prefix argument: %s", ctx->argv[2]); return; } - next_hop = normalize_prefix_str(ctx->argv[3]); + next_hop = v6_prefix + ? normalize_ipv6_addr_str(ctx->argv[3]) + : normalize_ipv4_addr_str(ctx->argv[3]); if (!next_hop) { - free(prefix); - ctl_error(ctx, "bad next hop argument: %s", ctx->argv[3]); - return; - } - - if (strchr(prefix, '.')) { - ovs_be32 hop_ipv4; - if (!ip_parse(ctx->argv[3], &hop_ipv4)) { - free(prefix); - free(next_hop); - ctl_error(ctx, "bad IPv4 nexthop argument: %s", ctx->argv[3]); - return; - } - } else { - struct in6_addr hop_ipv6; - if (!ipv6_parse(ctx->argv[3], &hop_ipv6)) { - free(prefix); - free(next_hop); - ctl_error(ctx, "bad IPv6 nexthop argument: %s", ctx->argv[3]); - return; - } + ctl_error(ctx, "bad %s nexthop argument: %s", + v6_prefix ? "IPv6" : "IPv4", ctx->argv[3]); + goto cleanup; } bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL; @@ -3892,10 +3881,8 @@ nbctl_lr_route_add(struct ctl_context *ctx) if (!may_exist) { ctl_error(ctx, "duplicate prefix: %s (policy: %s)", prefix, is_src_route ? "src-ip" : "dst-ip"); - free(next_hop); free(rt_prefix); - free(prefix); - return; + goto cleanup; } /* Update the next hop for an existing route. */ @@ -3912,9 +3899,7 @@ nbctl_lr_route_add(struct ctl_context *ctx) nbrec_logical_router_static_route_set_policy(route, policy); } free(rt_prefix); - free(next_hop); - free(prefix); - return; + goto cleanup; } } @@ -3938,6 +3923,8 @@ nbctl_lr_route_add(struct ctl_context *ctx) nbrec_logical_router_set_static_routes(lr, new_routes, lr->n_static_routes + 1); free(new_routes); + +cleanup: free(next_hop); free(prefix); }