ebb439
From 9d7ccd55a03eec88c2fd49a0345fc8fb2b429499 Mon Sep 17 00:00:00 2001
ebb439
Message-Id: <9d7ccd55a03eec88c2fd49a0345fc8fb2b429499.1602246561.git.lorenzo.bianconi@redhat.com>
ebb439
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
ebb439
Date: Fri, 2 Oct 2020 19:31:28 +0200
ebb439
Subject: [PATCH] northd: properly reconfigure ipam when subnet is changed
ebb439
ebb439
Reconfigure dynamic assigned addresses if subnet is modified
ebb439
removing IP out of configured netmask if present
ebb439
ebb439
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
ebb439
Acked-by: Mark Michelson <mmichels@redhat.com>
ebb439
Signed-off-by: Numan Siddique <numans@ovn.org>
ebb439
---
ebb439
 northd/ovn-northd.c |  2 +-
ebb439
 tests/ovn.at        | 18 ++++++++++++++++++
ebb439
 2 files changed, 19 insertions(+), 1 deletion(-)
ebb439
ebb439
--- a/northd/ovn-northd.c
ebb439
+++ b/northd/ovn-northd.c
ebb439
@@ -1754,7 +1754,7 @@ dynamic_ip4_changed(const char *lsp_addr
ebb439
     }
ebb439
 
ebb439
     uint32_t index = ip4 - ipam->start_ipv4;
ebb439
-    if (index > ipam->total_ipv4s ||
ebb439
+    if (index >= ipam->total_ipv4s - 1 ||
ebb439
         bitmap_is_set(ipam->allocated_ipv4s, index)) {
ebb439
         /* Previously assigned dynamic IPv4 address can no longer be used.
ebb439
          * It's either outside the subnet, conflicts with an excluded IP,
ebb439
--- a/tests/ovn.at
ebb439
+++ b/tests/ovn.at
ebb439
@@ -7473,6 +7473,24 @@ AT_CHECK([ovn-nbctl get Logical-Switch-P
ebb439
     ["22:33:44:55:66:77 172.16.1.250"
ebb439
 ])
ebb439
 
ebb439
+ovn-nbctl ls-add sw12
ebb439
+for i in $(seq 0 1); do
ebb439
+    for j in $(seq 1 99); do
ebb439
+        idx=$((i*100+j))
ebb439
+        ovn-nbctl lsp-add sw12 sw12-p${idx} -- \
ebb439
+        lsp-set-addresses sw12-p${idx} "00:00:00:00:$i:$j dynamic"
ebb439
+    done
ebb439
+done
ebb439
+ovn-nbctl --wait=sb set Logical-Switch sw12 other_config:subnet=192.10.2.0/24
ebb439
+AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.127], [0])
ebb439
+AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.128], [0])
ebb439
+AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.180], [0])
ebb439
+
ebb439
+ovn-nbctl --wait=sb set Logical-Switch sw12 other_config:subnet=192.10.2.0/25
ebb439
+AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.127], [1])
ebb439
+AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.128], [1])
ebb439
+AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.180], [1])
ebb439
+
ebb439
 as ovn-sb
ebb439
 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
ebb439