• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/include/net/
1/*
2 *
3 *		SNMP MIB entries for the IP subsystem.
4 *
5 *		Alan Cox <gw4pts@gw4pts.ampr.org>
6 *
7 *		We don't chose to implement SNMP in the kernel (this would
8 *		be silly as SNMP is a pain in the backside in places). We do
9 *		however need to collect the MIB statistics and export them
10 *		out of /proc (eventually)
11 *
12 *		This program is free software; you can redistribute it and/or
13 *		modify it under the terms of the GNU General Public License
14 *		as published by the Free Software Foundation; either version
15 *		2 of the License, or (at your option) any later version.
16 *
17 */
18
19#ifndef _SNMP_H
20#define _SNMP_H
21
22#include <linux/cache.h>
23#include <linux/snmp.h>
24#include <linux/smp.h>
25
26/*
27 * Mibs are stored in array of unsigned long.
28 */
29/*
30 * struct snmp_mib{}
31 *  - list of entries for particular API (such as /proc/net/snmp)
32 *  - name of entries.
33 */
34struct snmp_mib {
35	const char *name;
36	int entry;
37};
38
39#define SNMP_MIB_ITEM(_name,_entry)	{	\
40	.name = _name,				\
41	.entry = _entry,			\
42}
43
44#define SNMP_MIB_SENTINEL {	\
45	.name = NULL,		\
46	.entry = 0,		\
47}
48
49/*
50 * We use unsigned longs for most mibs but u64 for ipstats.
51 */
52#include <linux/u64_stats_sync.h>
53
54/* IPstats */
55#define IPSTATS_MIB_MAX	__IPSTATS_MIB_MAX
56struct ipstats_mib {
57	/* mibs[] must be first field of struct ipstats_mib */
58	u64		mibs[IPSTATS_MIB_MAX];
59	struct u64_stats_sync syncp;
60};
61
62/* ICMP */
63#define ICMP_MIB_DUMMY	__ICMP_MIB_MAX
64#define ICMP_MIB_MAX	(__ICMP_MIB_MAX + 1)
65
66struct icmp_mib {
67	unsigned long	mibs[ICMP_MIB_MAX];
68};
69
70#define ICMPMSG_MIB_MAX	__ICMPMSG_MIB_MAX
71struct icmpmsg_mib {
72	unsigned long	mibs[ICMPMSG_MIB_MAX];
73};
74
75/* ICMP6 (IPv6-ICMP) */
76#define ICMP6_MIB_MAX	__ICMP6_MIB_MAX
77struct icmpv6_mib {
78	unsigned long	mibs[ICMP6_MIB_MAX];
79};
80
81#define ICMP6MSG_MIB_MAX  __ICMP6MSG_MIB_MAX
82struct icmpv6msg_mib {
83	unsigned long	mibs[ICMP6MSG_MIB_MAX];
84};
85
86
87/* TCP */
88#define TCP_MIB_MAX	__TCP_MIB_MAX
89struct tcp_mib {
90	unsigned long	mibs[TCP_MIB_MAX];
91};
92
93/* UDP */
94#define UDP_MIB_MAX	__UDP_MIB_MAX
95struct udp_mib {
96	unsigned long	mibs[UDP_MIB_MAX];
97};
98
99/* Linux */
100#define LINUX_MIB_MAX	__LINUX_MIB_MAX
101struct linux_mib {
102	unsigned long	mibs[LINUX_MIB_MAX];
103};
104
105/* Linux Xfrm */
106#define LINUX_MIB_XFRMMAX	__LINUX_MIB_XFRMMAX
107struct linux_xfrm_mib {
108	unsigned long	mibs[LINUX_MIB_XFRMMAX];
109};
110
111#define DEFINE_SNMP_STAT(type, name)	\
112	__typeof__(type) __percpu *name[2]
113#define DECLARE_SNMP_STAT(type, name)	\
114	extern __typeof__(type) __percpu *name[2]
115
116#define SNMP_STAT_BHPTR(name)	(name[0])
117#define SNMP_STAT_USRPTR(name)	(name[1])
118
119#define SNMP_INC_STATS_BH(mib, field)	\
120			__this_cpu_inc(mib[0]->mibs[field])
121#define SNMP_INC_STATS_USER(mib, field)	\
122			this_cpu_inc(mib[1]->mibs[field])
123#define SNMP_INC_STATS(mib, field)	\
124			this_cpu_inc(mib[!in_softirq()]->mibs[field])
125#define SNMP_DEC_STATS(mib, field)	\
126			this_cpu_dec(mib[!in_softirq()]->mibs[field])
127#define SNMP_ADD_STATS_BH(mib, field, addend)	\
128			__this_cpu_add(mib[0]->mibs[field], addend)
129#define SNMP_ADD_STATS_USER(mib, field, addend)	\
130			this_cpu_add(mib[1]->mibs[field], addend)
131#define SNMP_ADD_STATS(mib, field, addend)	\
132			this_cpu_add(mib[!in_softirq()]->mibs[field], addend)
133/*
134 * Use "__typeof__(*mib[0]) *ptr" instead of "__typeof__(mib[0]) ptr"
135 * to make @ptr a non-percpu pointer.
136 */
137#define SNMP_UPD_PO_STATS(mib, basefield, addend)	\
138	do { \
139		__typeof__(*mib[0]) *ptr; \
140		preempt_disable(); \
141		ptr = this_cpu_ptr((mib)[!in_softirq()]); \
142		ptr->mibs[basefield##PKTS]++; \
143		ptr->mibs[basefield##OCTETS] += addend;\
144		preempt_enable(); \
145	} while (0)
146#define SNMP_UPD_PO_STATS_BH(mib, basefield, addend)	\
147	do { \
148		__typeof__(*mib[0]) *ptr = \
149			__this_cpu_ptr((mib)[!in_softirq()]); \
150		ptr->mibs[basefield##PKTS]++; \
151		ptr->mibs[basefield##OCTETS] += addend;\
152	} while (0)
153
154
155#if BITS_PER_LONG==32
156
157#define SNMP_ADD_STATS64_BH(mib, field, addend) 			\
158	do {								\
159		__typeof__(*mib[0]) *ptr = __this_cpu_ptr((mib)[0]);	\
160		u64_stats_update_begin(&ptr->syncp);			\
161		ptr->mibs[field] += addend;				\
162		u64_stats_update_end(&ptr->syncp);			\
163	} while (0)
164#define SNMP_ADD_STATS64_USER(mib, field, addend) 			\
165	do {								\
166		__typeof__(*mib[0]) *ptr;				\
167		preempt_disable();					\
168		ptr = __this_cpu_ptr((mib)[1]);				\
169		u64_stats_update_begin(&ptr->syncp);			\
170		ptr->mibs[field] += addend;				\
171		u64_stats_update_end(&ptr->syncp);			\
172		preempt_enable();					\
173	} while (0)
174#define SNMP_ADD_STATS64(mib, field, addend)				\
175	do {								\
176		__typeof__(*mib[0]) *ptr;				\
177		preempt_disable();					\
178		ptr = __this_cpu_ptr((mib)[!in_softirq()]);		\
179		u64_stats_update_begin(&ptr->syncp);			\
180		ptr->mibs[field] += addend;				\
181		u64_stats_update_end(&ptr->syncp);			\
182		preempt_enable();					\
183	} while (0)
184#define SNMP_INC_STATS64_BH(mib, field) SNMP_ADD_STATS64_BH(mib, field, 1)
185#define SNMP_INC_STATS64_USER(mib, field) SNMP_ADD_STATS64_USER(mib, field, 1)
186#define SNMP_INC_STATS64(mib, field) SNMP_ADD_STATS64(mib, field, 1)
187#define SNMP_UPD_PO_STATS64(mib, basefield, addend)			\
188	do {								\
189		__typeof__(*mib[0]) *ptr;				\
190		preempt_disable();					\
191		ptr = __this_cpu_ptr((mib)[!in_softirq()]);		\
192		u64_stats_update_begin(&ptr->syncp);			\
193		ptr->mibs[basefield##PKTS]++;				\
194		ptr->mibs[basefield##OCTETS] += addend;			\
195		u64_stats_update_end(&ptr->syncp);			\
196		preempt_enable();					\
197	} while (0)
198#define SNMP_UPD_PO_STATS64_BH(mib, basefield, addend)			\
199	do {								\
200		__typeof__(*mib[0]) *ptr;				\
201		ptr = __this_cpu_ptr((mib)[!in_softirq()]);		\
202		u64_stats_update_begin(&ptr->syncp);			\
203		ptr->mibs[basefield##PKTS]++;				\
204		ptr->mibs[basefield##OCTETS] += addend;			\
205		u64_stats_update_end(&ptr->syncp);			\
206	} while (0)
207#else
208#define SNMP_INC_STATS64_BH(mib, field)		SNMP_INC_STATS_BH(mib, field)
209#define SNMP_INC_STATS64_USER(mib, field)	SNMP_INC_STATS_USER(mib, field)
210#define SNMP_INC_STATS64(mib, field)		SNMP_INC_STATS(mib, field)
211#define SNMP_DEC_STATS64(mib, field)		SNMP_DEC_STATS(mib, field)
212#define SNMP_ADD_STATS64_BH(mib, field, addend) SNMP_ADD_STATS_BH(mib, field, addend)
213#define SNMP_ADD_STATS64_USER(mib, field, addend) SNMP_ADD_STATS_USER(mib, field, addend)
214#define SNMP_ADD_STATS64(mib, field, addend)	SNMP_ADD_STATS(mib, field, addend)
215#define SNMP_UPD_PO_STATS64(mib, basefield, addend) SNMP_UPD_PO_STATS(mib, basefield, addend)
216#define SNMP_UPD_PO_STATS64_BH(mib, basefield, addend) SNMP_UPD_PO_STATS_BH(mib, basefield, addend)
217#endif
218
219#endif
220