All of lore.kernel.org
 help / color / mirror / Atom feed
* [iproute PATCH] ip{,6}tunnel: have a shared stats parser/printer
@ 2015-12-11 12:23 Phil Sutter
  2015-12-18  1:14 ` Stephen Hemminger
  0 siblings, 1 reply; 9+ messages in thread
From: Phil Sutter @ 2015-12-11 12:23 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

This has a slight side-effect of not aborting when /proc/net/dev is
malformed, but OTOH stats are not parsed for uninteresting interfaces.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 ip/ip6tunnel.c | 21 ++-------------------
 ip/iptunnel.c  | 21 ++-------------------
 ip/tunnel.c    | 28 ++++++++++++++++++++++++++++
 ip/tunnel.h    |  1 +
 4 files changed, 33 insertions(+), 38 deletions(-)

diff --git a/ip/ip6tunnel.c b/ip/ip6tunnel.c
index 1737d884319ec..7a3cd0461fff1 100644
--- a/ip/ip6tunnel.c
+++ b/ip/ip6tunnel.c
@@ -341,10 +341,6 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
 	while (fgets(buf, sizeof(buf), fp) != NULL) {
 		char name[IFNAMSIZ];
 		int index, type;
-		unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
-			rx_fifo, rx_frame,
-			tx_bytes, tx_packets, tx_errs, tx_drops,
-			tx_fifo, tx_colls, tx_carrier, rx_multi;
 		struct ip6_tnl_parm2 p1;
 		char *ptr;
 
@@ -354,12 +350,6 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
 			fprintf(stderr, "Wrong format for /proc/net/dev. Giving up.\n");
 			goto end;
 		}
-		if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
-			   &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
-			   &rx_fifo, &rx_frame, &rx_multi,
-			   &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
-			   &tx_fifo, &tx_colls, &tx_carrier) != 14)
-			continue;
 		if (p->name[0] && strcmp(p->name, name))
 			continue;
 		index = ll_name_to_index(name);
@@ -385,15 +375,8 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
 		if (!ip6_tnl_parm_match(p, &p1))
 			continue;
 		print_tunnel(&p1);
-		if (show_stats) {
-			printf("%s", _SL_);
-			printf("RX: Packets    Bytes        Errors CsumErrs OutOfSeq Mcasts%s", _SL_);
-			printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-8ld%s",
-			       rx_packets, rx_bytes, rx_errs, rx_frame, rx_fifo, rx_multi, _SL_);
-			printf("TX: Packets    Bytes        Errors DeadLoop NoRoute  NoBufs%s", _SL_);
-			printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-6ld",
-			       tx_packets, tx_bytes, tx_errs, tx_colls, tx_carrier, tx_drops);
-		}
+		if (show_stats)
+			tnl_print_stats(ptr);
 		printf("\n");
 	}
 	err = 0;
diff --git a/ip/iptunnel.c b/ip/iptunnel.c
index a3ff99bd87eb8..65a4e6e9c1a5a 100644
--- a/ip/iptunnel.c
+++ b/ip/iptunnel.c
@@ -405,10 +405,6 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
 	while (fgets(buf, sizeof(buf), fp) != NULL) {
 		char name[IFNAMSIZ];
 		int index, type;
-		unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
-			rx_fifo, rx_frame,
-			tx_bytes, tx_packets, tx_errs, tx_drops,
-			tx_fifo, tx_colls, tx_carrier, rx_multi;
 		struct ip_tunnel_parm p1;
 		char *ptr;
 
@@ -419,12 +415,6 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
 			fprintf(stderr, "Wrong format for /proc/net/dev. Giving up.\n");
 			goto end;
 		}
-		if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
-			   &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
-			   &rx_fifo, &rx_frame, &rx_multi,
-			   &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
-			   &tx_fifo, &tx_colls, &tx_carrier) != 14)
-			continue;
 		if (p->name[0] && strcmp(p->name, name))
 			continue;
 		index = ll_name_to_index(name);
@@ -447,15 +437,8 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
 		    (p->i_key && p1.i_key != p->i_key))
 			continue;
 		print_tunnel(&p1);
-		if (show_stats) {
-			printf("%s", _SL_);
-			printf("RX: Packets    Bytes        Errors CsumErrs OutOfSeq Mcasts%s", _SL_);
-			printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-8ld%s",
-			       rx_packets, rx_bytes, rx_errs, rx_frame, rx_fifo, rx_multi, _SL_);
-			printf("TX: Packets    Bytes        Errors DeadLoop NoRoute  NoBufs%s", _SL_);
-			printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-6ld",
-			       tx_packets, tx_bytes, tx_errs, tx_colls, tx_carrier, tx_drops);
-		}
+		if (show_stats)
+			tnl_print_stats(ptr);
 		printf("\n");
 	}
 	err = 0;
diff --git a/ip/tunnel.c b/ip/tunnel.c
index 79f2201f2356f..1dd809227fed4 100644
--- a/ip/tunnel.c
+++ b/ip/tunnel.c
@@ -195,3 +195,31 @@ __be32 tnl_parse_key(const char *name, const char *key)
 	}
 	return htonl(uval);
 }
+
+/* tnl_print_stats - print tunnel statistics
+ *
+ * @buf - tunnel interface's line in /proc/net/dev,
+ *        starting past the interface name and following colon
+ */
+void tnl_print_stats(const char *buf)
+{
+	unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
+		      rx_fifo, rx_frame,
+		      tx_bytes, tx_packets, tx_errs, tx_drops,
+		      tx_fifo, tx_colls, tx_carrier, rx_multi;
+
+	if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
+	           &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
+	           &rx_fifo, &rx_frame, &rx_multi,
+	           &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
+	           &tx_fifo, &tx_colls, &tx_carrier) != 14)
+		return;
+
+	printf("%s", _SL_);
+	printf("RX: Packets    Bytes        Errors CsumErrs OutOfSeq Mcasts%s", _SL_);
+	printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-8ld%s",
+	       rx_packets, rx_bytes, rx_errs, rx_frame, rx_fifo, rx_multi, _SL_);
+	printf("TX: Packets    Bytes        Errors DeadLoop NoRoute  NoBufs%s", _SL_);
+	printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-6ld",
+	       tx_packets, tx_bytes, tx_errs, tx_colls, tx_carrier, tx_drops);
+}
diff --git a/ip/tunnel.h b/ip/tunnel.h
index 9fb4a186176fa..9a03c0d7756e3 100644
--- a/ip/tunnel.h
+++ b/ip/tunnel.h
@@ -32,5 +32,6 @@ int tnl_prl_ioctl(int cmd, const char *name, void *p);
 int tnl_6rd_ioctl(int cmd, const char *name, void *p);
 int tnl_ioctl_get_6rd(const char *name, void *p);
 __be32 tnl_parse_key(const char *name, const char *key);
+void tnl_print_stats(const char *buf);
 
 #endif
-- 
2.6.4

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

* Re: [iproute PATCH] ip{,6}tunnel: have a shared stats parser/printer
  2015-12-11 12:23 [iproute PATCH] ip{,6}tunnel: have a shared stats parser/printer Phil Sutter
@ 2015-12-18  1:14 ` Stephen Hemminger
  2015-12-18 10:52   ` Phil Sutter
  0 siblings, 1 reply; 9+ messages in thread
From: Stephen Hemminger @ 2015-12-18  1:14 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netdev

On Fri, 11 Dec 2015 13:23:44 +0100
Phil Sutter <phil@nwl.cc> wrote:

> This has a slight side-effect of not aborting when /proc/net/dev is
> malformed, but OTOH stats are not parsed for uninteresting interfaces.
> 
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
>  ip/ip6tunnel.c | 21 ++-------------------
>  ip/iptunnel.c  | 21 ++-------------------
>  ip/tunnel.c    | 28 ++++++++++++++++++++++++++++
>  ip/tunnel.h    |  1 +
>  4 files changed, 33 insertions(+), 38 deletions(-)
> 
> diff --git a/ip/ip6tunnel.c b/ip/ip6tunnel.c
> index 1737d884319ec..7a3cd0461fff1 100644
> --- a/ip/ip6tunnel.c
> +++ b/ip/ip6tunnel.c
> @@ -341,10 +341,6 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
>  	while (fgets(buf, sizeof(buf), fp) != NULL) {
>  		char name[IFNAMSIZ];
>  		int index, type;
> -		unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
> -			rx_fifo, rx_frame,
> -			tx_bytes, tx_packets, tx_errs, tx_drops,
> -			tx_fifo, tx_colls, tx_carrier, rx_multi;
>  		struct ip6_tnl_parm2 p1;
>  		char *ptr;
>  
> @@ -354,12 +350,6 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
>  			fprintf(stderr, "Wrong format for /proc/net/dev. Giving up.\n");
>  			goto end;
>  		}
> -		if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
> -			   &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
> -			   &rx_fifo, &rx_frame, &rx_multi,
> -			   &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
> -			   &tx_fifo, &tx_colls, &tx_carrier) != 14)
> -			continue;
>  		if (p->name[0] && strcmp(p->name, name))
>  			continue;
>  		index = ll_name_to_index(name);
> @@ -385,15 +375,8 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
>  		if (!ip6_tnl_parm_match(p, &p1))
>  			continue;
>  		print_tunnel(&p1);
> -		if (show_stats) {
> -			printf("%s", _SL_);
> -			printf("RX: Packets    Bytes        Errors CsumErrs OutOfSeq Mcasts%s", _SL_);
> -			printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-8ld%s",
> -			       rx_packets, rx_bytes, rx_errs, rx_frame, rx_fifo, rx_multi, _SL_);
> -			printf("TX: Packets    Bytes        Errors DeadLoop NoRoute  NoBufs%s", _SL_);
> -			printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-6ld",
> -			       tx_packets, tx_bytes, tx_errs, tx_colls, tx_carrier, tx_drops);
> -		}
> +		if (show_stats)
> +			tnl_print_stats(ptr);
>  		printf("\n");
>  	}
>  	err = 0;
> diff --git a/ip/iptunnel.c b/ip/iptunnel.c
> index a3ff99bd87eb8..65a4e6e9c1a5a 100644
> --- a/ip/iptunnel.c
> +++ b/ip/iptunnel.c
> @@ -405,10 +405,6 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
>  	while (fgets(buf, sizeof(buf), fp) != NULL) {
>  		char name[IFNAMSIZ];
>  		int index, type;
> -		unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
> -			rx_fifo, rx_frame,
> -			tx_bytes, tx_packets, tx_errs, tx_drops,
> -			tx_fifo, tx_colls, tx_carrier, rx_multi;
>  		struct ip_tunnel_parm p1;
>  		char *ptr;
>  
> @@ -419,12 +415,6 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
>  			fprintf(stderr, "Wrong format for /proc/net/dev. Giving up.\n");
>  			goto end;
>  		}
> -		if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
> -			   &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
> -			   &rx_fifo, &rx_frame, &rx_multi,
> -			   &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
> -			   &tx_fifo, &tx_colls, &tx_carrier) != 14)
> -			continue;
>  		if (p->name[0] && strcmp(p->name, name))
>  			continue;
>  		index = ll_name_to_index(name);
> @@ -447,15 +437,8 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
>  		    (p->i_key && p1.i_key != p->i_key))
>  			continue;
>  		print_tunnel(&p1);
> -		if (show_stats) {
> -			printf("%s", _SL_);
> -			printf("RX: Packets    Bytes        Errors CsumErrs OutOfSeq Mcasts%s", _SL_);
> -			printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-8ld%s",
> -			       rx_packets, rx_bytes, rx_errs, rx_frame, rx_fifo, rx_multi, _SL_);
> -			printf("TX: Packets    Bytes        Errors DeadLoop NoRoute  NoBufs%s", _SL_);
> -			printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-6ld",
> -			       tx_packets, tx_bytes, tx_errs, tx_colls, tx_carrier, tx_drops);
> -		}
> +		if (show_stats)
> +			tnl_print_stats(ptr);
>  		printf("\n");
>  	}
>  	err = 0;
> diff --git a/ip/tunnel.c b/ip/tunnel.c
> index 79f2201f2356f..1dd809227fed4 100644
> --- a/ip/tunnel.c
> +++ b/ip/tunnel.c
> @@ -195,3 +195,31 @@ __be32 tnl_parse_key(const char *name, const char *key)
>  	}
>  	return htonl(uval);
>  }
> +
> +/* tnl_print_stats - print tunnel statistics
> + *
> + * @buf - tunnel interface's line in /proc/net/dev,
> + *        starting past the interface name and following colon
> + */
> +void tnl_print_stats(const char *buf)
> +{
> +	unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
> +		      rx_fifo, rx_frame,
> +		      tx_bytes, tx_packets, tx_errs, tx_drops,
> +		      tx_fifo, tx_colls, tx_carrier, rx_multi;
> +
> +	if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
> +	           &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
> +	           &rx_fifo, &rx_frame, &rx_multi,
> +	           &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
> +	           &tx_fifo, &tx_colls, &tx_carrier) != 14)
> +		return;
> +
> +	printf("%s", _SL_);
> +	printf("RX: Packets    Bytes        Errors CsumErrs OutOfSeq Mcasts%s", _SL_);
> +	printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-8ld%s",
> +	       rx_packets, rx_bytes, rx_errs, rx_frame, rx_fifo, rx_multi, _SL_);
> +	printf("TX: Packets    Bytes        Errors DeadLoop NoRoute  NoBufs%s", _SL_);
> +	printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-6ld",
> +	       tx_packets, tx_bytes, tx_errs, tx_colls, tx_carrier, tx_drops);
> +}
> diff --git a/ip/tunnel.h b/ip/tunnel.h
> index 9fb4a186176fa..9a03c0d7756e3 100644
> --- a/ip/tunnel.h
> +++ b/ip/tunnel.h
> @@ -32,5 +32,6 @@ int tnl_prl_ioctl(int cmd, const char *name, void *p);
>  int tnl_6rd_ioctl(int cmd, const char *name, void *p);
>  int tnl_ioctl_get_6rd(const char *name, void *p);
>  __be32 tnl_parse_key(const char *name, const char *key);
> +void tnl_print_stats(const char *buf);
>  
>  #endif

I just fixed the sscanf formats and after that this patch caused build error.
tunnel.c: In function ‘tnl_print_stats’:
tunnel.c:211:13: error: ‘ptr’ undeclared (first use in this function)
  if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
             ^
tunnel.c:211:13: note: each undeclared identifier is reported only once for each function it appears in
<builtin>: recipe for target 'tunnel.o' failed

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

* Re: [iproute PATCH] ip{,6}tunnel: have a shared stats parser/printer
  2015-12-18  1:14 ` Stephen Hemminger
@ 2015-12-18 10:52   ` Phil Sutter
  2015-12-18 10:58     ` [iproute PATCH v2] " Phil Sutter
  0 siblings, 1 reply; 9+ messages in thread
From: Phil Sutter @ 2015-12-18 10:52 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

On Thu, Dec 17, 2015 at 05:14:21PM -0800, Stephen Hemminger wrote:
> I just fixed the sscanf formats and after that this patch caused build error.
> tunnel.c: In function ‘tnl_print_stats’:
> tunnel.c:211:13: error: ‘ptr’ undeclared (first use in this function)
>   if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
>              ^
> tunnel.c:211:13: note: each undeclared identifier is reported only once for each function it appears in
> <builtin>: recipe for target 'tunnel.o' failed

Ah, sorry. I obviously messed up conflict resolution while rebasing this
onto your master. Fixed version follows.

Thanks, Phil

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

* [iproute PATCH v2] ip{,6}tunnel: have a shared stats parser/printer
  2015-12-18 10:52   ` Phil Sutter
@ 2015-12-18 10:58     ` Phil Sutter
  2015-12-18 19:47       ` Stephen Hemminger
  2015-12-21 11:00       ` Daniel Borkmann
  0 siblings, 2 replies; 9+ messages in thread
From: Phil Sutter @ 2015-12-18 10:58 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

