From 1a12349c056b52b488591abb1671ad94a6db6526 Mon Sep 17 00:00:00 2001 From: Ahmad Hassan Date: Fri, 30 Sep 2011 15:10:33 +0100 Subject: Verify security group parameters Introduced various sanity checks before adding security group rule into the database. The checks have been implemented both in EC2 and openstack extension code. Implemented the suggestions made in first patch by Brian Fixed the unit tests in security groups Fixed pep8 issues in security group unit tests Fixes bug 869979. Change-Id: I2ac28666e90e7bdeacb7b1c2676c0719cfb9e441 --- nova/utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index a30d90ff1..ad0d5725d 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -37,6 +37,7 @@ import time import types import uuid import pyclbr +import netaddr from xml.sax import saxutils from eventlet import event @@ -908,6 +909,26 @@ def is_valid_ipv4(address): return True +def is_valid_cidr(address): + """Check if the provided ipv4 or ipv6 address is a valid + CIDR address or not""" + try: + # Validate the correct CIDR Address + netaddr.IPNetwork(address) + except netaddr.core.AddrFormatError: + return False + + # Prior validation partially verify /xx part + # Verify it here + ip_segment = address.split('/') + + if (len(ip_segment) <= 1 or + ip_segment[1] == ''): + return False + + return True + + def monkey_patch(): """ If the Flags.monkey_patch set as True, this function patches a decorator -- cgit