Blame view

net/ipv6/proc.c 11.4 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
  /*
   * INET		An implementation of the TCP/IP protocol suite for the LINUX
   *		operating system.  INET is implemented using the  BSD Socket
   *		interface as the means of communication with the user level.
   *
   *		This file implements the various access functions for the
   *		PROC file system.  This is very similar to the IPv4 version,
   *		except it reports the sockets in the INET6 address family.
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
   * Authors:	David S. Miller (davem@caip.rutgers.edu)
67ba4152e   Ian Morris   ipv6: White-space...
11
   *		YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
12
13
14
15
16
17
   *
   *		This program is free software; you can redistribute it and/or
   *		modify it under the terms of the GNU General Public License
   *		as published by the Free Software Foundation; either version
   *		2 of the License, or (at your option) any later version.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
19
20
21
22
23
  #include <linux/socket.h>
  #include <linux/net.h>
  #include <linux/ipv6.h>
  #include <linux/proc_fs.h>
  #include <linux/seq_file.h>
  #include <linux/stddef.h>
bc3b2d7fb   Paul Gortmaker   net: Add export.h...
24
  #include <linux/export.h>
457c4cbc5   Eric W. Biederman   [NET]: Make /proc...
25
  #include <net/net_namespace.h>
7f7d9a6b9   Herbert Xu   [IPV6]: Consolida...
26
  #include <net/ip.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
28
  #include <net/sock.h>
  #include <net/tcp.h>
1781f7f58   Herbert Xu   [UDP]: Restore mi...
29
  #include <net/udp.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
31
  #include <net/transp_v6.h>
  #include <net/ipv6.h>
4a4857b1c   Jia He   proc: Reduce cach...
32
33
34
35
  #define MAX4(a, b, c, d) \
  	max_t(u32, max_t(u32, a, b), max_t(u32, c, d))
  #define SNMP_MIB_MAX MAX4(UDP_MIB_MAX, TCP_MIB_MAX, \
  			IPSTATS_MIB_MAX, ICMP_MIB_MAX)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
  static int sockstat6_seq_show(struct seq_file *seq, void *v)
  {
dfb12eb70   Pavel Emelyanov   [IPV6][NETNS]: Di...
38
  	struct net *net = seq->private;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
40
  	seq_printf(seq, "TCP6: inuse %d
  ",
dfb12eb70   Pavel Emelyanov   [IPV6][NETNS]: Di...
41
  		       sock_prot_inuse_get(net, &tcpv6_prot));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
  	seq_printf(seq, "UDP6: inuse %d
  ",
dfb12eb70   Pavel Emelyanov   [IPV6][NETNS]: Di...
44
  		       sock_prot_inuse_get(net, &udpv6_prot));
ba4e58eca   Gerrit Renker   [NET]: Supporting...
45
46
  	seq_printf(seq, "UDPLITE6: inuse %d
  ",
dfb12eb70   Pavel Emelyanov   [IPV6][NETNS]: Di...
47
  			sock_prot_inuse_get(net, &udplitev6_prot));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48
49
  	seq_printf(seq, "RAW6: inuse %d
  ",
dfb12eb70   Pavel Emelyanov   [IPV6][NETNS]: Di...
50
  		       sock_prot_inuse_get(net, &rawv6_prot));
990204ddc   Eric Dumazet   inet: frags: brea...
51
52
  	seq_printf(seq, "FRAG6: inuse %u memory %lu
  ",
bd3df633f   Eric Dumazet   inet: frags: remo...
53
54
  		   atomic_read(&net->ipv6.frags.rhashtable.nelems),
  		   frag_mem_limit(&net->ipv6.frags));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
56
  	return 0;
  }
35f0a5df6   Denis V. Lunev   ipv6: consolidate...
57
58
59
60
61
62
63
64
65
66
67
68
  static int sockstat6_seq_open(struct inode *inode, struct file *file)
  {
  	return single_open_net(inode, file, sockstat6_seq_show);
  }
  
  static const struct file_operations sockstat6_seq_fops = {
  	.owner	 = THIS_MODULE,
  	.open	 = sockstat6_seq_open,
  	.read	 = seq_read,
  	.llseek	 = seq_lseek,
  	.release = single_release_net,
  };
5833929cc   Alexey Dobriyan   net: constify MIB...
69
  static const struct snmp_mib snmp6_ipstats_list[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
70
  /* ipv6 mib according to RFC 2465 */