This has a slight side-effect of not aborting when /proc/net/dev is
malformed, but OTOH stats are not parsed for uninteresting interfaces.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
Changes since v1:
- Fix conflict resolution (sscan from 'buf' instead of 'ptr').
---
 ip/ip6tunnel.c | 21 ++-------------------
 ip/iptunnel.c  | 21 ++-------------------
 ip/tunnel.c    | 28 ++++++++++++++++++++++++++++
 ip/tunnel.h    |  1 +
 4 files changed, 33 insertions(+), 38 deletions(-)

diff --git a/ip/ip6tunnel.c b/ip/ip6tunnel.c
index 1737d884319ec..7a3cd0461fff1 100644
--- a/ip/ip6tunnel.c
+++ b/ip/ip6tunnel.c
@@ -341,10 +341,6 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
 	while (fgets(buf, sizeof(buf), fp) != NULL) {
 		char name[IFNAMSIZ];
 		int index, type;
-		unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
-			rx_fifo, rx_frame,
-			tx_bytes, tx_packets, tx_errs, tx_drops,
-			tx_fifo, tx_colls, tx_carrier, rx_multi;
 		struct ip6_tnl_parm2 p1;
 		char *ptr;
 
@@ -354,12 +350,6 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
 			fprintf(stderr, "Wrong format for /proc/net/dev. Giving up.\n");
 			goto end;
 		}
