netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2 net-next] bridge: mdb: add user-space support for extended attributes
@ 2016-02-22 14:00 Nikolay Aleksandrov
  2016-02-22 14:09 ` Nikolay Aleksandrov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nikolay Aleksandrov @ 2016-02-22 14:00 UTC (permalink / raw)
  To: netdev; +Cc: roopa, stephen, Nikolay Aleksandrov

From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>

Recently support was added to the kernel to be able to add more per-mdb
entry attributes via standard netlink attributes of type MDBA_MDB_EATTR_.
This patch adds support to iproute2 to parse and output these
attributes. The first exported attribute is the mdb "timer" value which
is shown only when the "-d" iproute2 arg is used.

Example:
$ bridge -d mdb show
dev br0 port eth1 grp 239.0.0.11 permanent   0.00
dev br0 port eth2 grp 239.0.0.11 permanent   0.00
dev br0 port eth1 grp 239.0.0.10 temp 244.38
dev br0 port eth1 grp 239.0.0.1 temp 245.41
dev br0 port eth1 grp 239.0.0.5 temp 246.43
dev br0 port eth2 grp 239.0.0.5 temp 248.48
dev br0 port eth1 grp 239.0.0.2 temp 245.41

Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
note: this patch needs updated linux/if_bridge.h header to compile

 bridge/br_common.h |  3 +++
 bridge/mdb.c       | 15 ++++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/bridge/br_common.h b/bridge/br_common.h
index 169a162d0c01..41eb0dc38293 100644
--- a/bridge/br_common.h
+++ b/bridge/br_common.h
@@ -1,3 +1,6 @@
+#define MDB_RTA(r) \
+		((struct rtattr *)(((char *)(r)) + RTA_ALIGN(sizeof(struct br_mdb_entry))))
+
 extern int print_linkinfo(const struct sockaddr_nl *who,
 			  struct nlmsghdr *n,
 			  void *arg);
diff --git a/bridge/mdb.c b/bridge/mdb.c
index 24c4903542bf..922137369dac 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -49,7 +49,7 @@ static void br_print_router_ports(FILE *f, struct rtattr *attr)
 }
 
 static void print_mdb_entry(FILE *f, int ifindex, struct br_mdb_entry *e,
-			    struct nlmsghdr *n)
+			    struct nlmsghdr *n, struct rtattr **tb)
 {
 	SPRINT_BUF(abuf);
 	const void *src;
@@ -66,20 +66,29 @@ static void print_mdb_entry(FILE *f, int ifindex, struct br_mdb_entry *e,
 		(e->state & MDB_PERMANENT) ? "permanent" : "temp");
 	if (e->vid)
 		fprintf(f, " vid %hu", e->vid);
+	if (show_details && tb && tb[MDBA_MDB_EATTR_TIMER]) {
+		struct timeval tv;
+
+		__jiffies_to_tv(&tv, rta_getattr_u32(tb[MDBA_MDB_EATTR_TIMER]));
+		fprintf(f, "%4i.%.2i", (int)tv.tv_sec, (int)tv.tv_usec/10000);
+	}
 	fprintf(f, "\n");
 }
 
 static void br_print_mdb_entry(FILE *f, int ifindex, struct rtattr *attr,
 			       struct nlmsghdr *n)
 {
+	struct rtattr *etb[MDBA_MDB_EATTR_MAX + 1];
+	struct br_mdb_entry *e;
 	struct rtattr *i;
 	int rem;
-	struct br_mdb_entry *e;
 
 	rem = RTA_PAYLOAD(attr);
 	for (i = RTA_DATA(attr); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
 		e = RTA_DATA(i);
-		print_mdb_entry(f, ifindex, e, n);
+		parse_rtattr(etb, MDBA_MDB_EATTR_MAX, MDB_RTA(RTA_DATA(i)),
+			     RTA_PAYLOAD(i) - RTA_ALIGN(sizeof(*e)));
+		print_mdb_entry(f, ifindex, e, n, etb);
 	}
 }
 
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2 net-next] bridge: mdb: add user-space support for extended attributes
  2016-02-22 14:00 [PATCH iproute2 net-next] bridge: mdb: add user-space support for extended attributes Nikolay Aleksandrov
@ 2016-02-22 14:09 ` Nikolay Aleksandrov
  2016-02-22 14:16 ` [PATCH iproute2 net-next v2] " Nikolay Aleksandrov
  2016-03-02 17:23 ` [PATCH iproute2 net-next] " Stephen Hemminger
  2 siblings, 0 replies; 4+ messages in thread