edf391ff1   Neil Horman   snmp: add missing...
71
  	SNMP_MIB_ITEM("Ip6InReceives", IPSTATS_MIB_INPKTS),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
73
74
75
76
77
78
79
80
  	SNMP_MIB_ITEM("Ip6InHdrErrors", IPSTATS_MIB_INHDRERRORS),
  	SNMP_MIB_ITEM("Ip6InTooBigErrors", IPSTATS_MIB_INTOOBIGERRORS),
  	SNMP_MIB_ITEM("Ip6InNoRoutes", IPSTATS_MIB_INNOROUTES),
  	SNMP_MIB_ITEM("Ip6InAddrErrors", IPSTATS_MIB_INADDRERRORS),
  	SNMP_MIB_ITEM("Ip6InUnknownProtos", IPSTATS_MIB_INUNKNOWNPROTOS),
  	SNMP_MIB_ITEM("Ip6InTruncatedPkts", IPSTATS_MIB_INTRUNCATEDPKTS),
  	SNMP_MIB_ITEM("Ip6InDiscards", IPSTATS_MIB_INDISCARDS),
  	SNMP_MIB_ITEM("Ip6InDelivers", IPSTATS_MIB_INDELIVERS),
  	SNMP_MIB_ITEM("Ip6OutForwDatagrams", IPSTATS_MIB_OUTFORWDATAGRAMS),
edf391ff1   Neil Horman   snmp: add missing...
81
  	SNMP_MIB_ITEM("Ip6OutRequests", IPSTATS_MIB_OUTPKTS),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
83
84
85
86
87
88
89
90
91
92
  	SNMP_MIB_ITEM("Ip6OutDiscards", IPSTATS_MIB_OUTDISCARDS),
  	SNMP_MIB_ITEM("Ip6OutNoRoutes", IPSTATS_MIB_OUTNOROUTES),
  	SNMP_MIB_ITEM("Ip6ReasmTimeout", IPSTATS_MIB_REASMTIMEOUT),
  	SNMP_MIB_ITEM("Ip6ReasmReqds", IPSTATS_MIB_REASMREQDS),
  	SNMP_MIB_ITEM("Ip6ReasmOKs", IPSTATS_MIB_REASMOKS),
  	SNMP_MIB_ITEM("Ip6ReasmFails", IPSTATS_MIB_REASMFAILS),
  	SNMP_MIB_ITEM("Ip6FragOKs", IPSTATS_MIB_FRAGOKS),
  	SNMP_MIB_ITEM("Ip6FragFails", IPSTATS_MIB_FRAGFAILS),
  	SNMP_MIB_ITEM("Ip6FragCreates", IPSTATS_MIB_FRAGCREATES),
  	SNMP_MIB_ITEM("Ip6InMcastPkts", IPSTATS_MIB_INMCASTPKTS),
  	SNMP_MIB_ITEM("Ip6OutMcastPkts", IPSTATS_MIB_OUTMCASTPKTS),
edf391ff1   Neil Horman   snmp: add missing...
93
94
95
96
97
98
  	SNMP_MIB_ITEM("Ip6InOctets", IPSTATS_MIB_INOCTETS),
  	SNMP_MIB_ITEM("Ip6OutOctets", IPSTATS_MIB_OUTOCTETS),
  	SNMP_MIB_ITEM("Ip6InMcastOctets", IPSTATS_MIB_INMCASTOCTETS),
  	SNMP_MIB_ITEM("Ip6OutMcastOctets", IPSTATS_MIB_OUTMCASTOCTETS),
  	SNMP_MIB_ITEM("Ip6InBcastOctets", IPSTATS_MIB_INBCASTOCTETS),
  	SNMP_MIB_ITEM("Ip6OutBcastOctets", IPSTATS_MIB_OUTBCASTOCTETS),
