mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-08 10:08:05 +02:00
platform: add link type classification
This commit is contained in:
parent
1c078e9bd5
commit
9d92275ac9
4 changed files with 49 additions and 5 deletions
|
|
@ -503,6 +503,31 @@ nm_platform_link_get_type_name (int ifindex)
|
|||
return klass->link_get_type_name (platform, ifindex);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_platform_link_is_software:
|
||||
* @ifindex: Interface index.
|
||||
*
|
||||
* Returns: %TRUE if ifindex belongs to a software interface, not backed by
|
||||
* a physical device.
|
||||
*/
|
||||
gboolean
|
||||
nm_platform_link_is_software (int ifindex)
|
||||
{
|
||||
return (nm_platform_link_get_type (ifindex) & 0x10000);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_platform_link_supports_slaves:
|
||||
* @ifindex: Interface index.
|
||||
*
|
||||
* Returns: %TRUE if ifindex belongs to an interface capable of enslaving
|
||||
* other interfaces.
|
||||
*/
|
||||
gboolean
|
||||
nm_platform_link_supports_slaves (int ifindex)
|
||||
{
|
||||
return (nm_platform_link_get_type (ifindex) & 0x20000);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_platform_link_is_up:
|
||||
|
|
|
|||
|
|
@ -50,7 +50,17 @@ typedef enum {
|
|||
} NMPlatformError;
|
||||
|
||||
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,
|
||||
|
||||
/* Hardware types */
|
||||
|
|
@ -59,8 +69,8 @@ typedef enum {
|
|||
NM_LINK_TYPE_OLPC_MESH,
|
||||
NM_LINK_TYPE_WIFI,
|
||||
|
||||
/* Virtual types */
|
||||
NM_LINK_TYPE_DUMMY,
|
||||
/* Software types */
|
||||
NM_LINK_TYPE_DUMMY = 0x10000,
|
||||
NM_LINK_TYPE_GRE,
|
||||
NM_LINK_TYPE_GRETAP,
|
||||
NM_LINK_TYPE_IFB,
|
||||
|
|
@ -72,11 +82,10 @@ typedef enum {
|
|||
NM_LINK_TYPE_VETH,
|
||||
NM_LINK_TYPE_VLAN,
|
||||
|
||||
/* Virtual types with slaves */
|
||||
NM_LINK_TYPE_BRIDGE,
|
||||
/* Software types with slaves */
|
||||
NM_LINK_TYPE_BRIDGE = 0x10000 | 0x20000,
|
||||
NM_LINK_TYPE_BOND,
|
||||
NM_LINK_TYPE_TEAM,
|
||||
|
||||
} NMLinkType;
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -323,6 +332,8 @@ int nm_platform_link_get_ifindex (const char *name);
|
|||
const char *nm_platform_link_get_name (int ifindex);
|
||||
NMLinkType nm_platform_link_get_type (int ifindex);
|
||||
const char *nm_platform_link_get_type_name (int ifindex);
|
||||
gboolean nm_platform_link_is_software (int ifindex);
|
||||
gboolean nm_platform_link_supports_slaves (int ifindex);
|
||||
|
||||
gboolean nm_platform_link_set_up (int ifindex);
|
||||
gboolean nm_platform_link_set_down (int ifindex);
|
||||
|
|
|
|||
|
|
@ -47,6 +47,10 @@ dump_interface (NMPlatformLink *link)
|
|||
if (vlan_parent)
|
||||
printf (" vlan parent %d id %d\n", vlan_parent, vlan_id);
|
||||
|
||||
if (nm_platform_link_is_software (link->ifindex))
|
||||
printf (" class software\n");
|
||||
if (nm_platform_link_supports_slaves (link->ifindex))
|
||||
printf (" class supports-slaves\n");
|
||||
if (nm_platform_link_supports_carrier_detect (link->ifindex))
|
||||
printf (" feature carrier-detect\n");
|
||||
if (nm_platform_link_supports_vlans (link->ifindex))
|
||||
|
|
|
|||
|
|
@ -175,6 +175,8 @@ do_link_get_ifindex (char **argv)
|
|||
|
||||
LINK_CMD_GET_FULL (get_name, string, value)
|
||||
LINK_CMD_GET_FULL (get_type, decimal, value > 0)
|
||||
LINK_CMD_GET (is_software, boolean)
|
||||
LINK_CMD_GET (supports_slaves, boolean)
|
||||
|
||||
LINK_CMD (set_up)
|
||||
LINK_CMD (set_down)
|
||||
|
|
@ -686,6 +688,8 @@ static const command_t commands[] = {
|
|||
{ "link-get-ifindex>", "get interface index", do_link_get_ifindex, 1, "<ifname>" },
|
||||
{ "link-get-name", "get interface name", do_link_get_name, 1, "<ifindex>" },
|
||||
{ "link-get-type", "get interface type", do_link_get_type, 1, "<ifname/ifindex>" },
|
||||
{ "link-is-software", "check if interface is a software one", do_link_is_software, 1, "<ifname/ifindex>" },
|
||||
{ "link-supports-slaves", "check if interface supports slaves", do_link_supports_slaves, 1, "<ifname/ifindex>" },
|
||||
{ "link-set-up", "set interface up", do_link_set_up, 1, "<ifname/ifindex>" },
|
||||
{ "link-set-down", "set interface down", do_link_set_down, 1, "<ifname/ifindex>" },
|
||||
{ "link-set-arp", "activate interface arp", do_link_set_arp, 1, "<ifname/ifindex>" },
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue