device/ethernet: honor ID_NET_AUTO_LINK_LOCAL_ONLY udev property

We honored "NM_AUTO_DEFAULT_LINK_LOCAL_ONLY" udev property, for when we
generate a "Wired connection 1" (aka the "auto-default connection").

Systemd now also honors and may set ID_NET_AUTO_LINK_LOCAL_ONLY for
a similar purpose. Honore that too.

The NM specific variable still is preferred, also because "NM_AUTO_DEFAULT_LINK_LOCAL_ONLY"
is about something very NetworkManager specific (controlling "Wired connection 1").

Maybe one day, we should drop "data/90-nm-thunderbolt.rules" and only
rely on what systemd provides. But not yet.

See-also: https://github.com/systemd/systemd/pull/29767
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1413
This commit is contained in:
Thomas Haller 2023-10-30 17:59:15 +01:00
parent d12a882845
commit 36fb335b28
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
3 changed files with 28 additions and 5 deletions

4
NEWS
View file

@ -1,11 +1,13 @@
=============================================
NetworkManager-1.46
Overview of changes since NetworkManager-1.46
Overview of changes since NetworkManager-1.44
=============================================
* Change internal ABI of NMSetting types and NMSimpleConnection. The layout of
these structs was already hidden from public headers since 1.34 and this change
should not be noticeable.
* Honor udev property ID_NET_AUTO_LINK_LOCAL_ONLY=1 for enabling
link local addresses on default wired connection.
=============================================
NetworkManager-1.44

View file

@ -193,6 +193,24 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>NM_AUTO_DEFAULT_LINK_LOCAL_ONLY</varname></term>
<listitem><para>
If set to <literal>"1"</literal> or <literal>"true"</literal>, the
automatically generated connections "Wired connection N" will only
enable link local addressing for IPv4 and IPv6. This can be useful
on thunderbolt devices or host-to-host USB devices.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>ID_NET_AUTO_LINK_LOCAL_ONLY</varname></term>
<listitem><para>
Honored and treated the same as if <varname>NM_AUTO_DEFAULT_LINK_LOCAL_ONLY</varname>
were set.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

View file

@ -1707,6 +1707,7 @@ complete_connection(NMDevice *device,
static NMConnection *
new_default_connection(NMDevice *self)
{
const char *link_local_only = NULL;
NMConnection *connection;
NMSettingsConnection *const *connections;
NMSetting *setting;
@ -1714,7 +1715,6 @@ new_default_connection(NMDevice *self)
struct udev_device *dev;
const char *perm_hw_addr;
const char *iface;
const char *uprop = "0";
gs_free char *defname = NULL;
gs_free char *uuid = NULL;
guint i, n_connections;
@ -1763,10 +1763,13 @@ new_default_connection(NMDevice *self)
/* Check if we should create a Link-Local only connection */
dev = nm_platform_link_get_udev_device(nm_device_get_platform(NM_DEVICE(self)),
nm_device_get_ip_ifindex(self));
if (dev)
uprop = udev_device_get_property_value(dev, "NM_AUTO_DEFAULT_LINK_LOCAL_ONLY");
if (dev) {
link_local_only = udev_device_get_property_value(dev, "NM_AUTO_DEFAULT_LINK_LOCAL_ONLY");
if (!link_local_only)
link_local_only = udev_device_get_property_value(dev, "ID_NET_AUTO_LINK_LOCAL_ONLY");
}
if (_nm_utils_ascii_str_to_bool(uprop, FALSE)) {
if (_nm_utils_ascii_str_to_bool(link_local_only, FALSE)) {
setting = nm_setting_ip4_config_new();
g_object_set(setting,
NM_SETTING_IP_CONFIG_METHOD,