: fib_seq_show function adjustment to get a more sensable output of /proc/net/route
Subsystems (3)
PATCH 1/1 : fib_seq_show function adjustment to get a more sensable output of /proc/net/route
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
--- net/ipv4/fib_hash.c | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-)
net/ipv4/fib_hash.c +7 -8
@@ -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 ; }
Signature · 1 line
1.5.3.4
Quoted 11 lines · Denis Cheng
the temporary bf[127] char array is redundant, and the specified width 127 make the output of
/proc/net/routeinclude 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/routeis 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 0Signed-off-by Denis Cheng <[email protected]>
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)