]> granicus.if.org Git - libnl/commitdiff
lib/route: Add port state translation functions
authorJef Oliver <jef.oliver@intel.com>
Thu, 1 Sep 2016 00:27:06 +0000 (17:27 -0700)
committerThomas Haller <thaller@redhat.com>
Sat, 24 Sep 2016 11:51:29 +0000 (13:51 +0200)
This patch adds translation functions for translating the port
state between integers and strings.

Signed-off-by: Jef Oliver <jef.oliver@intel.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
include/netlink/route/link/bridge.h
lib/route/link/bridge.c
libnl-route-3.sym

index 438bb6a58a1d67ad797030c2a0f9c4d6ee3e6dda..b5f9b8183f96a3dbb17011bfe78ec40c48d2c773 100644 (file)
@@ -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);
index 69acf82deaac5103368f146e95e54a928d8ffc3f..015d24fcf60ba57cc5de22e1c305de911fe41718 100644 (file)
@@ -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;
index 13e1a51472b5eb1369296f63fd12d18f03c5218a..f80714f0bed1b38b0c50f951735d19e7774e2148 100644 (file)
@@ -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;
+