mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-01 04:30:29 +01:00
auto-default: check NM_AUTO_DEFAULT_LINK_LOCAL_ONLY from nm-device
When creating default connections automatically, we check if udev has set the NM_AUTO_DEFAULT_LINK_LOCAL_ONLY variable, and if so, we create the connection with method=link-local. It was checked only for ethernet connection type, which works fine because it's the only device type that we create connections automatically for. However, link-local connections are not specific to Ethernet, and if we add auto-default connections for more devices in the future we should honor this configuration too. Do it from nm-device, but only if the device class has defined a "new_default_connection" method so the behaviour is identical as the current one, but will be used by future implementors of this method too.
This commit is contained in:
parent
67faab3f4d
commit
5e3ebdedd4
2 changed files with 36 additions and 26 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include <linux/rtnetlink.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/if_infiniband.h>
|
||||
#include <libudev.h>
|
||||
|
||||
#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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue