o ipv4: convert /proc/net/snmp to seq_file

parent ce4982c9
......@@ -26,6 +26,7 @@
* Andi Kleen : Add support for open_requests and
* split functions for more readibility.
* Andi Kleen : Add support for /proc/net/netstat
* Arnaldo C. Melo : Convert to seq_file
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -115,52 +116,73 @@ static unsigned long fold_field(unsigned long *begin, int sz, int nr)
/*
* Called from the PROCfs module. This outputs /proc/net/snmp.
*/
int snmp_get_info(char *buffer, char **start, off_t offset, int length)
static int snmp_seq_show(struct seq_file *seq, void *v)
{
extern int sysctl_ip_default_ttl;
int len, i;
len = sprintf (buffer,
"Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates\n"
"Ip: %d %d", ipv4_devconf.forwarding ? 1 : 2, sysctl_ip_default_ttl);
for (i=0; i<offsetof(struct ip_mib, __pad)/sizeof(unsigned long); i++)
len += sprintf(buffer+len, " %lu", fold_field((unsigned long*)ip_statistics, sizeof(struct ip_mib), i));
len += sprintf (buffer + len,
"\nIcmp: InMsgs InErrors InDestUnreachs InTimeExcds InParmProbs InSrcQuenchs InRedirects InEchos InEchoReps InTimestamps InTimestampReps InAddrMasks InAddrMaskReps OutMsgs OutErrors OutDestUnreachs OutTimeExcds OutParmProbs OutSrcQuenchs OutRedirects OutEchos OutEchoReps OutTimestamps OutTimestampReps OutAddrMasks OutAddrMaskReps\n"
"Icmp:");
for (i=0; i<offsetof(struct icmp_mib, dummy)/sizeof(unsigned long); i++)
len += sprintf(buffer+len, " %lu", fold_field((unsigned long*)icmp_statistics, sizeof(struct icmp_mib), i));
len += sprintf (buffer + len,
"\nTcp: RtoAlgorithm RtoMin RtoMax MaxConn ActiveOpens PassiveOpens AttemptFails EstabResets CurrEstab InSegs OutSegs RetransSegs InErrs OutRsts\n"
"Tcp:");
for (i=0; i<offsetof(struct tcp_mib, __pad)/sizeof(unsigned long); i++)
len += sprintf(buffer+len, " %lu", fold_field((unsigned long*)tcp_statistics, sizeof(struct tcp_mib), i));
len += sprintf (buffer + len,
"\nUdp: InDatagrams NoPorts InErrors OutDatagrams\n"
int i;
seq_printf(seq, "Ip: Forwarding DefaultTTL InReceives InHdrErrors "
"InAddrErrors ForwDatagrams InUnknownProtos "
"InDiscards InDelivers OutRequests OutDiscards "
"OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs "
"ReasmFails FragOKs FragFails FragCreates\nIp: %d %d",
ipv4_devconf.forwarding ? 1 : 2, sysctl_ip_default_ttl);
for (i = 0;
i < offsetof(struct ip_mib, __pad) / sizeof(unsigned long); i++)
seq_printf(seq, " %lu",
fold_field((unsigned long *)ip_statistics,
sizeof(struct ip_mib), i));
seq_printf(seq, "\nIcmp: InMsgs InErrors InDestUnreachs InTimeExcds "
"InParmProbs InSrcQuenchs InRedirects InEchos "
"InEchoReps InTimestamps InTimestampReps InAddrMasks "
"InAddrMaskReps OutMsgs OutErrors OutDestUnreachs "
"OutTimeExcds OutParmProbs OutSrcQuenchs OutRedirects "
"OutEchos OutEchoReps OutTimestamps OutTimestampReps "
"OutAddrMasks OutAddrMaskReps\nIcmp:");
for (i = 0;
i < offsetof(struct icmp_mib, dummy) / sizeof(unsigned long); i++)
seq_printf(seq, " %lu",
fold_field((unsigned long *)icmp_statistics,
sizeof(struct icmp_mib), i));
seq_printf(seq, "\nTcp: RtoAlgorithm RtoMin RtoMax MaxConn ActiveOpens "
"PassiveOpens AttemptFails EstabResets CurrEstab "
"InSegs OutSegs RetransSegs InErrs OutRsts\nTcp:");
for (i = 0;
i < offsetof(struct tcp_mib, __pad) / sizeof(unsigned long); i++)
seq_printf(seq, " %lu",
fold_field((unsigned long *)tcp_statistics,
sizeof(struct tcp_mib), i));
seq_printf(seq, "\nUdp: InDatagrams NoPorts InErrors OutDatagrams\n"
"Udp:");
for (i=0; i<offsetof(struct udp_mib, __pad)/sizeof(unsigned long); i++)
len += sprintf(buffer+len, " %lu", fold_field((unsigned long*)udp_statistics, sizeof(struct udp_mib), i));
len += sprintf (buffer + len, "\n");
for (i = 0;
i < offsetof(struct udp_mib, __pad) / sizeof(unsigned long); i++)
seq_printf(seq, " %lu",
fold_field((unsigned long *)udp_statistics,
sizeof(struct udp_mib), i));
if (offset >= len)
{
*start = buffer;
seq_putc(seq, '\n');
return 0;
}
*start = buffer + offset;
len -= offset;
if (len > length)
len = length;
if (len < 0)
len = 0;
return len;
}
static int snmp_seq_open(struct inode *inode, struct file *file)
{
return single_open(file, snmp_seq_show, NULL);
}
static struct file_operations snmp_seq_fops = {
.open = snmp_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
/*
* Output /proc/net/netstat
*/
......@@ -181,7 +203,8 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
" TCPPureAcks TCPHPAcks"
" TCPRenoRecovery TCPSackRecovery"
" TCPSACKReneging"
" TCPFACKReorder TCPSACKReorder TCPRenoReorder TCPTSReorder"
" TCPFACKReorder TCPSACKReorder TCPRenoReorder"
" TCPTSReorder"
" TCPFullUndo TCPPartialUndo TCPDSACKUndo TCPLossUndo"
" TCPLoss TCPLostRetransmit"
" TCPRenoFailures TCPSackFailures TCPLossFailures"
......@@ -189,14 +212,14 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
" TCPTimeouts"
" TCPRenoRecoveryFail TCPSackRecoveryFail"
" TCPSchedulerFailed TCPRcvCollapsed"
" TCPDSACKOldSent TCPDSACKOfoSent TCPDSACKRecv TCPDSACKOfoRecv"
" TCPDSACKOldSent TCPDSACKOfoSent TCPDSACKRecv"
" TCPDSACKOfoRecv"
" TCPAbortOnSyn TCPAbortOnData TCPAbortOnClose"
" TCPAbortOnMemory TCPAbortOnTimeout TCPAbortOnLinger"
" TCPAbortFailed TCPMemoryPressures\n"
"TcpExt:");
for (i = 0;
i < offsetof(struct linux_mib, __pad) / sizeof(unsigned long);
i++)
i < offsetof(struct linux_mib, __pad) / sizeof(unsigned long); i++)
seq_printf(seq, " %lu",
fold_field((unsigned long *)net_statistics,
sizeof(struct linux_mib), i));
......@@ -219,20 +242,24 @@ static struct file_operations netstat_seq_fops = {
int __init ip_misc_proc_init(void)
{
int rc = 0;
struct proc_dir_entry *p = create_proc_entry("netstat", S_IRUGO, proc_net);
struct proc_dir_entry *p;
p = create_proc_entry("netstat", S_IRUGO, proc_net);
if (!p)
goto out_netstat;
p->proc_fops = &netstat_seq_fops;
if (!proc_net_create("snmp", 0, snmp_get_info))
p = create_proc_entry("snmp", S_IRUGO, proc_net);
if (!p)
goto out_snmp;
p->proc_fops = &snmp_seq_fops;
if (!proc_net_create("sockstat", 0, afinet_get_info))
goto out_sockstat;
out:
return rc;
out_sockstat:
proc_net_remove("snmp");
remove_proc_entry("snmp", proc_net);
out_snmp:
remove_proc_entry("netstat", proc_net);
out_netstat:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment