Pau Espin Pedrol has submitted this change and it was merged.

Change subject: lib/ippool: Fix listsize calculated 1 elem too small
......................................................................


lib/ippool: Fix listsize calculated 1 elem too small

Take the chance this commit is changing test output to also remove use
of IPPOOL_NOGATEWAY which is going to be removed soon, and instead test
IPPOOL_NOBROADCAST.

Change-Id: I95c24bc690490155bec9e3933d678e4668d7745f
---
M lib/ippool.c
M tests/lib/ippool_test.c
M tests/lib/ippool_test.ok
3 files changed, 21 insertions(+), 16 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/lib/ippool.c b/lib/ippool.c
index d9164a3..03323e2 100644
--- a/lib/ippool.c
+++ b/lib/ippool.c
@@ -215,7 +215,7 @@
                        flags |= IPPOOL_NONETWORK;
                }
 
-               dynsize = (1 << (addr.len*8 - addrprefixlen)) -1;
+               dynsize = (1 << (addr.len*8 - addrprefixlen));
                if (flags & IPPOOL_NONETWORK)   /* Exclude network address from 
pool */
                        dynsize--;
                if (flags & IPPOOL_NOGATEWAY)   /* Exclude gateway address from 
pool */
diff --git a/tests/lib/ippool_test.c b/tests/lib/ippool_test.c
index 79e43e7..f38c1be 100644
--- a/tests/lib/ippool_test.c
+++ b/tests/lib/ippool_test.c
@@ -90,20 +90,20 @@
 
 static void test_pool_sizes(void)
 {
-       /* 255 addresses [0..254] */
-       test_pool_size("192.168.23.0/24", 0, 255);
+       /* 256 addresses [0..255] */
+       test_pool_size("192.168.23.0/24", 0, 256);
+
+       /* 255 addresses [1..255] */
+       test_pool_size("192.168.23.0/24", IPPOOL_NONETWORK, 255);
 
        /* 254 addresses [1..254] */
-       test_pool_size("192.168.23.0/24", IPPOOL_NONETWORK, 254);
+       test_pool_size("192.168.23.0/24", IPPOOL_NONETWORK | 
IPPOOL_NOBROADCAST, 254);
 
-       /* 253 addresses [2..254] */
-       test_pool_size("192.168.23.0/24", IPPOOL_NOGATEWAY, 253);
+       /* 65534 addresses [0.1..255.254] */
+       test_pool_size("192.168.0.0/16", IPPOOL_NONETWORK | IPPOOL_NOBROADCAST, 
65534);
 
-       /* 65533 addresses [3..255.254] */
-       test_pool_size("192.168.0.0/16", IPPOOL_NOGATEWAY, 65533);
-
-       /* 255 prefixes of /64 each */
-       test_pool_size("2001:DB8::/56", 0, 255);
+       /* 256 prefixes of /64 each */
+       test_pool_size("2001:DB8::/56", 0, 256);
 }
 
 int main(int argc, char **argv)
diff --git a/tests/lib/ippool_test.ok b/tests/lib/ippool_test.ok
index c1398ab..a0eeb4b 100644
--- a/tests/lib/ippool_test.ok
+++ b/tests/lib/ippool_test.ok
@@ -1,4 +1,4 @@
-testing pool for prefix 192.168.23.0/24, flags=0x0, expected_size=255
+testing pool for prefix 192.168.23.0/24, flags=0x0, expected_size=256
 allocated address 192.168.23.0
 allocated address 192.168.23.1
 allocated address 192.168.23.2
@@ -254,7 +254,8 @@
 allocated address 192.168.23.252
 allocated address 192.168.23.253
 allocated address 192.168.23.254
-testing pool for prefix 192.168.23.0/24, flags=0x1, expected_size=254
+allocated address 192.168.23.255
+testing pool for prefix 192.168.23.0/24, flags=0x1, expected_size=255
 allocated address 192.168.23.1
 allocated address 192.168.23.2
 allocated address 192.168.23.3
@@ -509,7 +510,9 @@
 allocated address 192.168.23.252
 allocated address 192.168.23.253
 allocated address 192.168.23.254
-testing pool for prefix 192.168.23.0/24, flags=0x4, expected_size=253
+allocated address 192.168.23.255
+testing pool for prefix 192.168.23.0/24, flags=0x3, expected_size=254
+allocated address 192.168.23.1
 allocated address 192.168.23.2
 allocated address 192.168.23.3
 allocated address 192.168.23.4
@@ -763,7 +766,8 @@
 allocated address 192.168.23.252
 allocated address 192.168.23.253
 allocated address 192.168.23.254
-testing pool for prefix 192.168.0.0/16, flags=0x4, expected_size=65533
+testing pool for prefix 192.168.0.0/16, flags=0x3, expected_size=65534
+allocated address 192.168.0.1
 allocated address 192.168.0.2
 allocated address 192.168.0.3
 allocated address 192.168.0.4
@@ -66297,7 +66301,7 @@
 allocated address 192.168.255.252
 allocated address 192.168.255.253
 allocated address 192.168.255.254
-testing pool for prefix 2001:DB8::/56, flags=0x0, expected_size=255
+testing pool for prefix 2001:DB8::/56, flags=0x0, expected_size=256
 allocated address 2001:db8::
 allocated address 2001:db8:0:1::
 allocated address 2001:db8:0:2::
@@ -66553,3 +66557,4 @@
 allocated address 2001:db8:0:fc::
 allocated address 2001:db8:0:fd::
 allocated address 2001:db8:0:fe::
+allocated address 2001:db8:0:ff::

-- 
To view, visit https://gerrit.osmocom.org/4255
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I95c24bc690490155bec9e3933d678e4668d7745f
Gerrit-PatchSet: 2
Gerrit-Project: osmo-ggsn
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pes...@sysmocom.de>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol <pes...@sysmocom.de>

Reply via email to