Blame clients/tui/nm-editor-utils.c

Packit Service a1bd4f
/* SPDX-License-Identifier: GPL-2.0+ */
Packit 5756e2
/*
Packit 5756e2
 * Copyright (C) 2012, 2013 Red Hat, Inc.
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * SECTION:nm-editor-utils
Packit 5756e2
 * @short_description: Miscellaneous connection editor utilities
Packit 5756e2
 *
Packit 5756e2
 * nm-editor-utils contains helper functions for connection editors.
Packit 5756e2
 * The goal is that this should eventually be shared between nmtui,
Packit 5756e2
 * nm-connection-editor, and gnome-control-center.
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
#include "nm-default.h"
Packit 5756e2
Packit 5756e2
#include "nm-editor-utils.h"
Packit 5756e2
#if 0
Packit Service a1bd4f
    #include "nm-vpn-helpers.h"
Packit 5756e2
Packit 5756e2
static GSList *vpn_plugins;
Packit 5756e2
Packit 5756e2
static int
Packit 5756e2
sort_vpn_plugins (gconstpointer a, gconstpointer b)
Packit 5756e2
{
Packit Service a1bd4f
    NMVpnEditorPlugin *aa = NM_VPN_EDITOR_PLUGIN (a);
Packit Service a1bd4f
    NMVpnEditorPlugin *bb = NM_VPN_EDITOR_PLUGIN (b);
Packit Service a1bd4f
    char *aa_desc = NULL, *bb_desc = NULL;
Packit Service a1bd4f
    int ret;
Packit 5756e2
Packit Service a1bd4f
    g_object_get (aa, NM_VPN_EDITOR_PLUGIN_NAME, &aa_desc, NULL);
Packit Service a1bd4f
    g_object_get (bb, NM_VPN_EDITOR_PLUGIN_NAME, &bb_desc, NULL);
Packit 5756e2
Packit Service a1bd4f
    ret = g_strcmp0 (aa_desc, bb_desc);
Packit 5756e2
Packit Service a1bd4f
    g_free (aa_desc);
Packit Service a1bd4f
    g_free (bb_desc);
Packit 5756e2
Packit Service a1bd4f
    return ret;
Packit 5756e2
}
Packit 5756e2
#endif
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
wifi_connection_setup_func(NMConnection *connection, NMSettingConnection *s_con, NMSetting *s_hw)
Packit 5756e2
{
Packit Service a1bd4f
    g_object_set(G_OBJECT(s_hw), NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_INFRA, NULL);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
bond_connection_setup_func(NMConnection *connection, NMSettingConnection *s_con, NMSetting *s_hw)
Packit 5756e2
{
Packit Service a1bd4f
    NMSettingBond *          s_bond = NM_SETTING_BOND(s_hw);
Packit Service a1bd4f
    guint                    i;
Packit Service a1bd4f
    const char *             value;
Packit Service a1bd4f
    static const char *const options[] = {
Packit Service a1bd4f
        NM_SETTING_BOND_OPTION_MODE,
Packit Service a1bd4f
        NM_SETTING_BOND_OPTION_MIIMON,
Packit Service a1bd4f
        NM_SETTING_BOND_OPTION_DOWNDELAY,
Packit Service a1bd4f
        NM_SETTING_BOND_OPTION_UPDELAY,
Packit Service a1bd4f
    };
Packit Service a1bd4f
Packit Service a1bd4f
    for (i = 0; i < G_N_ELEMENTS(options); i++) {
Packit Service a1bd4f
        value = nm_setting_bond_get_option_default(s_bond, options[i]);
Packit Service a1bd4f
        if (value)
Packit Service a1bd4f
            nm_setting_bond_add_option(s_bond, options[i], value);
Packit Service a1bd4f
    }
Packit 5756e2
}
Packit 5756e2
Packit Service a1bd4f
typedef void (*NMEditorNewConnectionSetupFunc)(NMConnection *       connection,
Packit Service a1bd4f
                                               NMSettingConnection *s_con,
Packit Service a1bd4f
                                               NMSetting *          s_hw);
Packit 5756e2
Packit 5756e2
typedef struct {
Packit Service a1bd4f
    NMEditorConnectionTypeData data;
Packit 5756e2
Packit Service a1bd4f
    const char *                   id_format;
Packit Service a1bd4f
    NMEditorNewConnectionSetupFunc connection_setup_func;
Packit Service a1bd4f
    gboolean                       no_autoconnect;
Packit 5756e2
} NMEditorConnectionTypeDataReal;
Packit 5756e2
Packit 5756e2
static int
Packit Service a1bd4f
sort_types(gconstpointer a, gconstpointer b)
Packit 5756e2
{
Packit Service a1bd4f
    NMEditorConnectionTypeData *typea = *(NMEditorConnectionTypeData **) a;
Packit Service a1bd4f
    NMEditorConnectionTypeData *typeb = *(NMEditorConnectionTypeData **) b;
Packit Service a1bd4f
Packit Service a1bd4f
    if (typea->virtual && !typeb->virtual)
Packit Service a1bd4f
        return 1;
Packit Service a1bd4f
    else if (typeb->virtual && !typea->virtual)
Packit Service a1bd4f
        return -1;
Packit Service a1bd4f
Packit Service a1bd4f
    if (typea->setting_type == NM_TYPE_SETTING_VPN && typeb->setting_type != NM_TYPE_SETTING_VPN)
Packit Service a1bd4f
        return 1;
Packit Service a1bd4f
    else if (typeb->setting_type == NM_TYPE_SETTING_VPN
Packit Service a1bd4f
             && typea->setting_type != NM_TYPE_SETTING_VPN)
Packit Service a1bd4f
        return -1;
Packit Service a1bd4f
Packit Service a1bd4f
    return g_utf8_collate(typea->name, typeb->name);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nm_editor_utils_get_connection_type_list:
Packit 5756e2
 *
Packit 5756e2
 * Gets an array of information about supported connection types. The
Packit 5756e2
 * array is sorted in a standard presentation order (hardware types
Packit 5756e2
 * first, alphabetized, then virtual types, alphabetized, then VPN
Packit 5756e2
 * types, alphabetized).
Packit 5756e2
 *
Packit 5756e2
 * Returns: the array of connection type information
Packit 5756e2
 */
