diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index da568909b5..a87ef77c3b 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -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: diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index fbc7976ab7..e96d67fcc3 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -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); diff --git a/src/platform/tests/dump.c b/src/platform/tests/dump.c index a6e4a42016..9ffbba237c 100644 --- a/src/platform/tests/dump.c +++ b/src/platform/tests/dump.c @@ -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)) diff --git a/src/platform/tests/platform.c b/src/platform/tests/platform.c index e49b7f55f6..a059966f84 100644 --- a/src/platform/tests/platform.c +++ b/src/platform/tests/platform.c @@ -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, "" }, { "link-get-name", "get interface name", do_link_get_name, 1, "" }, { "link-get-type", "get interface type", do_link_get_type, 1, "" }, + { "link-is-software", "check if interface is a software one", do_link_is_software, 1, "" }, + { "link-supports-slaves", "check if interface supports slaves", do_link_supports_slaves, 1, "" }, { "link-set-up", "set interface up", do_link_set_up, 1, "" }, { "link-set-down", "set interface down", do_link_set_down, 1, "" }, { "link-set-arp", "activate interface arp", do_link_set_arp, 1, "" },