mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-28 14:40:45 +02:00
XXX device: simplify the nm_utils_complete_generic() machinery
This commit is contained in:
parent
81a239ef3b
commit
b960c0267f
26 changed files with 68 additions and 143 deletions
|
|
@ -250,23 +250,19 @@ nm_utils_ppp_ip_methods_enabled(NMConnection *connection,
|
|||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
_nm_utils_complete_generic_with_params(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,
|
||||
...)
|
||||
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)
|
||||
{
|
||||
NMSettingConnection *s_con;
|
||||
char *id;
|
||||
char *generated_ifname;
|
||||
gs_unref_hashtable GHashTable *parameters = NULL;
|
||||
va_list ap;
|
||||
const char *p_val;
|
||||
const char *p_key;
|
||||
gboolean valid;
|
||||
|
||||
g_assert(fallback_id_prefix);
|
||||
|
|
@ -302,20 +298,19 @@ _nm_utils_complete_generic_with_params(NMPlatform *platform,
|
|||
g_free(generated_ifname);
|
||||
}
|
||||
|
||||
/* Normalize */
|
||||
va_start(ap, ifname);
|
||||
while ((p_key = va_arg(ap, const char *))) {
|
||||
p_val = va_arg(ap, const char *);
|
||||
if (!p_val) {
|
||||
if (parameters)
|
||||
g_hash_table_remove(parameters, p_key);
|
||||
continue;
|
||||
}
|
||||
if (!parameters)
|
||||
parameters = g_hash_table_new(nm_str_hash, g_str_equal);
|
||||
g_hash_table_insert(parameters, (char *) p_key, (char *) p_val);
|
||||
if (nm_connection_get_setting_adsl(connection) || nm_connection_get_setting_cdma(connection)
|
||||
|| nm_connection_get_setting_gsm(connection)
|
||||
|| nm_connection_get_setting_olpc_mesh(connection)
|
||||
|| nm_connection_get_setting_pppoe(connection)
|
||||
|| nm_connection_get_setting_vpn(connection)) {
|
||||
parameters = g_hash_table_new(nm_str_hash, g_str_equal);
|
||||
g_hash_table_insert(parameters,
|
||||
NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD,
|
||||
NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
|
||||
} else {
|
||||
parameters = NULL;
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
valid = nm_connection_normalize(connection, parameters, NULL, NULL);
|
||||
nm_assert(valid);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,60 +23,14 @@ void nm_utils_ppp_ip_methods_enabled(NMConnection *connection,
|
|||
gboolean *out_ip4_enabled,
|
||||
gboolean *out_ip6_enabled);
|
||||
|
||||
void _nm_utils_complete_generic_with_params(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,
|
||||
...) 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);
|
||||
}
|
||||
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);
|
||||
|
||||
typedef gboolean(NMUtilsMatchFilterFunc)(NMConnection *connection, gpointer user_data);
|
||||
|
||||
|
|
|
|||
|
|
@ -117,8 +117,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("ADSL connection"),
|
||||
NULL,
|
||||
NULL,
|
||||
FALSE); /* No IPv6 yet by default */
|
||||
NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -404,8 +404,7 @@ complete_connection(NMDevice *device,
|
|||
preferred,
|
||||
fallback_prefix,
|
||||
NULL,
|
||||
NULL,
|
||||
is_dun ? FALSE : TRUE); /* No IPv6 yet for DUN */
|
||||
NULL);
|
||||
|
||||
setting_bdaddr = nm_setting_bluetooth_get_bdaddr(s_bt);
|
||||
if (setting_bdaddr) {
|
||||
|
|
|
|||
|
|
@ -161,8 +161,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("6LOWPAN connection"),
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
s_6lowpan = NM_SETTING_6LOWPAN(nm_connection_get_setting(connection, NM_TYPE_SETTING_6LOWPAN));
|
||||
if (!s_6lowpan) {
|
||||
|
|
|
|||
|
|
@ -94,8 +94,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("Bond connection"),
|
||||
"bond",
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_BOND);
|
||||
|
||||
|
|
|
|||
|
|
@ -164,8 +164,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("Bridge connection"),
|
||||
"bridge",
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_BRIDGE);
|
||||
|
||||
|
|
|
|||
|
|
@ -48,14 +48,14 @@ complete_connection(NMDevice *device,
|
|||
NMConnection *const *existing_connections,
|
||||
GError **error)
|
||||
{
|
||||
nm_utils_complete_generic_with_params(nm_device_get_platform(device),
|
||||
connection,
|
||||
NM_SETTING_DUMMY_SETTING_NAME,
|
||||
existing_connections,
|
||||
NULL,
|
||||
_("Dummy connection"),
|
||||
NULL,
|
||||
nm_device_get_ip_iface(device));
|
||||
nm_utils_complete_generic(nm_device_get_platform(device),
|
||||
connection,
|
||||
NM_SETTING_DUMMY_SETTING_NAME,
|
||||
existing_connections,
|
||||
NULL,
|
||||
_("Dummy connection"),
|
||||
NULL,
|
||||
nm_device_get_ip_iface(device));
|
||||
|
||||
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_DUMMY);
|
||||
|
||||
|
|
|
|||
|
|
@ -1640,8 +1640,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("Veth connection"),
|
||||
"veth",
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
s_veth = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_VETH);
|
||||
|
||||
|
|
@ -1698,8 +1697,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
s_pppoe ? _("PPPoE connection") : _("Wired connection"),
|
||||
NULL,
|
||||
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 */
|
||||
nm_setting_wired_get_mac_address(s_wired) ? NULL : nm_device_get_iface(device));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,8 +159,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("InfiniBand connection"),
|
||||
NULL,
|
||||
nm_setting_infiniband_get_mac_address(s_infiniband) ? NULL : nm_device_get_iface(device),
|
||||
TRUE);
|
||||
nm_setting_infiniband_get_mac_address(s_infiniband) ? NULL : nm_device_get_iface(device));
|
||||
|
||||
if (!nm_setting_infiniband_get_transport_mode(s_infiniband))
|
||||
g_object_set(G_OBJECT(s_infiniband),
|
||||
|
|
|
|||
|
|
@ -402,8 +402,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("IP tunnel connection"),
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
s_ip_tunnel = nm_connection_get_setting_ip_tunnel(connection);
|
||||
if (!s_ip_tunnel) {
|
||||
|
|
|
|||
|
|
@ -59,14 +59,14 @@ complete_connection(NMDevice *device,
|
|||
NMConnection *const *existing_connections,
|
||||
GError **error)
|
||||
{
|
||||
nm_utils_complete_generic_with_params(nm_device_get_platform(device),
|
||||
connection,
|
||||
NM_SETTING_LOOPBACK_SETTING_NAME,
|
||||
existing_connections,
|
||||
NULL,
|
||||
_("Loopback connection"),
|
||||
NULL,
|
||||
nm_device_get_ip_iface(device));
|
||||
nm_utils_complete_generic(nm_device_get_platform(device),
|
||||
connection,
|
||||
NM_SETTING_LOOPBACK_SETTING_NAME,
|
||||
existing_connections,
|
||||
NULL,
|
||||
_("Loopback connection"),
|
||||
NULL,
|
||||
nm_device_get_ip_iface(device));
|
||||
|
||||
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_LOOPBACK);
|
||||
|
||||
|
|
|
|||
|
|
@ -364,8 +364,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("MACVLAN connection"),
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
s_macvlan = nm_connection_get_setting_macvlan(connection);
|
||||
if (!s_macvlan) {
|
||||
|
|
|
|||
|
|
@ -143,8 +143,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("TUN connection"),
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
s_tun = nm_connection_get_setting_tun(connection);
|
||||
if (!s_tun) {
|
||||
|
|
|
|||
|
|
@ -379,8 +379,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("VLAN connection"),
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
s_vlan = nm_connection_get_setting_vlan(connection);
|
||||
if (!s_vlan) {
|
||||
|
|
|
|||
|
|
@ -184,8 +184,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("VRF connection"),
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
s_vrf = _nm_connection_get_setting(connection, NM_TYPE_SETTING_VRF);
|
||||
if (!s_vrf) {
|
||||
|
|
|
|||
|
|
@ -384,8 +384,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("VXLAN connection"),
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
s_vxlan = nm_connection_get_setting_vxlan(connection);
|
||||
if (!s_vxlan) {
|
||||
|
|
|
|||
|
|
@ -53,8 +53,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("WPAN connection"),
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
s_wpan = NM_SETTING_WPAN(nm_connection_get_setting(connection, NM_TYPE_SETTING_WPAN));
|
||||
if (!s_wpan) {
|
||||
|
|
|
|||
|
|
@ -130,8 +130,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("Team connection"),
|
||||
"team",
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
_nm_connection_ensure_setting(connection, NM_TYPE_SETTING_TEAM);
|
||||
|
||||
|
|
|
|||
|
|
@ -301,8 +301,7 @@ complete_connection(NMDevice *device,
|
|||
setting_name,
|
||||
setting_name,
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1074,8 +1074,7 @@ complete_connection(NMDevice *device,
|
|||
ssid_utf8,
|
||||
ssid_utf8,
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
if (hidden)
|
||||
g_object_set(s_wifi, NM_SETTING_WIRELESS_HIDDEN, TRUE, NULL);
|
||||
|
|
|
|||
|
|
@ -111,8 +111,7 @@ complete_connection(NMDevice *device,
|
|||
NULL,
|
||||
_("Mesh"),
|
||||
NULL,
|
||||
NULL,
|
||||
FALSE); /* No IPv6 by default */
|
||||
NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -319,8 +319,7 @@ complete_connection(NMDevice *device,
|
|||
setting_name,
|
||||
setting_name,
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE);
|
||||
NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1296,8 +1296,7 @@ complete_connection(NMDevice *device,
|
|||
ssid_utf8,
|
||||
ssid_utf8,
|
||||
NULL,
|
||||
nm_setting_wireless_get_mac_address(s_wifi) ? NULL : nm_device_get_iface(device),
|
||||
TRUE);
|
||||
nm_setting_wireless_get_mac_address(s_wifi) ? NULL : nm_device_get_iface(device));
|
||||
|
||||
if (hidden)
|
||||
g_object_set(s_wifi, NM_SETTING_WIRELESS_HIDDEN, TRUE, NULL);
|
||||
|
|
|
|||
|
|
@ -917,8 +917,7 @@ complete_connection(NMModem *modem,
|
|||
NULL,
|
||||
_("GSM connection"),
|
||||
NULL,
|
||||
NULL,
|
||||
FALSE); /* No IPv6 yet by default */
|
||||
NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -938,8 +937,7 @@ complete_connection(NMModem *modem,
|
|||
NULL,
|
||||
_("CDMA connection"),
|
||||
NULL,
|
||||
iface,
|
||||
FALSE); /* No IPv6 yet by default */
|
||||
iface);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6952,8 +6952,7 @@ impl_manager_add_and_activate_connection(NMDBusObject *obj,
|
|||
NULL,
|
||||
_("VPN connection"),
|
||||
NULL,
|
||||
NULL,
|
||||
FALSE); /* No IPv6 by default for now */
|
||||
NULL);
|
||||
} else {
|
||||
conns = nm_settings_connections_array_to_connections(
|
||||
nm_settings_get_connections(priv->settings, NULL),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue