From patchwork Wed Apr 7 21:18:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan Shribman X-Patchwork-Id: 1463526 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=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=kqzD+sbm; dkim-atps=neutral Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FFy2L3vPvz9sW5 for ; Thu, 8 Apr 2021 07:19:20 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id AA32D83A80; Wed, 7 Apr 2021 21:19:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Oy7MnuVsbKVB; Wed, 7 Apr 2021 21:19:17 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTP id AAC8D8376E; Wed, 7 Apr 2021 21:19:16 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 87C65C000C; Wed, 7 Apr 2021 21:19:16 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7820DC000A for ; Wed, 7 Apr 2021 21:19:14 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 522EA837A1 for ; Wed, 7 Apr 2021 21:19:14 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Vxp2tz9OcpgI for ; Wed, 7 Apr 2021 21:19:13 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by smtp1.osuosl.org (Postfix) with ESMTPS id 8572A8376E for ; Wed, 7 Apr 2021 21:19:13 +0000 (UTC) Received: by mail-wr1-x433.google.com with SMTP id i18so15983768wrm.5 for ; Wed, 07 Apr 2021 14:19:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=z0MZNHkn9PMDEKjZMSoZV8iU6hUSeQjiKEkelMTHL0A=; b=kqzD+sbm6MazKLfXqUJCrmfGr+5cUp3TgrNXL0AlE6iAvuH4VyOFhjK2of82eQXN1F FPEbPjdKo3F3d0jGdHB+gzLG4gDLsyh+s0fEkGA80h/DAq4WpY9EnloYsgwJQPTwcq4o DwMSJWa6hrA8Wxko6w89YDdJSJGPrNibcGHNz6N6JRfhwwvC+5L3aZxEDozUBbzP01Uu Qk4ZUeQYpE7AxFyNJEFiw84vvcXuhW6rCaDYAmJFp0D4W2XskpYQLKe/esLAviCrBzTn dVHCigtOGx5k0RQGClwaULrsXtE4jmkqo6CPEKK/myNqD8DMNec1KkWF81fKG8P52SdF qBcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=z0MZNHkn9PMDEKjZMSoZV8iU6hUSeQjiKEkelMTHL0A=; b=I/eksXi73tx7/PEecsoFCjA0C0H+pzqPVlXIF59/p/Hgr7LuerP0dqmH0V0akcIrMh j/wHS0tQTTC4L/qXxY3IEAr1kDTkvwbPAa6m9QTzzSvjeW69FjurTMTZaUtPe/D4b/kZ c6EaqMDeLckWPvCwULaKx38AUs+z8EMk/yEBDGItZvWzDgYzqQWReI7ctV7t9L9LYI2q OsNtsEsc7Bb0c5fNuaYm7TId0loqoUvDqQSAGK/Mh3zC6QZOVWcz1fDbhlw0/VK9YiIj R+mwMMUJg6Uihd01OYwtH+bSK4wDvM1DG5hWLG0pEgcocaM75YFmINdSCh7NauenkNFz Oh6A== X-Gm-Message-State: AOAM531+PzLlq1Yr4fidx0LiiwnH8OKpH9xmswQLEzhkBiYJ+KGT19jL u4vhohnntqPb/4ca4hGQwgYrs+AsqqF9yB5I X-Google-Smtp-Source: ABdhPJxiEPa+xdsnRDU4jwiObip7PFDVJupb0MKgt2SHwb4aeTcGsTFs7tcwNujC6hTuXNPEjLOZvg== X-Received: by 2002:a5d:4c52:: with SMTP id n18mr6839989wrt.210.1617830351257; Wed, 07 Apr 2021 14:19:11 -0700 (PDT) Received: from localhost.localdomain (bl9-205-140.dsl.telepac.pt. [85.242.205.140]) by smtp.gmail.com with ESMTPSA id o1sm16042306wrw.23.2021.04.07.14.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Apr 2021 14:19:10 -0700 (PDT) From: Aidan Shribman To: ovs Date: Wed, 7 Apr 2021 21:18:22 +0000 Message-Id: <20210407211821.3047146-1-aidan.shribman@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Cc: Aidan Shribman Subject: [ovs-dev] [PATCH ovn] ovn-nbctl: fails to delete and add lr-nat in trx 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" The delete operation did not update the internal state cuasing the add operation to wrongly believe that the lr-nat entry is still present and thus can't be added. Below is the sequance is failed before and now passes: *** echo "add switch" ovn-nbctl ls-del ls0 2>/dev/null ovn-nbctl ls-add ls0 ovn-nbctl ls-list ovn-nbctl show ls0 ovn-nbctl lsp-del lsp0 2>/dev/null ovn-nbctl lsp-add ls0 lsp0 00:00:00:00:00:01 10.0.0.0/24 ovn-nbctl lsp-list ls0 echo "add router" ovn-nbctl ls-del lr0 2>/dev/null ovn-nbctl lr-add lr0 ovn-nbctl lr-list ovn-nbctl show lr0 echo "add nat" ovn-nbctl lr-nat-del lr0 2>/dev/null ovn-nbctl lr-nat-add lr0 dnat_and_snat 192.168.0.3 10.0.0.3 \ lsp0 f0:00:00:00:00:03 ovn-nbctl lr-nat-list lr0 echo "FIXED: delete nat (all of type) + add nat" ovn-nbctl lr-nat-del lr0 dnat_and_snat -- \ --may-exist lr-nat-add lr0 dnat_and_snat 192.168.0.3 10.0.0.3 \ lsp0 f0:00:00:00:00:03 ovn-nbctl lr-nat-list lr0 echo "FIXED: delete nat (all of external_ip) + add" ovn-nbctl lr-nat-del lr0 dnat_and_snat 192.168.0.3 -- \ --may-exist lr-nat-add lr0 dnat_and_snat 192.168.0.3 10.0.0.3 \ lsp0 f0:00:00:00:00:03 ovn-nbctl lr-nat-list lr0 *** Signed-off-by: Aidan Shribman Fixed: 1928226 (ovn-nbctl fails to delete/add lr-nat in trx) --- utilities/ovn-nbctl.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index 184058356..621a5a9fc 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -4531,11 +4531,18 @@ nbctl_lr_nat_del(struct ctl_context *ctx) if (ctx->argc == 3) { /*Deletes all NATs with the specified type. */ + struct nbrec_nat **keep_nat = xmalloc(lr->n_nat * sizeof *keep_nat); + size_t n_keep_nat = 0; for (size_t i = 0; i < lr->n_nat; i++) { - if (!strcmp(nat_type, lr->nat[i]->type)) { - nbrec_logical_router_update_nat_delvalue(lr, lr->nat[i]); + if (strcmp(nat_type, lr->nat[i]->type)) { + keep_nat[n_keep_nat++] = lr->nat[i]; } } + if (n_keep_nat < lr->n_nat) { + nbrec_logical_router_verify_nat(lr); + nbrec_logical_router_set_nat(lr, keep_nat, n_keep_nat); + } + free(keep_nat); return; } @@ -4547,31 +4554,27 @@ nbctl_lr_nat_del(struct ctl_context *ctx) int is_snat = !strcmp("snat", nat_type); /* Remove the matching NAT. */ + struct nbrec_nat **keep_nat = xmalloc(lr->n_nat * sizeof *keep_nat); + size_t n_keep_nat = 0; for (size_t i = 0; i < lr->n_nat; i++) { struct nbrec_nat *nat = lr->nat[i]; - 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)) { - nbrec_logical_router_update_nat_delvalue(lr, nat); - should_return = true; + if (!old_ip || strcmp(nat_type, nat->type) || strcmp(nat_ip, old_ip)) { + keep_nat[n_keep_nat++] = lr->nat[i]; } free(old_ip); - if (should_return) { - goto cleanup; - } } - if (must_exist) { + if (n_keep_nat < lr->n_nat) { + nbrec_logical_router_verify_nat(lr); + nbrec_logical_router_set_nat(lr, keep_nat, n_keep_nat); + } else 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); } - -cleanup: + free(keep_nat); free(nat_ip); }