mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-07 03:48:09 +02:00
core: add configuration flag to choose slaves activation order
Commits39d0559d9a("platform: sort links by name instead of ifindex") and529a0a1a7f("manager: sort slaves to be autoconnected by device name") changed the order of activation of slaves. Introduce a system-wide configuration property to preserve the old behavior. https://bugzilla.redhat.com/show_bug.cgi?id=1452585 (cherry picked from commit31656a066b)
This commit is contained in:
parent
6110b11235
commit
3fefef8594
7 changed files with 52 additions and 20 deletions
|
|
@ -409,6 +409,19 @@ no-auto-default=*
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><varname>slaves-order</varname></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
This key specifies in which order slave connections are
|
||||||
|
auto-activated on boot or when the master activates
|
||||||
|
them. Allowed values are <literal>name</literal> (order
|
||||||
|
connection by interface name, the default), or
|
||||||
|
<literal>index</literal> (order slaves by their kernel
|
||||||
|
index).
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
</variablelist>
|
</variablelist>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@
|
||||||
#define NM_CONFIG_KEYFILE_KEY_MAIN_DHCP "dhcp"
|
#define NM_CONFIG_KEYFILE_KEY_MAIN_DHCP "dhcp"
|
||||||
#define NM_CONFIG_KEYFILE_KEY_MAIN_DEBUG "debug"
|
#define NM_CONFIG_KEYFILE_KEY_MAIN_DEBUG "debug"
|
||||||
#define NM_CONFIG_KEYFILE_KEY_MAIN_HOSTNAME_MODE "hostname-mode"
|
#define NM_CONFIG_KEYFILE_KEY_MAIN_HOSTNAME_MODE "hostname-mode"
|
||||||
|
#define NM_CONFIG_KEYFILE_KEY_MAIN_SLAVES_ORDER "slaves-order"
|
||||||
#define NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND "backend"
|
#define NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND "backend"
|
||||||
#define NM_CONFIG_KEYFILE_KEY_CONFIG_ENABLE "enable"
|
#define NM_CONFIG_KEYFILE_KEY_CONFIG_ENABLE "enable"
|
||||||
#define NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS ".was"
|
#define NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS ".was"
|
||||||
|
|
|
||||||
|
|
@ -2459,10 +2459,14 @@ platform_query_devices (NMManager *self)
|
||||||
NMPlatformLink *links;
|
NMPlatformLink *links;
|
||||||
int i;
|
int i;
|
||||||
gboolean guess_assume;
|
gboolean guess_assume;
|
||||||
|
const char *order;
|
||||||
|
|
||||||
guess_assume = nm_config_get_first_start (nm_config_get ());
|
guess_assume = nm_config_get_first_start (nm_config_get ());
|
||||||
|
order = nm_config_data_get_value_cached (NM_CONFIG_GET_DATA,
|
||||||
links_array = nm_platform_link_get_all (NM_PLATFORM_GET);
|
NM_CONFIG_KEYFILE_GROUP_MAIN,
|
||||||
|
NM_CONFIG_KEYFILE_KEY_MAIN_SLAVES_ORDER,
|
||||||
|
NM_CONFIG_GET_VALUE_STRIP);
|
||||||
|
links_array = nm_platform_link_get_all (NM_PLATFORM_GET, !nm_streq0 (order, "index"));
|
||||||
links = (NMPlatformLink *) links_array->data;
|
links = (NMPlatformLink *) links_array->data;
|
||||||
for (i = 0; i < links_array->len; i++) {
|
for (i = 0; i < links_array->len; i++) {
|
||||||
gs_free NMConfigDeviceStateData *dev_state = NULL;
|
gs_free NMConfigDeviceStateData *dev_state = NULL;
|
||||||
|
|
@ -3016,7 +3020,7 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
compare_slaves (gconstpointer a, gconstpointer b, gpointer _unused)
|
compare_slaves (gconstpointer a, gconstpointer b, gpointer sort_by_name)
|
||||||
{
|
{
|
||||||
const SlaveConnectionInfo *a_info = a;
|
const SlaveConnectionInfo *a_info = a;
|
||||||
const SlaveConnectionInfo *b_info = b;
|
const SlaveConnectionInfo *b_info = b;
|
||||||
|
|
@ -3027,8 +3031,12 @@ compare_slaves (gconstpointer a, gconstpointer b, gpointer _unused)
|
||||||
if (!b_info->device)
|
if (!b_info->device)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return g_strcmp0 (nm_device_get_iface (a_info->device),
|
if (GPOINTER_TO_INT (sort_by_name)) {
|
||||||
nm_device_get_iface (b_info->device));
|
return g_strcmp0 (nm_device_get_iface (a_info->device),
|
||||||
|
nm_device_get_iface (b_info->device));
|
||||||
|
}
|
||||||
|
|
||||||
|
return nm_device_get_ifindex (a_info->device) - nm_device_get_ifindex (b_info->device);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -3042,11 +3050,17 @@ autoconnect_slaves (NMManager *self,
|
||||||
if (should_connect_slaves (NM_CONNECTION (master_connection), master_device)) {
|
if (should_connect_slaves (NM_CONNECTION (master_connection), master_device)) {
|
||||||
gs_free SlaveConnectionInfo *slaves = NULL;
|
gs_free SlaveConnectionInfo *slaves = NULL;
|
||||||
guint i, n_slaves = 0;
|
guint i, n_slaves = 0;
|
||||||
|
const char *value;
|
||||||
|
|
||||||
slaves = find_slaves (self, master_connection, master_device, &n_slaves);
|
slaves = find_slaves (self, master_connection, master_device, &n_slaves);
|
||||||
if (n_slaves > 1) {
|
if (n_slaves > 1) {
|
||||||
|
value = nm_config_data_get_value_cached (NM_CONFIG_GET_DATA,
|
||||||
|
NM_CONFIG_KEYFILE_GROUP_MAIN,
|
||||||
|
NM_CONFIG_KEYFILE_KEY_MAIN_SLAVES_ORDER,
|
||||||
|
NM_CONFIG_GET_VALUE_STRIP);
|
||||||
g_qsort_with_data (slaves, n_slaves, sizeof (slaves[0]),
|
g_qsort_with_data (slaves, n_slaves, sizeof (slaves[0]),
|
||||||
compare_slaves, NULL);
|
compare_slaves,
|
||||||
|
GINT_TO_POINTER (!nm_streq0 (value, "index")));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < n_slaves; i++) {
|
for (i = 0; i < n_slaves; i++) {
|
||||||
|
|
|
||||||
|
|
@ -437,7 +437,8 @@ nm_platform_sysctl_get_int_checked (NMPlatform *self, const char *pathid, int di
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_link_get_all_presort (gconstpointer p_a,
|
_link_get_all_presort (gconstpointer p_a,
|
||||||
gconstpointer p_b)
|
gconstpointer p_b,
|
||||||
|
gpointer sort_by_name)
|
||||||
{
|
{
|
||||||
const NMPlatformLink *a = p_a;
|
const NMPlatformLink *a = p_a;
|
||||||
const NMPlatformLink *b = p_b;
|
const NMPlatformLink *b = p_b;
|
||||||
|
|
@ -448,13 +449,16 @@ _link_get_all_presort (gconstpointer p_a,
|
||||||
if (b->ifindex == 1)
|
if (b->ifindex == 1)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Initialized links first */
|
if (GPOINTER_TO_INT (sort_by_name)) {
|
||||||
if (a->initialized > b->initialized)
|
/* Initialized links first */
|
||||||
return -1;
|
if (a->initialized > b->initialized)
|
||||||
if (a->initialized < b->initialized)
|
return -1;
|
||||||
return 1;
|
if (a->initialized < b->initialized)
|
||||||
|
return 1;
|
||||||
|
|
||||||
return strcmp (a->name, b->name);
|
return strcmp (a->name, b->name);
|
||||||
|
} else
|
||||||
|
return a->ifindex - b->ifindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -465,7 +469,7 @@ _link_get_all_presort (gconstpointer p_a,
|
||||||
* owned by the caller and should be freed with g_array_unref().
|
* owned by the caller and should be freed with g_array_unref().
|
||||||
*/
|
*/
|
||||||
GArray *
|
GArray *
|
||||||
nm_platform_link_get_all (NMPlatform *self)
|
nm_platform_link_get_all (NMPlatform *self, gboolean sort_by_name)
|
||||||
{
|
{
|
||||||
GArray *links, *result;
|
GArray *links, *result;
|
||||||
guint i, j, nresult;
|
guint i, j, nresult;
|
||||||
|
|
@ -479,9 +483,9 @@ nm_platform_link_get_all (NMPlatform *self)
|
||||||
if (!links || links->len == 0)
|
if (!links || links->len == 0)
|
||||||
return links;
|
return links;
|
||||||
|
|
||||||
/* first sort the links by their ifindex. Below we will sort further by moving
|
/* first sort the links by their ifindex or name. Below we will sort
|
||||||
* children/slaves to the end. */
|
* further by moving children/slaves to the end. */
|
||||||
g_array_sort (links, _link_get_all_presort);
|
g_array_sort_with_data (links, _link_get_all_presort, GINT_TO_POINTER (sort_by_name));
|
||||||
|
|
||||||
unseen = g_hash_table_new (g_direct_hash, g_direct_equal);
|
unseen = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||||
for (i = 0; i < links->len; i++) {
|
for (i = 0; i < links->len; i++) {
|
||||||
|
|
|
||||||
|
|
@ -763,7 +763,7 @@ const NMPlatformLink *nm_platform_link_get (NMPlatform *self, int ifindex);
|
||||||
const NMPlatformLink *nm_platform_link_get_by_ifname (NMPlatform *self, const char *ifname);
|
const NMPlatformLink *nm_platform_link_get_by_ifname (NMPlatform *self, const char *ifname);
|
||||||
const NMPlatformLink *nm_platform_link_get_by_address (NMPlatform *self, gconstpointer address, size_t length);
|
const NMPlatformLink *nm_platform_link_get_by_address (NMPlatform *self, gconstpointer address, size_t length);
|
||||||
|
|
||||||
GArray *nm_platform_link_get_all (NMPlatform *self);
|
GArray *nm_platform_link_get_all (NMPlatform *self, gboolean sort_by_name);
|
||||||
NMPlatformError nm_platform_link_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
|
NMPlatformError nm_platform_link_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
|
||||||
NMPlatformError nm_platform_link_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, const NMPlatformLink **out_link);
|
NMPlatformError nm_platform_link_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, const NMPlatformLink **out_link);
|
||||||
NMPlatformError nm_platform_link_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
|
NMPlatformError nm_platform_link_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ link_callback (NMPlatform *platform, int obj_type_i, int ifindex, NMPlatformLink
|
||||||
|
|
||||||
/* Check the data */
|
/* Check the data */
|
||||||
g_assert (received->ifindex > 0);
|
g_assert (received->ifindex > 0);
|
||||||
links = nm_platform_link_get_all (NM_PLATFORM_GET);
|
links = nm_platform_link_get_all (NM_PLATFORM_GET, TRUE);
|
||||||
for (i = 0; i < links->len; i++) {
|
for (i = 0; i < links->len; i++) {
|
||||||
cached = &g_array_index (links, NMPlatformLink, i);
|
cached = &g_array_index (links, NMPlatformLink, i);
|
||||||
if (cached->ifindex == received->ifindex) {
|
if (cached->ifindex == received->ifindex) {
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ test_link_get_all (void)
|
||||||
|
|
||||||
platform = nm_linux_platform_new (TRUE, NM_PLATFORM_NETNS_SUPPORT_DEFAULT);
|
platform = nm_linux_platform_new (TRUE, NM_PLATFORM_NETNS_SUPPORT_DEFAULT);
|
||||||
|
|
||||||
links = nm_platform_link_get_all (platform);
|
links = nm_platform_link_get_all (platform, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue