diff --git a/src/core/devices/nm-device-ethernet.c b/src/core/devices/nm-device-ethernet.c index aedacc248b..5d58b69d67 100644 --- a/src/core/devices/nm-device-ethernet.c +++ b/src/core/devices/nm-device-ethernet.c @@ -1711,10 +1711,8 @@ new_default_connection(NMDevice *self) NMSettingsConnection *const *connections; NMSetting *setting; gs_unref_hashtable GHashTable *existing_ids = NULL; - 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; @@ -1760,30 +1758,6 @@ new_default_connection(NMDevice *self) iface, NULL); - /* 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 (_nm_utils_ascii_str_to_bool(uprop, FALSE)) { - setting = nm_setting_ip4_config_new(); - g_object_set(setting, - NM_SETTING_IP_CONFIG_METHOD, - NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL, - NULL); - nm_connection_add_setting(connection, setting); - - setting = nm_setting_ip6_config_new(); - g_object_set(setting, - NM_SETTING_IP_CONFIG_METHOD, - NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL, - NM_SETTING_IP_CONFIG_MAY_FAIL, - TRUE, - NULL); - nm_connection_add_setting(connection, setting); - } - return connection; } diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 71b597fb34..c3886b7db0 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "libnm-std-aux/unaligned.h" #include "libnm-glib-aux/nm-uuid.h" @@ -8098,6 +8099,39 @@ nm_device_owns_iface(NMDevice *self, const char *iface) return FALSE; } +static void +apply_udev_auto_default_configs(NMDevice *self, NMConnection *connection) +{ + struct udev_device *dev; + const char *uprop; + NMSetting *setting; + + dev = nm_platform_link_get_udev_device(nm_device_get_platform(NM_DEVICE(self)), + nm_device_get_ip_ifindex(self)); + if (!dev) + return; + + uprop = udev_device_get_property_value(dev, "NM_AUTO_DEFAULT_LINK_LOCAL_ONLY"); + + if (_nm_utils_ascii_str_to_bool(uprop, FALSE)) { + setting = nm_setting_ip4_config_new(); + g_object_set(setting, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL, + NULL); + nm_connection_add_setting(connection, setting); + + setting = nm_setting_ip6_config_new(); + g_object_set(setting, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + nm_connection_add_setting(connection, setting); + } +} + NMConnection * nm_device_new_default_connection(NMDevice *self) { @@ -8111,6 +8145,8 @@ nm_device_new_default_connection(NMDevice *self) if (!connection) return NULL; + apply_udev_auto_default_configs(self, connection); + if (!nm_connection_normalize(connection, NULL, NULL, &error)) { _LOGD(LOGD_DEVICE, "device generated an invalid default connection: %s", error->message); g_error_free(error);