Subject: Re: [PATCH iproute2 net-next v4] bridge: mdb: add support for extended router port information

From: Stephen Hemminger <[email-masked]>
Date: Sun, 13 Mar 2016 23:37:08 -0700

On Mon,  7 Mar 2016 11:10:32 +0100
Nikolay Aleksandrov <[email-masked]> wrote:

>  	rem = RTA_PAYLOAD(attr);
>  	for (i = RTA_DATA(attr); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
>  		port_ifindex = RTA_DATA(i);
> -		fprintf(f, "%s ", ll_index_to_name(*port_ifindex));
> +		if (show_stats) {
> +			struct rtattr *tb[MDBA_ROUTER_PATTR_MAX + 1];
> +
> +			parse_rtattr(tb, MDBA_ROUTER_PATTR_MAX,
> +				     MDB_RTR_RTA(RTA_DATA(i)),
> +				     RTA_PAYLOAD(i) -
> +				     RTA_ALIGN(sizeof(*port_ifindex)));
> +
> +			fprintf(f, "router ports on %s: %s",
> +				ll_index_to_name(brifidx),
> +				ll_index_to_name(*port_ifindex));
> +			if (tb[MDBA_ROUTER_PATTR_TIMER]) {
> +				struct timeval tv;
> +				__u32 tval;
> +
> +				tval = rta_getattr_u32(
> +						tb[MDBA_ROUTER_PATTR_TIMER]);
> +				__jiffies_to_tv(&tv, tval);
> +				fprintf(f, " %4i.%.2i",
> +					(int)tv.tv_sec, (int)tv.tv_usec/10000);
> +			}

You are having to cut lines short here to fit 80 characters, maybe
good time to make statistics a helper function.