netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [net/ipv4]: fib_seq_show function adjustment to get a more sensable output of /proc/net/route
@ 2007-10-22 18:26 Denis Cheng
  2007-10-22 19:31 ` Eric Dumazet
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Cheng @ 2007-10-22 18:26 UTC (permalink / raw)
  To: David S. Miller, Jeff Garzik; +Cc: netdev, linux-kernel, Denis Cheng

the temporary bf[127] char array is redundant, and the specified width 127 make the output of /proc/net/route include many trailing spaces;
since most terminal's cols are less than 127, this made every fib entry occupy two lines,

after applied this patch, the output of /proc/net/route is more sensable like this:

Iface	Destination	Gateway 	Flags	RefCnt	Use	Metric	Mask		MTU	Window	IRTT
eth0	0001A8C0	00000000	0001	0	0	0	00FFFFFF	0	0	0
lo	0000007F	00000000	0001	0	0	0	000000FF	0	0	0
eth0	00000000	0101A8C0	0003	0	0	0	00000000	0	0	0

Signed-off-by: Denis Cheng <crquan@gmail.com>
---
 net/ipv4/fib_hash.c |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/net/ipv4/fib_hash.c b/net/ipv4/fib_hash.c
index 527a6e0..2a4033e 100644
--- a/net/ipv4/fib_hash.c
+++ b/net/ipv4/fib_hash.c
@@ -992,7 +992,6 @@ static unsigned fib_flag_trans(int type, __be32 mask, struct fib_info *fi)
 static int fib_seq_show(struct seq_file *seq, void *v)
 {
 	struct fib_iter_state *iter;
-	char bf[128];
 	__be32 prefix, mask;
 	unsigned flags;
 	struct fib_node *f;
@@ -1000,9 +999,9 @@ static int fib_seq_show(struct seq_file *seq, void *v)
 	struct fib_info *fi;
 
 	if (v == SEQ_START_TOKEN) {
-		seq_printf(seq, "%-127s\n", "Iface\tDestination\tGateway "
+		seq_printf(seq, "Iface\tDestination\tGateway "
 			   "\tFlags\tRefCnt\tUse\tMetric\tMask\t\tMTU"
-			   "\tWindow\tIRTT");
+			   "\tWindow\tIRTT\n");
 		goto out;
 	}
 
@@ -1014,18 +1013,18 @@ static int fib_seq_show(struct seq_file *seq, void *v)
 	mask	= FZ_MASK(iter->zone);
 	flags	= fib_flag_trans(fa->fa_type, mask, fi);
 	if (fi)
-		snprintf(bf, sizeof(bf),
-			 "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
+		seq_printf(seq,
+			 "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u\n",
 			 fi->fib_dev ? fi->fib_dev->name : "*", prefix,
 			 fi->fib_nh->nh_gw, flags, 0, 0, fi->fib_priority,
 			 mask, (fi->fib_advmss ? fi->fib_advmss + 40 : 0),
 			 fi->fib_window,
 			 fi->fib_rtt >> 3);
 	else
-		snprintf(bf, sizeof(bf),
-			 "*\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
+		seq_printf(seq,
+			 "*\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u\n",
 			 prefix, 0, flags, 0, 0, 0, mask, 0, 0, 0);
-	seq_printf(seq, "%-127s\n", bf);
+
 out:
 	return 0;
 }
-- 
1.5.3.4


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

* Re: [PATCH] [net/ipv4]: fib_seq_show function adjustment to get a more sensable output of /proc/net/route
  2007-10-22 18:26 [PATCH] [net/ipv4]: fib_seq_show function adjustment to get a more sensable output of /proc/net/route Denis Cheng
@ 2007-10-22 19:31 ` Eric Dumazet
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Dumazet @ 2007-10-22 19:31 UTC (permalink / raw)
  To: Denis Cheng; +Cc: David S. Miller, Jeff Garzik, netdev, linux-kernel

Denis Cheng a écrit :
> the temporary bf[127] char array is redundant, and the specified width 127 make the output of /proc/net/route include many trailing spaces;
> since most terminal's cols are less than 127, this made every fib entry occupy two lines,
> 
> after applied this patch, the output of /proc/net/route is more sensable like this:
> 
> Iface	Destination	Gateway 	Flags	RefCnt	Use	Metric	Mask		MTU	Window	IRTT
> eth0	0001A8C0	00000000	0001	0	0	0	00FFFFFF	0	0	0
> lo	0000007F	00000000	0001	0	0	0	000000FF	0	0	0
> eth0	00000000	0101A8C0	0003	0	0	0	00000000	0	0	0
> 
> Signed-off-by: Denis Cheng <crquan@gmail.com>

Hum... did you test your patch with many routes declared ? (more than 32 on 
i386/x86_64)

127 is not a random value, but chosen as a power of two minus 1.
PAGE_SIZE is garanted to be a multiple of 128 (127 chars + line_feed) on all 
arches.

So each read() on /proc/net/route delivers PAGE_SIZE/128 lines.

With your patch, some lines might be truncated (one every 32 on i386)



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

end of thread, other threads:[~2007-10-22 19:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-22 18:26 [PATCH] [net/ipv4]: fib_seq_show function adjustment to get a more sensable output of /proc/net/route Denis Cheng
2007-10-22 19:31 ` Eric Dumazet

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).