From patchwork Fri Apr 8 22:51:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasikanth V X-Patchwork-Id: 90438 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id F142DB6F73 for ; Sat, 9 Apr 2011 08:51:53 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753190Ab1DHWvt (ORCPT ); Fri, 8 Apr 2011 18:51:49 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:48441 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752630Ab1DHWvt (ORCPT ); Fri, 8 Apr 2011 18:51:49 -0400 Received: by iyb14 with SMTP id 14so3857918iyb.19 for ; Fri, 08 Apr 2011 15:51:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=BPJfaM+iwZ6nCV+okrw54xluCNmVMHPOJeNLCmm4Qs8=; b=bjR9iC/TulRtjLioPfHjN9AXVua4X6LKbTBk4Qca5bhHW2v6l85tRU7KnsF8BURSh0 Qq2M+Ny4vt+1hidPdJmQunraAUoBxAMe+tqGbXUk3Qp7jzIOGuJpnhhV8iYzQ7YDGqZf vS4RDmuAnogDRggNplfiu97MirO3wrrGt2aqQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=a5JgcvVE2IG3cbeN1Re1aruG6QCzqdsW/POh1Pf4EfAnM6cJFRsFq2AMs5DXGMGEoU jlxW0EgDMuvBvo1IGIrZEGLWBlmVh8NV+VH4Ztc9rXhufdqG6hZOiX79EiN8L485t+qm uyJJaOzXRm3/vKqyTAOPSBwr//USQW8e8qpQM= Received: by 10.43.131.5 with SMTP id ho5mr515174icc.257.1302303108164; Fri, 08 Apr 2011 15:51:48 -0700 (PDT) Received: from localhost.localdomain ([122.164.79.151]) by mx.google.com with ESMTPS id 19sm2161491ibx.1.2011.04.08.15.51.44 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 08 Apr 2011 15:51:47 -0700 (PDT) From: Sasikanth V To: "David S. Miller" , Alexey Kuznetsov , James Morris , Patrick McHardy Cc: netdev@vger.kernel.org, Sasikanth V Subject: [PATCH] IPV4:Removed the unnecessary loops and made /proc/net/snmp ouput more readable Date: Sat, 9 Apr 2011 04:21:39 +0530 Message-Id: <1302303099-6880-1-git-send-email-sasikanth.v19@gmail.com> X-Mailer: git-send-email 1.7.3.4 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Sasikanth V --- net/ipv4/proc.c | 75 ++++++++++++++++++++---------------------------------- 1 files changed, 28 insertions(+), 47 deletions(-) diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c index b14ec7d..b4eda92 100644 --- a/net/ipv4/proc.c +++ b/net/ipv4/proc.c @@ -265,12 +265,9 @@ static void icmpmsg_put_line(struct seq_file *seq, unsigned long *vals, if (count) { seq_printf(seq, "\nIcmpMsg:"); for (j = 0; j < count; ++j) - seq_printf(seq, " %sType%u", + seq_printf(seq, " %sType%u\t%lu", type[j] & 0x100 ? "Out" : "In", - type[j] & 0xff); - seq_printf(seq, "\nIcmpMsg:"); - for (j = 0; j < count; ++j) - seq_printf(seq, " %lu", vals[j]); + type[j] & 0xff, vals[j]); } } @@ -305,26 +302,26 @@ static void icmp_put(struct seq_file *seq) int i; struct net *net = seq->private; - seq_puts(seq, "\nIcmp: InMsgs InErrors"); - for (i=0; icmpmibmap[i].name != NULL; i++) - seq_printf(seq, " In%s", icmpmibmap[i].name); - seq_printf(seq, " OutMsgs OutErrors"); - for (i=0; icmpmibmap[i].name != NULL; i++) - seq_printf(seq, " Out%s", icmpmibmap[i].name); - seq_printf(seq, "\nIcmp: %lu %lu", + seq_puts(seq, "Icmp:\n"); + seq_printf(seq, "%-32s\t%lu\n%-32s\t%lu\n","InMsgs", snmp_fold_field((void __percpu **) net->mib.icmp_statistics, ICMP_MIB_INMSGS), + "InErrors", snmp_fold_field((void __percpu **) net->mib.icmp_statistics, ICMP_MIB_INERRORS)); + for (i=0; icmpmibmap[i].name != NULL; i++) - seq_printf(seq, " %lu", - snmp_fold_field((void __percpu **) net->mib.icmpmsg_statistics, - icmpmibmap[i].index)); - seq_printf(seq, " %lu %lu", + seq_printf(seq, "%s%-32s\t%lu\n", "In",icmpmibmap[i].name, + snmp_fold_field((void __percpu **) net->mib.icmpmsg_statistics, + icmpmibmap[i].index)); + + seq_printf(seq, "%-32s\t%lu\n%-32s\t%lu\n","OutMsgs", snmp_fold_field((void __percpu **) net->mib.icmp_statistics, ICMP_MIB_OUTMSGS), + "OutErrors", snmp_fold_field((void __percpu **) net->mib.icmp_statistics, ICMP_MIB_OUTERRORS)); + for (i=0; icmpmibmap[i].name != NULL; i++) - seq_printf(seq, " %lu", - snmp_fold_field((void __percpu **) net->mib.icmpmsg_statistics, - icmpmibmap[i].index | 0x100)); + seq_printf(seq, "%s%-32s\t%lu\n", "Out", icmpmibmap[i].name, + snmp_fold_field((void __percpu **) net->mib.icmpmsg_statistics, + icmpmibmap[i].index | 0x100)); } /* @@ -335,18 +332,15 @@ static int snmp_seq_show(struct seq_file *seq, void *v) int i; struct net *net = seq->private; - seq_puts(seq, "Ip: Forwarding DefaultTTL"); - - for (i = 0; snmp4_ipstats_list[i].name != NULL; i++) - seq_printf(seq, " %s", snmp4_ipstats_list[i].name); - - seq_printf(seq, "\nIp: %d %d", - IPV4_DEVCONF_ALL(net, FORWARDING) ? 1 : 2, + seq_puts(seq, "Ip:\n"); + seq_printf(seq, "%-32s\t%d\n%-32s\t%d\n", "Forwarding", + IPV4_DEVCONF_ALL(net, FORWARDING) ? 1 : 2,"DefaultTTL", sysctl_ip_default_ttl); BUILD_BUG_ON(offsetof(struct ipstats_mib, mibs) != 0); + for (i = 0; snmp4_ipstats_list[i].name != NULL; i++) - seq_printf(seq, " %llu", + seq_printf(seq, "%-32s\t%llu\n", snmp4_ipstats_list[i].name, snmp_fold_field64((void __percpu **)net->mib.ip_statistics, snmp4_ipstats_list[i].entry, offsetof(struct ipstats_mib, syncp))); @@ -354,45 +348,32 @@ static int snmp_seq_show(struct seq_file *seq, void *v) icmp_put(seq); /* RFC 2011 compatibility */ icmpmsg_put(seq); - seq_puts(seq, "\nTcp:"); - for (i = 0; snmp4_tcp_list[i].name != NULL; i++) - seq_printf(seq, " %s", snmp4_tcp_list[i].name); - - seq_puts(seq, "\nTcp:"); + seq_puts(seq, "Tcp:\n"); for (i = 0; snmp4_tcp_list[i].name != NULL; i++) { /* MaxConn field is signed, RFC 2012 */ if (snmp4_tcp_list[i].entry == TCP_MIB_MAXCONN) - seq_printf(seq, " %ld", + seq_printf(seq, "%-32s\t%lu\n", snmp4_tcp_list[i].name, snmp_fold_field((void __percpu **)net->mib.tcp_statistics, snmp4_tcp_list[i].entry)); else - seq_printf(seq, " %lu", + seq_printf(seq, "%-32s\t%lu\n", snmp4_tcp_list[i].name, snmp_fold_field((void __percpu **)net->mib.tcp_statistics, snmp4_tcp_list[i].entry)); } - seq_puts(seq, "\nUdp:"); - for (i = 0; snmp4_udp_list[i].name != NULL; i++) - seq_printf(seq, " %s", snmp4_udp_list[i].name); - - seq_puts(seq, "\nUdp:"); + seq_puts(seq, "Udp:\n"); for (i = 0; snmp4_udp_list[i].name != NULL; i++) - seq_printf(seq, " %lu", + seq_printf(seq, "%-32s\t%lu\n", snmp4_udp_list[i].name, snmp_fold_field((void __percpu **)net->mib.udp_statistics, snmp4_udp_list[i].entry)); /* the UDP and UDP-Lite MIBs are the same */ - seq_puts(seq, "\nUdpLite:"); - for (i = 0; snmp4_udp_list[i].name != NULL; i++) - seq_printf(seq, " %s", snmp4_udp_list[i].name); - - seq_puts(seq, "\nUdpLite:"); + seq_puts(seq, "UdpLite:\n"); for (i = 0; snmp4_udp_list[i].name != NULL; i++) - seq_printf(seq, " %lu", + seq_printf(seq, "%-32s\t%lu\n", snmp4_udp_list[i].name, snmp_fold_field((void __percpu **)net->mib.udplite_statistics, snmp4_udp_list[i].entry)); - seq_putc(seq, '\n'); return 0; }