core: allow addresses with zero prefix length

There is really no problem here, allow it.

Previously we would assert against a non-zero prefix length.
But I am not sure that all callers really ensured that this
couldn't happen. Anyway, there is no problem we such addresses,
really.

Only we need to make sure that nm_ip4_config_add_dependent_routes()
and nm_ip6_config_add_dependent_routes() don't add prefix routes for
such addresses (which is the case now).
This commit is contained in:
Thomas Haller 2018-12-14 17:04:21 +01:00
parent 9a6a354013
commit 3102b49f62
3 changed files with 4 additions and 3 deletions

View file

@ -310,7 +310,6 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
SD_DHCP_OPTION_IP_ADDRESS_LEASE_TIME,
(guint64) (ts_time + a_lifetime));
// TODO: ensure a_plen of zero is handled correctly.
nm_ip4_config_add_address (ip4_config,
&((const NMPlatformIP4Address) {
.address = a_address.s_addr,

View file

@ -2113,7 +2113,7 @@ nm_ip4_config_add_address (NMIP4Config *self, const NMPlatformIP4Address *new)
{
g_return_if_fail (self);
g_return_if_fail (new);
g_return_if_fail (new->plen > 0 && new->plen <= 32);
g_return_if_fail (new->plen <= 32);
g_return_if_fail (NM_IP4_CONFIG_GET_PRIVATE (self)->ifindex > 0);
_add_address (self, NULL, new);

View file

@ -485,6 +485,8 @@ nm_ip6_config_add_dependent_routes (NMIP6Config *self,
if (NM_FLAGS_HAS (my_addr->n_ifa_flags, IFA_F_NOPREFIXROUTE))
continue;
if (my_addr->plen == 0)
continue;
has_peer = !IN6_IS_ADDR_UNSPECIFIED (&my_addr->peer_address);
@ -1593,7 +1595,7 @@ nm_ip6_config_add_address (NMIP6Config *self, const NMPlatformIP6Address *new)
{
g_return_if_fail (self);
g_return_if_fail (new);
g_return_if_fail (new->plen > 0 && new->plen <= 128);
g_return_if_fail (new->plen <= 128);
g_return_if_fail (NM_IP6_CONFIG_GET_PRIVATE (self)->ifindex > 0);
_add_address (self, NULL, new);