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>
This commit is contained in:
Martin Basti 2016-09-02 17:07:03 +02:00 committed by David Kupka
parent 81d64d530c
commit 71ad8d4fc9
2 changed files with 7 additions and 7 deletions

View File

@ -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)

View File

@ -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),