Blob Blame History Raw
From 3dde59a7b7f0bb634fa5943b185b1cf1d4ed6907 Mon Sep 17 00:00:00 2001
Message-Id: <3dde59a7b7f0bb634fa5943b185b1cf1d4ed6907.1594372314.git.lorenzo.bianconi@redhat.com>
From: Mark Michelson <mmichels@redhat.com>
Date: Tue, 2 Jun 2020 09:06:32 -0400
Subject: [PATCH] northd: Fix IPAM IPv4 start address calculation.

IPAM assumes the other_config:subnet of the logical switch is a network
address, which can result in unusual address assignments.

As an example, consider the following configuration:

ovn-nbctl set logical_switch ls other_config:subnet=172.16.1.254/29

172.16.1.254 is not a network address of a /29 network, but ovn-northd
doesn't care. ovn-northd starts IP address allocation at 172.16.1.254, with 7
assignable addresses in the subnet. The first address (172.16.1.255) is
reserved for router port use. The first IP addresses to a logical switch
port is 172.16.2.0, then 172.16.2.1, and so on.

This patch changes the behavior by using the provided netmask to change
the starting IP address to the network address of the subnet. In the
previous example, the provided 172.16.1.254/29 would be converted
internally to 172.16.1.248/29 . Therefore, the first IP address
allocated to a switch port would be 172.16.1.250. Further allocations would
continue up until 172.16.1.254.

Reported at: https://bugzilla.redhat.com/show_bug.cgi?id=1823287

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

--- a/ovn/northd/ovn-northd.c
+++ b/ovn/northd/ovn-northd.c
@@ -764,7 +764,7 @@ init_ipam_info_for_datapath(struct ovn_d
         return;
     }
 
-    od->ipam_info.start_ipv4 = ntohl(subnet) + 1;
+    od->ipam_info.start_ipv4 = ntohl(subnet & mask) + 1;
     od->ipam_info.total_ipv4s = ~ntohl(mask);
     od->ipam_info.allocated_ipv4s =
         bitmap_allocate(od->ipam_info.total_ipv4s);
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -6636,6 +6636,17 @@ AT_CHECK([ovn-nbctl get Logical-Switch-P
     ["00:11:22:a8:6e:0b 192.168.110.10 ae01::2"
 ])
 
+# Configure subnet using address from middle of the subnet and ensure
+# address is allocated from the beginning.
+
+ovn-nbctl ls-add sw11
+ovn-nbctl --wait=sb set Logical-Switch sw11 other_config:subnet=172.16.1.254/29
+ovn-nbctl --wait=sb lsp-add sw11 p103 -- lsp-set-addresses p103 "22:33:44:55:66:77 dynamic"
+
+AT_CHECK([ovn-nbctl get Logical-Switch-Port p103 dynamic_addresses], [0],
+    ["22:33:44:55:66:77 172.16.1.250"
+])
+
 as ovn-sb
 OVS_APP_EXIT_AND_WAIT([ovsdb-server])