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

parent ce4982c9
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
* Andi Kleen : Add support for open_requests and * Andi Kleen : Add support for open_requests and
* split functions for more readibility. * split functions for more readibility.
* Andi Kleen : Add support for /proc/net/netstat * 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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) ...@@ -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. * Called from the PROCfs module. This outputs /proc/net/snmp.
*/ */
static int snmp_seq_show(struct seq_file *seq, void *v)
int snmp_get_info(char *buffer, char **start, off_t offset, int length)
{ {
extern int sysctl_ip_default_ttl; extern int sysctl_ip_default_ttl;
int len, i; int 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"
"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");
if (offset >= len) seq_printf(seq, "Ip: Forwarding DefaultTTL InReceives InHdrErrors "
{ "InAddrErrors ForwDatagrams InUnknownProtos "
*start = buffer; "InDiscards InDelivers OutRequests OutDiscards "
return 0; "OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs "
} "ReasmFails FragOKs FragFails FragCreates\nIp: %d %d",
*start = buffer + offset; ipv4_devconf.forwarding ? 1 : 2, sysctl_ip_default_ttl);
len -= offset;
if (len > length) for (i = 0;
len = length; i < offsetof(struct ip_mib, __pad) / sizeof(unsigned long); i++)
if (len < 0) seq_printf(seq, " %lu",
len = 0; fold_field((unsigned long *)ip_statistics,
return len; 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++)
seq_printf(seq, " %lu",
fold_field((unsigned long *)udp_statistics,
sizeof(struct udp_mib), i));
seq_putc(seq, '\n');
return 0;
}
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 * Output /proc/net/netstat
*/ */
...@@ -181,7 +203,8 @@ static int netstat_seq_show(struct seq_file *seq, void *v) ...@@ -181,7 +203,8 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
" TCPPureAcks TCPHPAcks" " TCPPureAcks TCPHPAcks"
" TCPRenoRecovery TCPSackRecovery" " TCPRenoRecovery TCPSackRecovery"
" TCPSACKReneging" " TCPSACKReneging"
" TCPFACKReorder TCPSACKReorder TCPRenoReorder TCPTSReorder" " TCPFACKReorder TCPSACKReorder TCPRenoReorder"
" TCPTSReorder"
" TCPFullUndo TCPPartialUndo TCPDSACKUndo TCPLossUndo" " TCPFullUndo TCPPartialUndo TCPDSACKUndo TCPLossUndo"
" TCPLoss TCPLostRetransmit" " TCPLoss TCPLostRetransmit"
" TCPRenoFailures TCPSackFailures TCPLossFailures" " TCPRenoFailures TCPSackFailures TCPLossFailures"
...@@ -189,14 +212,14 @@ static int netstat_seq_show(struct seq_file *seq, void *v) ...@@ -189,14 +212,14 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
" TCPTimeouts" " TCPTimeouts"
" TCPRenoRecoveryFail TCPSackRecoveryFail" " TCPRenoRecoveryFail TCPSackRecoveryFail"
" TCPSchedulerFailed TCPRcvCollapsed" " TCPSchedulerFailed TCPRcvCollapsed"
" TCPDSACKOldSent TCPDSACKOfoSent TCPDSACKRecv TCPDSACKOfoRecv" " TCPDSACKOldSent TCPDSACKOfoSent TCPDSACKRecv"
" TCPDSACKOfoRecv"
" TCPAbortOnSyn TCPAbortOnData TCPAbortOnClose" " TCPAbortOnSyn TCPAbortOnData TCPAbortOnClose"
" TCPAbortOnMemory TCPAbortOnTimeout TCPAbortOnLinger" " TCPAbortOnMemory TCPAbortOnTimeout TCPAbortOnLinger"
" TCPAbortFailed TCPMemoryPressures\n" " TCPAbortFailed TCPMemoryPressures\n"
"TcpExt:"); "TcpExt:");
for (i = 0; for (i = 0;
i < offsetof(struct linux_mib, __pad) / sizeof(unsigned long); i < offsetof(struct linux_mib, __pad) / sizeof(unsigned long); i++)
i++)
seq_printf(seq, " %lu", seq_printf(seq, " %lu",
fold_field((unsigned long *)net_statistics, fold_field((unsigned long *)net_statistics,
sizeof(struct linux_mib), i)); sizeof(struct linux_mib), i));
...@@ -219,20 +242,24 @@ static struct file_operations netstat_seq_fops = { ...@@ -219,20 +242,24 @@ static struct file_operations netstat_seq_fops = {
int __init ip_misc_proc_init(void) int __init ip_misc_proc_init(void)
{ {
int rc = 0; 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) if (!p)
goto out_netstat; goto out_netstat;
p->proc_fops = &netstat_seq_fops; 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; goto out_snmp;
p->proc_fops = &snmp_seq_fops;
if (!proc_net_create("sockstat", 0, afinet_get_info)) if (!proc_net_create("sockstat", 0, afinet_get_info))
goto out_sockstat; goto out_sockstat;
out: out:
return rc; return rc;
out_sockstat: out_sockstat:
proc_net_remove("snmp"); remove_proc_entry("snmp", proc_net);
out_snmp: out_snmp:
remove_proc_entry("netstat", proc_net); remove_proc_entry("netstat", proc_net);
out_netstat: 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