-		if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
-			   &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
-			   &rx_fifo, &rx_frame, &rx_multi,
-			   &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
-			   &tx_fifo, &tx_colls, &tx_carrier) != 14)
-			continue;
 		if (p->name[0] && strcmp(p->name, name))
 			continue;
 		index = ll_name_to_index(name);
@@ -385,15 +375,8 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
 		if (!ip6_tnl_parm_match(p, &p1))
 			continue;
 		print_tunnel(&p1);
-		if (show_stats) {
-			printf("%s", _SL_);
-			printf("RX: Packets    Bytes        Errors CsumErrs OutOfSeq Mcasts%s", _SL_);
-			printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-8ld%s",
-			       rx_packets, rx_bytes, rx_errs, rx_frame, rx_fifo, rx_multi, _SL_);
-			printf("TX: Packets    Bytes        Errors DeadLoop NoRoute  NoBufs%s", _SL_);
-			printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-6ld",
-			       tx_packets, tx_bytes, tx_errs, tx_colls, tx_carrier, tx_drops);
-		}
+		if (show_stats)
+			tnl_print_stats(ptr);
 		printf("\n");
 	}
 	err = 0;
diff --git a/ip/iptunnel.c b/ip/iptunnel.c
index a3ff99bd87eb8..65a4e6e9c1a5a 100644
--- a/ip/iptunnel.c
+++ b/ip/iptunnel.c
@@ -405,10 +405,6 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
 	while (fgets(buf, sizeof(buf), fp) != NULL) {
 		char name[IFNAMSIZ];
 		int index, type;
-		unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
-			rx_fifo, rx_frame,
-			tx_bytes, tx_packets, tx_errs, tx_drops,
-			tx_fifo, tx_colls, tx_carrier, rx_multi;
 		struct ip_tunnel_parm p1;
 		char *ptr;
 
@@ -419,12 +415,6 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
 			fprintf(stderr, "Wrong format for /proc/net/dev. Giving up.\n");
 			goto end;
 		}
