1 |
1275 |
phoenix |
/*
|
2 |
|
|
* INET An implementation of the TCP/IP protocol suite for the LINUX
|
3 |
|
|
* operating system. INET is implemented using the BSD Socket
|
4 |
|
|
* interface as the means of communication with the user level.
|
5 |
|
|
*
|
6 |
|
|
* This file implements the various access functions for the
|
7 |
|
|
* PROC file system. This is very similar to the IPv4 version,
|
8 |
|
|
* except it reports the sockets in the INET6 address family.
|
9 |
|
|
*
|
10 |
|
|
* Version: $Id: proc.c,v 1.1.1.1 2004-04-15 01:14:46 phoenix Exp $
|
11 |
|
|
*
|
12 |
|
|
* Authors: David S. Miller (davem@caip.rutgers.edu)
|
13 |
|
|
*
|
14 |
|
|
* This program is free software; you can redistribute it and/or
|
15 |
|
|
* modify it under the terms of the GNU General Public License
|
16 |
|
|
* as published by the Free Software Foundation; either version
|
17 |
|
|
* 2 of the License, or (at your option) any later version.
|
18 |
|
|
*/
|
19 |
|
|
#include <linux/sched.h>
|
20 |
|
|
#include <linux/socket.h>
|
21 |
|
|
#include <linux/net.h>
|
22 |
|
|
#include <linux/in6.h>
|
23 |
|
|
#include <linux/stddef.h>
|
24 |
|
|
#include <net/sock.h>
|
25 |
|
|
#include <net/tcp.h>
|
26 |
|
|
#include <net/transp_v6.h>
|
27 |
|
|
#include <net/ipv6.h>
|
28 |
|
|
|
29 |
|
|
static int fold_prot_inuse(struct proto *proto)
|
30 |
|
|
{
|
31 |
|
|
int res = 0;
|
32 |
|
|
int cpu;
|
33 |
|
|
|
34 |
|
|
for (cpu=0; cpu<smp_num_cpus; cpu++)
|
35 |
|
|
res += proto->stats[cpu_logical_map(cpu)].inuse;
|
36 |
|
|
|
37 |
|
|
return res;
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
int afinet6_get_info(char *buffer, char **start, off_t offset, int length)
|
41 |
|
|
{
|
42 |
|
|
int len = 0;
|
43 |
|
|
len += sprintf(buffer+len, "TCP6: inuse %d\n",
|
44 |
|
|
fold_prot_inuse(&tcpv6_prot));
|
45 |
|
|
len += sprintf(buffer+len, "UDP6: inuse %d\n",
|
46 |
|
|
fold_prot_inuse(&udpv6_prot));
|
47 |
|
|
len += sprintf(buffer+len, "RAW6: inuse %d\n",
|
48 |
|
|
fold_prot_inuse(&rawv6_prot));
|
49 |
|
|
len += sprintf(buffer+len, "FRAG6: inuse %d memory %d\n",
|
50 |
|
|
ip6_frag_nqueues, atomic_read(&ip6_frag_mem));
|
51 |
|
|
*start = buffer + offset;
|
52 |
|
|
len -= offset;
|
53 |
|
|
if(len > length)
|
54 |
|
|
len = length;
|
55 |
|
|
return len;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
struct snmp6_item
|
60 |
|
|
{
|
61 |
|
|
char *name;
|
62 |
|
|
unsigned long *ptr;
|
63 |
|
|
int mibsize;
|
64 |
|
|
} snmp6_list[] = {
|
65 |
|
|
/* ipv6 mib according to draft-ietf-ipngwg-ipv6-mib-04 */
|
66 |
|
|
#define SNMP6_GEN(x) { #x , &ipv6_statistics[0].x, sizeof(struct ipv6_mib)/sizeof(unsigned long) }
|
67 |
|
|
SNMP6_GEN(Ip6InReceives),
|
68 |
|
|
SNMP6_GEN(Ip6InHdrErrors),
|
69 |
|
|
SNMP6_GEN(Ip6InTooBigErrors),
|
70 |
|
|
SNMP6_GEN(Ip6InNoRoutes),
|
71 |
|
|
SNMP6_GEN(Ip6InAddrErrors),
|
72 |
|
|
SNMP6_GEN(Ip6InUnknownProtos),
|
73 |
|
|
SNMP6_GEN(Ip6InTruncatedPkts),
|
74 |
|
|
SNMP6_GEN(Ip6InDiscards),
|
75 |
|
|
SNMP6_GEN(Ip6InDelivers),
|
76 |
|
|
SNMP6_GEN(Ip6OutForwDatagrams),
|
77 |
|
|
SNMP6_GEN(Ip6OutRequests),
|
78 |
|
|
SNMP6_GEN(Ip6OutDiscards),
|
79 |
|
|
SNMP6_GEN(Ip6OutNoRoutes),
|
80 |
|
|
SNMP6_GEN(Ip6ReasmTimeout),
|
81 |
|
|
SNMP6_GEN(Ip6ReasmReqds),
|
82 |
|
|
SNMP6_GEN(Ip6ReasmOKs),
|
83 |
|
|
SNMP6_GEN(Ip6ReasmFails),
|
84 |
|
|
SNMP6_GEN(Ip6FragOKs),
|
85 |
|
|
SNMP6_GEN(Ip6FragFails),
|
86 |
|
|
SNMP6_GEN(Ip6FragCreates),
|
87 |
|
|
SNMP6_GEN(Ip6InMcastPkts),
|
88 |
|
|
SNMP6_GEN(Ip6OutMcastPkts),
|
89 |
|
|
#undef SNMP6_GEN
|
90 |
|
|
/* icmpv6 mib according to draft-ietf-ipngwg-ipv6-icmp-mib-02
|
91 |
|
|
|
92 |
|
|
Exceptions: {In|Out}AdminProhibs are removed, because I see
|
93 |
|
|
no good reasons to account them separately
|
94 |
|
|
of another dest.unreachs.
|
95 |
|
|
OutErrs is zero identically.
|
96 |
|
|
OutEchos too.
|
97 |
|
|
OutRouterAdvertisements too.
|
98 |
|
|
OutGroupMembQueries too.
|
99 |
|
|
*/
|
100 |
|
|
#define SNMP6_GEN(x) { #x , &icmpv6_statistics[0].x, sizeof(struct icmpv6_mib)/sizeof(unsigned long) }
|
101 |
|
|
SNMP6_GEN(Icmp6InMsgs),
|
102 |
|
|
SNMP6_GEN(Icmp6InErrors),
|
103 |
|
|
SNMP6_GEN(Icmp6InDestUnreachs),
|
104 |
|
|
SNMP6_GEN(Icmp6InPktTooBigs),
|
105 |
|
|
SNMP6_GEN(Icmp6InTimeExcds),
|
106 |
|
|
SNMP6_GEN(Icmp6InParmProblems),
|
107 |
|
|
SNMP6_GEN(Icmp6InEchos),
|
108 |
|
|
SNMP6_GEN(Icmp6InEchoReplies),
|
109 |
|
|
SNMP6_GEN(Icmp6InGroupMembQueries),
|
110 |
|
|
SNMP6_GEN(Icmp6InGroupMembResponses),
|
111 |
|
|
SNMP6_GEN(Icmp6InGroupMembReductions),
|
112 |
|
|
SNMP6_GEN(Icmp6InRouterSolicits),
|
113 |
|
|
SNMP6_GEN(Icmp6InRouterAdvertisements),
|
114 |
|
|
SNMP6_GEN(Icmp6InNeighborSolicits),
|
115 |
|
|
SNMP6_GEN(Icmp6InNeighborAdvertisements),
|
116 |
|
|
SNMP6_GEN(Icmp6InRedirects),
|
117 |
|
|
SNMP6_GEN(Icmp6OutMsgs),
|
118 |
|
|
SNMP6_GEN(Icmp6OutDestUnreachs),
|
119 |
|
|
SNMP6_GEN(Icmp6OutPktTooBigs),
|
120 |
|
|
SNMP6_GEN(Icmp6OutTimeExcds),
|
121 |
|
|
SNMP6_GEN(Icmp6OutParmProblems),
|
122 |
|
|
SNMP6_GEN(Icmp6OutEchoReplies),
|
123 |
|
|
SNMP6_GEN(Icmp6OutRouterSolicits),
|
124 |
|
|
SNMP6_GEN(Icmp6OutNeighborSolicits),
|
125 |
|
|
SNMP6_GEN(Icmp6OutNeighborAdvertisements),
|
126 |
|
|
SNMP6_GEN(Icmp6OutRedirects),
|
127 |
|
|
SNMP6_GEN(Icmp6OutGroupMembResponses),
|
128 |
|
|
SNMP6_GEN(Icmp6OutGroupMembReductions),
|
129 |
|
|
#undef SNMP6_GEN
|
130 |
|
|
#define SNMP6_GEN(x) { "Udp6" #x , &udp_stats_in6[0].Udp##x, sizeof(struct udp_mib)/sizeof(unsigned long) }
|
131 |
|
|
SNMP6_GEN(InDatagrams),
|
132 |
|
|
SNMP6_GEN(NoPorts),
|
133 |
|
|
SNMP6_GEN(InErrors),
|
134 |
|
|
SNMP6_GEN(OutDatagrams)
|
135 |
|
|
#undef SNMP6_GEN
|
136 |
|
|
};
|
137 |
|
|
|
138 |
|
|
static unsigned long fold_field(unsigned long *ptr, int size)
|
139 |
|
|
{
|
140 |
|
|
unsigned long res = 0;
|
141 |
|
|
int i;
|
142 |
|
|
|
143 |
|
|
for (i=0; i<smp_num_cpus; i++) {
|
144 |
|
|
res += ptr[2*cpu_logical_map(i)*size];
|
145 |
|
|
res += ptr[(2*cpu_logical_map(i)+1)*size];
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
return res;
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
int afinet6_get_snmp(char *buffer, char **start, off_t offset, int length)
|
152 |
|
|
{
|
153 |
|
|
int len = 0;
|
154 |
|
|
int i;
|
155 |
|
|
|
156 |
|
|
for (i=0; i<sizeof(snmp6_list)/sizeof(snmp6_list[0]); i++)
|
157 |
|
|
len += sprintf(buffer+len, "%-32s\t%ld\n", snmp6_list[i].name,
|
158 |
|
|
fold_field(snmp6_list[i].ptr, snmp6_list[i].mibsize));
|
159 |
|
|
|
160 |
|
|
len -= offset;
|
161 |
|
|
|
162 |
|
|
if (len > length)
|
163 |
|
|
len = length;
|
164 |
|
|
if(len < 0)
|
165 |
|
|
len = 0;
|
166 |
|
|
|
167 |
|
|
*start = buffer + offset;
|
168 |
|
|
|
169 |
|
|
return len;
|
170 |
|
|
}
|