platform: track kernel support for IFLA_PERM_ADDRESS

Track whether kernel supports netlink API IFLA_PERM_ADDRESS. To use the
platform cache preferably if kernel supports IFLA_PERM_ADDRESS. To fall
back to the old ethtool call directly if kernel does not support
IFLA_PERM_ADDRESS.

https://bugzilla.redhat.com/show_bug.cgi?id=1987286

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/673

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/961

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
This commit is contained in:
Wen Liang 2021-08-18 20:58:52 -04:00 committed by Wen Liang
parent 60bad3a41e
commit 6da4464154
3 changed files with 23 additions and 0 deletions

View file

@ -3058,6 +3058,15 @@ _new_from_nl_link(NMPlatform * platform,
}
if (tb[IFLA_PERM_ADDRESS]) {
if (!_nm_platform_kernel_support_detected(
NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_PERM_ADDRESS)) {
/* support for IFLA_PERM_ADDRESS was added in f74877a5457d34d604dba6dbbb13c4c05bac8b93,
* kernel 5.6, 30 March 2020.
*
* We can only detect support if the attribute is present. A missing attribute
* is not conclusive. */
_nm_platform_kernel_support_init(NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_PERM_ADDRESS, 1);
}
_nmp_link_address_set(&obj->link.l_perm_address, tb[IFLA_PERM_ADDRESS]);
perm_address_complete_from_cache = FALSE;
}

View file

@ -349,6 +349,12 @@ static const struct {
.name = "IFLA_BR_VLAN_STATS_ENABLE",
.desc = "IFLA_BR_VLAN_STATS_ENABLE bridge link attribute",
},
[NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_PERM_ADDRESS] =
{
.compile_time_default = (IFLA_MAX >= 54 /* IFLA_PERM_ADDRESS */),
.name = "IFLA_PERM_ADDRESS",
.desc = "IFLA_PERM_ADDRESS netlink attribute",
},
};
int
@ -1779,6 +1785,13 @@ nm_platform_link_get_permanent_address(NMPlatform * self,
*out_address = plink->l_perm_address;
return TRUE;
}
if (nm_platform_kernel_support_get_full(NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_PERM_ADDRESS,
FALSE)
== NM_OPTION_BOOL_TRUE) {
/* kernel supports the netlink API IFLA_PERM_ADDRESS, but we don't have the
* address cached. There is no need to fallback to ethtool ioctl. */
return FALSE;
}
return nm_platform_link_get_permanent_address_ethtool(self, plink->ifindex, out_address);
}

View file

@ -1018,6 +1018,7 @@ typedef enum {
NM_PLATFORM_KERNEL_SUPPORT_TYPE_FRA_UID_RANGE,
NM_PLATFORM_KERNEL_SUPPORT_TYPE_FRA_PROTOCOL,
NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_BR_VLAN_STATS_ENABLED,
NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_PERM_ADDRESS,
/* this also includes FRA_SPORT_RANGE and FRA_DPORT_RANGE which
* were added at the same time. */