From patchwork Fri Sep 25 11:21:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1371179 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=Sy4axtc4; 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 4ByTzH6pCwz9sSJ for ; Fri, 25 Sep 2020 21:22:35 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id E114F203C8; Fri, 25 Sep 2020 11:22: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 kgnDnucRq6AI; Fri, 25 Sep 2020 11:22:29 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id EA14D20198; Fri, 25 Sep 2020 11:22:28 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id ADDF6C0859; Fri, 25 Sep 2020 11:22:28 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3EB72C0051 for ; Fri, 25 Sep 2020 11:22:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 330288757E for ; Fri, 25 Sep 2020 11:22:27 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zFB83g0eK5eO for ; Fri, 25 Sep 2020 11:22:26 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by hemlock.osuosl.org (Postfix) with ESMTPS id 532D38756D for ; Fri, 25 Sep 2020 11:22:26 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601032945; 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=n41odWNiQmNlg9QC+H+PNJAKa95UrGT/R+mWFwO8BCg=; b=Sy4axtc4ucsVFKhAmPPaDtc/hsnLanrlRyrrKZXRkRookO+NaaipJOSMgzNvk0ive3HlnF nzlJUTthHTwiIpfZkxBUSYr2yodx8WhzJttH5bwE94xX9F5SkrTHl8SHioZ2rOcPT0fwHx /jkoy53OkEPp6+d30F2RpgAYRohzjL8= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-588-_vibibf6MmOdt3GwRxr5gQ-1; Fri, 25 Sep 2020 07:22:07 -0400 X-MC-Unique: _vibibf6MmOdt3GwRxr5gQ-1 Received: by mail-wr1-f69.google.com with SMTP id v12so950435wrm.9 for ; Fri, 25 Sep 2020 04:22:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=n41odWNiQmNlg9QC+H+PNJAKa95UrGT/R+mWFwO8BCg=; b=kUJp4jFPjyyKzpnqXQUHAV0FtPa81w7CEz/s6XF7BMBhV9M8DC1TTxEDi4mfRqh7ku FL7cKJJATMC0K3a092zpg9WWUhdVoy//OHEkVONSF+RQRvczbp7Kk/S9v+mGFCdUmVAC kDWdghiSHKCN6nQv0Pss/Fq5ySF/VHTFdMrtNxNKPosvwbLMnkdtfP5dCuz8cylpH1z+ VhAExHPfJ77wuqbo9t7/KWHeb9i8U2NpQ5GCert2mCg1bTTIGBGOD4g0v4RdVWMbn+OW eCBba9sxcKVTboozvQF/iPn+ovzGG+TcMHZH8/Sh5BZHfehYsmmgW44/TVpbFnarjAjw Zmog== X-Gm-Message-State: AOAM532bKQ46Q3gvjQ+29FFGTh7x2u7mT3wwQHtTq/1Ek+jb/by+lDpm HQBi77dKurTul9H4A9XpkMP/VbjnJYmt2G7073uHOO34Uj4L2AmcOe8V+hGyRz4+QH3cYFE0WaM IoPVgk1v34d7AlnxVEA== X-Received: by 2002:a5d:4246:: with SMTP id s6mr3908520wrr.414.1601032925916; Fri, 25 Sep 2020 04:22:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+anZrVdCEa8aYlYi51RRZHuDb6KH0Kd6+t+FG+gad+9+ZUNwwh0HK9icIbiyjIhkaQLqvBQ== X-Received: by 2002:a5d:4246:: with SMTP id s6mr3908500wrr.414.1601032925652; Fri, 25 Sep 2020 04:22:05 -0700 (PDT) Received: from lore-desk.redhat.com ([151.66.98.27]) by smtp.gmail.com with ESMTPSA id 88sm2664108wrl.76.2020.09.25.04.22.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 04:22:05 -0700 (PDT) From: Lorenzo Bianconi To: ovs-dev@openvswitch.org Date: Fri, 25 Sep 2020 13:21:58 +0200 Message-Id: <8e1242b09cee0f6bb967496873bea34c0e4ea233.1601032854.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lorenzo.bianconi@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH ovn] ovn-nbctl: add --may-exist/--if-exists options for policy routing 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" Introduce the following options to avoid error reporting for policy routing: 1) --may-exist: the lr-policy-add does not result in an error if a policy with the same priority and match string is already present 2) --if-exists: the lr-policy-del does not result in an error if a policy with the specified uuid is not present in the db Signed-off-by: Lorenzo Bianconi --- tests/ovn-nbctl.at | 7 ++++++- utilities/ovn-nbctl.8.xml | 20 +++++++++++++++----- utilities/ovn-nbctl.c | 16 ++++++++++------ 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at index baf7a87f5..3dbedc843 100644 --- a/tests/ovn-nbctl.at +++ b/tests/ovn-nbctl.at @@ -1651,6 +1651,8 @@ AT_CHECK([ovn-nbctl lr-policy-add lr0 100 "ip4.src == 1.1.1.0/24" drop], [1], [] [ovn-nbctl: Same routing policy already existed on the logical router lr0. ]) +AT_CHECK([ovn-nbctl --may-exist lr-policy-add lr0 100 "ip4.src == 1.1.1.0/24" drop]) + dnl Add duplicated policy AT_CHECK([ovn-nbctl lr-policy-add lr0 103 "ip4.src == 1.1.1.0/24" deny], [1], [], [ovn-nbctl: deny: action must be one of "allow", "drop", and "reroute" @@ -1675,10 +1677,13 @@ Routing Policies dnl Delete policy by specified uuid -AT_CHECK([ovn-nbctl lr-policy-del lr0 $(ovn-nbctl --bare --column _uuid list logical_router_policy)]) +uuid=$(ovn-nbctl --bare --column _uuid list logical_router_policy) +AT_CHECK([ovn-nbctl lr-policy-del lr0 $uuid]) AT_CHECK([ovn-nbctl list logical-router-policy], [0], [dnl ]) +AT_CHECK([ovn-nbctl --if-exists lr-policy-del lr0 $uuid]) + dnl Add policy with reroute action AT_CHECK([ovn-nbctl lr-policy-add lr0 102 "ip4.src == 3.1.2.0/24" reroute 3.3.3.3]) diff --git a/utilities/ovn-nbctl.8.xml b/utilities/ovn-nbctl.8.xml index fcc4312dd..59302296b 100644 --- a/utilities/ovn-nbctl.8.xml +++ b/utilities/ovn-nbctl.8.xml @@ -737,8 +737,9 @@