-		if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
-			   &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
-			   &rx_fifo, &rx_frame, &rx_multi,
-			   &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
-			   &tx_fifo, &tx_colls, &tx_carrier) != 14)
-			continue;
 		if (p->name[0] && strcmp(p->name, name))
 			continue;
 		index = ll_name_to_index(name);
@@ -447,15 +437,8 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
 		    (p->i_key && p1.i_key != p->i_key))
 			continue;
 		print_tunnel(&p1);
-		if (show_stats) {
-			printf("%s", _SL_);
-			printf("RX: Packets    Bytes        Errors CsumErrs OutOfSeq Mcasts%s", _SL_);
-			printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-8ld%s",
-			       rx_packets, rx_bytes, rx_errs, rx_frame, rx_fifo, rx_multi, _SL_);
-			printf("TX: Packets    Bytes        Errors DeadLoop NoRoute  NoBufs%s", _SL_);
-			printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-6ld",
-			       tx_packets, tx_bytes, tx_errs, tx_colls, tx_carrier, tx_drops);
-		}
+		if (show_stats)
+			tnl_print_stats(ptr);
 		printf("\n");
 	}
 	err = 0;
diff --git a/ip/tunnel.c b/ip/tunnel.c
index 79f2201f2356f..1dd809227fed4 100644
--- a/ip/tunnel.c
+++ b/ip/tunnel.c
@@ -195,3 +195,31 @@ __be32 tnl_parse_key(const char *name, const char *key)
 	}
 	return htonl(uval);
 }
