summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Basti <mbasti@redhat.com>2016-09-02 17:07:03 +0200
committerDavid Kupka <dkupka@redhat.com>2016-09-07 16:22:03 +0200
commit71ad8d4fc982b5349248d50338e1d16ce45c523e (patch)
tree4e59604db2722432ef625f8da575a029a94a0bf7
parent81d64d530cca148198312d3d993502575b288f63 (diff)
downloadfreeipa-71ad8d4fc982b5349248d50338e1d16ce45c523e.tar.gz
freeipa-71ad8d4fc982b5349248d50338e1d16ce45c523e.tar.xz
freeipa-71ad8d4fc982b5349248d50338e1d16ce45c523e.zip
Allow broadcast ip addresses
Currently environments may use prefix /31 on point-to-point connections what makes IPA validators to fail. IPA should not care if IP address is broadcast or not. In some cases (when prefix is not specified) IPA cannot decide properly if broadcast address is really broadcast. This commit allows usage of broadcast addresses in: * host plugin * dns plugin * server-installer * client-installer https://fedorahosted.org/freeipa/ticket/5814 Reviewed-By: David Kupka <dkupka@redhat.com>
-rw-r--r--ipapython/ipautil.py10
-rw-r--r--ipatests/test_ipapython/test_ipautil.py4
2 files changed, 7 insertions, 7 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index 8a9aa0ed2..6ef39ab12 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -132,8 +132,7 @@ class CheckedIPAddress(UnsafeIPAddress):
Reserved or link-local addresses are never accepted.
"""
def __init__(self, addr, match_local=False, parse_netmask=True,
- allow_loopback=False, allow_broadcast=False,
- allow_multicast=False):
+ allow_loopback=False, allow_multicast=False):
super(CheckedIPAddress, self).__init__(addr)
if isinstance(addr, CheckedIPAddress):
@@ -199,15 +198,14 @@ class CheckedIPAddress(UnsafeIPAddress):
elif self.version == 6:
self._net = netaddr.IPNetwork(str(self) + '/64')
- if not allow_broadcast and (self.version == 4 and
- self == self._net.broadcast):
- raise ValueError("cannot use broadcast IP address {}".format(addr))
-
self.prefixlen = self._net.prefixlen
def is_network_addr(self):
return self == self._net.network
+ def is_broadcast_addr(self):
+ return self.version == 4 and self == self._net.broadcast
+
def valid_ip(addr):
return netaddr.valid_ipv4(addr) or netaddr.valid_ipv6(addr)
diff --git a/ipatests/test_ipapython/test_ipautil.py b/ipatests/test_ipapython/test_ipautil.py
index ea9251bc2..be59665ba 100644
--- a/ipatests/test_ipapython/test_ipautil.py
+++ b/ipatests/test_ipapython/test_ipautil.py
@@ -55,8 +55,10 @@ def test_ip_address():
('241.1.2.3',),
('169.254.1.2',),
('10.11.12.0/24', (10, 11, 12, 0), 24),
+ ('10.0.0.255', (10, 0, 0, 255), 8),
('224.5.6.7',),
- ('10.11.12.255/24',),
+ ('10.11.12.255/24', (10, 11, 12, 255), 24),
+ ('255.255.255.255',),
('::/0',),
('2001::1', (0x2001, 0, 0, 0, 0, 0, 0, 1), 64),