Logical Router Policy Commands

-
lr-policy-add router priority - match action [nexthop] +
[--may-exist]lr-policy-add + router priority match + action [nexthop] [options key=value]]

@@ -754,6 +755,13 @@ The supported option is : pkt_mark.

+

+ If --may-exist is specified, adding a duplicated + routing policy with the same priority and match string is not + really created. Without --may-exist, adding a + duplicated routing policy results in error. +

+

The following example shows a policy to lr1, which will drop packets from192.168.100.0/24. @@ -771,8 +779,8 @@

-
lr-policy-del router [{priority | uuid} - [match]]
+
[--if-exists] lr-policy-del + router [{priority | uuid} [match]]

Deletes polices from router. If only router @@ -784,7 +792,9 @@

If router and uuid are supplied, then the - policy with sepcified uuid is deleted. + policy with sepcified uuid is deleted. It is an error if + uuid does not exist, unless --if-exists + is specified.

diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index c54e63937..caf99dfeb 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -3648,12 +3648,15 @@ nbctl_lr_policy_add(struct ctl_context *ctx) /* Check if same routing policy already exists. * A policy is uniquely identified by priority and match */ + bool may_exist = !!shash_find(&ctx->options, "--may-exist"); for (int i = 0; i < lr->n_policies; i++) { const struct nbrec_logical_router_policy *policy = lr->policies[i]; if (policy->priority == priority && !strcmp(policy->match, ctx->argv[3])) { - ctl_error(ctx, "Same routing policy already existed on the " - "logical router %s.", ctx->argv[1]); + if (!may_exist) { + ctl_error(ctx, "Same routing policy already existed on the " + "logical router %s.", ctx->argv[1]); + } return; } } @@ -3733,7 +3736,6 @@ nbctl_lr_policy_del(struct ctl_context *ctx) ctx->error = error; return; } - } /* If uuid was specified, delete routing policy with the * specified uuid. */ @@ -3751,7 +3753,9 @@ nbctl_lr_policy_del(struct ctl_context *ctx) } } if (n_policies == lr->n_policies) { - ctl_error(ctx, "Logical router policy uuid is not found."); + if (!shash_find(&ctx->options, "--if-exists")) { + ctl_error(ctx, "Logical router policy uuid is not found."); + } return; } @@ -6529,9 +6533,9 @@ static const struct ctl_command_syntax nbctl_commands[] = { /* Policy commands */ { "lr-policy-add", 4, INT_MAX, "ROUTER PRIORITY MATCH ACTION [NEXTHOP] [OPTIONS - KEY=VALUE ...]", - NULL, nbctl_lr_policy_add, NULL, "", RW }, + NULL, nbctl_lr_policy_add, NULL, "--may-exist", RW }, { "lr-policy-del", 1, 3, "ROUTER [{PRIORITY | UUID} [MATCH]]", NULL, - nbctl_lr_policy_del, NULL, "", RW }, + nbctl_lr_policy_del, NULL, "--if-exists", RW }, { "lr-policy-list", 1, 1, "ROUTER", NULL, nbctl_lr_policy_list, NULL, "", RO },