[PATCH v2 3/5] lib/route: SRIOV Utility Functions

Jef Oliver jef.oliver at intel.com
Mon Nov 7 13:33:56 PST 2016


This patch adds utility functions for translating link state and
VLAN protocols for SRIOV VFs.

Signed-off-by: Jef Oliver <jef.oliver at intel.com>
---
 include/netlink/route/link/sriov.h |  7 +++++++
 lib/route/link/sriov.c             | 39 ++++++++++++++++++++++++++++++++++++++
 libnl-route-3.sym                  |  4 ++++
 3 files changed, 50 insertions(+)

diff --git a/include/netlink/route/link/sriov.h b/include/netlink/route/link/sriov.h
index 71d0dbe..8289b80 100644
--- a/include/netlink/route/link/sriov.h
+++ b/include/netlink/route/link/sriov.h
@@ -105,6 +105,13 @@ extern int rtnl_link_vf_get_vlans(struct rtnl_link_vf *, nl_vf_vlans_t **);
 extern int rtnl_link_vf_vlan_alloc(nl_vf_vlans_t **, int);
 extern void rtnl_link_vf_vlan_put(nl_vf_vlans_t *);
 
+/* Utility functions */
+extern char *rtnl_link_vf_linkstate2str(uint32_t, char *, size_t);
+extern int rtnl_link_vf_str2linkstate(const char *);
+
+extern char *rtnl_link_vf_vlanproto2str(uint16_t, char *, size_t);
+extern int rtnl_link_vf_str2vlanproto(const char *);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/route/link/sriov.c b/lib/route/link/sriov.c
index 2896541..5f083e9 100644
--- a/lib/route/link/sriov.c
+++ b/lib/route/link/sriov.c
@@ -799,6 +799,45 @@ void rtnl_link_vf_vlan_put(nl_vf_vlans_t *vf_vlans) {
 	return;
 }
 
+/** @} */
+
+/**
+ * @name Utilities
+ * @{
+ */
+
+static const struct trans_tbl vf_link_states[] = {
+	__ADD(IFLA_VF_LINK_STATE_AUTO, autodetect),
+	__ADD(IFLA_VF_LINK_STATE_ENABLE, up),
+	__ADD(IFLA_VF_LINK_STATE_DISABLE, down),
+};
+
+char *rtnl_link_vf_linkstate2str(uint32_t ls, char *buf, size_t len)
+{
+	return __type2str(ls, buf, len, vf_link_states,
+			  ARRAY_SIZE(vf_link_states));
+}
+
+int rtnl_link_vf_str2linkstate(const char *name)
+{
+	return __str2type(name, vf_link_states, ARRAY_SIZE(vf_link_states));
+}
+
+static const struct trans_tbl vf_vlan_proto[] = {
+	__ADD(ETH_P_8021Q, 8021Q),
+	__ADD(ETH_P_8021AD, 8021AD),
+};
+
+char *rtnl_link_vf_vlanproto2str(uint16_t proto, char *buf, size_t len)
+{
+	return __type2str(proto, buf, len, vf_vlan_proto,
+			  ARRAY_SIZE(vf_vlan_proto));
+}
+
+int rtnl_link_vf_str2vlanproto(const char *name)
+{
+	return __str2type(name, vf_vlan_proto, ARRAY_SIZE(vf_vlan_proto));
+}
 
 /** @} */
 
diff --git a/libnl-route-3.sym b/libnl-route-3.sym
index 469da87..67e705d 100644
--- a/libnl-route-3.sym
+++ b/libnl-route-3.sym
@@ -1006,5 +1006,9 @@ global:
 	rtnl_link_vf_vlan_alloc;
 	rtnl_link_vf_vlan_free;
 	rtnl_link_vf_vlan_put;
+	rtnl_link_vf_linkstate2str;
+	rtnl_link_vf_str2linkstate;
+	rtnl_link_vf_vlanproto2str;
+	rtnl_link_vf_str2vlanproto;
 } libnl_3_2_28;
 
-- 
2.10.1




More information about the libnl mailing list