platform: rename "user_ipv6ll" API to "inet6_addr_gen_mode"

The term "user_ipv6ll" is confusing and not something somebody familiar
with kernel or `ip -d link` would understand.

Also, it maps a boolean to addr-gen-mode "none" or "eui64", although
there are 2 more address generation modes in kernel.

Don't abstract the underlying API, and name things as they are in
kernel.
This commit is contained in:
Thomas Haller 2021-08-23 22:31:51 +02:00
parent 0d0f532b12
commit 98ed0e9858
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
6 changed files with 74 additions and 62 deletions

View file

@ -3145,8 +3145,12 @@ _set_ip_ifindex(NMDevice *self, int ifindex, const char *ifname)
nm_platform_process_events_ensure_link(platform, priv->ip_ifindex, priv->ip_iface);
if (nm_platform_kernel_support_get(NM_PLATFORM_KERNEL_SUPPORT_TYPE_USER_IPV6LL))
nm_platform_link_set_user_ipv6ll_enabled(platform, priv->ip_ifindex, TRUE);
if (nm_platform_kernel_support_get(
NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_INET6_ADDR_GEN_MODE)) {
nm_platform_link_set_inet6_addr_gen_mode(platform,
priv->ip_ifindex,
NM_IN6_ADDR_GEN_MODE_NONE);
}
if (!nm_platform_link_is_up(platform, priv->ip_ifindex))
nm_platform_link_change_flags(platform, priv->ip_ifindex, IFF_UP, TRUE);
@ -6091,8 +6095,10 @@ realize_start_setup(NMDevice * self,
if (priv->firmware_version)
_notify(self, PROP_FIRMWARE_VERSION);
if (nm_platform_kernel_support_get(NM_PLATFORM_KERNEL_SUPPORT_TYPE_USER_IPV6LL))
priv->ipv6ll_handle = nm_platform_link_get_user_ipv6ll_enabled(platform, priv->ifindex);
if (nm_platform_kernel_support_get(
NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_INET6_ADDR_GEN_MODE))
priv->ipv6ll_handle = (nm_platform_link_get_inet6_addr_gen_mode(platform, priv->ifindex)
== NM_IN6_ADDR_GEN_MODE_NONE);
if (nm_platform_link_supports_sriov(platform, priv->ifindex))
capabilities |= NM_DEVICE_CAP_SRIOV;
@ -11197,21 +11203,23 @@ set_nm_ipv6ll(NMDevice *self, gboolean enable)
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
int ifindex = nm_device_get_ip_ifindex(self);
if (!nm_platform_kernel_support_get(NM_PLATFORM_KERNEL_SUPPORT_TYPE_USER_IPV6LL))
if (!nm_platform_kernel_support_get(NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_INET6_ADDR_GEN_MODE))
return;
priv->ipv6ll_handle = enable;
if (ifindex > 0) {
const char *detail = enable ? "enable" : "disable";
int r;
int r;
_LOGD(LOGD_IP6, "will %s userland IPv6LL", detail);
r = nm_platform_link_set_user_ipv6ll_enabled(nm_device_get_platform(self), ifindex, enable);
_LOGD(LOGD_IP6, "will %s userland IPv6LL", enable ? "enable" : "disable");
r = nm_platform_link_set_inet6_addr_gen_mode(nm_device_get_platform(self),
ifindex,
enable ? NM_IN6_ADDR_GEN_MODE_NONE
: NM_IN6_ADDR_GEN_MODE_EUI64);
if (r < 0) {
_NMLOG(NM_IN_SET(r, -NME_PL_NOT_FOUND, -NME_PL_OPNOTSUPP) ? LOGL_DEBUG : LOGL_WARN,
LOGD_IP6,
"failed to %s userspace IPv6LL address handling (%s)",
detail,
enable ? "enable" : "disable",
nm_strerror(r));
}

View file

@ -702,7 +702,9 @@ main(int argc, char *argv[])
guint32 default_ra_timeout;
int max_addresses;
nm_platform_link_set_user_ipv6ll_enabled(NM_PLATFORM_GET, gl.ifindex, TRUE);
nm_platform_link_set_inet6_addr_gen_mode(NM_PLATFORM_GET,
gl.ifindex,
NM_IN6_ADDR_GEN_MODE_NONE);
if (global_opt.stable_id
&& (global_opt.stable_id[0] >= '0' && global_opt.stable_id[0] <= '9')

View file

@ -602,28 +602,47 @@ test_bridge_addr(void)
g_assert(plink);
g_assert(!nm_platform_link_get_permanent_address(NM_PLATFORM_GET, plink, &hw_perm_addr));
if (nm_platform_kernel_support_get(NM_PLATFORM_KERNEL_SUPPORT_TYPE_USER_IPV6LL)) {
g_assert(!nm_platform_link_get_user_ipv6ll_enabled(NM_PLATFORM_GET, link.ifindex));
if (nm_platform_kernel_support_get(NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_INET6_ADDR_GEN_MODE)) {
g_assert_cmpint(nm_platform_link_get_inet6_addr_gen_mode(NM_PLATFORM_GET, link.ifindex),
==,
NM_IN6_ADDR_GEN_MODE_EUI64);
g_assert_cmpint(_nm_platform_link_get_inet6_addr_gen_mode(plink),
==,
NM_IN6_ADDR_GEN_MODE_EUI64);
g_assert_cmpint(_nm_platform_uint8_inv(plink->inet6_addr_gen_mode_inv),
==,
NM_IN6_ADDR_GEN_MODE_EUI64);
g_assert(NMTST_NM_ERR_SUCCESS(
nm_platform_link_set_user_ipv6ll_enabled(NM_PLATFORM_GET, link.ifindex, TRUE)));
g_assert(nm_platform_link_get_user_ipv6ll_enabled(NM_PLATFORM_GET, link.ifindex));
nm_platform_link_set_inet6_addr_gen_mode(NM_PLATFORM_GET,
link.ifindex,
NM_IN6_ADDR_GEN_MODE_NONE)));
g_assert_cmpint(nm_platform_link_get_inet6_addr_gen_mode(NM_PLATFORM_GET, link.ifindex),
==,
NM_IN6_ADDR_GEN_MODE_NONE);
plink = nm_platform_link_get(NM_PLATFORM_GET, link.ifindex);
g_assert(plink);
g_assert(!nm_platform_link_get_permanent_address(NM_PLATFORM_GET, plink, &hw_perm_addr));
g_assert_cmpint(_nm_platform_link_get_inet6_addr_gen_mode(plink),
==,
NM_IN6_ADDR_GEN_MODE_NONE);
g_assert_cmpint(_nm_platform_uint8_inv(plink->inet6_addr_gen_mode_inv),
==,
NM_IN6_ADDR_GEN_MODE_NONE);
g_assert(NMTST_NM_ERR_SUCCESS(
nm_platform_link_set_user_ipv6ll_enabled(NM_PLATFORM_GET, link.ifindex, FALSE)));
g_assert(!nm_platform_link_get_user_ipv6ll_enabled(NM_PLATFORM_GET, link.ifindex));
nm_platform_link_set_inet6_addr_gen_mode(NM_PLATFORM_GET,
link.ifindex,
NM_IN6_ADDR_GEN_MODE_EUI64)));
g_assert_cmpint(nm_platform_link_get_inet6_addr_gen_mode(NM_PLATFORM_GET, link.ifindex),
==,
NM_IN6_ADDR_GEN_MODE_EUI64);
plink = nm_platform_link_get(NM_PLATFORM_GET, link.ifindex);
g_assert(plink);
g_assert(!nm_platform_link_get_permanent_address(NM_PLATFORM_GET, plink, &hw_perm_addr));
g_assert_cmpint(_nm_platform_link_get_inet6_addr_gen_mode(plink),
==,
NM_IN6_ADDR_GEN_MODE_EUI64);
g_assert_cmpint(_nm_platform_uint8_inv(plink->inet6_addr_gen_mode_inv),
==,
NM_IN6_ADDR_GEN_MODE_EUI64);

View file

@ -1282,9 +1282,10 @@ _parse_af_inet6(NMPlatform * platform,
/* Hack to detect support addrgenmode of the kernel. We only parse
* netlink messages that we receive from kernel, hence this check
* is valid. */
if (!_nm_platform_kernel_support_detected(NM_PLATFORM_KERNEL_SUPPORT_TYPE_USER_IPV6LL)) {
if (!_nm_platform_kernel_support_detected(
NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_INET6_ADDR_GEN_MODE)) {
/* IFLA_INET6_ADDR_GEN_MODE was added in kernel 3.17, dated 5 October, 2014. */
_nm_platform_kernel_support_init(NM_PLATFORM_KERNEL_SUPPORT_TYPE_USER_IPV6LL,
_nm_platform_kernel_support_init(NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_INET6_ADDR_GEN_MODE,
tb[IFLA_INET6_ADDR_GEN_MODE] ? 1 : -1);
}
@ -7507,17 +7508,16 @@ link_change_flags(NMPlatform *platform, int ifindex, unsigned flags_mask, unsign
}
static int
link_set_user_ipv6ll_enabled(NMPlatform *platform, int ifindex, gboolean enabled)
link_set_inet6_addr_gen_mode(NMPlatform *platform, int ifindex, guint8 mode)
{
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
guint8 mode = enabled ? NM_IN6_ADDR_GEN_MODE_NONE : NM_IN6_ADDR_GEN_MODE_EUI64;
char sbuf[100];
char sbuf[100];
_LOGD("link: change %d: user-ipv6ll: set IPv6 address generation mode to %s",
ifindex,
nm_platform_link_inet6_addrgenmode2str(mode, sbuf, sizeof(sbuf)));
if (!nm_platform_kernel_support_get(NM_PLATFORM_KERNEL_SUPPORT_TYPE_USER_IPV6LL)) {
if (!nm_platform_kernel_support_get(NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_INET6_ADDR_GEN_MODE)) {
_LOGD("link: change %d: user-ipv6ll: not supported", ifindex);
return -NME_PL_OPNOTSUPP;
}
@ -9667,7 +9667,7 @@ nm_linux_platform_class_init(NMLinuxPlatformClass *klass)
platform_class->link_change_flags = link_change_flags;
platform_class->link_set_user_ipv6ll_enabled = link_set_user_ipv6ll_enabled;
platform_class->link_set_inet6_addr_gen_mode = link_set_inet6_addr_gen_mode;
platform_class->link_set_token = link_set_token;
platform_class->link_set_address = link_set_address;

View file

@ -306,10 +306,10 @@ static const struct {
.name = "EXTENDED_IFA_FLAGS",
.desc = "IPv6 temporary addresses support",
},
[NM_PLATFORM_KERNEL_SUPPORT_TYPE_USER_IPV6LL] =
[NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_INET6_ADDR_GEN_MODE] =
{
.compile_time_default = TRUE,
.name = "USER_IPV6LL",
.name = "IFLA_INET6_ADDR_GEN_MODE",
.desc = "IFLA_INET6_ADDR_GEN_MODE support",
},
[NM_PLATFORM_KERNEL_SUPPORT_TYPE_RTA_PREF] =
@ -1656,47 +1656,20 @@ nm_platform_link_get_udev_device(NMPlatform *self, int ifindex)
return obj_cache ? obj_cache->_link.udev.device : NULL;
}
/**
* nm_platform_link_get_user_ip6vll_enabled:
* @self: platform instance
* @ifindex: Interface index
*
* Check whether NM handles IPv6LL address creation for the link. If the
* platform or OS doesn't support changing the IPv6LL address mode, this call
* will fail and return %FALSE.
*
* Returns: %TRUE if NM handles the IPv6LL address for @ifindex
*/
gboolean
nm_platform_link_get_user_ipv6ll_enabled(NMPlatform *self, int ifindex)
int
nm_platform_link_get_inet6_addr_gen_mode(NMPlatform *self, int ifindex)
{
const NMPlatformLink *pllink;
pllink = nm_platform_link_get(self, ifindex);
if (pllink && pllink->inet6_addr_gen_mode_inv)
return _nm_platform_uint8_inv(pllink->inet6_addr_gen_mode_inv) == NM_IN6_ADDR_GEN_MODE_NONE;
return FALSE;
return _nm_platform_link_get_inet6_addr_gen_mode(nm_platform_link_get(self, ifindex));
}
/**
* nm_platform_link_set_user_ip6vll_enabled:
* @self: platform instance
* @ifindex: Interface index
*
* Set whether NM handles IPv6LL address creation for the link. If the
* platform or OS doesn't support changing the IPv6LL address mode, this call
* will fail and return %FALSE.
*
* Returns: the negative nm-error on failure.
*/
int
nm_platform_link_set_user_ipv6ll_enabled(NMPlatform *self, int ifindex, gboolean enabled)
nm_platform_link_set_inet6_addr_gen_mode(NMPlatform *self, int ifindex, guint8 mode)
{
_CHECK_SELF(self, klass, -NME_BUG);
g_return_val_if_fail(ifindex > 0, -NME_BUG);
return klass->link_set_user_ipv6ll_enabled(self, ifindex, enabled);
return klass->link_set_inet6_addr_gen_mode(self, ifindex, mode);
}
/**

View file

@ -1016,7 +1016,7 @@ typedef void (*NMPlatformAsyncCallback)(GError *error, gpointer user_data);
typedef enum {
NM_PLATFORM_KERNEL_SUPPORT_TYPE_EXTENDED_IFA_FLAGS,
NM_PLATFORM_KERNEL_SUPPORT_TYPE_USER_IPV6LL,
NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_INET6_ADDR_GEN_MODE,
NM_PLATFORM_KERNEL_SUPPORT_TYPE_RTA_PREF,
NM_PLATFORM_KERNEL_SUPPORT_TYPE_FRA_L3MDEV,
NM_PLATFORM_KERNEL_SUPPORT_TYPE_FRA_UID_RANGE,
@ -1113,7 +1113,7 @@ typedef struct {
unsigned flags_mask,
unsigned flags_set);
int (*link_set_user_ipv6ll_enabled)(NMPlatform *self, int ifindex, gboolean enabled);
int (*link_set_inet6_addr_gen_mode)(NMPlatform *self, int ifindex, guint8 enabled);
gboolean (*link_set_token)(NMPlatform *self, int ifindex, NMUtilsIPv6IfaceId iid);
gboolean (*link_get_permanent_address_ethtool)(NMPlatform * self,
@ -1398,6 +1398,16 @@ _nm_platform_uint8_inv(guint8 scope)
return (guint8) ~scope;
}
static inline int
_nm_platform_link_get_inet6_addr_gen_mode(const NMPlatformLink *pllink)
{
if (!pllink)
return -ENODEV;
if (!nm_platform_kernel_support_get(NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_INET6_ADDR_GEN_MODE))
return -EOPNOTSUPP;
return _nm_platform_uint8_inv(pllink->inet6_addr_gen_mode_inv);
}
/**
* nm_platform_route_type_coerce:
* @table: the route type, in its original value.
@ -1815,7 +1825,7 @@ gboolean nm_platform_link_is_up(NMPlatform *self, int ifindex);
gboolean nm_platform_link_is_connected(NMPlatform *self, int ifindex);
gboolean nm_platform_link_uses_arp(NMPlatform *self, int ifindex);
guint32 nm_platform_link_get_mtu(NMPlatform *self, int ifindex);
gboolean nm_platform_link_get_user_ipv6ll_enabled(NMPlatform *self, int ifindex);
int nm_platform_link_get_inet6_addr_gen_mode(NMPlatform *self, int ifindex);
gconstpointer nm_platform_link_get_address(NMPlatform *self, int ifindex, size_t *length);
@ -1865,7 +1875,7 @@ const char *nm_platform_link_get_path(NMPlatform *self, int ifindex);
struct udev_device *nm_platform_link_get_udev_device(NMPlatform *self, int ifindex);
int nm_platform_link_set_user_ipv6ll_enabled(NMPlatform *self, int ifindex, gboolean enabled);
int nm_platform_link_set_inet6_addr_gen_mode(NMPlatform *self, int ifindex, guint8 mode);
gboolean nm_platform_link_set_ipv6_token(NMPlatform *self, int ifindex, NMUtilsIPv6IfaceId iid);
gboolean nm_platform_link_get_permanent_address_ethtool(NMPlatform * self,