Skip to content

Commit

Permalink
Prevent the user from creating a single IP address sized network
Browse files Browse the repository at this point in the history
If the user doesn't specify a mask when creating a subnet, the mask
defaults to /32 (IPv4) or /128 (IPv6) making it impossible to allocate
an IP address when later launching an instance. This patch prevents
creating a subnet with such a small mask.

Fixes bug #1102504

Change-Id: I4962e0a416b8ec9aca013e41783994f65c22a989
  • Loading branch information
jpichon committed Jan 25, 2013
1 parent 59b7e60 commit 05207f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 15 additions & 0 deletions openstack_dashboard/dashboards/project/networks/tests.py
Expand Up @@ -364,6 +364,21 @@ def test_network_create_post_with_subnet_nocidr(self):
self.assertContains(res, escape('Specify "Network Address" or '
'clear "Create Subnet" checkbox.'))

def test_network_create_post_with_subnet_cidr_without_mask(self):
network = self.networks.first()
subnet = self.subnets.first()

form_data = {'net_name': network.name,
'admin_state': network.admin_state_up,
'with_subnet': True}
form_data.update(form_data_subnet(subnet, cidr='10.0.0.0',
allocation_pools=[]))
url = reverse('horizon:project:networks:create')
res = self.client.post(url, form_data)

expected_msg = "The subnet in the Network Address is too small (/32)."
self.assertContains(res, expected_msg)

def test_network_create_post_with_subnet_cidr_inconsistent(self):
network = self.networks.first()
subnet = self.subnets.first()
Expand Down
8 changes: 7 additions & 1 deletion openstack_dashboard/dashboards/project/networks/workflows.py
Expand Up @@ -104,9 +104,15 @@ def _check_subnet_data(self, cleaned_data, is_create=True):
'clear "Create Subnet" checkbox.')
raise forms.ValidationError(msg)
if cidr:
if netaddr.IPNetwork(cidr).version is not ip_version:
subnet = netaddr.IPNetwork(cidr)
if subnet.version != ip_version:
msg = _('Network Address and IP version are inconsistent.')
raise forms.ValidationError(msg)
if (ip_version == 4 and subnet.prefixlen == 32) or \
(ip_version == 6 and subnet.prefixlen == 128):
msg = _("The subnet in the Network Address is too small (/%s)."
% subnet.prefixlen)
raise forms.ValidationError(msg)
if not no_gateway and gateway_ip:
if netaddr.IPAddress(gateway_ip).version is not ip_version:
msg = _('Gateway IP and IP version are inconsistent.')
Expand Down

0 comments on commit 05207f5

Please sign in to comment.