summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWen Liang <liangwen12year@gmail.com>2022-09-08 09:28:28 +0200
committerThomas Haller <thaller@redhat.com>2022-09-08 19:43:31 +0200
commit96d266cf518f221df37008c87e49b42b09f7da89 (patch)
tree1faa001c05bf142c7d4543231ea7cea4a6750b70
parentef51d0f980bdadd8274aafc609f92a9730f0c55e (diff)
downloadNetworkManager-96d266cf518f221df37008c87e49b42b09f7da89.tar.gz
platform: add NMPIPAddressSyncFlags parameter to nm_platform_ip_address_sync()
Previously, nm_platform_ip_address_sync() would always add the "IFA_F_NOPREFIXROUTE" flag. Add a way to let the caller control that. Add a flags argument, with a new flag "with-noprefixroute". By default (with flags "none"), nm_platform_ip_address_sync() would no longer add "IFA_F_NOPREFIXROUTE" flag, but the caller can now opt-in to that. The purpose is that on "lo" interface we will want to let kernel handle the prefix route. So have a per-ifindex opt-in for controlling this. During nm_platform_ip_address_flush() we use "none" flags, because the function anyway doesn't add any addresses, so it wouldn't matter. There is no change in behavior. Co-authored-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--src/core/nm-l3cfg.c3
-rw-r--r--src/libnm-platform/nm-platform.c51
-rw-r--r--src/libnm-platform/nm-platform.h16
3 files changed, 47 insertions, 23 deletions
diff --git a/src/core/nm-l3cfg.c b/src/core/nm-l3cfg.c
index 963e381b14..f2ed0f63fb 100644
--- a/src/core/nm-l3cfg.c
+++ b/src/core/nm-l3cfg.c
@@ -4559,7 +4559,8 @@ _l3_commit_one(NML3Cfg *self,
addr_family,
self->priv.ifindex,
addresses,
- addresses_prune);
+ addresses_prune,
+ NMP_IP_ADDRESS_SYNC_FLAGS_WITH_NOPREFIXROUTE);
_nodev_routes_sync(self, addr_family, commit_type, routes_nodev);
diff --git a/src/libnm-platform/nm-platform.c b/src/libnm-platform/nm-platform.c
index e2c2df866b..68e1952c2f 100644
--- a/src/libnm-platform/nm-platform.c
+++ b/src/libnm-platform/nm-platform.c
@@ -4105,6 +4105,9 @@ ip6_address_scope_cmp_descending(gconstpointer p_a, gconstpointer p_b, gpointer
* by the function.
* Addresses that are both contained in @known_addresses and @addresses_prune
* will be configured.
+ * @flags: #NMPIPAddressSyncFlags to affect the sync. If "with-noprefixroute"
+ * flag is set, the method will automatically set IFA_F_NOPREFIXROUTE for
+ * all addresses.
*
* A convenience function to synchronize addresses for a specific interface
* with the least possible disturbance. It simply removes addresses that are
@@ -4113,11 +4116,12 @@ ip6_address_scope_cmp_descending(gconstpointer p_a, gconstpointer p_b, gpointer
* Returns: %TRUE on success.
*/
gboolean
-nm_platform_ip_address_sync(NMPlatform *self,
- int addr_family,
- int ifindex,
- GPtrArray *known_addresses,
- GPtrArray *addresses_prune)
+nm_platform_ip_address_sync(NMPlatform *self,
+ int addr_family,
+ int ifindex,
+ GPtrArray *known_addresses,
+ GPtrArray *addresses_prune,
+ NMPIPAddressSyncFlags flags)
{
gint32 now = 0;
const int IS_IPv4 = NM_IS_IPv4(addr_family);
@@ -4529,18 +4533,24 @@ next_plat:;
nm_platform_ip4_broadcast_address_from_addr(&known_address->a4),
lifetime,
preferred,
- IFA_F_NOPREFIXROUTE,
+ NM_FLAGS_HAS(flags, NMP_IP_ADDRESS_SYNC_FLAGS_WITH_NOPREFIXROUTE)
+ ? IFA_F_NOPREFIXROUTE
+ : 0,
known_address->a4.label))
success = FALSE;
} else {
- if (!nm_platform_ip6_address_add(self,
- ifindex,
- known_address->a6.address,
- known_address->a6.plen,
- known_address->a6.peer_address,
- lifetime,
- preferred,
- IFA_F_NOPREFIXROUTE | known_address->a6.n_ifa_flags))
+ if (!nm_platform_ip6_address_add(
+ self,
+ ifindex,
+ known_address->a6.address,
+ known_address->a6.plen,
+ known_address->a6.peer_address,
+ lifetime,
+ preferred,
+ (NM_FLAGS_HAS(flags, NMP_IP_ADDRESS_SYNC_FLAGS_WITH_NOPREFIXROUTE)
+ ? IFA_F_NOPREFIXROUTE
+ : 0)
+ | known_address->a6.n_ifa_flags))
success = FALSE;
}
}
@@ -4568,7 +4578,12 @@ nm_platform_ip_address_flush(NMPlatform *self, int addr_family, int ifindex)
addresses_prune =
nm_platform_ip_address_get_prune_list(self, addr_family2, ifindex, NULL, 0);
- if (!nm_platform_ip_address_sync(self, addr_family2, ifindex, NULL, addresses_prune))
+ if (!nm_platform_ip_address_sync(self,
+ addr_family2,
+ ifindex,
+ NULL,
+ addresses_prune,
+ NMP_IP_ADDRESS_SYNC_FLAGS_NONE))
success = FALSE;
}
return success;
@@ -8634,7 +8649,8 @@ nm_platform_ip4_address_cmp(const NMPlatformIP4Address *a,
* NetworkManager actively sets.
*
* NM actively only sets IFA_F_NOPREFIXROUTE (and IFA_F_MANAGETEMPADDR for IPv6),
- * where nm_platform_ip_address_sync() always sets IFA_F_NOPREFIXROUTE.
+ * where nm_platform_ip_address_sync() sets IFA_F_NOPREFIXROUTE depending on
+ * NMP_IP_ADDRESS_SYNC_FLAGS_WITH_NOPREFIXROUTE.
* There are thus no flags to compare for IPv4. */
NM_CMP_DIRECT(nm_platform_ip4_broadcast_address_from_addr(a),
@@ -8702,7 +8718,8 @@ nm_platform_ip6_address_cmp(const NMPlatformIP6Address *a,
* NetworkManager actively sets.
*
* NM actively only sets IFA_F_NOPREFIXROUTE and IFA_F_MANAGETEMPADDR,
- * where nm_platform_ip_address_sync() always sets IFA_F_NOPREFIXROUTE.
+ * where nm_platform_ip_address_sync() sets IFA_F_NOPREFIXROUTE depending on
+ * NMP_IP_ADDRESS_SYNC_FLAGS_WITH_NOPREFIXROUTE.
* We thus only care about IFA_F_MANAGETEMPADDR. */
NM_CMP_DIRECT(a->n_ifa_flags & IFA_F_MANAGETEMPADDR,
b->n_ifa_flags & IFA_F_MANAGETEMPADDR);
diff --git a/src/libnm-platform/nm-platform.h b/src/libnm-platform/nm-platform.h
index 2570a47dda..9aaed5dd1f 100644
--- a/src/libnm-platform/nm-platform.h
+++ b/src/libnm-platform/nm-platform.h
@@ -2324,11 +2324,17 @@ nm_platform_ip_address_delete(NMPlatform *
}
}
-gboolean nm_platform_ip_address_sync(NMPlatform *self,
- int addr_family,
- int ifindex,
- GPtrArray *known_addresses,
- GPtrArray *addresses_prune);
+typedef enum {
+ NMP_IP_ADDRESS_SYNC_FLAGS_NONE = 0,
+ NMP_IP_ADDRESS_SYNC_FLAGS_WITH_NOPREFIXROUTE = (1 << 0),
+} NMPIPAddressSyncFlags;
+
+gboolean nm_platform_ip_address_sync(NMPlatform *self,
+ int addr_family,
+ int ifindex,
+ GPtrArray *known_addresses,
+ GPtrArray *addresses_prune,
+ NMPIPAddressSyncFlags flags);
GPtrArray *
nm_platform_ip_address_get_prune_list(NMPlatform *self,