Packit 5756e2
NMEditorConnectionTypeData **
Packit Service a1bd4f
nm_editor_utils_get_connection_type_list(void)
Packit 5756e2
{
Packit Service a1bd4f
    GPtrArray *                         array;
Packit Service a1bd4f
    NMEditorConnectionTypeDataReal *    item;
Packit Service a1bd4f
    static NMEditorConnectionTypeData **list;
Packit 5756e2
#if 0
Packit Service a1bd4f
    GHashTable *vpn_plugins_hash;
Packit Service a1bd4f
    gboolean have_vpn_plugins;
Packit 5756e2
#endif
Packit 5756e2
Packit Service a1bd4f
    if (list)
Packit Service a1bd4f
        return list;
Packit Service a1bd4f
Packit Service a1bd4f
    array = g_ptr_array_new();
Packit Service a1bd4f
Packit Service a1bd4f
    item                    = g_new0(NMEditorConnectionTypeDataReal, 1);
Packit Service a1bd4f
    item->data.name         = _("Ethernet");
Packit Service a1bd4f
    item->data.setting_type = NM_TYPE_SETTING_WIRED;
Packit Service a1bd4f
    item->data.device_type  = NM_TYPE_DEVICE_ETHERNET;
Packit Service a1bd4f
    item->data.virtual      = FALSE;
Packit Service a1bd4f
    item->id_format         = _("Ethernet connection %d");
Packit Service a1bd4f
    g_ptr_array_add(array, item);
Packit Service a1bd4f
Packit Service d0b836
    item                    = g_new0(NMEditorConnectionTypeDataReal, 1);
Packit Service d0b836
    item->data.name         = _("Veth");
Packit Service d0b836
    item->data.setting_type = NM_TYPE_SETTING_VETH;
Packit Service d0b836
    item->data.device_type  = NM_TYPE_DEVICE_VETH;
Packit Service d0b836
    item->data.virtual      = TRUE;
Packit Service d0b836
    item->id_format         = _("Veth connection %d");
Packit Service d0b836
    g_ptr_array_add(array, item);
Packit Service d0b836
Packit Service a1bd4f
    item                        = g_new0(NMEditorConnectionTypeDataReal, 1);
Packit Service a1bd4f
    item->data.name             = _("Wi-Fi");
Packit Service a1bd4f
    item->data.setting_type     = NM_TYPE_SETTING_WIRELESS;
Packit Service a1bd4f
    item->data.device_type      = NM_TYPE_DEVICE_WIFI;
Packit Service a1bd4f
    item->data.virtual          = FALSE;
Packit Service a1bd4f
    item->id_format             = _("Wi-Fi connection %d");
Packit Service a1bd4f
    item->connection_setup_func = wifi_connection_setup_func;
Packit Service a1bd4f
    g_ptr_array_add(array, item);
Packit Service a1bd4f
Packit Service a1bd4f
    item                    = g_new0(NMEditorConnectionTypeDataReal, 1);
Packit Service a1bd4f
    item->data.name         = _("InfiniBand");
Packit Service a1bd4f
    item->data.setting_type = NM_TYPE_SETTING_INFINIBAND;
Packit Service a1bd4f
    item->data.device_type  = NM_TYPE_DEVICE_INFINIBAND;
Packit Service a1bd4f
    item->data.virtual      = FALSE;
Packit Service a1bd4f
    item->id_format         = _("InfiniBand connection %d");
Packit Service a1bd4f
    g_ptr_array_add(array, item);
Packit 5756e2
Packit 5756e2
#if 0
Packit Service a1bd4f
    item = g_new0 (NMEditorConnectionTypeDataReal, 1);
Packit Service a1bd4f
    item->data.name = _("Mobile Broadband");
Packit Service a1bd4f
    item->data.setting_type = NM_TYPE_SETTING_GSM;
Packit Service a1bd4f
    item->data.virtual = FALSE;
Packit Service a1bd4f
    item->id_format = _("Mobile broadband connection %d");
Packit Service a1bd4f
    item->no_autoconnect = TRUE;
Packit Service a1bd4f
    g_ptr_array_add (array, item);
Packit 5756e2
#endif
Packit 5756e2
Packit Service a1bd4f
    item                    = g_new0(NMEditorConnectionTypeDataReal, 1);
Packit Service a1bd4f
    item->data.name         = _("DSL");
Packit Service a1bd4f
    item->data.setting_type = NM_TYPE_SETTING_PPPOE;
Packit Service a1bd4f
    item->data.device_type  = NM_TYPE_DEVICE_ETHERNET;
Packit Service a1bd4f
    item->data.virtual      = FALSE;
Packit Service a1bd4f
    item->id_format         = _("DSL connection %d");
Packit Service a1bd4f
    item->no_autoconnect    = TRUE;
Packit Service a1bd4f
    g_ptr_array_add(array, item);
Packit Service a1bd4f
Packit Service a1bd4f
    item                        = g_new0(NMEditorConnectionTypeDataReal, 1);
Packit Service a1bd4f
    item->data.name             = _("Bond");
Packit Service a1bd4f
    item->data.setting_type     = NM_TYPE_SETTING_BOND;
Packit Service a1bd4f
    item->data.device_type      = NM_TYPE_DEVICE_BOND;
Packit Service a1bd4f
    item->data.virtual          = TRUE;
Packit Service a1bd4f
    item->id_format             = _("Bond connection %d");
Packit Service a1bd4f
    item->connection_setup_func = bond_connection_setup_func;
Packit Service a1bd4f
    g_ptr_array_add(array, item);
Packit Service a1bd4f
Packit Service a1bd4f
    item                          = g_new0(NMEditorConnectionTypeDataReal, 1);
Packit Service a1bd4f
    item->data.name               = _("Bridge");
Packit Service a1bd4f
    item->data.setting_type       = NM_TYPE_SETTING_BRIDGE;
Packit Service a1bd4f
    item->data.slave_setting_type = NM_TYPE_SETTING_BRIDGE_PORT;
Packit Service a1bd4f
    item->data.device_type        = NM_TYPE_DEVICE_BRIDGE;
Packit Service a1bd4f
    item->data.virtual            = TRUE;
Packit Service a1bd4f
    item->id_format               = _("Bridge connection %d");
Packit Service a1bd4f
    g_ptr_array_add(array, item);
Packit Service a1bd4f
Packit Service a1bd4f
    item                          = g_new0(NMEditorConnectionTypeDataReal, 1);
Packit Service a1bd4f
    item->data.name               = _("Team");
Packit Service a1bd4f
    item->data.setting_type       = NM_TYPE_SETTING_TEAM;
Packit Service a1bd4f
    item->data.slave_setting_type = NM_TYPE_SETTING_TEAM_PORT;
Packit Service a1bd4f
    item->data.device_type        = NM_TYPE_DEVICE_TEAM;
Packit Service a1bd4f
    item->data.virtual            = TRUE;
Packit Service a1bd4f
    item->id_format               = _("Team connection %d");
Packit Service a1bd4f
    g_ptr_array_add(array, item);
Packit Service a1bd4f
Packit Service a1bd4f
    item                    = g_new0(NMEditorConnectionTypeDataReal, 1);
Packit Service a1bd4f
    item->data.name         = _("VLAN");
Packit Service a1bd4f
    item->data.setting_type = NM_TYPE_SETTING_VLAN;
Packit Service a1bd4f
    item->data.device_type  = NM_TYPE_DEVICE_VLAN;
Packit Service a1bd4f
    item->data.virtual      = TRUE;
Packit Service a1bd4f
    item->id_format         = _("VLAN connection %d");
Packit Service a1bd4f
    g_ptr_array_add(array, item);
Packit Service a1bd4f
Packit Service a1bd4f
    item                    = g_new0(NMEditorConnectionTypeDataReal, 1);
Packit Service a1bd4f
    item->data.name         = _("IP tunnel");
Packit Service a1bd4f
    item->data.setting_type = NM_TYPE_SETTING_IP_TUNNEL;
Packit Service a1bd4f
    item->data.device_type  = NM_TYPE_DEVICE_IP_TUNNEL;
Packit Service a1bd4f
    item->data.virtual      = TRUE;
Packit Service a1bd4f
    item->id_format         = _("IP tunnel connection %d");
Packit Service a1bd4f
    g_ptr_array_add(array, item);
Packit 5756e2
Packit 5756e2
#if 0
Packit Service a1bd4f
    /* Add "VPN" only if there are plugins */
Packit Service a1bd4f
    vpn_plugins_hash = nm_vpn_get_plugin_infos ();
Packit Service a1bd4f
    have_vpn_plugins  = vpn_plugins_hash && g_hash_table_size (vpn_plugins_hash);
Packit Service a1bd4f
    if (have_vpn_plugins) {
Packit Service a1bd4f
        GHashTableIter iter;
Packit Service a1bd4f
        gpointer name, plugin;
Packit Service a1bd4f
Packit Service a1bd4f
        item = g_new0 (NMEditorConnectionTypeDataReal, 1);
Packit Service a1bd4f
        item->data.name = _("VPN");
Packit Service a1bd4f
        item->data.setting_type = NM_TYPE_SETTING_VPN;
Packit Service a1bd4f
        item->data.virtual = TRUE;
Packit Service a1bd4f
        item->id_format = _("VPN connection %d");
Packit Service a1bd4f
        item->no_autoconnect = TRUE;
Packit Service a1bd4f
        g_ptr_array_add (array, item);
Packit Service a1bd4f
Packit Service a1bd4f
        vpn_plugins = NULL;
Packit Service a1bd4f
        g_hash_table_iter_init (&iter, vpn_plugins_hash);
Packit Service a1bd4f
        while (g_hash_table_iter_next (&iter, &name, &plugin))
Packit Service a1bd4f
            vpn_plugins = g_slist_prepend (vpn_plugins, plugin);
Packit Service a1bd4f
        vpn_plugins = g_slist_sort (vpn_plugins, sort_vpn_plugins);
Packit Service a1bd4f
    }
Packit 5756e2
#endif
Packit 5756e2
Packit Service a1bd4f
    g_ptr_array_sort(array, sort_types);
Packit Service a1bd4f
    g_ptr_array_add(array, NULL);
Packit 5756e2
Packit Service a1bd4f
    list = (NMEditorConnectionTypeData **) g_ptr_array_free(array, FALSE);
Packit Service a1bd4f
    return list;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static gboolean
Packit Service a1bd4f
_assert_format_int(const char *format)
Packit 5756e2
{
Packit Service a1bd4f
    g_assert(format);
Packit Service a1bd4f
    format = strchr(format, '%');
Packit Service a1bd4f
    g_assert(format);
Packit Service a1bd4f
    format++;
Packit Service a1bd4f
    g_assert(!strchr(format, '%'));
Packit Service a1bd4f
    g_assert(format[0] == 'd');
Packit Service a1bd4f
    return TRUE;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static char *
Packit Service a1bd4f
get_available_connection_name(const char *format, NMClient *client)
Packit 5756e2
{
Packit Service a1bd4f
    const GPtrArray *conns;
Packit Service a1bd4f
    GSList *         names = NULL, *iter;
Packit Service a1bd4f
    char *           cname = NULL;
Packit Service a1bd4f
    int              i     = 0;
Packit Service a1bd4f
Packit Service a1bd4f
    nm_assert(_assert_format_int(format));
Packit Service a1bd4f
Packit Service a1bd4f
    conns = nm_client_get_connections(client);
Packit Service a1bd4f
    for (i = 0; i < conns->len; i++) {
Packit Service a1bd4f
        const char *id;
Packit Service a1bd4f
Packit Service a1bd4f
        id = nm_connection_get_id(NM_CONNECTION(conns->pdata[i]));
Packit Service a1bd4f
        g_assert(id);
Packit Service a1bd4f
        names = g_slist_append(names, (gpointer) id);
Packit Service a1bd4f
    }
Packit Service a1bd4f
Packit Service a1bd4f
    /* Find the next available unique connection name */
Packit Service a1bd4f
    for (i = 1; !cname && i < 10000; i++) {
Packit Service a1bd4f
        char *   temp;
Packit Service a1bd4f
        gboolean found = FALSE;
Packit Service a1bd4f
Packit Service a1bd4f
        NM_PRAGMA_WARNING_DISABLE("-Wformat-nonliteral")
Packit Service a1bd4f
        temp = g_strdup_printf(format, i);
Packit Service a1bd4f
        NM_PRAGMA_WARNING_REENABLE
Packit Service a1bd4f
        for (iter = names; iter; iter = g_slist_next(iter)) {
Packit Service a1bd4f
            if (!strcmp(iter->data, temp)) {
Packit Service a1bd4f
                found = TRUE;
Packit Service a1bd4f
                break;
Packit Service a1bd4f
            }
Packit Service a1bd4f
        }
Packit Service a1bd4f
        if (!found)
Packit Service a1bd4f
            cname = temp;
Packit Service a1bd4f
        else
Packit Service a1bd4f
            g_free(temp);
Packit Service a1bd4f
    }
Packit Service a1bd4f
Packit Service a1bd4f
    g_slist_free(names);
Packit Service a1bd4f
    return cname;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static char *
Packit Service a1bd4f
get_available_iface_name(const char *try_name, NMClient *client)
Packit 5756e2
{
Packit Service a1bd4f
    const GPtrArray *connections;
Packit Service a1bd4f
    NMConnection *   connection;
Packit Service a1bd4f
    char *           new_name;
Packit Service a1bd4f
    unsigned         num    = 1;
Packit Service a1bd4f
    int              i      = 0;
Packit Service a1bd4f
    const char *     ifname = NULL;
Packit Service a1bd4f
Packit Service a1bd4f
    connections = nm_client_get_connections(client);
Packit Service a1bd4f
Packit Service a1bd4f
    new_name = g_strdup(try_name);
Packit Service a1bd4f
    while (i < connections->len) {
Packit Service a1bd4f
        connection = NM_CONNECTION(connections->pdata[i]);
Packit Service a1bd4f
        ifname     = nm_connection_get_interface_name(connection);
Packit Service a1bd4f
        if (g_strcmp0(new_name, ifname) == 0) {
Packit Service a1bd4f
            g_free(new_name);
Packit Service a1bd4f
            new_name = g_strdup_printf("%s%d", try_name, num++);
Packit Service a1bd4f
            i        = 0;
Packit Service a1bd4f
        } else
Packit Service a1bd4f
            i++;
Packit Service a1bd4f
    }
Packit Service a1bd4f
    return new_name;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nm_editor_utils_create_connection:
Packit 5756e2
 * @type: the type of the connection's primary #NMSetting
Packit 5756e2
 * @master: (allow-none): the connection's master, if any
Packit 5756e2
 * @client: an #NMClient
Packit 5756e2
 *
Packit 5756e2
 * Creates a new #NMConnection of the given type, automatically
Packit 5756e2
 * creating a UUID and an appropriate not-currently-in-use connection
Packit 5756e2
 * name, setting #NMSettingConnection:autoconnect appropriately for
Packit 5756e2
 * the connection type, filling in slave-related information if
Packit 5756e2
 * @master is not %NULL, and initializing any other mandatory-to-set
Packit 5756e2
 * properties to reasonable initial values.
Packit 5756e2
 *
Packit 5756e2
 * Returns: a new #NMConnection
Packit 5756e2
 */
Packit 5756e2
NMConnection *
Packit Service a1bd4f
nm_editor_utils_create_connection(GType type, NMConnection *master, NMClient *client)
Packit 5756e2
{
Packit Service a1bd4f
    NMEditorConnectionTypeData **   types;
Packit Service a1bd4f
    NMEditorConnectionTypeDataReal *type_data           = NULL;
Packit Service a1bd4f
    const char *                    master_setting_type = NULL, *master_uuid = NULL;
Packit Service a1bd4f
    GType                master_type = G_TYPE_INVALID, slave_setting_type = G_TYPE_INVALID;
Packit Service a1bd4f
    NMConnection *       connection;
Packit Service a1bd4f
    NMSettingConnection *s_con;
Packit Service a1bd4f
    NMSetting *          s_hw, *s_slave;
Packit Service a1bd4f
    char *               uuid, *id, *ifname;
Packit Service a1bd4f
    int                  i;
Packit Service a1bd4f
Packit Service a1bd4f
    if (master) {
Packit Service a1bd4f
        NMSettingConnection *master_s_con;
Packit Service a1bd4f
Packit Service a1bd4f
        master_s_con        = nm_connection_get_setting_connection(master);
Packit Service a1bd4f
        master_setting_type = nm_setting_connection_get_connection_type(master_s_con);
Packit Service a1bd4f
        master_uuid         = nm_setting_connection_get_uuid(master_s_con);
Packit Service a1bd4f
        master_type         = nm_setting_lookup_type(master_setting_type);
Packit Service a1bd4f
    }
Packit Service a1bd4f
Packit Service a1bd4f
    types = nm_editor_utils_get_connection_type_list();
Packit Service a1bd4f
    for (i = 0; types[i]; i++) {
Packit Service a1bd4f
        if (types[i]->setting_type == type)
Packit Service a1bd4f
            type_data = (NMEditorConnectionTypeDataReal *) types[i];
Packit Service a1bd4f
        if (types[i]->setting_type == master_type)
Packit Service a1bd4f
            slave_setting_type = types[i]->slave_setting_type;
Packit Service a1bd4f
    }
Packit Service a1bd4f
    if (!type_data) {
Packit Service a1bd4f
        g_return_val_if_reached(NULL);
Packit Service a1bd4f
        return NULL;
Packit Service a1bd4f
    }
Packit Service a1bd4f
Packit Service a1bd4f
    connection = nm_simple_connection_new();
Packit Service a1bd4f
Packit Service a1bd4f
    s_con = NM_SETTING_CONNECTION(nm_setting_connection_new());
Packit Service a1bd4f
    nm_connection_add_setting(connection, NM_SETTING(s_con));
Packit Service a1bd4f
Packit Service a1bd4f
    s_hw = g_object_new(type, NULL);
Packit Service a1bd4f
    nm_connection_add_setting(connection, s_hw);
Packit Service a1bd4f
Packit Service a1bd4f
    if (type == NM_TYPE_SETTING_BOND)
Packit Service a1bd4f
        ifname = get_available_iface_name("nm-bond", client);
Packit Service a1bd4f
    else if (type == NM_TYPE_SETTING_TEAM)
Packit Service a1bd4f
        ifname = get_available_iface_name("nm-team", client);
Packit Service a1bd4f
    else if (type == NM_TYPE_SETTING_BRIDGE)
Packit Service a1bd4f
        ifname = get_available_iface_name("nm-bridge", client);
Packit Service a1bd4f
    else
Packit Service a1bd4f
        ifname = NULL;
Packit Service a1bd4f
Packit Service a1bd4f
    if (slave_setting_type != G_TYPE_INVALID) {
Packit Service a1bd4f
        s_slave = g_object_new(slave_setting_type, NULL);
Packit Service a1bd4f
        nm_connection_add_setting(connection, s_slave);
Packit Service a1bd4f
    }
Packit Service a1bd4f
Packit Service a1bd4f
    uuid = nm_utils_uuid_generate();
Packit Service a1bd4f
    id   = get_available_connection_name(type_data->id_format, client);
Packit Service a1bd4f
Packit Service a1bd4f
    g_object_set(s_con,
Packit Service a1bd4f
                 NM_SETTING_CONNECTION_UUID,
Packit Service a1bd4f
                 uuid,
Packit Service a1bd4f
                 NM_SETTING_CONNECTION_ID,
Packit Service a1bd4f
                 id,
Packit Service a1bd4f
                 NM_SETTING_CONNECTION_TYPE,
Packit Service a1bd4f
                 nm_setting_get_name(s_hw),
Packit Service a1bd4f
                 NM_SETTING_CONNECTION_AUTOCONNECT,
Packit Service a1bd4f
                 !type_data->no_autoconnect,
Packit Service a1bd4f
                 NM_SETTING_CONNECTION_MASTER,
Packit Service a1bd4f
                 master_uuid,
Packit Service a1bd4f
                 NM_SETTING_CONNECTION_SLAVE_TYPE,
Packit Service a1bd4f
                 master_setting_type,
Packit Service a1bd4f
                 NM_SETTING_CONNECTION_INTERFACE_NAME,
Packit Service a1bd4f
                 ifname,
Packit Service a1bd4f
                 NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    g_free(uuid);
Packit Service a1bd4f
    g_free(id);
Packit Service a1bd4f
    g_free(ifname);
Packit Service a1bd4f
Packit Service a1bd4f
    if (type_data->connection_setup_func)
Packit Service a1bd4f
        type_data->connection_setup_func(connection, s_con, s_hw);
Packit Service a1bd4f
Packit Service a1bd4f
    return connection;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nm_editor_utils_get_connection_type_data:
Packit 5756e2
 * @conn: an #NMConnection
Packit 5756e2
 *
Packit 5756e2
 * Gets the #NMEditorConnectionTypeData corresponding to
Packit 5756e2
 * @conn's connection type.
Packit 5756e2
 *
Packit 5756e2
 * Returns: the #NMEditorConnectionTypeData
Packit 5756e2
 */
Packit 5756e2
NMEditorConnectionTypeData *
Packit Service a1bd4f
nm_editor_utils_get_connection_type_data(NMConnection *conn)
Packit 5756e2
{
Packit Service a1bd4f
    NMSettingConnection *        s_con;
Packit Service a1bd4f
    const char *                 conn_type;
Packit Service a1bd4f
    GType                        conn_gtype;
Packit Service a1bd4f
    NMEditorConnectionTypeData **types;
Packit Service a1bd4f
    int                          i;
Packit Service a1bd4f
Packit Service a1bd4f
    s_con = nm_connection_get_setting_connection(conn);
Packit Service a1bd4f
    g_return_val_if_fail(s_con != NULL, NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    conn_type  = nm_setting_connection_get_connection_type(s_con);
Packit Service a1bd4f
    conn_gtype = nm_setting_lookup_type(conn_type);
Packit Service a1bd4f
    g_return_val_if_fail(conn_gtype != G_TYPE_INVALID, NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    types = nm_editor_utils_get_connection_type_list();
Packit Service a1bd4f
    for (i = 0; types[i]; i++) {
Packit Service a1bd4f
        if (types[i]->setting_type == conn_gtype)
Packit Service a1bd4f
            return types[i];
Packit Service a1bd4f
    }
Packit Service a1bd4f
Packit Service a1bd4f
    return NULL;
Packit 5756e2
}