core: don't add prefix route for external addresses

If the user adds an address manually, kernel automatically adds a
prefix route for it unless the address has the NOPREFIXROUTE
flag. When ip_config_merge_and_apply() gets called, NM also adds its
prefix route and so we end up with two routes that differ only for the
metric.

This is a problem because the route added by NM is not removed if the
user removes the previously added address. Also, it seems confusing to
have multiple instances of the same routes.

This commit skips the addition of a prefix route for addresses added
manually outside of NetworkManager.
This commit is contained in:
Beniamino Galvani 2019-10-17 11:36:38 +02:00
parent 3eb2f435ae
commit ea1679aac0
2 changed files with 5 additions and 0 deletions

View file

@ -704,6 +704,9 @@ nm_ip4_config_add_dependent_routes (NMIP4Config *self,
/* The destination network depends on the peer-address. */
network = nm_utils_ip4_address_clear_host_address (my_addr->peer_address, my_addr->plen);
if (my_addr->external)
continue;
if (_ipv4_is_zeronet (network)) {
/* Kernel doesn't add device-routes for destinations that
* start with 0.x.y.z. Skip them. */

View file

@ -480,6 +480,8 @@ nm_ip6_config_add_dependent_routes (NMIP6Config *self,
gboolean has_peer;
int routes_n, routes_i;
if (my_addr->external)
continue;
if (NM_FLAGS_HAS (my_addr->n_ifa_flags, IFA_F_NOPREFIXROUTE))
continue;
if (my_addr->plen == 0)