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.
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.
10 * Version: $Id: proc.c,v 1.17 2002/02/01 22:01:04 davem Exp $
12 * Authors: David S. Miller (davem@caip.rutgers.edu)
13 * YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
20 #include <linux/config.h>
21 #include <linux/sched.h>
22 #include <linux/socket.h>
23 #include <linux/net.h>
24 #include <linux/ipv6.h>
25 #include <linux/proc_fs.h>
26 #include <linux/seq_file.h>
27 #include <linux/stddef.h>
30 #include <net/transp_v6.h>
34 static struct proc_dir_entry *proc_net_devsnmp6;
36 static int fold_prot_inuse(struct proto *proto)
41 for (cpu=0; cpu<NR_CPUS; cpu++)
42 res += proto->stats[cpu].inuse;
47 static int sockstat6_seq_show(struct seq_file *seq, void *v)
49 seq_printf(seq, "TCP6: inuse %d\n",
50 fold_prot_inuse(&tcpv6_prot));
51 seq_printf(seq, "UDP6: inuse %d\n",
52 fold_prot_inuse(&udpv6_prot));
53 seq_printf(seq, "RAW6: inuse %d\n",
54 fold_prot_inuse(&rawv6_prot));
55 seq_printf(seq, "FRAG6: inuse %d memory %d\n",
56 ip6_frag_nqueues, atomic_read(&ip6_frag_mem));
65 #define SNMP6_SENTINEL { .name = NULL, .offset = 0 }
67 static struct snmp6_item snmp6_ipv6_list[] = {
68 /* ipv6 mib according to RFC 2465 */
69 #define SNMP6_GEN(x) { .name = #x , .offset = offsetof(struct ipv6_mib, x) }
70 SNMP6_GEN(Ip6InReceives),
71 SNMP6_GEN(Ip6InHdrErrors),
72 SNMP6_GEN(Ip6InTooBigErrors),
73 SNMP6_GEN(Ip6InNoRoutes),
74 SNMP6_GEN(Ip6InAddrErrors),
75 SNMP6_GEN(Ip6InUnknownProtos),
76 SNMP6_GEN(Ip6InTruncatedPkts),
77 SNMP6_GEN(Ip6InDiscards),
78 SNMP6_GEN(Ip6InDelivers),
79 SNMP6_GEN(Ip6OutForwDatagrams),
80 SNMP6_GEN(Ip6OutRequests),
81 SNMP6_GEN(Ip6OutDiscards),
82 SNMP6_GEN(Ip6OutNoRoutes),
83 SNMP6_GEN(Ip6ReasmTimeout),
84 SNMP6_GEN(Ip6ReasmReqds),
85 SNMP6_GEN(Ip6ReasmOKs),
86 SNMP6_GEN(Ip6ReasmFails),
87 SNMP6_GEN(Ip6FragOKs),
88 SNMP6_GEN(Ip6FragFails),
89 SNMP6_GEN(Ip6FragCreates),
90 SNMP6_GEN(Ip6InMcastPkts),
91 SNMP6_GEN(Ip6OutMcastPkts),
96 static struct snmp6_item snmp6_icmp6_list[] = {
97 /* icmpv6 mib according to RFC 2466
99 Exceptions: {In|Out}AdminProhibs are removed, because I see
100 no good reasons to account them separately
101 of another dest.unreachs.
102 OutErrs is zero identically.
104 OutRouterAdvertisements too.
105 OutGroupMembQueries too.
107 #define SNMP6_GEN(x) { .name = #x , .offset = offsetof(struct icmpv6_mib, x) }
108 SNMP6_GEN(Icmp6InMsgs),
109 SNMP6_GEN(Icmp6InErrors),
110 SNMP6_GEN(Icmp6InDestUnreachs),
111 SNMP6_GEN(Icmp6InPktTooBigs),
112 SNMP6_GEN(Icmp6InTimeExcds),
113 SNMP6_GEN(Icmp6InParmProblems),
114 SNMP6_GEN(Icmp6InEchos),
115 SNMP6_GEN(Icmp6InEchoReplies),
116 SNMP6_GEN(Icmp6InGroupMembQueries),
117 SNMP6_GEN(Icmp6InGroupMembResponses),
118 SNMP6_GEN(Icmp6InGroupMembReductions),
119 SNMP6_GEN(Icmp6InRouterSolicits),
120 SNMP6_GEN(Icmp6InRouterAdvertisements),
121 SNMP6_GEN(Icmp6InNeighborSolicits),
122 SNMP6_GEN(Icmp6InNeighborAdvertisements),
123 SNMP6_GEN(Icmp6InRedirects),
124 SNMP6_GEN(Icmp6OutMsgs),
125 SNMP6_GEN(Icmp6OutDestUnreachs),
126 SNMP6_GEN(Icmp6OutPktTooBigs),
127 SNMP6_GEN(Icmp6OutTimeExcds),
128 SNMP6_GEN(Icmp6OutParmProblems),
129 SNMP6_GEN(Icmp6OutEchoReplies),
130 SNMP6_GEN(Icmp6OutRouterSolicits),
131 SNMP6_GEN(Icmp6OutNeighborSolicits),
132 SNMP6_GEN(Icmp6OutNeighborAdvertisements),
133 SNMP6_GEN(Icmp6OutRedirects),
134 SNMP6_GEN(Icmp6OutGroupMembResponses),
135 SNMP6_GEN(Icmp6OutGroupMembReductions),
140 static struct snmp6_item snmp6_udp6_list[] = {
141 #define SNMP6_GEN(x) { .name = "Udp6" #x , .offset = offsetof(struct udp_mib, Udp##x) }
142 SNMP6_GEN(InDatagrams),
145 SNMP6_GEN(OutDatagrams),
151 fold_field(void *mib[], int offt)
153 unsigned long res = 0;
156 for (i = 0; i < NR_CPUS; i++) {
157 if (!cpu_possible(i))
160 *((unsigned long *) (((void *)per_cpu_ptr(mib[0], i)) +
163 *((unsigned long *) (((void *)per_cpu_ptr(mib[1], i)) +
170 snmp6_seq_show_item(struct seq_file *seq, void **mib, struct snmp6_item *itemlist)
173 for (i=0; itemlist[i].name; i++)
174 seq_printf(seq, "%-32s\t%lu\n", itemlist[i].name,
175 fold_field(mib, itemlist[i].offset));
178 static int snmp6_seq_show(struct seq_file *seq, void *v)
180 struct inet6_dev *idev = (struct inet6_dev *)seq->private;
183 seq_printf(seq, "%-32s\t%u\n", "ifIndex", idev->dev->ifindex);
184 snmp6_seq_show_item(seq, (void **)idev->stats.icmpv6, snmp6_icmp6_list);
186 snmp6_seq_show_item(seq, (void **)ipv6_statistics, snmp6_ipv6_list);
187 snmp6_seq_show_item(seq, (void **)icmpv6_statistics, snmp6_icmp6_list);
188 snmp6_seq_show_item(seq, (void **)udp_stats_in6, snmp6_udp6_list);
193 static int sockstat6_seq_open(struct inode *inode, struct file *file)
195 return single_open(file, sockstat6_seq_show, NULL);
198 static struct file_operations sockstat6_seq_fops = {
199 .owner = THIS_MODULE,
200 .open = sockstat6_seq_open,
203 .release = single_release,
206 static int snmp6_seq_open(struct inode *inode, struct file *file)
208 return single_open(file, snmp6_seq_show, PDE(inode)->data);
211 static struct file_operations snmp6_seq_fops = {
212 .owner = THIS_MODULE,
213 .open = snmp6_seq_open,
216 .release = single_release,
219 int snmp6_register_dev(struct inet6_dev *idev)
222 struct proc_dir_entry *p;
224 if (!idev || !idev->dev)
227 if (snmp6_mib_init((void **)idev->stats.icmpv6, sizeof(struct icmpv6_mib),
228 __alignof__(struct icmpv6_mib)) < 0)
231 if (!proc_net_devsnmp6) {
235 p = create_proc_entry(idev->dev->name, S_IRUGO, proc_net_devsnmp6);
239 p->proc_fops = &snmp6_seq_fops;
241 idev->stats.proc_dir_entry = p;
245 snmp6_mib_free((void **)idev->stats.icmpv6);
250 int snmp6_unregister_dev(struct inet6_dev *idev)
252 if (!proc_net_devsnmp6)
254 if (!idev || !idev->stats.proc_dir_entry)
256 remove_proc_entry(idev->stats.proc_dir_entry->name,
258 snmp6_mib_free((void **)idev->stats.icmpv6);
263 int __init ipv6_misc_proc_init(void)
267 if (!proc_net_fops_create("snmp6", S_IRUGO, &snmp6_seq_fops))
268 goto proc_snmp6_fail;
270 proc_net_devsnmp6 = proc_mkdir("dev_snmp6", proc_net);
271 if (!proc_net_devsnmp6)
272 goto proc_dev_snmp6_fail;
274 if (!proc_net_fops_create("sockstat6", S_IRUGO, &sockstat6_seq_fops))
275 goto proc_sockstat6_fail;
280 proc_net_remove("dev_snmp6");
282 proc_net_remove("snmp6");
288 void ipv6_misc_proc_exit(void)
290 proc_net_remove("sockstat6");
291 proc_net_remove("dev_snmp6");
292 proc_net_remove("snmp6");
295 #else /* CONFIG_PROC_FS */
298 int snmp6_register_dev(struct inet6_dev *idev)
302 if (!idev || !idev->dev)
305 if (snmp6_mib_init((void **)idev->stats.icmpv6, sizeof(struct icmpv6_mib),
306 __alignof__(struct icmpv6_mib)) < 0)
315 int snmp6_unregister_dev(struct inet6_dev *idev)
317 snmp6_mib_free((void **)idev->stats.icmpv6);