platform: don't assign meaning to NMLinkType numeric values

It would be better if we would be able to use NMLinkType enum
as an index (e.g. into an array of LinkDesc structures). For that,
it is necessary that the enum is just consecutive numbers.

Don't assign special meaning to the enum. Also, this was only
used at two places, that we can solve differently.
This commit is contained in:
Thomas Haller 2020-02-20 11:16:27 +01:00
parent 4f9f228fed
commit 6db35d95a5
2 changed files with 34 additions and 12 deletions

View file

@ -118,20 +118,18 @@ typedef struct _NMPNetns NMPNetns;
typedef struct _NMPObject NMPObject;
typedef enum {
/* Please don't interpret type numbers outside nm-platform and use functions
* like nm_platform_link_is_software() and nm_platform_supports_slaves().
*
* type & 0x10000 -> Software device type
* type & 0x20000 -> Type supports slaves
*/
/* No type, used as error value */
NM_LINK_TYPE_NONE,
/* Unknown type */
NM_LINK_TYPE_UNKNOWN,
NM_LINK_TYPE_ANY,
#define _NM_LINK_TYPE_REAL_FIRST NM_LINK_TYPE_ETHERNET
/* Hardware types */
#define _NM_LINK_TYPE_HW_FIRST NM_LINK_TYPE_ETHERNET
NM_LINK_TYPE_ETHERNET,
NM_LINK_TYPE_INFINIBAND,
NM_LINK_TYPE_OLPC_MESH,
@ -141,9 +139,11 @@ typedef enum {
NM_LINK_TYPE_WPAN,
NM_LINK_TYPE_6LOWPAN,
NM_LINK_TYPE_WIFI_P2P,
#define _NM_LINK_TYPE_HW_LAST NM_LINK_TYPE_WIFI_P2P
/* Software types */
NM_LINK_TYPE_BNEP = 0x10000, /* Bluetooth Ethernet emulation */
#define _NM_LINK_TYPE_SW_FIRST NM_LINK_TYPE_BNEP
NM_LINK_TYPE_BNEP, /* Bluetooth Ethernet emulation */
NM_LINK_TYPE_DUMMY,
NM_LINK_TYPE_GRE,
NM_LINK_TYPE_GRETAP,
@ -165,15 +165,37 @@ typedef enum {
NM_LINK_TYPE_VRF,
NM_LINK_TYPE_VXLAN,
NM_LINK_TYPE_WIREGUARD,
#define _NM_LINK_TYPE_SW_LAST NM_LINK_TYPE_WIREGUARD
/* Software types with slaves */
NM_LINK_TYPE_BRIDGE = 0x10000 | 0x20000,
#define _NM_LINK_TYPE_SW_MASTER_FIRST NM_LINK_TYPE_BRIDGE
NM_LINK_TYPE_BRIDGE,
NM_LINK_TYPE_BOND,
NM_LINK_TYPE_TEAM,
#define _NM_LINK_TYPE_SW_MASTER_LAST NM_LINK_TYPE_TEAM
#define _NM_LINK_TYPE_REAL_LAST NM_LINK_TYPE_TEAM
#define _NM_LINK_TYPE_REAL_NUM ((int) (_NM_LINK_TYPE_REAL_LAST - _NM_LINK_TYPE_REAL_FIRST + 1))
NM_LINK_TYPE_ANY = G_MAXUINT32,
} NMLinkType;
static inline gboolean
nm_link_type_is_software (NMLinkType link_type)
{
G_STATIC_ASSERT (_NM_LINK_TYPE_SW_LAST + 1 == _NM_LINK_TYPE_SW_MASTER_FIRST);
return link_type >= _NM_LINK_TYPE_SW_FIRST
&& link_type <= _NM_LINK_TYPE_SW_MASTER_LAST;
}
static inline gboolean
nm_link_type_supports_slaves (NMLinkType link_type)
{
return link_type >= _NM_LINK_TYPE_SW_MASTER_FIRST
&& link_type <= _NM_LINK_TYPE_SW_MASTER_LAST;
}
typedef enum {
NMP_OBJECT_TYPE_UNKNOWN,
NMP_OBJECT_TYPE_LINK,

View file

@ -1448,7 +1448,7 @@ nm_platform_link_get_unmanaged (NMPlatform *self, int ifindex, gboolean *unmanag
gboolean
nm_platform_link_is_software (NMPlatform *self, int ifindex)
{
return (nm_platform_link_get_type (self, ifindex) & 0x10000);
return nm_link_type_is_software (nm_platform_link_get_type (self, ifindex));
}
/**
@ -1462,7 +1462,7 @@ nm_platform_link_is_software (NMPlatform *self, int ifindex)
gboolean
nm_platform_link_supports_slaves (NMPlatform *self, int ifindex)
{
return (nm_platform_link_get_type (self, ifindex) & 0x20000);
return nm_link_type_supports_slaves (nm_platform_link_get_type (self, ifindex));
}
/**