From: Nikolay Aleksandrov @ 2016-02-22 14:09 UTC (permalink / raw)
  To: Nikolay Aleksandrov, netdev; +Cc: roopa, stephen

On 02/22/2016 03:00 PM, Nikolay Aleksandrov wrote:
> From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
> 
> Recently support was added to the kernel to be able to add more per-mdb
> entry attributes via standard netlink attributes of type MDBA_MDB_EATTR_.
> This patch adds support to iproute2 to parse and output these
> attributes. The first exported attribute is the mdb "timer" value which
> is shown only when the "-d" iproute2 arg is used.
> 
> Example:
> $ bridge -d mdb show
> dev br0 port eth1 grp 239.0.0.11 permanent   0.00
> dev br0 port eth2 grp 239.0.0.11 permanent   0.00
> dev br0 port eth1 grp 239.0.0.10 temp 244.38
> dev br0 port eth1 grp 239.0.0.1 temp 245.41
> dev br0 port eth1 grp 239.0.0.5 temp 246.43
> dev br0 port eth2 grp 239.0.0.5 temp 248.48
> dev br0 port eth1 grp 239.0.0.2 temp 245.41
> 
> Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
> ---
> note: this patch needs updated linux/if_bridge.h header to compile
> 

Self-NAK. I'll use the "-s"/stats as that seems to be used for some time
values instead and will update the man page. v2 coming up.

