]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/net/snmp.h
8139cp: fix checksum broken
[net-next-2.6.git] / include / net / snmp.h
CommitLineData
1da177e4
LT
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 *
1da177e4
LT
17 */
18
19#ifndef _SNMP_H
20#define _SNMP_H
21
22#include <linux/cache.h>
23#include <linux/snmp.h>
d647b36a 24#include <linux/smp.h>
1da177e4
LT
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 {
5833929c 35 const char *name;
1da177e4
LT
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/*
4ce3c183 50 * We use unsigned longs for most mibs but u64 for ipstats.
1da177e4 51 */
4ce3c183 52#include <linux/u64_stats_sync.h>
1da177e4 53
1da177e4
LT
54/* IPstats */
55#define IPSTATS_MIB_MAX __IPSTATS_MIB_MAX
56struct ipstats_mib {
4ce3c183
ED
57 /* mibs[] must be first field of struct ipstats_mib */
58 u64 mibs[IPSTATS_MIB_MAX];
59 struct u64_stats_sync syncp;
ec733b15 60};
1da177e4
LT
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];
ec733b15 68};
1da177e4 69
96793b48
DS
70#define ICMPMSG_MIB_MAX __ICMPMSG_MIB_MAX
71struct icmpmsg_mib {
72 unsigned long mibs[ICMPMSG_MIB_MAX];
ec733b15 73};
96793b48 74
1da177e4
LT
75/* ICMP6 (IPv6-ICMP) */
76#define ICMP6_MIB_MAX __ICMP6_MIB_MAX
77struct icmpv6_mib {
78 unsigned long mibs[ICMP6_MIB_MAX];
ec733b15 79};
1da177e4 80
14878f75
DS
81#define ICMP6MSG_MIB_MAX __ICMP6MSG_MIB_MAX
82struct icmpv6msg_mib {
83 unsigned long mibs[ICMP6MSG_MIB_MAX];
ec733b15 84};
14878f75
DS
85
86
1da177e4
LT
87/* TCP */
88#define TCP_MIB_MAX __TCP_MIB_MAX
89struct tcp_mib {
90 unsigned long mibs[TCP_MIB_MAX];
ec733b15 91};
1da177e4
LT
92
93/* UDP */
94#define UDP_MIB_MAX __UDP_MIB_MAX
95struct udp_mib {
96 unsigned long mibs[UDP_MIB_MAX];
ec733b15 97};
1da177e4 98
1da177e4
LT
99/* Linux */
100#define LINUX_MIB_MAX __LINUX_MIB_MAX
101struct linux_mib {
102 unsigned long mibs[LINUX_MIB_MAX];
103};
104
558f82ef
MN
105/* Linux Xfrm */
106#define LINUX_MIB_XFRMMAX __LINUX_MIB_XFRMMAX
107struct linux_xfrm_mib {
108 unsigned long mibs[LINUX_MIB_XFRMMAX];
109};
1da177e4
LT
110
111/*
112 * FIXME: On x86 and some other CPUs the split into user and softirq parts
113 * is not needed because addl $1,memory is atomic against interrupts (but
114 * atomic_inc would be overkill because of the lock cycles). Wants new
115 * nonlocked_atomic_inc() primitives -AK
116 */
117#define DEFINE_SNMP_STAT(type, name) \
7d720c3e 118 __typeof__(type) __percpu *name[2]
1da177e4 119#define DECLARE_SNMP_STAT(type, name) \
7d720c3e 120 extern __typeof__(type) __percpu *name[2]
1da177e4
LT
121
122#define SNMP_STAT_BHPTR(name) (name[0])
123#define SNMP_STAT_USRPTR(name) (name[1])
124
4eb41d10
CL
125#define SNMP_INC_STATS_BH(mib, field) \
126 __this_cpu_inc(mib[0]->mibs[field])
127#define SNMP_INC_STATS_USER(mib, field) \
128 this_cpu_inc(mib[1]->mibs[field])
129#define SNMP_INC_STATS(mib, field) \
130 this_cpu_inc(mib[!in_softirq()]->mibs[field])
131#define SNMP_DEC_STATS(mib, field) \
132 this_cpu_dec(mib[!in_softirq()]->mibs[field])
133#define SNMP_ADD_STATS_BH(mib, field, addend) \
134 __this_cpu_add(mib[0]->mibs[field], addend)
135#define SNMP_ADD_STATS_USER(mib, field, addend) \
136 this_cpu_add(mib[1]->mibs[field], addend)
aa2ea058 137#define SNMP_ADD_STATS(mib, field, addend) \
8f1c14b2 138 this_cpu_add(mib[!in_softirq()]->mibs[field], addend)
7d720c3e
TH
139/*
140 * Use "__typeof__(*mib[0]) *ptr" instead of "__typeof__(mib[0]) ptr"
141 * to make @ptr a non-percpu pointer.
142 */
edf391ff
NH
143#define SNMP_UPD_PO_STATS(mib, basefield, addend) \
144 do { \
7d720c3e 145 __typeof__(*mib[0]) *ptr; \
4eb41d10
CL
146 preempt_disable(); \
147 ptr = this_cpu_ptr((mib)[!in_softirq()]); \
edf391ff
NH
148 ptr->mibs[basefield##PKTS]++; \
149 ptr->mibs[basefield##OCTETS] += addend;\
4eb41d10 150 preempt_enable(); \
edf391ff
NH
151 } while (0)
152#define SNMP_UPD_PO_STATS_BH(mib, basefield, addend) \
153 do { \
7d720c3e 154 __typeof__(*mib[0]) *ptr = \
4eb41d10 155 __this_cpu_ptr((mib)[!in_softirq()]); \
edf391ff
NH
156 ptr->mibs[basefield##PKTS]++; \
157 ptr->mibs[basefield##OCTETS] += addend;\
158 } while (0)
4ce3c183
ED
159
160
161#if BITS_PER_LONG==32
162
163#define SNMP_ADD_STATS64_BH(mib, field, addend) \
164 do { \
165 __typeof__(*mib[0]) *ptr = __this_cpu_ptr((mib)[0]); \
166 u64_stats_update_begin(&ptr->syncp); \
167 ptr->mibs[field] += addend; \
168 u64_stats_update_end(&ptr->syncp); \
169 } while (0)
170#define SNMP_ADD_STATS64_USER(mib, field, addend) \
171 do { \
172 __typeof__(*mib[0]) *ptr; \
173 preempt_disable(); \
174 ptr = __this_cpu_ptr((mib)[1]); \
175 u64_stats_update_begin(&ptr->syncp); \
176 ptr->mibs[field] += addend; \
177 u64_stats_update_end(&ptr->syncp); \
178 preempt_enable(); \
179 } while (0)
180#define SNMP_ADD_STATS64(mib, field, addend) \
181 do { \
182 __typeof__(*mib[0]) *ptr; \
183 preempt_disable(); \
184 ptr = __this_cpu_ptr((mib)[!in_softirq()]); \
185 u64_stats_update_begin(&ptr->syncp); \
186 ptr->mibs[field] += addend; \
187 u64_stats_update_end(&ptr->syncp); \
188 preempt_enable(); \
189 } while (0)
190#define SNMP_INC_STATS64_BH(mib, field) SNMP_ADD_STATS64_BH(mib, field, 1)
191#define SNMP_INC_STATS64_USER(mib, field) SNMP_ADD_STATS64_USER(mib, field, 1)
192#define SNMP_INC_STATS64(mib, field) SNMP_ADD_STATS64(mib, field, 1)
193#define SNMP_UPD_PO_STATS64(mib, basefield, addend) \
194 do { \
195 __typeof__(*mib[0]) *ptr; \
196 preempt_disable(); \
197 ptr = __this_cpu_ptr((mib)[!in_softirq()]); \
198 u64_stats_update_begin(&ptr->syncp); \
199 ptr->mibs[basefield##PKTS]++; \
200 ptr->mibs[basefield##OCTETS] += addend; \
201 u64_stats_update_end(&ptr->syncp); \
202 preempt_enable(); \
203 } while (0)
204#define SNMP_UPD_PO_STATS64_BH(mib, basefield, addend) \
205 do { \
206 __typeof__(*mib[0]) *ptr; \
207 ptr = __this_cpu_ptr((mib)[!in_softirq()]); \
208 u64_stats_update_begin(&ptr->syncp); \
209 ptr->mibs[basefield##PKTS]++; \
210 ptr->mibs[basefield##OCTETS] += addend; \
211 u64_stats_update_end(&ptr->syncp); \
212 } while (0)
213#else
214#define SNMP_INC_STATS64_BH(mib, field) SNMP_INC_STATS_BH(mib, field)
215#define SNMP_INC_STATS64_USER(mib, field) SNMP_INC_STATS_USER(mib, field)
216#define SNMP_INC_STATS64(mib, field) SNMP_INC_STATS(mib, field)
217#define SNMP_DEC_STATS64(mib, field) SNMP_DEC_STATS(mib, field)
218#define SNMP_ADD_STATS64_BH(mib, field, addend) SNMP_ADD_STATS_BH(mib, field, addend)
219#define SNMP_ADD_STATS64_USER(mib, field, addend) SNMP_ADD_STATS_USER(mib, field, addend)
220#define SNMP_ADD_STATS64(mib, field, addend) SNMP_ADD_STATS(mib, field, addend)
221#define SNMP_UPD_PO_STATS64(mib, basefield, addend) SNMP_UPD_PO_STATS(mib, basefield, addend)
222#define SNMP_UPD_PO_STATS64_BH(mib, basefield, addend) SNMP_UPD_PO_STATS_BH(mib, basefield, addend)
223#endif
224
1da177e4 225#endif