initrd: don't create a default connection if there's already one

Certain arguments (such as "nameserver") don't specify a connection they
apply to and using them would generate a default ethernet connection.
This is probably not the right thing to do.

(cherry picked from commit 6da2058237)
This commit is contained in:
Lubomir Rintel 2019-07-02 10:03:00 +02:00
parent 24c3a0c88f
commit 0d9a62c25e

View file

@ -32,6 +32,20 @@
/*****************************************************************************/
static gboolean
_connection_matches_type (gpointer key, gpointer value, gpointer user_data)
{
NMConnection *connection = value;
const char *type_name = user_data;
NMSettingConnection *s_con;
s_con = nm_connection_get_setting_connection (connection);
if (type_name == NULL)
return nm_setting_connection_get_master (s_con) == NULL;
else
return strcmp (nm_setting_connection_get_connection_type (s_con), type_name) == 0;
}
static NMConnection *
get_conn (GHashTable *connections, const char *ifname, const char *type_name)
{
@ -49,7 +63,18 @@ get_conn (GHashTable *connections, const char *ifname, const char *type_name)
multi_connect = NM_CONNECTION_MULTI_CONNECT_MULTIPLE;
}
connection = g_hash_table_lookup (connections, (gpointer)basename);
connection = g_hash_table_lookup (connections, (gpointer) basename);
if (!connection && !ifname) {
/*
* If ifname was not given, we'll match the connection by type.
* If the type was not given either, then we're happy with any connection but slaves.
* This is so that things like "bond=bond0:eth1,eth2 nameserver=1.3.3.7 end up
* slapping the nameserver to the most reasonable connection (bond0).
*/
connection = g_hash_table_find (connections,
_connection_matches_type,
(gpointer) type_name);
}
if (connection) {
setting = (NMSetting *)nm_connection_get_setting_connection (connection);
@ -658,7 +683,6 @@ parse_rd_peerdns (GHashTable *connections, char *argument)
NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, auto_dns,
NULL);
s_ip = nm_connection_get_setting_ip6_config (connection);
g_object_set (s_ip,
NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, auto_dns,