diff options
-rw-r--r-- | lib/ippool.c | 2 | ||||
-rw-r--r-- | tests/lib/ippool_test.c | 20 | ||||
-rw-r--r-- | tests/lib/ippool_test.ok | 15 |
3 files changed, 21 insertions, 16 deletions
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 @@ int ippool_new(struct ippool_t **this, const struct in46_prefix *dyn, const stru 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_size(const char *pfx, unsigned int flags, unsigned int exp 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); - /* 254 addresses [1..254] */ - test_pool_size("192.168.23.0/24", IPPOOL_NONETWORK, 254); + /* 255 addresses [1..255] */ + test_pool_size("192.168.23.0/24", IPPOOL_NONETWORK, 255); - /* 253 addresses [2..254] */ - test_pool_size("192.168.23.0/24", IPPOOL_NOGATEWAY, 253); + /* 254 addresses [1..254] */ + test_pool_size("192.168.23.0/24", IPPOOL_NONETWORK | IPPOOL_NOBROADCAST, 254); - /* 65533 addresses [3..255.254] */ - test_pool_size("192.168.0.0/16", IPPOOL_NOGATEWAY, 65533); + /* 65534 addresses [0.1..255.254] */ + test_pool_size("192.168.0.0/16", IPPOOL_NONETWORK | IPPOOL_NOBROADCAST, 65534); - /* 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.251 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.251 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.251 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.251 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:fb:: allocated address 2001:db8:0:fc:: allocated address 2001:db8:0:fd:: allocated address 2001:db8:0:fe:: +allocated address 2001:db8:0:ff:: |