[PATCH 2/5] lib/route: Add port state translation functions
Jef Oliver
jef.oliver at intel.com
Wed Aug 31 17:27:06 PDT 2016
This patch adds translation functions for translating the port
state between integers and strings.
Signed-off-by: Jef Oliver <jef.oliver at intel.com>
---
include/netlink/route/link/bridge.h | 3 +++
lib/route/link/bridge.c | 25 +++++++++++++++++++++++++
libnl-route-3.sym | 6 ++++++
3 files changed, 34 insertions(+)
diff --git a/include/netlink/route/link/bridge.h b/include/netlink/route/link/bridge.h
index 438bb6a..b5f9b81 100644
--- a/include/netlink/route/link/bridge.h
+++ b/include/netlink/route/link/bridge.h
@@ -61,6 +61,9 @@ extern int rtnl_link_bridge_get_flags(struct rtnl_link *);
extern char * rtnl_link_bridge_flags2str(int, char *, size_t);
extern int rtnl_link_bridge_str2flags(const char *);
+extern char * rtnl_link_bridge_portstate2str(int, char *, size_t);
+extern int rtnl_link_bridge_str2portstate(const char *);
+
extern int rtnl_link_bridge_add(struct nl_sock *sk, const char *name);
extern int rtnl_link_bridge_pvid(struct rtnl_link *link);
diff --git a/lib/route/link/bridge.c b/lib/route/link/bridge.c
index 69acf82..015d24f 100644
--- a/lib/route/link/bridge.c
+++ b/lib/route/link/bridge.c
@@ -709,6 +709,31 @@ int rtnl_link_bridge_str2flags(const char *name)
/** @} */
+static const struct trans_tbl port_states[] = {
+ __ADD(BR_STATE_DISABLED, disabled),
+ __ADD(BR_STATE_LISTENING, listening),
+ __ADD(BR_STATE_LEARNING, learning),
+ __ADD(BR_STATE_FORWARDING, forwarding),
+ __ADD(BR_STATE_BLOCKING, blocking),
+};
+
+/**
+ * @name Port State Translation
+ * @{
+ */
+
+char *rtnl_link_bridge_portstate2str(int st, char *buf, size_t len)
+{
+ return __type2str(st, buf, len, port_states, ARRAY_SIZE(port_states));
+}
+
+int rtnl_link_bridge_str2portstate(const char *name)
+{
+ return __str2type(name, port_states, ARRAY_SIZE(port_states));
+}
+
+/** @} */
+
int rtnl_link_bridge_pvid(struct rtnl_link *link)
{
struct bridge_data *bd;
diff --git a/libnl-route-3.sym b/libnl-route-3.sym
index 13e1a51..f80714f 100644
--- a/libnl-route-3.sym
+++ b/libnl-route-3.sym
@@ -947,3 +947,9 @@ global:
rtnl_neigh_ll_get;
} libnl_3_2_27;
+libnl_3_2_29 {
+global:
+ rtnl_link_bridge_portstate2str;
+ rtnl_link_bridge_str2portstate;
+} libnl_3_2_28;
+
--
2.9.3
More information about the libnl
mailing list