Sorry about the noise,
 Nik

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH iproute2 net-next v2] bridge: mdb: add user-space support for extended attributes
  2016-02-22 14:00 [PATCH iproute2 net-next] bridge: mdb: add user-space support for extended attributes Nikolay Aleksandrov
  2016-02-22 14:09 ` Nikolay Aleksandrov
@ 2016-02-22 14:16 ` Nikolay Aleksandrov
  2016-03-02 17:23 ` [PATCH iproute2 net-next] " Stephen Hemminger
  2 siblings, 0 replies; 4+ messages in thread
From: Nikolay Aleksandrov @ 2016-02-22 14:16 UTC (permalink / raw)
  To: netdev; +Cc: roopa, stephen, Nikolay Aleksandrov

From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>

Recently support was added to the kernel to be able to add more per-mdb
entry attributes via standard netlink attributes of type MDBA_MDB_EATTR_.
This patch adds support to iproute2 to parse and output these
attributes. The first exported attribute is the mdb "timer" value which
is shown only when the "-s" iproute2 arg is used.

Example:
$ bridge -s mdb show
dev br0 port eth1 grp 239.0.0.11 permanent   0.00
dev br0 port eth1 grp 239.0.0.10 temp 244.15
dev br0 port eth1 grp 239.0.0.1 temp 245.21
dev br0 port eth1 grp 239.0.0.5 temp 246.43
dev br0 port eth2 grp 239.0.0.5 temp 248.44
dev br0 port eth1 grp 239.0.0.2 temp 245.32

Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
note: this patch needs updated linux/if_bridge.h header to compile

v2: use -s instead of -d and update bridge's man page

 bridge/br_common.h |  3 +++
 bridge/mdb.c       | 15 ++++++++++++---
 man/man8/bridge.8  |  5 +++++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/bridge/br_common.h b/bridge/br_common.h
index 169a162d0c01..41eb0dc38293 100644
--- a/bridge/br_common.h
+++ b/bridge/br_common.h
@@ -1,3 +1,6 @@
+#define MDB_RTA(r) \
+		((struct rtattr *)(((char *)(r)) + RTA_ALIGN(sizeof(struct br_mdb_entry))))
+
 extern int print_linkinfo(const struct sockaddr_nl *who,
 			  struct nlmsghdr *n,
 			  void *arg);
diff --git a/bridge/mdb.c b/bridge/mdb.c
index 24c4903542bf..09d4b2255857 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -49,7 +49,7 @@ static void br_print_router_ports(FILE *f, struct rtattr *attr)
 }
 
 static void print_mdb_entry(FILE *f, int ifindex, struct br_mdb_entry *e,
-			    struct nlmsghdr *n)
+			    struct nlmsghdr *n, struct rtattr **tb)
 {
 	SPRINT_BUF(abuf);
 	const void *src;
@@ -66,20 +66,29 @@ static void print_mdb_entry(FILE *f, int ifindex, struct br_mdb_entry *e,
 		(e->state & MDB_PERMANENT) ? "permanent" : "temp");
 	if (e->vid)
 		fprintf(f, " vid %hu", e->vid);
+	if (show_stats && tb && tb[MDBA_MDB_EATTR_TIMER]) {
+		struct timeval tv;
+
+		__jiffies_to_tv(&tv, rta_getattr_u32(tb[MDBA_MDB_EATTR_TIMER]));
+		fprintf(f, "%4i.%.2i", (int)tv.tv_sec, (int)tv.tv_usec/10000);
+	}
 	fprintf(f, "\n");
 }
 
 static void br_print_mdb_entry(FILE *f, int ifindex, struct rtattr *attr,
 			       struct nlmsghdr *n)
 {
+	struct rtattr *etb[MDBA_MDB_EATTR_MAX + 1];
+	struct br_mdb_entry *e;
 	struct rtattr *i;
 	int rem;
-	struct br_mdb_entry *e;
 
 	rem = RTA_PAYLOAD(attr);
 	for (i = RTA_DATA(attr); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
 		e = RTA_DATA(i);
-		print_mdb_entry(f, ifindex, e, n);
+		parse_rtattr(etb, MDBA_MDB_EATTR_MAX, MDB_RTA(RTA_DATA(i)),
+			     RTA_PAYLOAD(i) - RTA_ALIGN(sizeof(*e)));
+		print_mdb_entry(f, ifindex, e, n, etb);
 	}
 }
 
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index efd416e71d55..0e98edf4762f 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -503,6 +503,11 @@ With the
 option, the command becomes verbose. It prints out the ports known to have
 a connected router.
 
+.PP
+With the
+.B -statistics
+option, the command displays timer values for mdb entries.
+
 .SH bridge vlan - VLAN filter list
 
 .B vlan
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2 net-next] bridge: mdb: add user-space support for extended attributes
  2016-02-22 14:00 [PATCH iproute2 net-next] bridge: mdb: add user-space support for extended attributes Nikolay Aleksandrov
  2016-02-22 14:09 ` Nikolay Aleksandrov
  2016-02-22 14:16 ` [PATCH iproute2 net-next v2] " Nikolay Aleksandrov
@ 2016-03-02 17:23 ` Stephen Hemminger
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2016-03-02 17:23 UTC (permalink / raw)
  To: Nikolay Aleksandrov; +Cc: netdev, roopa, Nikolay Aleksandrov

On Mon, 22 Feb 2016 15:00:21 +0100
Nikolay Aleksandrov <razor@blackwall.org> wrote:

> From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
> 
> Recently support was added to the kernel to be able to add more per-mdb
> entry attributes via standard netlink attributes of type MDBA_MDB_EATTR_.
> This patch adds support to iproute2 to parse and output these
> attributes. The first exported attribute is the mdb "timer" value which
> is shown only when the "-d" iproute2 arg is used.
> 
> Example:
> $ bridge -d mdb show
> dev br0 port eth1 grp 239.0.0.11 permanent   0.00
> dev br0 port eth2 grp 239.0.0.11 permanent   0.00
> dev br0 port eth1 grp 239.0.0.10 temp 244.38
> dev br0 port eth1 grp 239.0.0.1 temp 245.41
> dev br0 port eth1 grp 239.0.0.5 temp 246.43
> dev br0 port eth2 grp 239.0.0.5 temp 248.48
> dev br0 port eth1 grp 239.0.0.2 temp 245.41
> 
> Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-03-02 17:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-22 14:00 [PATCH iproute2 net-next] bridge: mdb: add user-space support for extended attributes Nikolay Aleksandrov
2016-02-22 14:09 ` Nikolay Aleksandrov
2016-02-22 14:16 ` [PATCH iproute2 net-next v2] " Nikolay Aleksandrov
2016-03-02 17:23 ` [PATCH iproute2 net-next] " Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).