Signed-off-by: Mark Michelson <mmich...@redhat.com>
---
 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 4e10052fd..d70ead1bd 100644
--- a/utilities/ovn-nbctl.c
+++ b/utilities/ovn-nbctl.c
@@ -4396,13 +4396,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];
@@ -4410,15 +4421,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
-- 
2.25.4

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to