mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-06 16:21:50 +00:00
libnm-util: add nm_utils_check_virtual_device_compatibility()
Add a function encoding the logic of what virtual types support what slave/parent types, so clients don't need to encode it themselves.
This commit is contained in:
parent
a9c8addc91
commit
4a5e2ced08
|
@ -603,6 +603,7 @@ global:
|
|||
nm_utils_ap_mode_security_valid;
|
||||
nm_utils_bin2hexstr;
|
||||
nm_utils_deinit;
|
||||
nm_utils_check_virtual_device_compatibility;
|
||||
nm_utils_escape_ssid;
|
||||
nm_utils_file_is_pkcs12;
|
||||
nm_utils_gvalue_hash_dup;
|
||||
|
|
|
@ -38,6 +38,7 @@ void _nm_register_setting (const char *name,
|
|||
#define _nm_register_setting(name, type, priority, error_quark) _nm_register_setting ((name ""), type, priority, error_quark)
|
||||
|
||||
gboolean _nm_setting_is_base_type (NMSetting *setting);
|
||||
gboolean _nm_setting_type_is_base_type (GType type);
|
||||
GType _nm_setting_lookup_setting_type (const char *name);
|
||||
GType _nm_setting_lookup_setting_type_by_quark (GQuark error_quark);
|
||||
gint _nm_setting_compare_priority (gconstpointer a, gconstpointer b);
|
||||
|
|
|
@ -199,25 +199,31 @@ _nm_setting_lookup_setting_by_type (GType type)
|
|||
}
|
||||
|
||||
static guint32
|
||||
_get_setting_priority (NMSetting *setting)
|
||||
_get_setting_type_priority (GType type)
|
||||
{
|
||||
NMSettingPrivate *priv;
|
||||
const SettingInfo *info;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING (setting), G_MAXUINT32);
|
||||
priv = NM_SETTING_GET_PRIVATE (setting);
|
||||
_ensure_setting_info (setting, priv);
|
||||
return priv->info->priority;
|
||||
g_return_val_if_fail (g_type_is_a (type, NM_TYPE_SETTING), G_MAXUINT32);
|
||||
|
||||
info = _nm_setting_lookup_setting_by_type (type);
|
||||
return info->priority;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_nm_setting_is_base_type (NMSetting *setting)
|
||||
_nm_setting_type_is_base_type (GType type)
|
||||
{
|
||||
/* Historical oddity: PPPoE is a base-type even though it's not
|
||||
* priority 1. It needs to be sorted *after* lower-level stuff like
|
||||
* WiFi security or 802.1x for secrets, but it's still allowed as a
|
||||
* base type.
|
||||
*/
|
||||
return _get_setting_priority (setting) == 1 || NM_IS_SETTING_PPPOE (setting);
|
||||
return _get_setting_type_priority (type) == 1 || (type == NM_TYPE_SETTING_PPPOE);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_nm_setting_is_base_type (NMSetting *setting)
|
||||
{
|
||||
return _nm_setting_type_is_base_type (G_OBJECT_TYPE (setting));
|
||||
}
|
||||
|
||||
GType
|
||||
|
@ -254,8 +260,8 @@ _nm_setting_compare_priority (gconstpointer a, gconstpointer b)
|
|||
{
|
||||
guint32 prio_a, prio_b;
|
||||
|
||||
prio_a = _get_setting_priority (NM_SETTING (a));
|
||||
prio_b = _get_setting_priority (NM_SETTING (b));
|
||||
prio_a = _get_setting_type_priority (G_OBJECT_TYPE (a));
|
||||
prio_b = _get_setting_type_priority (G_OBJECT_TYPE (b));
|
||||
|
||||
if (prio_a < prio_b)
|
||||
return -1;
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "nm-utils-private.h"
|
||||
#include "nm-glib-compat.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-setting-private.h"
|
||||
#include "crypto.h"
|
||||
|
||||
/**
|
||||
|
@ -2327,3 +2328,64 @@ nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst)
|
|||
INET6_ADDRSTRLEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_check_virtual_device_compatibility:
|
||||
* @virtual_type: a virtual connection type
|
||||
* @other_type: a connection type to test against @virtual_type
|
||||
*
|
||||
* Determines if a connection of type @virtual_type can (in the
|
||||
* general case) work with connections of type @other_type.
|
||||
*
|
||||
* If @virtual_type is %NM_TYPE_SETTING_VLAN, then this checks if
|
||||
* @other_type is a valid type for the parent of a VLAN.
|
||||
*
|
||||
* If @virtual_type is a "master" type (eg, %NM_TYPE_SETTING_BRIDGE),
|
||||
* then this checks if @other_type is a valid type for a slave of that
|
||||
* master.
|
||||
*
|
||||
* Note that even if this returns %TRUE it is not guaranteed that
|
||||
* <emphasis>every</emphasis> connection of type @other_type is
|
||||
* compatible with @virtual_type; it may depend on the exact
|
||||
* configuration of the two connections, or on the capabilities of an
|
||||
* underlying device driver.
|
||||
*
|
||||
* Returns: %TRUE or %FALSE
|
||||
*
|
||||
* Since: 0.9.10
|
||||
*/
|
||||
gboolean
|
||||
nm_utils_check_virtual_device_compatibility (GType virtual_type, GType other_type)
|
||||
{
|
||||
g_return_val_if_fail (_nm_setting_type_is_base_type (virtual_type), FALSE);
|
||||
g_return_val_if_fail (_nm_setting_type_is_base_type (other_type), FALSE);
|
||||
|
||||
if (virtual_type == NM_TYPE_SETTING_BOND) {
|
||||
return ( other_type == NM_TYPE_SETTING_INFINIBAND
|
||||
|| other_type == NM_TYPE_SETTING_WIRED
|
||||
|| other_type == NM_TYPE_SETTING_BRIDGE
|
||||
|| other_type == NM_TYPE_SETTING_BOND
|
||||
|| other_type == NM_TYPE_SETTING_TEAM
|
||||
|| other_type == NM_TYPE_SETTING_VLAN);
|
||||
} else if (virtual_type == NM_TYPE_SETTING_BRIDGE) {
|
||||
return ( other_type == NM_TYPE_SETTING_WIRED
|
||||
|| other_type == NM_TYPE_SETTING_BOND
|
||||
|| other_type == NM_TYPE_SETTING_TEAM
|
||||
|| other_type == NM_TYPE_SETTING_VLAN);
|
||||
} else if (virtual_type == NM_TYPE_SETTING_TEAM) {
|
||||
return ( other_type == NM_TYPE_SETTING_WIRED
|
||||
|| other_type == NM_TYPE_SETTING_BRIDGE
|
||||
|| other_type == NM_TYPE_SETTING_BOND
|
||||
|| other_type == NM_TYPE_SETTING_TEAM
|
||||
|| other_type == NM_TYPE_SETTING_VLAN);
|
||||
} else if (virtual_type == NM_TYPE_SETTING_VLAN) {
|
||||
return ( other_type == NM_TYPE_SETTING_WIRED
|
||||
|| other_type == NM_TYPE_SETTING_WIRELESS
|
||||
|| other_type == NM_TYPE_SETTING_BRIDGE
|
||||
|| other_type == NM_TYPE_SETTING_BOND
|
||||
|| other_type == NM_TYPE_SETTING_TEAM
|
||||
|| other_type == NM_TYPE_SETTING_VLAN);
|
||||
} else {
|
||||
g_warn_if_reached ();
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,6 +174,9 @@ const char *nm_utils_inet4_ntop (in_addr_t inaddr, char *dst);
|
|||
NM_AVAILABLE_IN_0_9_10
|
||||
const char *nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst);
|
||||
|
||||
NM_AVAILABLE_IN_0_9_10
|
||||
gboolean nm_utils_check_virtual_device_compatibility (GType virtual_type, GType other_type);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_UTILS_H */
|
||||
|
|
Loading…
Reference in a new issue