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));
60 static struct snmp_item snmp6_ipstats_list[] = {
61 /* ipv6 mib according to RFC 2465 */
62 #define SNMP6_GEN(x) SNMP_ITEM(struct ipstats_mib, x, "Ip6" #x)
63 SNMP6_GEN(InReceives),
64 SNMP6_GEN(InHdrErrors),
65 SNMP6_GEN(InTooBigErrors),
66 SNMP6_GEN(InNoRoutes),
67 SNMP6_GEN(InAddrErrors),
68 SNMP6_GEN(InUnknownProtos),
69 SNMP6_GEN(InTruncatedPkts),
70 SNMP6_GEN(InDiscards),
71 SNMP6_GEN(InDelivers),
72 SNMP6_GEN(OutForwDatagrams),
73 SNMP6_GEN(OutRequests),
74 SNMP6_GEN(OutDiscards),
75 SNMP6_GEN(OutNoRoutes),
76 SNMP6_GEN(ReasmTimeout),
77 SNMP6_GEN(ReasmReqds),
79 SNMP6_GEN(ReasmFails),
82 SNMP6_GEN(FragCreates),
83 SNMP6_GEN(InMcastPkts),
84 SNMP6_GEN(OutMcastPkts),
89 static struct snmp_item snmp6_icmp6_list[] = {
90 /* icmpv6 mib according to RFC 2466
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.
97 OutRouterAdvertisements too.
98 OutGroupMembQueries too.
100 #define SNMP6_GEN(x) SNMP_ITEM(struct icmpv6_mib, x, #x)
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),
133 static struct snmp_item snmp6_udp6_list[] = {
134 #define SNMP6_GEN(x) SNMP_ITEM(struct udp_mib, Udp##x, "Udp6" #x)
135 SNMP6_GEN(InDatagrams),
138 SNMP6_GEN(OutDatagrams),
144 fold_field(void *mib[], int offt)
146 unsigned long res = 0;
149 for (i = 0; i < NR_CPUS; i++) {
150 if (!cpu_possible(i))
153 *((unsigned long *) (((void *)per_cpu_ptr(mib[0], i)) +
156 *((unsigned long *) (((void *)per_cpu_ptr(mib[1], i)) +
163 snmp6_seq_show_item(struct seq_file *seq, void **mib, struct snmp_item *itemlist)
166 for (i=0; itemlist[i].name; i++)
167 seq_printf(seq, "%-32s\t%lu\n", itemlist[i].name,
168 fold_field(mib, itemlist[i].offset));
171 static int snmp6_seq_show(struct seq_file *seq, void *v)
173 struct inet6_dev *idev = (struct inet6_dev *)seq->private;
176 seq_printf(seq, "%-32s\t%u\n", "ifIndex", idev->dev->ifindex);
177 snmp6_seq_show_item(seq, (void **)idev->stats.icmpv6, snmp6_icmp6_list);
179 snmp6_seq_show_item(seq, (void **)ipv6_statistics, snmp6_ipstats_list);
180 snmp6_seq_show_item(seq, (void **)icmpv6_statistics, snmp6_icmp6_list);
181 snmp6_seq_show_item(seq, (void **)udp_stats_in6, snmp6_udp6_list);
186 static int sockstat6_seq_open(struct inode *inode, struct file *file)
188 return single_open(file, sockstat6_seq_show, NULL);
191 static struct file_operations sockstat6_seq_fops = {
192 .owner = THIS_MODULE,
193 .open = sockstat6_seq_open,
196 .release = single_release,
199 static int snmp6_seq_open(struct inode *inode, struct file *file)
201 return single_open(file, snmp6_seq_show, PDE(inode)->data);
204 static struct file_operations snmp6_seq_fops = {
205 .owner = THIS_MODULE,
206 .open = snmp6_seq_open,
209 .release = single_release,
212 int snmp6_register_dev(struct inet6_dev *idev)
215 struct proc_dir_entry *p;
217 if (!idev || !idev->dev)
220 if (snmp6_mib_init((void **)idev->stats.icmpv6, sizeof(struct icmpv6_mib),
221 __alignof__(struct icmpv6_mib)) < 0)
224 if (!proc_net_devsnmp6) {
228 p = create_proc_entry(idev->dev->name, S_IRUGO, proc_net_devsnmp6);
232 p->proc_fops = &snmp6_seq_fops;
234 idev->stats.proc_dir_entry = p;
238 snmp6_mib_free((void **)idev->stats.icmpv6);
243 int snmp6_unregister_dev(struct inet6_dev *idev)
245 if (!proc_net_devsnmp6)
247 if (!idev || !idev->stats.proc_dir_entry)
249 remove_proc_entry(idev->stats.proc_dir_entry->name,
251 snmp6_mib_free((void **)idev->stats.icmpv6);
256 int __init ipv6_misc_proc_init(void)
260 if (!proc_net_fops_create("snmp6", S_IRUGO, &snmp6_seq_fops))
261 goto proc_snmp6_fail;
263 proc_net_devsnmp6 = proc_mkdir("dev_snmp6", proc_net);
264 if (!proc_net_devsnmp6)
265 goto proc_dev_snmp6_fail;
267 if (!proc_net_fops_create("sockstat6", S_IRUGO, &sockstat6_seq_fops))
268 goto proc_sockstat6_fail;
273 proc_net_remove("dev_snmp6");
275 proc_net_remove("snmp6");
281 void ipv6_misc_proc_exit(void)
283 proc_net_remove("sockstat6");
284 proc_net_remove("dev_snmp6");
285 proc_net_remove("snmp6");
288 #else /* CONFIG_PROC_FS */
291 int snmp6_register_dev(struct inet6_dev *idev)
295 if (!idev || !idev->dev)
298 if (snmp6_mib_init((void **)idev->stats.icmpv6, sizeof(struct icmpv6_mib),
299 __alignof__(struct icmpv6_mib)) < 0)
308 int snmp6_unregister_dev(struct inet6_dev *idev)
310 snmp6_mib_free((void **)idev->stats.icmpv6);