Blob Blame History Raw
From 9d7ccd55a03eec88c2fd49a0345fc8fb2b429499 Mon Sep 17 00:00:00 2001
Message-Id: <9d7ccd55a03eec88c2fd49a0345fc8fb2b429499.1602246561.git.lorenzo.bianconi@redhat.com>
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Date: Fri, 2 Oct 2020 19:31:28 +0200
Subject: [PATCH] northd: properly reconfigure ipam when subnet is changed

Reconfigure dynamic assigned addresses if subnet is modified
removing IP out of configured netmask if present

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Acked-by: Mark Michelson <mmichels@redhat.com>
Signed-off-by: Numan Siddique <numans@ovn.org>
---
 northd/ovn-northd.c |  2 +-
 tests/ovn.at        | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -1754,7 +1754,7 @@ dynamic_ip4_changed(const char *lsp_addr
     }
 
     uint32_t index = ip4 - ipam->start_ipv4;
-    if (index > ipam->total_ipv4s ||
+    if (index >= ipam->total_ipv4s - 1 ||
         bitmap_is_set(ipam->allocated_ipv4s, index)) {
         /* Previously assigned dynamic IPv4 address can no longer be used.
          * It's either outside the subnet, conflicts with an excluded IP,
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -7473,6 +7473,24 @@ AT_CHECK([ovn-nbctl get Logical-Switch-P
     ["22:33:44:55:66:77 172.16.1.250"
 ])
 
+ovn-nbctl ls-add sw12
+for i in $(seq 0 1); do
+    for j in $(seq 1 99); do
+        idx=$((i*100+j))
+        ovn-nbctl lsp-add sw12 sw12-p${idx} -- \
+        lsp-set-addresses sw12-p${idx} "00:00:00:00:$i:$j dynamic"
+    done
+done
+ovn-nbctl --wait=sb set Logical-Switch sw12 other_config:subnet=192.10.2.0/24
+AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.127], [0])
+AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.128], [0])
+AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.180], [0])
+
+ovn-nbctl --wait=sb set Logical-Switch sw12 other_config:subnet=192.10.2.0/25
+AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.127], [1])
+AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.128], [1])
+AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.180], [1])
+
 as ovn-sb
 OVS_APP_EXIT_AND_WAIT([ovsdb-server])