fda3f402f   Nicolas Dichtel   snmp6: remove IPS...
99
  	/* IPSTATS_MIB_CSUMERRORS is not relevant in IPv6 (no checksum) */
1f07d03e2   Eric Dumazet   net: add SNMP cou...
100
101
102
103
  	SNMP_MIB_ITEM("Ip6InNoECTPkts", IPSTATS_MIB_NOECTPKTS),
  	SNMP_MIB_ITEM("Ip6InECT1Pkts", IPSTATS_MIB_ECT1PKTS),
  	SNMP_MIB_ITEM("Ip6InECT0Pkts", IPSTATS_MIB_ECT0PKTS),
  	SNMP_MIB_ITEM("Ip6InCEPkts", IPSTATS_MIB_CEPKTS),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
105
  	SNMP_MIB_SENTINEL
  };
5833929cc   Alexey Dobriyan   net: constify MIB...
106
  static const struct snmp_mib snmp6_icmp6_list[] = {
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
107
  /* icmpv6 mib according to RFC 2466 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
108
109
  	SNMP_MIB_ITEM("Icmp6InMsgs", ICMP6_MIB_INMSGS),
  	SNMP_MIB_ITEM("Icmp6InErrors", ICMP6_MIB_INERRORS),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
  	SNMP_MIB_ITEM("Icmp6OutMsgs", ICMP6_MIB_OUTMSGS),
1f8438a85   Eric Dumazet   icmp: Account for...
111
  	SNMP_MIB_ITEM("Icmp6OutErrors", ICMP6_MIB_OUTERRORS),
6a5dc9e59   Eric Dumazet   net: Add MIB coun...
112
  	SNMP_MIB_ITEM("Icmp6InCsumErrors", ICMP6_MIB_CSUMERRORS),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
113
114
  	SNMP_MIB_SENTINEL
  };
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
115
  /* RFC 4293 v6 ICMPMsgStatsTable; named items for RFC 2466 compatibility */
36cbd3dcc   Jan Engelhardt   net: mark read-on...
116
  static const char *const icmp6type2name[256] = {
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
117
118
119
120
  	[ICMPV6_DEST_UNREACH] = "DestUnreachs",
  	[ICMPV6_PKT_TOOBIG] = "PktTooBigs",
  	[ICMPV6_TIME_EXCEED] = "TimeExcds",
  	[ICMPV6_PARAMPROB] = "ParmProblems",
fa95c2832   Wang Chen   [IPV6]: RFC 2011 ...
121
  	[ICMPV6_ECHO_REQUEST] = "Echos",
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
122
123
124
125
126
127
128
129
130
  	[ICMPV6_ECHO_REPLY] = "EchoReplies",
  	[ICMPV6_MGM_QUERY] = "GroupMembQueries",
  	[ICMPV6_MGM_REPORT] = "GroupMembResponses",
  	[ICMPV6_MGM_REDUCTION] = "GroupMembReductions",
  	[ICMPV6_MLD2_REPORT] = "MLDv2Reports",
  	[NDISC_ROUTER_ADVERTISEMENT] = "RouterAdvertisements",
  	[NDISC_ROUTER_SOLICITATION] = "RouterSolicits",
  	[NDISC_NEIGHBOUR_ADVERTISEMENT] = "NeighborAdvertisements",
  	[NDISC_NEIGHBOUR_SOLICITATION] = "NeighborSolicits",
fa95c2832   Wang Chen   [IPV6]: RFC 2011 ...
131
  	[NDISC_REDIRECT] = "Redirects",
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
132
  };
5833929cc   Alexey Dobriyan   net: constify MIB...
133
  static const struct snmp_mib snmp6_udp6_list[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
134
135
136
137
  	SNMP_MIB_ITEM("Udp6InDatagrams", UDP_MIB_INDATAGRAMS),
  	SNMP_MIB_ITEM("Udp6NoPorts", UDP_MIB_NOPORTS),
  	SNMP_MIB_ITEM("Udp6InErrors", UDP_MIB_INERRORS),
  	SNMP_MIB_ITEM("Udp6OutDatagrams", UDP_MIB_OUTDATAGRAMS),
870be3925   Eric Dumazet   ipv6/udp: report ...
138
139
  	SNMP_MIB_ITEM("Udp6RcvbufErrors", UDP_MIB_RCVBUFERRORS),
  	SNMP_MIB_ITEM("Udp6SndbufErrors", UDP_MIB_SNDBUFERRORS),
6a5dc9e59   Eric Dumazet   net: Add MIB coun...
140
  	SNMP_MIB_ITEM("Udp6InCsumErrors", UDP_MIB_CSUMERRORS),
36cbb2452   Rick Jones   udp: Increment UD...
141
  	SNMP_MIB_ITEM("Udp6IgnoredMulti", UDP_MIB_IGNOREDMULTI),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
142
143
  	SNMP_MIB_SENTINEL
  };
5833929cc   Alexey Dobriyan   net: constify MIB...
144
  static const struct snmp_mib snmp6_udplite6_list[] = {
ba4e58eca   Gerrit Renker   [NET]: Supporting...
145
146
147
148
  	SNMP_MIB_ITEM("UdpLite6InDatagrams", UDP_MIB_INDATAGRAMS),
  	SNMP_MIB_ITEM("UdpLite6NoPorts", UDP_MIB_NOPORTS),
  	SNMP_MIB_ITEM("UdpLite6InErrors", UDP_MIB_INERRORS),
  	SNMP_MIB_ITEM("UdpLite6OutDatagrams", UDP_MIB_OUTDATAGRAMS),
870be3925   Eric Dumazet   ipv6/udp: report ...
149
150
  	SNMP_MIB_ITEM("UdpLite6RcvbufErrors", UDP_MIB_RCVBUFERRORS),
  	SNMP_MIB_ITEM("UdpLite6SndbufErrors", UDP_MIB_SNDBUFERRORS),
6a5dc9e59   Eric Dumazet   net: Add MIB coun...
151
  	SNMP_MIB_ITEM("UdpLite6InCsumErrors", UDP_MIB_CSUMERRORS),
ba4e58eca   Gerrit Renker   [NET]: Supporting...
152
153
  	SNMP_MIB_SENTINEL
  };
2a24444f8   Eric Dumazet   ipv6: reduce perc...
154
  static void snmp6_seq_show_icmpv6msg(struct seq_file *seq, atomic_long_t *smib)
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
155
  {
5ece6c2dd   Alexey Dobriyan   net: fix tiny out...
156
  	char name[32];
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
157
158
159
160
161
  	int i;
  
  	/* print by name -- deprecated items */
  	for (i = 0; i < ICMP6MSG_MIB_MAX; i++) {
  		int icmptype;
36cbd3dcc   Jan Engelhardt   net: mark read-on...
162
  		const char *p;
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
163
164
165
166
167
  
  		icmptype = i & 0xff;
  		p = icmp6type2name[icmptype];
  		if (!p)	/* don't print un-named types here */
  			continue;
5ece6c2dd   Alexey Dobriyan   net: fix tiny out...
168
  		snprintf(name, sizeof(name), "Icmp6%s%s",
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
169
170
171
  			i & 0x100 ? "Out" : "In", p);
  		seq_printf(seq, "%-32s\t%lu
  ", name,
2a24444f8   Eric Dumazet   ipv6: reduce perc...
172
  			   atomic_long_read(smib + i));
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
173
174
175
176
177
  	}
  
  	/* print by number (nonzero only) - ICMPMsgStat format */
  	for (i = 0; i < ICMP6MSG_MIB_MAX; i++) {
  		unsigned long val;
2a24444f8   Eric Dumazet   ipv6: reduce perc...
178
  		val = atomic_long_read(smib + i);
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
179
180
  		if (!val)
  			continue;
5ece6c2dd   Alexey Dobriyan   net: fix tiny out...
181
  		snprintf(name, sizeof(name), "Icmp6%sType%u",
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
182
183
184
185
  			i & 0x100 ?  "Out" : "In", i & 0xff);
  		seq_printf(seq, "%-32s\t%lu
  ", name, val);
  	}
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
186
  }
be281e554   Eric Dumazet   ipv6: reduce per ...
187
188
189
  /* can be called either with percpu mib (pcpumib != NULL),
   * or shared one (smib != NULL)
   */
c9f2dba61   WANG Cong   snmp: fix some le...
190
  static void snmp6_seq_show_item(struct seq_file *seq, void __percpu *pcpumib,
be281e554   Eric Dumazet   ipv6: reduce per ...
191
  				atomic_long_t *smib,
5833929cc   Alexey Dobriyan   net: constify MIB...
192
  				const struct snmp_mib *itemlist)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
193
  {
4a4857b1c   Jia He   proc: Reduce cach...
194
  	unsigned long buff[SNMP_MIB_MAX];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
195
  	int i;
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
196

4a4857b1c   Jia He   proc: Reduce cach...
197
198
199
200
201
202
203
204
205
206
207
208
209
  	if (pcpumib) {
  		memset(buff, 0, sizeof(unsigned long) * SNMP_MIB_MAX);
  
  		snmp_get_cpu_field_batch(buff, itemlist, pcpumib);
  		for (i = 0; itemlist[i].name; i++)
  			seq_printf(seq, "%-32s\t%lu
  ",
  				   itemlist[i].name, buff[i]);
  	} else {
  		for (i = 0; itemlist[i].name; i++)
  			seq_printf(seq, "%-32s\t%lu
  ", itemlist[i].name,
  				   atomic_long_read(smib + itemlist[i].entry));
be281e554   Eric Dumazet   ipv6: reduce per ...
210
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
211
  }
698365fa1   WANG Cong   net: clean up snm...
212
  static void snmp6_seq_show_item64(struct seq_file *seq, void __percpu *mib,
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
213
214
  				  const struct snmp_mib *itemlist, size_t syncpoff)
  {
4a4857b1c   Jia He   proc: Reduce cach...
215
  	u64 buff64[SNMP_MIB_MAX];
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
216
  	int i;
3500cd73d   Christian Perle   proc: snmp6: Use ...
217
  	memset(buff64, 0, sizeof(u64) * SNMP_MIB_MAX);
4a4857b1c   Jia He   proc: Reduce cach...
218
219
  
  	snmp_get_cpu_field64_batch(buff64, itemlist, mib, syncpoff);
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
220
  	for (i = 0; itemlist[i].name; i++)
4a4857b1c   Jia He   proc: Reduce cach...
221
222
  		seq_printf(seq, "%-32s\t%llu
  ", itemlist[i].name, buff64[i]);
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
223
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
224
225
  static int snmp6_seq_show(struct seq_file *seq, void *v)
  {
2b4209e4b   Denis V. Lunev   netns: register g...
226
  	struct net *net = (struct net *)seq->private;
698365fa1   WANG Cong   net: clean up snm...
227
  	snmp6_seq_show_item64(seq, net->mib.ipv6_statistics,
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
228
  			    snmp6_ipstats_list, offsetof(struct ipstats_mib, syncp));
c9f2dba61   WANG Cong   snmp: fix some le...
229
  	snmp6_seq_show_item(seq, net->mib.icmpv6_statistics,
be281e554   Eric Dumazet   ipv6: reduce per ...
230
  			    NULL, snmp6_icmp6_list);
2a24444f8   Eric Dumazet   ipv6: reduce perc...
231
  	snmp6_seq_show_icmpv6msg(seq, net->mib.icmpv6msg_statistics->mibs);
c9f2dba61   WANG Cong   snmp: fix some le...
232
  	snmp6_seq_show_item(seq, net->mib.udp_stats_in6,
be281e554   Eric Dumazet   ipv6: reduce per ...
233
  			    NULL, snmp6_udp6_list);
c9f2dba61   WANG Cong   snmp: fix some le...
234
  	snmp6_seq_show_item(seq, net->mib.udplite_stats_in6,
be281e554   Eric Dumazet   ipv6: reduce per ...
235
  			    NULL, snmp6_udplite6_list);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
236
237
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
238
239
  static int snmp6_seq_open(struct inode *inode, struct file *file)
  {
2b4209e4b   Denis V. Lunev   netns: register g...
240
  	return single_open_net(inode, file, snmp6_seq_show);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
241
  }
9a32144e9   Arjan van de Ven   [PATCH] mark stru...
242
  static const struct file_operations snmp6_seq_fops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
243
244
245
246
  	.owner	 = THIS_MODULE,
  	.open	 = snmp6_seq_open,
  	.read	 = seq_read,
  	.llseek	 = seq_lseek,
2b4209e4b   Denis V. Lunev   netns: register g...
247
  	.release = single_release_net,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
248
  };
7b43ccecc   Denis V. Lunev   ipv6: separate se...
249
250
251
252
253
254
  static int snmp6_dev_seq_show(struct seq_file *seq, void *v)
  {
  	struct inet6_dev *idev = (struct inet6_dev *)seq->private;
  
  	seq_printf(seq, "%-32s\t%u
  ", "ifIndex", idev->dev->ifindex);
698365fa1   WANG Cong   net: clean up snm...
255
  	snmp6_seq_show_item64(seq, idev->stats.ipv6,
766e9f1be   Eric Dumazet   ipv6: fix per dev...
256
  			    snmp6_ipstats_list, offsetof(struct ipstats_mib, syncp));
be281e554   Eric Dumazet   ipv6: reduce per ...
257
  	snmp6_seq_show_item(seq, NULL, idev->stats.icmpv6dev->mibs,
7d720c3e4   Tejun Heo   percpu: add __per...
258
  			    snmp6_icmp6_list);
2a24444f8   Eric Dumazet   ipv6: reduce perc...
259
  	snmp6_seq_show_icmpv6msg(seq, idev->stats.icmpv6msgdev->mibs);
7b43ccecc   Denis V. Lunev   ipv6: separate se...
260
261
262
263
264
  	return 0;
  }
  
  static int snmp6_dev_seq_open(struct inode *inode, struct file *file)
  {
d9dda78ba   Al Viro   procfs: new helpe...
265
  	return single_open(file, snmp6_dev_seq_show, PDE_DATA(inode));
7b43ccecc   Denis V. Lunev   ipv6: separate se...
266
267
268
269
270
271
272
273
274
  }
  
  static const struct file_operations snmp6_dev_seq_fops = {
  	.owner	 = THIS_MODULE,
  	.open	 = snmp6_dev_seq_open,
  	.read	 = seq_read,
  	.llseek	 = seq_lseek,
  	.release = single_release,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
275
276
277
  int snmp6_register_dev(struct inet6_dev *idev)
  {
  	struct proc_dir_entry *p;
835bcc049   Denis V. Lunev   netns: move /proc...
278
  	struct net *net;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
279
280
281
  
  	if (!idev || !idev->dev)
  		return -EINVAL;
835bcc049   Denis V. Lunev   netns: move /proc...
282
  	net = dev_net(idev->dev);
835bcc049   Denis V. Lunev   netns: move /proc...
283
  	if (!net->mib.proc_net_devsnmp6)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284
  		return -ENOENT;
0bb53a66f   Denis V. Lunev   ipv6: assign PDE-...
285
  	p = proc_create_data(idev->dev->name, S_IRUGO,
7b43ccecc   Denis V. Lunev   ipv6: separate se...
286
287
  			     net->mib.proc_net_devsnmp6,
  			     &snmp6_dev_seq_fops, idev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
288
289
  	if (!p)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
290
291
292
293
294
295
  	idev->stats.proc_dir_entry = p;
  	return 0;
  }
  
  int snmp6_unregister_dev(struct inet6_dev *idev)
  {
835bcc049   Denis V. Lunev   netns: move /proc...
296
297
  	struct net *net = dev_net(idev->dev);
  	if (!net->mib.proc_net_devsnmp6)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
298
  		return -ENOENT;
c3f6c21d6   Jiri Slaby   NET: ipv6, remove...
299
  	if (!idev->stats.proc_dir_entry)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
300
  		return -EINVAL;
a8ca16ea7   David Howells   proc: Supply a fu...
301
  	proc_remove(idev->stats.proc_dir_entry);
5632c5152   Stephen Hemminger   [IPV6]: Track dev...
302
  	idev->stats.proc_dir_entry = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
303
304
  	return 0;
  }
2c8c1e729   Alexey Dobriyan   net: spread __net...
305
  static int __net_init ipv6_proc_init_net(struct net *net)
d0538ca35   Pavel Emelyanov   [SOCK][NETNS]: Re...
306
  {
d4beaa66a   Gao feng   net: proc: change...
307
308
  	if (!proc_create("sockstat6", S_IRUGO, net->proc_net,
  			 &sockstat6_seq_fops))
d0538ca35   Pavel Emelyanov   [SOCK][NETNS]: Re...
309
  		return -ENOMEM;
06f38527d   Denis V. Lunev   netns: register /...
310

d4beaa66a   Gao feng   net: proc: change...
311
  	if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
06f38527d   Denis V. Lunev   netns: register /...
312
313
314
315
316
  		goto proc_snmp6_fail;
  
  	net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
  	if (!net->mib.proc_net_devsnmp6)
  		goto proc_dev_snmp6_fail;
d0538ca35   Pavel Emelyanov   [SOCK][NETNS]: Re...
317
  	return 0;
06f38527d   Denis V. Lunev   netns: register /...
318

4855d6f31   Igor Maravic   net: ipv6: proc: ...
319
  proc_dev_snmp6_fail:
ece31ffd5   Gao feng   net: proc: change...
320
  	remove_proc_entry("snmp6", net->proc_net);
06f38527d   Denis V. Lunev   netns: register /...
321
  proc_snmp6_fail:
ece31ffd5   Gao feng   net: proc: change...
322
  	remove_proc_entry("sockstat6", net->proc_net);
06f38527d   Denis V. Lunev   netns: register /...
323
  	return -ENOMEM;
d0538ca35   Pavel Emelyanov   [SOCK][NETNS]: Re...
324
  }
2c8c1e729   Alexey Dobriyan   net: spread __net...
325
  static void __net_exit ipv6_proc_exit_net(struct net *net)
d0538ca35   Pavel Emelyanov   [SOCK][NETNS]: Re...
326
  {
ece31ffd5   Gao feng   net: proc: change...
327
328
329
  	remove_proc_entry("sockstat6", net->proc_net);
  	remove_proc_entry("dev_snmp6", net->proc_net);
  	remove_proc_entry("snmp6", net->proc_net);
d0538ca35   Pavel Emelyanov   [SOCK][NETNS]: Re...
330
331
332
333
334
335
  }
  
  static struct pernet_operations ipv6_proc_ops = {
  	.init = ipv6_proc_init_net,
  	.exit = ipv6_proc_exit_net,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
336
337
  int __init ipv6_misc_proc_init(void)
  {
06f38527d   Denis V. Lunev   netns: register /...
338
  	return register_pernet_subsys(&ipv6_proc_ops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
339
340
341
342
  }
  
  void ipv6_misc_proc_exit(void)
  {
d0538ca35   Pavel Emelyanov   [SOCK][NETNS]: Re...
343
  	unregister_pernet_subsys(&ipv6_proc_ops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
344
  }