utils: add ifname argument to nm_utils_complete_generic()

It's a common thing to complete a connection with an interface name;
adding it to the common path is goint to save as a few tens of lines
later on.
This commit is contained in:
Lubomir Rintel 2019-05-07 10:15:10 +02:00
parent 27eb2b2f97
commit 28a39eda44
23 changed files with 31 additions and 4 deletions

View file

@ -249,13 +249,15 @@ nm_utils_complete_generic (NMPlatform *platform,
const char *preferred_id,
const char *fallback_id_prefix,
const char *ifname_prefix,
const char *ifname,
gboolean default_enable_ipv6)
{
NMSettingConnection *s_con;
char *id, *ifname;
char *id, *generated_ifname;
GHashTable *parameters;
g_assert (fallback_id_prefix);
g_return_if_fail (ifname_prefix == NULL || ifname == NULL);
s_con = nm_connection_get_setting_connection (connection);
if (!s_con) {
@ -278,10 +280,12 @@ nm_utils_complete_generic (NMPlatform *platform,
}
/* Add an interface name, if requested */
if (ifname_prefix && !nm_setting_connection_get_interface_name (s_con)) {
ifname = get_new_connection_ifname (platform, existing_connections, ifname_prefix);
if (ifname) {
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_INTERFACE_NAME, ifname, NULL);
g_free (ifname);
} else if (ifname_prefix && !nm_setting_connection_get_interface_name (s_con)) {
generated_ifname = get_new_connection_ifname (platform, existing_connections, ifname_prefix);
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_INTERFACE_NAME, generated_ifname, NULL);
g_free (generated_ifname);
}
/* Normalize */

View file

@ -41,6 +41,7 @@ void nm_utils_complete_generic (NMPlatform *platform,
const char *preferred_id,
const char *fallback_id_prefix,
const char *ifname_prefix,
const char *ifname,
gboolean default_enable_ipv6);
typedef gboolean (NMUtilsMatchFilterFunc) (NMConnection *connection, gpointer user_data);

View file

@ -131,6 +131,7 @@ complete_connection (NMDevice *device,
NULL,
_("ADSL connection"),
NULL,
NULL,
FALSE); /* No IPv6 yet by default */
return TRUE;
}

View file

@ -341,6 +341,7 @@ complete_connection (NMDevice *device,
preferred,
fallback_prefix,
NULL,
NULL,
is_dun ? FALSE : TRUE); /* No IPv6 yet for DUN */
setting_bdaddr = nm_setting_bluetooth_get_bdaddr (s_bt);

View file

@ -190,6 +190,7 @@ complete_connection (NMDevice *device,
NULL,
_("6LOWPAN connection"),
NULL,
NULL,
TRUE);
s_6lowpan = NM_SETTING_6LOWPAN (nm_connection_get_setting (connection, NM_TYPE_SETTING_6LOWPAN));

View file

@ -70,6 +70,7 @@ complete_connection (NMDevice *device,
NULL,
_("Bond connection"),
"bond",
NULL,
TRUE);
s_bond = nm_connection_get_setting_bond (connection);

View file

@ -153,6 +153,7 @@ complete_connection (NMDevice *device,
NULL,
_("Bridge connection"),
"bridge",
NULL,
TRUE);
s_bridge = nm_connection_get_setting_bridge (connection);

View file

@ -66,6 +66,7 @@ complete_connection (NMDevice *device,
NULL,
_("Dummy connection"),
NULL,
NULL,
TRUE);
s_dummy = nm_connection_get_setting_dummy (connection);

View file

@ -1411,6 +1411,7 @@ complete_connection (NMDevice *device,
NULL,
s_pppoe ? _("PPPoE connection") : _("Wired connection"),
NULL,
NULL,
s_pppoe ? FALSE : TRUE); /* No IPv6 by default yet for PPPoE */
s_wired = nm_connection_get_setting_wired (connection);

View file

@ -169,6 +169,7 @@ complete_connection (NMDevice *device,
NULL,
_("InfiniBand connection"),
NULL,
NULL,
TRUE);
s_infiniband = nm_connection_get_setting_infiniband (connection);

View file

@ -421,6 +421,7 @@ complete_connection (NMDevice *device,
NULL,
_("IP tunnel connection"),
NULL,
NULL,
TRUE);
s_ip_tunnel = nm_connection_get_setting_ip_tunnel (connection);

View file

@ -364,6 +364,7 @@ complete_connection (NMDevice *device,
NULL,
_("MACVLAN connection"),
NULL,
NULL,
TRUE);
s_macvlan = nm_connection_get_setting_macvlan (connection);

View file

@ -156,6 +156,7 @@ complete_connection (NMDevice *device,
NULL,
_("TUN connection"),
NULL,
NULL,
TRUE);
s_tun = nm_connection_get_setting_tun (connection);

View file

@ -399,6 +399,7 @@ complete_connection (NMDevice *device,
NULL,
_("VLAN connection"),
NULL,
NULL,
TRUE);
s_vlan = nm_connection_get_setting_vlan (connection);

View file

@ -368,6 +368,7 @@ complete_connection (NMDevice *device,
NULL,
_("VXLAN connection"),
NULL,
NULL,
TRUE);
s_vxlan = nm_connection_get_setting_vxlan (connection);

View file

@ -67,6 +67,7 @@ complete_connection (NMDevice *device,
NULL,
_("WPAN connection"),
NULL,
NULL,
TRUE);
s_wpan = NM_SETTING_WPAN (nm_connection_get_setting (connection, NM_TYPE_SETTING_WPAN));

View file

@ -101,6 +101,7 @@ complete_connection (NMDevice *device,
NULL,
_("Team connection"),
"team",
NULL,
TRUE);
s_team = nm_connection_get_setting_team (connection);

View file

@ -874,6 +874,7 @@ complete_connection (NMDevice *device,
ssid_utf8,
ssid_utf8,
NULL,
NULL,
TRUE);
perm_hw_addr = nm_device_get_permanent_hw_address (device);

View file

@ -133,6 +133,7 @@ complete_connection (NMDevice *device,
NULL,
_("Mesh"),
NULL,
NULL,
FALSE); /* No IPv6 by default */
return TRUE;

View file

@ -331,6 +331,7 @@ complete_connection (NMDevice *device,
setting_name,
setting_name,
NULL,
NULL,
TRUE);
return TRUE;

View file

@ -906,6 +906,7 @@ complete_connection (NMDevice *device,
ssid_utf8,
ssid_utf8,
NULL,
NULL,
TRUE);
if (hidden)

View file

@ -701,6 +701,7 @@ complete_connection (NMModem *modem,
NULL,
_("GSM connection"),
NULL,
NULL,
FALSE); /* No IPv6 yet by default */
return TRUE;
@ -725,6 +726,7 @@ complete_connection (NMModem *modem,
NULL,
_("CDMA connection"),
NULL,
NULL,
FALSE); /* No IPv6 yet by default */
return TRUE;

View file

@ -5517,6 +5517,7 @@ impl_manager_add_and_activate_connection (NMDBusObject *obj,
NULL,
_("VPN connection"),
NULL,
NULL,
FALSE); /* No IPv6 by default for now */
} else {
conns = nm_settings_connections_array_to_connections (nm_settings_get_connections (priv->settings, NULL), -1);