+
+/* tnl_print_stats - print tunnel statistics
+ *
+ * @buf - tunnel interface's line in /proc/net/dev,
+ *        starting past the interface name and following colon
+ */
+void tnl_print_stats(const char *buf)
+{
+	unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
+		      rx_fifo, rx_frame,
+		      tx_bytes, tx_packets, tx_errs, tx_drops,
+		      tx_fifo, tx_colls, tx_carrier, rx_multi;
+
+	if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
+	           &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
+	           &rx_fifo, &rx_frame, &rx_multi,
+	           &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
+	           &tx_fifo, &tx_colls, &tx_carrier) != 14)
+		return;
+
+	printf("%s", _SL_);
+	printf("RX: Packets    Bytes        Errors CsumErrs OutOfSeq Mcasts%s", _SL_);
+	printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-8ld%s",
+	       rx_packets, rx_bytes, rx_errs, rx_frame, rx_fifo, rx_multi, _SL_);
+	printf("TX: Packets    Bytes        Errors DeadLoop NoRoute  NoBufs%s", _SL_);
+	printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-6ld",
+	       tx_packets, tx_bytes, tx_errs, tx_colls, tx_carrier, tx_drops);
+}
diff --git a/ip/tunnel.h b/ip/tunnel.h
index 9fb4a186176fa..9a03c0d7756e3 100644
--- a/ip/tunnel.h
+++ b/ip/tunnel.h
@@ -32,5 +32,6 @@ int tnl_prl_ioctl(int cmd, const char *name, void *p);
 int tnl_6rd_ioctl(int cmd, const char *name, void *p);
 int tnl_ioctl_get_6rd(const char *name, void *p);
 __be32 tnl_parse_key(const char *name, const char *key);
+void tnl_print_stats(const char *buf);
 
 #endif
-- 
2.6.4

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

