mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 01:47:58 +02:00
initrd/cmdline: split add_conn() from get_conn()
No change in behavior. Will be useful when we'll want to unconditionally add new connection without the matching behavior.
This commit is contained in:
parent
30f8154319
commit
e1a068e93c
1 changed files with 49 additions and 32 deletions
|
|
@ -31,6 +31,49 @@ _connection_matches_type (gpointer key, gpointer value, gpointer user_data)
|
|||
return strcmp (nm_setting_connection_get_connection_type (s_con), type_name) == 0;
|
||||
}
|
||||
|
||||
static NMConnection *
|
||||
add_conn (GHashTable *connections,
|
||||
const char *basename,
|
||||
const char *id,
|
||||
const char *ifname,
|
||||
const char *type_name,
|
||||
NMConnectionMultiConnect multi_connect)
|
||||
{
|
||||
NMConnection *connection;
|
||||
NMSetting *setting;
|
||||
|
||||
connection = nm_simple_connection_new ();
|
||||
g_hash_table_insert (connections, g_strdup (basename), connection);
|
||||
|
||||
/* Start off assuming dynamic IP configurations. */
|
||||
|
||||
setting = nm_setting_ip4_config_new ();
|
||||
nm_connection_add_setting (connection, setting);
|
||||
g_object_set (setting,
|
||||
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
||||
NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
|
||||
NULL);
|
||||
|
||||
setting = nm_setting_ip6_config_new ();
|
||||
nm_connection_add_setting (connection, setting);
|
||||
g_object_set (setting,
|
||||
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
||||
NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
|
||||
NULL);
|
||||
|
||||
setting = nm_setting_connection_new ();
|
||||
nm_connection_add_setting (connection, setting);
|
||||
g_object_set (setting,
|
||||
NM_SETTING_CONNECTION_ID, id,
|
||||
NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (),
|
||||
NM_SETTING_CONNECTION_INTERFACE_NAME, ifname,
|
||||
NM_SETTING_CONNECTION_TYPE, type_name,
|
||||
NM_SETTING_CONNECTION_MULTI_CONNECT, multi_connect,
|
||||
NULL);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
static NMConnection *
|
||||
get_conn (GHashTable *connections, const char *ifname, const char *type_name)
|
||||
{
|
||||
|
|
@ -61,40 +104,15 @@ get_conn (GHashTable *connections, const char *ifname, const char *type_name)
|
|||
(gpointer) type_name);
|
||||
}
|
||||
|
||||
if (connection) {
|
||||
setting = (NMSetting *)nm_connection_get_setting_connection (connection);
|
||||
} else {
|
||||
connection = nm_simple_connection_new ();
|
||||
g_hash_table_insert (connections, g_strdup (basename), connection);
|
||||
|
||||
/* Start off assuming dynamic IP configurations. */
|
||||
|
||||
setting = nm_setting_ip4_config_new ();
|
||||
nm_connection_add_setting (connection, setting);
|
||||
g_object_set (setting,
|
||||
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
||||
NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
|
||||
NULL);
|
||||
|
||||
setting = nm_setting_ip6_config_new ();
|
||||
nm_connection_add_setting (connection, setting);
|
||||
g_object_set (setting,
|
||||
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
||||
NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
|
||||
NULL);
|
||||
|
||||
setting = nm_setting_connection_new ();
|
||||
nm_connection_add_setting (connection, setting);
|
||||
g_object_set (setting,
|
||||
NM_SETTING_CONNECTION_ID, ifname ?: "Wired Connection",
|
||||
NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (),
|
||||
NM_SETTING_CONNECTION_INTERFACE_NAME, ifname,
|
||||
NM_SETTING_CONNECTION_MULTI_CONNECT, multi_connect,
|
||||
NULL);
|
||||
|
||||
if (!connection) {
|
||||
if (!type_name)
|
||||
type_name = NM_SETTING_WIRED_SETTING_NAME;
|
||||
|
||||
connection = add_conn (connections, basename,
|
||||
ifname ?: "Wired Connection",
|
||||
ifname, type_name, multi_connect);
|
||||
}
|
||||
setting = (NMSetting *)nm_connection_get_setting_connection (connection);
|
||||
|
||||
if (type_name) {
|
||||
g_object_set (setting, NM_SETTING_CONNECTION_TYPE, type_name, NULL);
|
||||
|
|
@ -849,7 +867,6 @@ nmi_cmdline_reader_parse (const char *sysfs_dir, const char *const*argv)
|
|||
}
|
||||
|
||||
connection = get_conn (connections, NULL, NM_SETTING_WIRED_SETTING_NAME);
|
||||
|
||||
s_wired = nm_connection_get_setting_wired (connection);
|
||||
g_object_set (s_wired,
|
||||
NM_SETTING_WIRED_MAC_ADDRESS, bootif,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue