glib-aux,platform: merge branch 'th/misc'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1370
This commit is contained in:
Thomas Haller 2022-09-08 19:46:39 +02:00
commit a4cf48f8bc
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
9 changed files with 147 additions and 98 deletions

View file

@ -2737,7 +2737,8 @@ _ethtool_state_set(NMDevice *self)
static gboolean
is_loopback(NMDevice *self)
{
return NM_IS_DEVICE_GENERIC(self) && NM_DEVICE_GET_PRIVATE(self)->ifindex == 1;
return NM_IS_DEVICE_GENERIC(self)
&& NM_DEVICE_GET_PRIVATE(self)->ifindex == NM_LOOPBACK_IFINDEX;
}
gboolean

View file

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

View file

@ -7087,7 +7087,7 @@ nm_manager_write_device_state(NMManager *self, NMDevice *device, int *out_ifinde
ifindex = nm_device_get_ip_ifindex(device);
if (ifindex <= 0)
return FALSE;
if (ifindex == 1) {
if (ifindex == NM_LOOPBACK_IFINDEX) {
/* ignore loopback */
return FALSE;
}

View file

@ -1301,19 +1301,19 @@ test_software_detect(gconstpointer user_data)
nmtstp_kernel_support_get(NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_BR_VLAN_STATS_ENABLED)
? TRUE
: FALSE;
lnk_bridge.group_fwd_mask = 8;
lnk_bridge.group_addr = (NMEtherAddr){{0x01, 0x80, 0xC2, 0x00, 0x00, 0x08}};
lnk_bridge.mcast_snooping = TRUE;
lnk_bridge.mcast_router = 1;
lnk_bridge.mcast_query_use_ifaddr = TRUE;
lnk_bridge.mcast_querier = TRUE;
lnk_bridge.mcast_hash_max = 1024;
lnk_bridge.mcast_last_member_count = 2;
lnk_bridge.mcast_startup_query_count = 3;
lnk_bridge.mcast_last_member_interval = 5000;
lnk_bridge.mcast_membership_interval = 25000;
lnk_bridge.mcast_querier_interval = 26000;
lnk_bridge.mcast_query_interval = 12000;
lnk_bridge.group_fwd_mask = 8;
lnk_bridge.group_addr = NM_ETHER_ADDR_INIT(0x01, 0x80, 0xC2, 0x00, 0x00, 0x08);
lnk_bridge.mcast_snooping = TRUE;
lnk_bridge.mcast_router = 1;
lnk_bridge.mcast_query_use_ifaddr = TRUE;
lnk_bridge.mcast_querier = TRUE;
lnk_bridge.mcast_hash_max = 1024;
lnk_bridge.mcast_last_member_count = 2;
lnk_bridge.mcast_startup_query_count = 3;
lnk_bridge.mcast_last_member_interval = 5000;
lnk_bridge.mcast_membership_interval = 25000;
lnk_bridge.mcast_querier_interval = 26000;
lnk_bridge.mcast_query_interval = 12000;
lnk_bridge.mcast_query_response_interval = 5200;
lnk_bridge.mcast_startup_query_interval = 3000;

View file

@ -393,6 +393,12 @@ typedef struct {
#define NM_BOND_PORT_QUEUE_ID_DEF 0
/****************************************************************************/
/* ifindex generation is per-net namespace, and loopback is always the first
* device in the network namespace, thus any loopback device should get ifindex 1. */
#define NM_LOOPBACK_IFINDEX 1
/*****************************************************************************/
/* NM_CRYPTO_ERROR is part of public API in libnm (implemented in libnm-core).

View file

@ -25,6 +25,30 @@ typedef struct _NMIPAddr {
.array = { 0 } \
}
#define _NM_IN6ADDR_INIT(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, aa, ab, ac, ad, ae, af) \
{ \
.s6_addr = { \
(a0), \
(a1), \
(a2), \
(a3), \
(a4), \
(a5), \
(a6), \
(a7), \
(a8), \
(a9), \
(aa), \
(ab), \
(ac), \
(ad), \
(ae), \
(af), \
} \
}
#define NM_IN6ADDR_INIT(...) ((struct in6_addr) _NM_IN6ADDR_INIT(__VA_ARGS__))
extern const NMIPAddr nm_ip_addr_zero;
/* This doesn't really belong here, but since it's convenient to re-use nm_ip_addr_zero.ether_addr
@ -230,15 +254,19 @@ gboolean nm_ip6_addr_is_ula(const struct in6_addr *address);
/*****************************************************************************/
#define NM_IPV4LL_NETWORK ((in_addr_t) htonl(0xA9FE0000lu))
#define NM_IPV4LL_NETMASK ((in_addr_t) htonl(0xFFFF0000lu))
#define NM_IPV4LL_NETWORK ((in_addr_t) htonl(0xA9FE0000lu)) /* 169.254.0.0 */
#define NM_IPV4LL_NETMASK ((in_addr_t) htonl(0xFFFF0000lu)) /* 255.255.0.0 */
#define NM_IPV4LO_NETWORK ((in_addr_t) htonl(0x7F000000lu)) /* 127.0.0.0 */
#define NM_IPV4LO_NETMASK ((in_addr_t) htonl(0xFF000000lu)) /* 255.0.0.0 */
#define NM_IPV4LO_PREFIXLEN 8
#define NM_IPV4LO_ADDR1 ((in_addr_t) htonl(0x7F000001lu)) /* 127.0.0.1 */
static inline gboolean
nm_ip4_addr_is_loopback(in_addr_t addr)
{
/* There is also IN_LOOPBACK() in <linux/in.h>, but there the
* argument is in host order not `in_addr_t`. */
return (addr & htonl(0xFF000000u)) == htonl(0x7F000000u);
return (addr & NM_IPV4LO_NETMASK) == NM_IPV4LO_NETWORK;
}
static inline gboolean

View file

@ -259,6 +259,10 @@ test_nm_ip4_addr_is_loopback(void)
g_assert(!nm_ip4_addr_is_loopback(nmtst_inet4_from_string("126.5.0.1")));
g_assert(!nm_ip4_addr_is_loopback(nmtst_inet4_from_string("128.5.0.1")));
g_assert(!nm_ip4_addr_is_loopback(nmtst_inet4_from_string("129.5.0.1")));
g_assert_cmpint(nmtst_inet4_from_string("127.0.0.0"), ==, NM_IPV4LO_NETWORK);
g_assert_cmpint(nmtst_inet4_from_string("127.0.0.1"), ==, NM_IPV4LO_ADDR1);
g_assert_cmpint(nmtst_inet4_from_string("255.0.0.0"), ==, NM_IPV4LO_NETMASK);
g_assert_cmpint(nm_ip4_addr_netmask_to_prefix(NM_IPV4LO_NETMASK), ==, NM_IPV4LO_PREFIXLEN);
}
/*****************************************************************************/

View file

@ -948,9 +948,9 @@ _link_get_all_presort(gconstpointer p_a, gconstpointer p_b, gpointer sort_by_nam
const NMPlatformLink *b = NMP_OBJECT_CAST_LINK(*((const NMPObject **) p_b));
/* Loopback always first */
if (a->ifindex == 1)
if (a->ifindex == NM_LOOPBACK_IFINDEX)
return -1;
if (b->ifindex == 1)
if (b->ifindex == NM_LOOPBACK_IFINDEX)
return 1;
if (GPOINTER_TO_INT(sort_by_name)) {
@ -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;
@ -4706,9 +4721,6 @@ nm_platform_ip_route_get_prune_list(NMPlatform *self,
GPtrArray *routes_prune = NULL;
const NMDedupMultiHeadEntry *head_entry;
CList *iter;
NMPlatformIP4Route rt_local4;
NMPlatformIP6Route rt_local6;
NMPlatformIP6Route rt_mcast6;
const NMPlatformLink *pllink;
const NMPlatformLnkVrf *lnk_vrf;
guint32 local_table;
@ -4733,10 +4745,6 @@ nm_platform_ip_route_get_prune_list(NMPlatform *self,
lnk_vrf = nm_platform_link_get_lnk_vrf(self, pllink->master, NULL);
local_table = lnk_vrf ? lnk_vrf->table : RT_TABLE_LOCAL;
rt_local4.plen = 0;
rt_local6.plen = 0;
rt_mcast6.plen = 0;
c_list_for_each (iter, &head_entry->lst_entries_head) {
const NMPObject *obj = c_list_entry(iter, NMDedupMultiEntry, lst_entries)->obj;
const NMPlatformIPXRoute *rt = NMP_OBJECT_CAST_IPX_ROUTE(obj);
@ -4768,29 +4776,26 @@ nm_platform_ip_route_get_prune_list(NMPlatform *self,
&& rt->rx.metric == 0
&& rt->r4.scope_inv == nm_platform_route_scope_inv(RT_SCOPE_HOST)
&& rt->r4.gateway == INADDR_ANY) {
if (rt_local4.plen == 0) {
rt_local4 = (NMPlatformIP4Route){
.ifindex = ifindex,
.type_coerced = nm_platform_route_type_coerce(RTN_LOCAL),
.plen = 32,
.rt_source = NM_IP_CONFIG_SOURCE_RTPROT_KERNEL,
.metric = 0,
.table_coerced = nm_platform_route_table_coerce(local_table),
.scope_inv = nm_platform_route_scope_inv(RT_SCOPE_HOST),
.gateway = INADDR_ANY,
};
}
/* the possible "network" depends on the addresses we have. We don't check that
* carefully. If the other parameters match, we assume that this route is the one
* generated by kernel. */
rt_local4.network = rt->r4.network;
rt_local4.pref_src = rt->r4.pref_src;
const NMPlatformIP4Route r = {
.ifindex = ifindex,
.type_coerced = nm_platform_route_type_coerce(RTN_LOCAL),
.plen = 32,
.rt_source = NM_IP_CONFIG_SOURCE_RTPROT_KERNEL,
.metric = 0,
.table_coerced = nm_platform_route_table_coerce(local_table),
.scope_inv = nm_platform_route_scope_inv(RT_SCOPE_HOST),
.gateway = INADDR_ANY,
/* the possible "network" depends on the addresses we have. We don't check that
* carefully. If the other parameters match, we assume that this route is the one
* generated by kernel. */
.network = rt->r4.network,
.pref_src = rt->r4.pref_src,
};
/* to be more confident about comparing the value, use our nm_platform_ip4_route_cmp()
* implementation. That will also consider parameters that we leave unspecified here. */
if (nm_platform_ip4_route_cmp(&rt->r4,
&rt_local4,
&r,
NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY)
== 0)
continue;
@ -4805,23 +4810,20 @@ nm_platform_ip_route_get_prune_list(NMPlatform *self,
&& rt->rx.plen == 128 && rt->rx.rt_source == NM_IP_CONFIG_SOURCE_RTPROT_KERNEL
&& rt->rx.metric == 0 && rt->r6.rt_pref == NM_ICMPV6_ROUTER_PREF_MEDIUM
&& IN6_IS_ADDR_UNSPECIFIED(&rt->r6.gateway)) {
if (rt_local6.plen == 0) {
rt_local6 = (NMPlatformIP6Route){
.ifindex = ifindex,
.type_coerced = nm_platform_route_type_coerce(RTN_LOCAL),
.plen = 128,
.rt_source = NM_IP_CONFIG_SOURCE_RTPROT_KERNEL,
.metric = 0,
.table_coerced = nm_platform_route_table_coerce(local_table),
.rt_pref = NM_ICMPV6_ROUTER_PREF_MEDIUM,
.gateway = IN6ADDR_ANY_INIT,
};
}
rt_local6.network = rt->r6.network;
const NMPlatformIP6Route r = {
.ifindex = ifindex,
.type_coerced = nm_platform_route_type_coerce(RTN_LOCAL),
.plen = 128,
.rt_source = NM_IP_CONFIG_SOURCE_RTPROT_KERNEL,
.metric = 0,
.table_coerced = nm_platform_route_table_coerce(local_table),
.rt_pref = NM_ICMPV6_ROUTER_PREF_MEDIUM,
.gateway = IN6ADDR_ANY_INIT,
.network = rt->r6.network,
};
if (nm_platform_ip6_route_cmp(&rt->r6,
&rt_local6,
&r,
NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY)
== 0)
continue;
@ -4843,22 +4845,21 @@ nm_platform_ip_route_get_prune_list(NMPlatform *self,
&& rt->rx.plen == 8 && rt->rx.rt_source == NM_IP_CONFIG_SOURCE_RTPROT_BOOT
&& rt->rx.metric == 256 && rt->r6.rt_pref == NM_ICMPV6_ROUTER_PREF_MEDIUM
&& IN6_IS_ADDR_UNSPECIFIED(&rt->r6.gateway)) {
if (rt_mcast6.plen == 0) {
rt_mcast6 = (NMPlatformIP6Route){
.ifindex = ifindex,
.type_coerced = nm_platform_route_type_coerce(RTN_UNICAST),
.plen = 8,
.rt_source = NM_IP_CONFIG_SOURCE_RTPROT_BOOT,
.metric = 256,
.table_coerced = nm_platform_route_table_coerce(local_table),
.rt_pref = NM_ICMPV6_ROUTER_PREF_MEDIUM,
.gateway = IN6ADDR_ANY_INIT,
.network = {{{0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}},
};
}
const NMPlatformIP6Route r = {
.ifindex = ifindex,
.type_coerced = nm_platform_route_type_coerce(RTN_UNICAST),
.plen = 8,
.rt_source = NM_IP_CONFIG_SOURCE_RTPROT_BOOT,
.metric = 256,
.table_coerced = nm_platform_route_table_coerce(local_table),
.rt_pref = NM_ICMPV6_ROUTER_PREF_MEDIUM,
.gateway = IN6ADDR_ANY_INIT,
.network =
NM_IN6ADDR_INIT(0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
};
if (nm_platform_ip6_route_cmp(&rt->r6,
&rt_mcast6,
&r,
NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY)
== 0)
continue;
@ -8633,7 +8634,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),
@ -8701,7 +8703,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);

View file

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