summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2015-04-17 10:04:21 +0200
committerThomas Haller <thaller@redhat.com>2015-06-17 15:28:01 +0200
commit0ab54aeb479c2bb12753360c5b37c681e4bd353e (patch)
tree570a0b3fde9af2ae1f60dad8aeacc05d5b9fedb6
parent7c4a657efaad4b9a5159df574ee187503ea18f55 (diff)
downloadNetworkManager-0ab54aeb479c2bb12753360c5b37c681e4bd353e.tar.gz
platform: refactor link-type to string conversion
(cherry picked from commit b484b03acf66f99ef59cc688de291f07f1cc5603)
-rw-r--r--src/platform/nm-linux-platform.c108
1 files changed, 72 insertions, 36 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index d945cf6bac..fee5f5b2c1 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -848,43 +848,79 @@ check_support_user_ipv6ll (NMPlatform *platform)
/* Object type specific utilities */
+typedef struct {
+ const NMLinkType nm_type;
+ const char *type_string;
+
+ /* IFLA_INFO_KIND / rtnl_link_get_type() where applicable; the rtnl type
+ * should only be specified if the device type can be created without
+ * additional parameters, and if the device type can be determined from
+ * the rtnl_type. eg, tun/tap should not be specified since both
+ * tun and tap devices use "tun", and InfiniBand should not be
+ * specified because a PKey is required at creation. Drivers set this
+ * value from their 'struct rtnl_link_ops' structure.
+ */
+ const char *rtnl_type;
+
+ /* uevent DEVTYPE where applicable, from /sys/class/net/<ifname>/uevent;
+ * drivers set this value from their SET_NETDEV_DEV() call and the
+ * 'struct device_type' name member.
+ */
+ const char *devtype;
+} LinkDesc;
+
+static const LinkDesc linktypes[] = {
+ { NM_LINK_TYPE_NONE, "none", NULL, NULL },
+ { NM_LINK_TYPE_UNKNOWN, "unknown", NULL, NULL },
+
+ { NM_LINK_TYPE_ETHERNET, "ethernet", NULL, NULL },
+ { NM_LINK_TYPE_INFINIBAND, "infiniband", NULL, NULL },
+ { NM_LINK_TYPE_OLPC_MESH, "olpc-mesh", NULL, NULL },
+ { NM_LINK_TYPE_WIFI, "wifi", NULL, "wlan" },
+ { NM_LINK_TYPE_WWAN_ETHERNET, "wwan", NULL, "wwan" },
+ { NM_LINK_TYPE_WIMAX, "wimax", "wimax", "wimax" },
+
+ { NM_LINK_TYPE_DUMMY, "dummy", "dummy", NULL },
+ { NM_LINK_TYPE_GRE, "gre", "gre", NULL },
+ { NM_LINK_TYPE_GRETAP, "gretap", "gretap", NULL },
+ { NM_LINK_TYPE_IFB, "ifb", "ifb", NULL },
+ { NM_LINK_TYPE_LOOPBACK, "loopback", NULL, NULL },
+ { NM_LINK_TYPE_MACVLAN, "macvlan", "macvlan", NULL },
+ { NM_LINK_TYPE_MACVTAP, "macvtap", "macvtap", NULL },
+ { NM_LINK_TYPE_OPENVSWITCH, "openvswitch", "openvswitch", NULL },
+ { NM_LINK_TYPE_TAP, "tap", NULL, NULL },
+ { NM_LINK_TYPE_TUN, "tun", NULL, NULL },
+ { NM_LINK_TYPE_VETH, "veth", "veth", NULL },
+ { NM_LINK_TYPE_VLAN, "vlan", "vlan", "vlan" },
+ { NM_LINK_TYPE_VXLAN, "vxlan", "vxlan", "vxlan" },
+
+ { NM_LINK_TYPE_BRIDGE, "bridge", "bridge", "bridge" },
+ { NM_LINK_TYPE_BOND, "bond", "bond", "bond" },
+ { NM_LINK_TYPE_TEAM, "team", "team", NULL },
+};
+
static const char *
-type_to_string (NMLinkType type)
+nm_link_type_to_rtnl_type_string (NMLinkType type)
{
- /* Note that this only has to support virtual types */
- switch (type) {
- case NM_LINK_TYPE_DUMMY:
- return "dummy";
- case NM_LINK_TYPE_GRE:
- return "gre";
- case NM_LINK_TYPE_GRETAP:
- return "gretap";
- case NM_LINK_TYPE_IFB:
- return "ifb";
- case NM_LINK_TYPE_MACVLAN:
- return "macvlan";
- case NM_LINK_TYPE_MACVTAP:
- return "macvtap";
- case NM_LINK_TYPE_TAP:
- return "tap";
- case NM_LINK_TYPE_TUN:
- return "tun";
- case NM_LINK_TYPE_VETH:
- return "veth";
- case NM_LINK_TYPE_VLAN:
- return "vlan";
- case NM_LINK_TYPE_VXLAN:
- return "vxlan";
- case NM_LINK_TYPE_BRIDGE:
- return "bridge";
- case NM_LINK_TYPE_BOND:
- return "bond";
- case NM_LINK_TYPE_TEAM:
- return "team";
- default:
- g_warning ("Wrong type: %d", type);
- return NULL;
+ int i;
+
+ for (i = 0; i < G_N_ELEMENTS (linktypes); i++) {
+ if (type == linktypes[i].nm_type)
+ return linktypes[i].rtnl_type;
+ }
+ g_return_val_if_reached (NULL);
+}
+
+static const char *
+nm_link_type_to_string (NMLinkType type)
+{
+ int i;
+
+ for (i = 0; i < G_N_ELEMENTS (linktypes); i++) {
+ if (type == linktypes[i].nm_type)
+ return linktypes[i].type_string;
}
+ g_return_val_if_reached (NULL);
}
#define DEVTYPE_PREFIX "DEVTYPE="
@@ -2298,7 +2334,7 @@ build_rtnl_link (int ifindex, const char *name, NMLinkType type)
rtnllink = _nm_rtnl_link_alloc (ifindex, name);
if (type) {
- nle = rtnl_link_set_type (rtnllink, type_to_string (type));
+ nle = rtnl_link_set_type (rtnllink, nm_link_type_to_rtnl_type_string (type));
g_assert (!nle);
}
return (struct nl_object *) rtnllink;
@@ -2322,7 +2358,7 @@ link_add (NMPlatform *platform, const char *name, NMLinkType type, const void *a
}
debug ("link: add link '%s' of type '%s' (%d)",
- name, type_to_string (type), (int) type);
+ name, nm_link_type_to_string (type), (int) type);
l = build_rtnl_link (0, name, type);