* Re: [iproute PATCH v2] ip{,6}tunnel: have a shared stats parser/printer
  2015-12-18 10:58     ` [iproute PATCH v2] " Phil Sutter
@ 2015-12-18 19:47       ` Stephen Hemminger
  2015-12-21 11:00       ` Daniel Borkmann
  1 sibling, 0 replies; 9+ messages in thread
From: Stephen Hemminger @ 2015-12-18 19:47 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netdev

On Fri, 18 Dec 2015 11:58:06 +0100
Phil Sutter <phil@nwl.cc> wrote:

> This has a slight side-effect of not aborting when /proc/net/dev is
> malformed, but OTOH stats are not parsed for uninteresting interfaces.
> 
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
> Changes since v1:
> - Fix conflict resolution (sscan from 'buf' instead of 'ptr').

Applied thanks.

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

* Re: [iproute PATCH v2] ip{,6}tunnel: have a shared stats parser/printer
  2015-12-18 10:58     ` [iproute PATCH v2] " Phil Sutter
  2015-12-18 19:47       ` Stephen Hemminger
@ 2015-12-21 11:00       ` Daniel Borkmann
  2015-12-21 19:36         ` Phil Sutter
  2015-12-21 19:42         ` [iproute PATCH] iptunnel: Fix compile error in ip/tunnel.c Phil Sutter
  1 sibling, 2 replies; 9+ messages in thread
From: Daniel Borkmann @ 2015-12-21 11:00 UTC (permalink / raw)
  To: Phil Sutter, Stephen Hemminger; +Cc: netdev

On 12/18/2015 11:58 AM, Phil Sutter wrote:
> This has a slight side-effect of not aborting when /proc/net/dev is
> malformed, but OTOH stats are not parsed for uninteresting interfaces.
>
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
> Changes since v1:
> - Fix conflict resolution (sscan from 'buf' instead of 'ptr').
[...]

Hmm, did you actually compile that?

The code is still the same as in v1 ... the only thing added is the "Changes since v1"
description. ;)

[...]
> +void tnl_print_stats(const char *buf)
> +{
> +	unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
> +		      rx_fifo, rx_frame,
> +		      tx_bytes, tx_packets, tx_errs, tx_drops,
> +		      tx_fifo, tx_colls, tx_carrier, rx_multi;
> +
> +	if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",

   s/ptr/buf/

> +	           &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
> +	           &rx_fifo, &rx_frame, &rx_multi,
> +	           &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
> +	           &tx_fifo, &tx_colls, &tx_carrier) != 14)
> +		return;
> +
> +	printf("%s", _SL_);
> +	printf("RX: Packets    Bytes        Errors CsumErrs OutOfSeq Mcasts%s", _SL_);
> +	printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-8ld%s",
> +	       rx_packets, rx_bytes, rx_errs, rx_frame, rx_fifo, rx_multi, _SL_);
> +	printf("TX: Packets    Bytes        Errors DeadLoop NoRoute  NoBufs%s", _SL_);
> +	printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-6ld",
> +	       tx_packets, tx_bytes, tx_errs, tx_colls, tx_carrier, tx_drops);
> +}

