diff --git a/openwisp_ipam/api/views.py b/openwisp_ipam/api/views.py index 1a61bb0..139613d 100644 --- a/openwisp_ipam/api/views.py +++ b/openwisp_ipam/api/views.py @@ -137,10 +137,15 @@ def count(self): if self.stop is not None: return self.stop - self.start broadcast = int(self.subnet.subnet.broadcast_address) - if self.subnet.subnet.max_prefixlen == 32: - if self.subnet.subnet._prefixlen == 32: + # IPV4 + if self.subnet.subnet.version == 4: + # Networks with a mask of 32 will return a list + # containing the single host address + if self.subnet.subnet.prefixlen == 32: return 1 + # Other than subnet /32, exclude broadcast return broadcast - self.network - 1 + # IPV6 else: return broadcast - self.network diff --git a/openwisp_ipam/tests/test_admin.py b/openwisp_ipam/tests/test_admin.py index fe3184e..f4f829f 100644 --- a/openwisp_ipam/tests/test_admin.py +++ b/openwisp_ipam/tests/test_admin.py @@ -426,3 +426,12 @@ def assert_response(response): reverse('admin:ipam_export_subnet', args=[subnet.id]), follow=True ) assert_response(response) + + def test_subnet_32(self): + subnet = self._create_subnet(subnet='192.168.0.0/32', description='Subnet 32') + try: + response = self.client.get(reverse('ipam:hosts', args=(subnet.id,))) + self.assertIsNone(response.data['next']) + self.assertIsNone(response.data['previous']) + except ValueError as err: + self.fail(f'subnet/32: {err}')