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); }