tunnel.c: In function ‘tnl_print_stats’:
tunnel.c:211:13: error: ‘buff’ undeclared (first use in this function)
   if (sscanf(buff, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
              ^
tunnel.c:211:13: note: each undeclared identifier is reported only once for each function it appears in
make[1]: *** [tunnel.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [all] Error 2

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

* Re: [iproute PATCH v2] ip{,6}tunnel: have a shared stats parser/printer
  2015-12-21 11:00       ` Daniel Borkmann
@ 2015-12-21 19:36         ` Phil Sutter
  2015-12-21 19:42         ` [iproute PATCH] iptunnel: Fix compile error in ip/tunnel.c Phil Sutter
  1 sibling, 0 replies; 9+ messages in thread
From: Phil Sutter @ 2015-12-21 19:36 UTC (permalink / raw)
  To: Daniel Borkmann; +Cc: Stephen Hemminger, netdev

On Mon, Dec 21, 2015 at 12:00:06PM +0100, Daniel Borkmann wrote:
> On 12/18/2015 11:58 AM, Phil Sutter wrote:
> > This has a slight side-effect of not aborting when /proc/net/dev is
> > malformed, but OTOH stats are not parsed for uninteresting interfaces.
> >
> > Signed-off-by: Phil Sutter <phil@nwl.cc>
> > ---
> > Changes since v1:
> > - Fix conflict resolution (sscan from 'buf' instead of 'ptr').
> [...]
> 
> Hmm, did you actually compile that?
> 
> The code is still the same as in v1 ... the only thing added is the "Changes since v1"
> description. ;)

Oh man. I certainly double-checked it, especially since I messed it up
the first time already. Quick forensics in my local clone revealed what
had happened:

1) Exported the V2 patch into a dedicated patch subdir.
2) ???
3) Edited the V1 patch in $TOPDIR and sent that out.

Face -> Desk.

Fix follows. :(

Thanks for reporting,

Phil

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

* [iproute PATCH] iptunnel: Fix compile error in ip/tunnel.c
  2015-12-21 11:00       ` Daniel Borkmann
  2015-12-21 19:36         ` Phil Sutter
@ 2015-12-21 19:42         ` Phil Sutter
  2015-12-22  5:34           ` Stephen Hemminger
  1 sibling, 1 reply; 9+ messages in thread
From: Phil Sutter @ 2015-12-21 19:42 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger, Daniel Borkmann

I repeatedly failed to get this right, so now I have to clean up my mess
afterwards.

Fixes: 7d6aadcd0a1dc ("ip{,6}tunnel: have a shared stats parser/printer")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 ip/tunnel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ip/tunnel.c b/ip/tunnel.c
index 1dd8092..39f825b 100644
--- a/ip/tunnel.c
+++ b/ip/tunnel.c
@@ -208,7 +208,7 @@ void tnl_print_stats(const char *buf)
 		      tx_bytes, tx_packets, tx_errs, tx_drops,
 		      tx_fifo, tx_colls, tx_carrier, rx_multi;
 
-	if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
+	if (sscanf(buf, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
 	           &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
 	           &rx_fifo, &rx_frame, &rx_multi,
 	           &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
-- 
2.5.3

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

* Re: [iproute PATCH] iptunnel: Fix compile error in ip/tunnel.c
  2015-12-21 19:42         ` [iproute PATCH] iptunnel: Fix compile error in ip/tunnel.c Phil Sutter
@ 2015-12-22  5:34           ` Stephen Hemminger
  0 siblings, 0 replies; 9+ messages in thread
From: Stephen Hemminger @ 2015-12-22  5:34 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netdev, Daniel Borkmann

On Mon, 21 Dec 2015 20:42:56 +0100
Phil Sutter <phil@nwl.cc> wrote:

> I repeatedly failed to get this right, so now I have to clean up my mess
> afterwards.
> 
> Fixes: 7d6aadcd0a1dc ("ip{,6}tunnel: have a shared stats parser/printer")
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
>  ip/tunnel.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/ip/tunnel.c b/ip/tunnel.c
> index 1dd8092..39f825b 100644
> --- a/ip/tunnel.c
> +++ b/ip/tunnel.c
> @@ -208,7 +208,7 @@ void tnl_print_stats(const char *buf)
>  		      tx_bytes, tx_packets, tx_errs, tx_drops,
>  		      tx_fifo, tx_colls, tx_carrier, rx_multi;
>  
> -	if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
> +	if (sscanf(buf, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
>  	           &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
>  	           &rx_fifo, &rx_frame, &rx_multi,
>  	           &tx_bytes, &tx_packets, &tx_errs, &tx_drops,

Applied..

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

end of thread, other threads:[~2015-12-22  5:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-11 12:23 [iproute PATCH] ip{,6}tunnel: have a shared stats parser/printer Phil Sutter
2015-12-18  1:14 ` Stephen Hemminger
2015-12-18 10:52   ` Phil Sutter
2015-12-18 10:58     ` [iproute PATCH v2] " Phil Sutter
2015-12-18 19:47       ` Stephen Hemminger
2015-12-21 11:00       ` Daniel Borkmann
2015-12-21 19:36         ` Phil Sutter
2015-12-21 19:42         ` [iproute PATCH] iptunnel: Fix compile error in ip/tunnel.c Phil Sutter
2015-12-22  5:34           ` Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.