device: simplify the nm_utils_complete_generic() machinery
The point is to get rid of device/connection type specific arguments, to eventually be able to complete the connection on AddAndActivate before knowing which factory is going to take care of creating the device. Aside from that, the whole thing is pretty awful -- with complicated macros and variadic argument (ugh). Let's get rid of that.
This commit is contained in:
@@ -250,23 +250,19 @@ nm_utils_ppp_ip_methods_enabled(NMConnection *connection,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
void
|
void
|
||||||
_nm_utils_complete_generic_with_params(NMPlatform *platform,
|
nm_utils_complete_generic(NMPlatform *platform,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
const char *ctype,
|
const char *ctype,
|
||||||
NMConnection *const *existing_connections,
|
NMConnection *const *existing_connections,
|
||||||
const char *preferred_id,
|
const char *preferred_id,
|
||||||
const char *fallback_id_prefix,
|
const char *fallback_id_prefix,
|
||||||
const char *ifname_prefix,
|
const char *ifname_prefix,
|
||||||
const char *ifname,
|
const char *ifname)
|
||||||
...)
|
|
||||||
{
|
{
|
||||||
NMSettingConnection *s_con;
|
NMSettingConnection *s_con;
|
||||||
char *id;
|
char *id;
|
||||||
char *generated_ifname;
|
char *generated_ifname;
|
||||||
gs_unref_hashtable GHashTable *parameters = NULL;
|
gs_unref_hashtable GHashTable *parameters = NULL;
|
||||||
va_list ap;
|
|
||||||
const char *p_val;
|
|
||||||
const char *p_key;
|
|
||||||
|
|
||||||
g_assert(fallback_id_prefix);
|
g_assert(fallback_id_prefix);
|
||||||
g_return_if_fail(ifname_prefix == NULL || ifname == NULL);
|
g_return_if_fail(ifname_prefix == NULL || ifname == NULL);
|
||||||
@@ -301,20 +297,22 @@ _nm_utils_complete_generic_with_params(NMPlatform *platform,
|
|||||||
g_free(generated_ifname);
|
g_free(generated_ifname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Normalize */
|
if (nm_connection_get_setting_adsl(connection) || nm_connection_get_setting_cdma(connection)
|
||||||
va_start(ap, ifname);
|
|| nm_connection_get_setting_olpc_mesh(connection)
|
||||||
while ((p_key = va_arg(ap, const char *))) {
|
|| nm_connection_get_setting_pppoe(connection)
|
||||||
p_val = va_arg(ap, const char *);
|
|| nm_connection_get_setting_vpn(connection)) {
|
||||||
if (!p_val) {
|
parameters = g_hash_table_new(nm_str_hash, g_str_equal);
|
||||||
if (parameters)
|
g_hash_table_insert(parameters,
|
||||||
g_hash_table_remove(parameters, p_key);
|
NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD,
|
||||||
continue;
|
NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
|
||||||
}
|
} else {
|
||||||
if (!parameters)
|
parameters = NULL;
|
||||||
parameters = g_hash_table_new(nm_str_hash, g_str_equal);
|
|
||||||
g_hash_table_insert(parameters, (char *) p_key, (char *) p_val);
|
|
||||||
}
|
}
|
||||||
va_end(ap);
|
|
||||||
|
/* We ignore the result, because the caller validates the connection.
|
||||||
|
* The only reason we do a normalization attempt here is
|
||||||
|
* NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD.
|
||||||
|
* Could we perhaps, one day, get rid of it? */
|
||||||
nm_connection_normalize(connection, parameters, NULL, NULL);
|
nm_connection_normalize(connection, parameters, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,60 +23,14 @@ void nm_utils_ppp_ip_methods_enabled(NMConnection *connection,
|
|||||||
gboolean *out_ip4_enabled,
|
gboolean *out_ip4_enabled,
|
||||||
gboolean *out_ip6_enabled);
|
gboolean *out_ip6_enabled);
|
||||||
|
|
||||||
void _nm_utils_complete_generic_with_params(NMPlatform *platform,
|
void nm_utils_complete_generic(NMPlatform *platform,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
const char *ctype,
|
const char *ctype,
|
||||||
NMConnection *const *existing_connections,
|
NMConnection *const *existing_connections,
|
||||||
const char *preferred_id,
|
const char *preferred_id,
|
||||||
const char *fallback_id_prefix,
|
const char *fallback_id_prefix,
|
||||||
const char *ifname_prefix,
|
const char *ifname_prefix,
|
||||||
const char *ifname,
|
const char *ifname);
|
||||||
...) G_GNUC_NULL_TERMINATED;
|
|
||||||
|
|
||||||
#define nm_utils_complete_generic_with_params(platform, \
|
|
||||||
connection, \
|
|
||||||
ctype, \
|
|
||||||
existing_connections, \
|
|
||||||
preferred_id, \
|
|
||||||
fallback_id_prefix, \
|
|
||||||
ifname_prefix, \
|
|
||||||
ifname, \
|
|
||||||
...) \
|
|
||||||
_nm_utils_complete_generic_with_params(platform, \
|
|
||||||
connection, \
|
|
||||||
ctype, \
|
|
||||||
existing_connections, \
|
|
||||||
preferred_id, \
|
|
||||||
fallback_id_prefix, \
|
|
||||||
ifname_prefix, \
|
|
||||||
ifname, \
|
|
||||||
##__VA_ARGS__, \
|
|
||||||
NULL)
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
nm_utils_complete_generic(NMPlatform *platform,
|
|
||||||
NMConnection *connection,
|
|
||||||
const char *ctype,
|
|
||||||
NMConnection *const *existing_connections,
|
|
||||||
const char *preferred_id,
|
|
||||||
const char *fallback_id_prefix,
|
|
||||||
const char *ifname_prefix,
|
|
||||||
const char *ifname,
|
|
||||||
gboolean default_enable_ipv6)
|
|
||||||
{
|
|
||||||
nm_utils_complete_generic_with_params(platform,
|
|
||||||
connection,
|
|
||||||
ctype,
|
|
||||||
existing_connections,
|
|
||||||
preferred_id,
|
|
||||||
fallback_id_prefix,
|
|
||||||
ifname_prefix,
|
|
||||||
ifname,
|
|
||||||
NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD,
|
|
||||||
default_enable_ipv6
|
|
||||||
? NM_SETTING_IP6_CONFIG_METHOD_AUTO
|
|
||||||
: NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef gboolean(NMUtilsMatchFilterFunc)(NMConnection *connection, gpointer user_data);
|
typedef gboolean(NMUtilsMatchFilterFunc)(NMConnection *connection, gpointer user_data);
|
||||||
|
|
||||||
|
@@ -117,8 +117,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("ADSL connection"),
|
_("ADSL connection"),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
FALSE); /* No IPv6 yet by default */
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -404,8 +404,7 @@ complete_connection(NMDevice *device,
|
|||||||
preferred,
|
preferred,
|
||||||
fallback_prefix,
|
fallback_prefix,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
is_dun ? FALSE : TRUE); /* No IPv6 yet for DUN */
|
|
||||||
|
|
||||||
setting_bdaddr = nm_setting_bluetooth_get_bdaddr(s_bt);
|
setting_bdaddr = nm_setting_bluetooth_get_bdaddr(s_bt);
|
||||||
if (setting_bdaddr) {
|
if (setting_bdaddr) {
|
||||||
|
@@ -161,8 +161,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("6LOWPAN connection"),
|
_("6LOWPAN connection"),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
s_6lowpan = NM_SETTING_6LOWPAN(nm_connection_get_setting(connection, NM_TYPE_SETTING_6LOWPAN));
|
s_6lowpan = NM_SETTING_6LOWPAN(nm_connection_get_setting(connection, NM_TYPE_SETTING_6LOWPAN));
|
||||||
if (!s_6lowpan) {
|
if (!s_6lowpan) {
|
||||||
|
@@ -94,8 +94,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("Bond connection"),
|
_("Bond connection"),
|
||||||
"bond",
|
"bond",
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_BOND);
|
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_BOND);
|
||||||
|
|
||||||
|
@@ -164,8 +164,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("Bridge connection"),
|
_("Bridge connection"),
|
||||||
"bridge",
|
"bridge",
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_BRIDGE);
|
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_BRIDGE);
|
||||||
|
|
||||||
|
@@ -48,14 +48,14 @@ complete_connection(NMDevice *device,
|
|||||||
NMConnection *const *existing_connections,
|
NMConnection *const *existing_connections,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
nm_utils_complete_generic_with_params(nm_device_get_platform(device),
|
nm_utils_complete_generic(nm_device_get_platform(device),
|
||||||
connection,
|
connection,
|
||||||
NM_SETTING_DUMMY_SETTING_NAME,
|
NM_SETTING_DUMMY_SETTING_NAME,
|
||||||
existing_connections,
|
existing_connections,
|
||||||
NULL,
|
NULL,
|
||||||
_("Dummy connection"),
|
_("Dummy connection"),
|
||||||
NULL,
|
NULL,
|
||||||
nm_device_get_ip_iface(device));
|
nm_device_get_ip_iface(device));
|
||||||
|
|
||||||
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_DUMMY);
|
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_DUMMY);
|
||||||
|
|
||||||
|
@@ -1640,8 +1640,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("Veth connection"),
|
_("Veth connection"),
|
||||||
"veth",
|
"veth",
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
s_veth = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_VETH);
|
s_veth = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_VETH);
|
||||||
|
|
||||||
@@ -1698,8 +1697,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
s_pppoe ? _("PPPoE connection") : _("Wired connection"),
|
s_pppoe ? _("PPPoE connection") : _("Wired connection"),
|
||||||
NULL,
|
NULL,
|
||||||
nm_setting_wired_get_mac_address(s_wired) ? NULL : nm_device_get_iface(device),
|
nm_setting_wired_get_mac_address(s_wired) ? NULL : nm_device_get_iface(device));
|
||||||
s_pppoe ? FALSE : TRUE); /* No IPv6 by default yet for PPPoE */
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@@ -159,8 +159,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("InfiniBand connection"),
|
_("InfiniBand connection"),
|
||||||
NULL,
|
NULL,
|
||||||
nm_setting_infiniband_get_mac_address(s_infiniband) ? NULL : nm_device_get_iface(device),
|
nm_setting_infiniband_get_mac_address(s_infiniband) ? NULL : nm_device_get_iface(device));
|
||||||
TRUE);
|
|
||||||
|
|
||||||
if (!nm_setting_infiniband_get_transport_mode(s_infiniband))
|
if (!nm_setting_infiniband_get_transport_mode(s_infiniband))
|
||||||
g_object_set(G_OBJECT(s_infiniband),
|
g_object_set(G_OBJECT(s_infiniband),
|
||||||
|
@@ -402,8 +402,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("IP tunnel connection"),
|
_("IP tunnel connection"),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
s_ip_tunnel = nm_connection_get_setting_ip_tunnel(connection);
|
s_ip_tunnel = nm_connection_get_setting_ip_tunnel(connection);
|
||||||
if (!s_ip_tunnel) {
|
if (!s_ip_tunnel) {
|
||||||
|
@@ -59,14 +59,14 @@ complete_connection(NMDevice *device,
|
|||||||
NMConnection *const *existing_connections,
|
NMConnection *const *existing_connections,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
nm_utils_complete_generic_with_params(nm_device_get_platform(device),
|
nm_utils_complete_generic(nm_device_get_platform(device),
|
||||||
connection,
|
connection,
|
||||||
NM_SETTING_LOOPBACK_SETTING_NAME,
|
NM_SETTING_LOOPBACK_SETTING_NAME,
|
||||||
existing_connections,
|
existing_connections,
|
||||||
NULL,
|
NULL,
|
||||||
_("Loopback connection"),
|
_("Loopback connection"),
|
||||||
NULL,
|
NULL,
|
||||||
nm_device_get_ip_iface(device));
|
nm_device_get_ip_iface(device));
|
||||||
|
|
||||||
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_LOOPBACK);
|
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_LOOPBACK);
|
||||||
|
|
||||||
|
@@ -365,8 +365,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("MACVLAN connection"),
|
_("MACVLAN connection"),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
s_macvlan = nm_connection_get_setting_macvlan(connection);
|
s_macvlan = nm_connection_get_setting_macvlan(connection);
|
||||||
if (!s_macvlan) {
|
if (!s_macvlan) {
|
||||||
|
@@ -143,8 +143,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("TUN connection"),
|
_("TUN connection"),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
s_tun = nm_connection_get_setting_tun(connection);
|
s_tun = nm_connection_get_setting_tun(connection);
|
||||||
if (!s_tun) {
|
if (!s_tun) {
|
||||||
|
@@ -379,8 +379,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("VLAN connection"),
|
_("VLAN connection"),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
s_vlan = nm_connection_get_setting_vlan(connection);
|
s_vlan = nm_connection_get_setting_vlan(connection);
|
||||||
if (!s_vlan) {
|
if (!s_vlan) {
|
||||||
|
@@ -184,8 +184,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("VRF connection"),
|
_("VRF connection"),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
s_vrf = _nm_connection_get_setting(connection, NM_TYPE_SETTING_VRF);
|
s_vrf = _nm_connection_get_setting(connection, NM_TYPE_SETTING_VRF);
|
||||||
if (!s_vrf) {
|
if (!s_vrf) {
|
||||||
|
@@ -384,8 +384,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("VXLAN connection"),
|
_("VXLAN connection"),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
s_vxlan = nm_connection_get_setting_vxlan(connection);
|
s_vxlan = nm_connection_get_setting_vxlan(connection);
|
||||||
if (!s_vxlan) {
|
if (!s_vxlan) {
|
||||||
|
@@ -53,8 +53,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("WPAN connection"),
|
_("WPAN connection"),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
s_wpan = NM_SETTING_WPAN(nm_connection_get_setting(connection, NM_TYPE_SETTING_WPAN));
|
s_wpan = NM_SETTING_WPAN(nm_connection_get_setting(connection, NM_TYPE_SETTING_WPAN));
|
||||||
if (!s_wpan) {
|
if (!s_wpan) {
|
||||||
|
@@ -130,8 +130,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("Team connection"),
|
_("Team connection"),
|
||||||
"team",
|
"team",
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_TEAM);
|
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_TEAM);
|
||||||
|
|
||||||
|
@@ -301,8 +301,7 @@ complete_connection(NMDevice *device,
|
|||||||
setting_name,
|
setting_name,
|
||||||
setting_name,
|
setting_name,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@@ -1074,8 +1074,7 @@ complete_connection(NMDevice *device,
|
|||||||
ssid_utf8,
|
ssid_utf8,
|
||||||
ssid_utf8,
|
ssid_utf8,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
if (hidden)
|
if (hidden)
|
||||||
g_object_set(s_wifi, NM_SETTING_WIRELESS_HIDDEN, TRUE, NULL);
|
g_object_set(s_wifi, NM_SETTING_WIRELESS_HIDDEN, TRUE, NULL);
|
||||||
|
@@ -111,8 +111,7 @@ complete_connection(NMDevice *device,
|
|||||||
NULL,
|
NULL,
|
||||||
_("Mesh"),
|
_("Mesh"),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
FALSE); /* No IPv6 by default */
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@@ -319,8 +319,7 @@ complete_connection(NMDevice *device,
|
|||||||
setting_name,
|
setting_name,
|
||||||
setting_name,
|
setting_name,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@@ -1296,8 +1296,7 @@ complete_connection(NMDevice *device,
|
|||||||
ssid_utf8,
|
ssid_utf8,
|
||||||
ssid_utf8,
|
ssid_utf8,
|
||||||
NULL,
|
NULL,
|
||||||
nm_setting_wireless_get_mac_address(s_wifi) ? NULL : nm_device_get_iface(device),
|
nm_setting_wireless_get_mac_address(s_wifi) ? NULL : nm_device_get_iface(device));
|
||||||
TRUE);
|
|
||||||
|
|
||||||
if (hidden)
|
if (hidden)
|
||||||
g_object_set(s_wifi, NM_SETTING_WIRELESS_HIDDEN, TRUE, NULL);
|
g_object_set(s_wifi, NM_SETTING_WIRELESS_HIDDEN, TRUE, NULL);
|
||||||
|
@@ -917,8 +917,7 @@ complete_connection(NMModem *modem,
|
|||||||
NULL,
|
NULL,
|
||||||
_("GSM connection"),
|
_("GSM connection"),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -938,8 +937,7 @@ complete_connection(NMModem *modem,
|
|||||||
NULL,
|
NULL,
|
||||||
_("CDMA connection"),
|
_("CDMA connection"),
|
||||||
NULL,
|
NULL,
|
||||||
iface,
|
iface);
|
||||||
TRUE);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@@ -6952,8 +6952,7 @@ impl_manager_add_and_activate_connection(NMDBusObject *obj,
|
|||||||
NULL,
|
NULL,
|
||||||
_("VPN connection"),
|
_("VPN connection"),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL);
|
||||||
FALSE); /* No IPv6 by default for now */
|
|
||||||
} else {
|
} else {
|
||||||
conns = nm_settings_connections_array_to_connections(
|
conns = nm_settings_connections_array_to_connections(
|
||||||
nm_settings_get_connections(priv->settings, NULL),
|
nm_settings_get_connections(priv->settings, NULL),
|
||||||
|
Reference in New Issue
Block a user