[PATCH v2] Add new rtnl_bridge_get_port_state api

roopa at cumulusnetworks.com roopa at cumulusnetworks.com
Tue Jan 8 19:45:11 EST 2013


From: roopa <roopa at cumulusnetworks.com>

This patch adds support to get bridge port
state of an AF_BRIDGE link object.

changes from v1 to v2:
	- Added documentation:
		- Hooked bridge port AF_BRIDGE documentation
		under route Link (interfaces).

Signed-off-by: Wilson Kok <wkok at cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa at cumulusnetworks.com>
---
 doc/route.txt                       |   29 ++++++++++++++++++++++++++
 include/Makefile.am                 |    1 +
 include/netlink/route/link/bridge.h |   28 +++++++++++++++++++++++++
 lib/route/link/bridge.c             |   39 ++++++++++++++++++++++++++++++++++-
 4 files changed, 96 insertions(+), 1 deletion(-)
 create mode 100644 include/netlink/route/link/bridge.h

diff --git a/doc/route.txt b/doc/route.txt
index 61a84c4..4e91a12 100644
--- a/doc/route.txt
+++ b/doc/route.txt
@@ -710,6 +710,35 @@ if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0)
 rtnl_link_put(link);
 -----
 
+[[link_bridge]]
+==== Bridge
+
+[source,c]
+-----
+extern int		rtnl_bridge_get_port_state(struct rtnl_link *link);
+-----
+
+.Example: Get bridge port state
+[source,c]
+-----
+struct rtnl_link *link, *link_filter;
+int ifindex, port_state;
+
+link_needle = rtnl_link_alloc();
+
+/* Here cache is assumed to contain AF_BRIDGE objects, and eth0 a bridge port */
+ifindex = rtnl_link_name2i(cache, "eth0");
+rtnl_link_set_ifindex(link_needle, ifindex);
+rtnl_link_set_family(link_needle, AF_BRIDGE);
+
+link = nl_cache_search(cache, OBJ_CAST(link_needle));
+if (link)
+	port_state = rtnl_bridge_get_port_state(link);
+
+rtnl_link_put(link_needle);
+rtnl_link_put(link);
+-----
+
 == Neighbouring
 
 == Routing
diff --git a/include/Makefile.am b/include/Makefile.am
index e0f41fc..4db7844 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -49,6 +49,7 @@ nobase_libnlinclude_HEADERS = \
 	netlink/route/link/info-api.h \
 	netlink/route/link/inet.h \
 	netlink/route/link/vlan.h \
+	netlink/route/link/bridge.h \
 	netlink/route/qdisc/cbq.h \
 	netlink/route/qdisc/dsmark.h \
 	netlink/route/qdisc/fifo.h \
diff --git a/include/netlink/route/link/bridge.h b/include/netlink/route/link/bridge.h
new file mode 100644
index 0000000..3525e98
--- /dev/null
+++ b/include/netlink/route/link/bridge.h
@@ -0,0 +1,28 @@
+/*
+ * netlink/route/link/bridge.h		Bridge interface
+ *
+ *	This library is free software; you can redistribute it and/or
+ *	modify it under the terms of the GNU Lesser General Public
+ *	License as published by the Free Software Foundation version 2.1
+ *	of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf at suug.ch>
+ */
+
+#ifndef NETLINK_LINK_BRIDGE_H_
+#define NETLINK_LINK_BRIDGE_H_
+
+#include <netlink/netlink.h>
+#include <netlink/route/link.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int rtnl_bridge_get_port_state(struct rtnl_link *link);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/route/link/bridge.c b/lib/route/link/bridge.c
index cd9f462..d64202e 100644
--- a/lib/route/link/bridge.c
+++ b/lib/route/link/bridge.c
@@ -1,5 +1,5 @@
 /*
- * lib/route/link/bridge.c	AF_BRIDGE link oeprations
+ * lib/route/link/bridge.c	AF_BRIDGE link operations
  *
  *	This library is free software; you can redistribute it and/or
  *	modify it under the terms of the GNU Lesser General Public
@@ -9,12 +9,23 @@
  * Copyright (c) 2010 Thomas Graf <tgraf at suug.ch>
  */
 
+/**
+ * @ingroup link
+ * @defgroup bridge Bridge
+ * Bridge link operations
+ *
+ * @route_doc{link_bridge, Bridge Documentation}
+ *
+ * @{
+ */
+
 #include <netlink-local.h>
 #include <netlink/netlink.h>
 #include <netlink/attr.h>
 #include <netlink/route/rtnl.h>
 #include <netlink/route/link/api.h>
 
+/** @cond SKIP */
 #define BRIDGE_ATTR_PORT_STATE	0x0001
 
 struct bridge_data
@@ -22,6 +33,7 @@ struct bridge_data
 	uint8_t			b_port_state;
 	uint32_t                ce_mask; /* HACK to support attr macros */
 };
+/** @endcond */
 
 static void *bridge_alloc(struct rtnl_link *link)
 {
@@ -92,6 +104,29 @@ static struct rtnl_link_af_ops bridge_ops = {
 	.ao_compare			= &bridge_compare,
 };
 
+/**
+ * @name Bridge Object
+ * @{
+ */
+
+/**
+ * Get bridge port state
+ * @arg link            Link object
+ *
+ * @return port state if link has bridge port af data, otherwise -1 is returned.
+ */
+int rtnl_bridge_get_port_state(struct rtnl_link *link)
+{
+	struct bridge_data *data = link->l_af_data[AF_BRIDGE];
+
+	if (data && (data->ce_mask & BRIDGE_ATTR_PORT_STATE))
+		return data->b_port_state;
+
+	return -1;
+}
+
+/** @} */
+
 static void __init bridge_init(void)
 {
 	rtnl_link_af_register(&bridge_ops);
@@ -101,3 +136,5 @@ static void __exit bridge_exit(void)
 {
 	rtnl_link_af_unregister(&bridge_ops);
 }
+
+/** @} */
-- 
1.7.10.4




More information about the libnl mailing list