]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/net/snmp.h
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/bp/bp
[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/*
50 * We use all unsigned longs. Linux will soon be so reliable that even
51 * these will rapidly get too small 8-). Seriously consider the IpInReceives
52 * count on the 20Gb/s + networks people expect in a few years time!
53 */
54
1da177e4
LT
55/* IPstats */
56#define IPSTATS_MIB_MAX __IPSTATS_MIB_MAX
57struct ipstats_mib {
58 unsigned long mibs[IPSTATS_MIB_MAX];
ec733b15 59};
1da177e4
LT
60
61/* ICMP */
62#define ICMP_MIB_DUMMY __ICMP_MIB_MAX
63#define ICMP_MIB_MAX (__ICMP_MIB_MAX + 1)
64
65struct icmp_mib {
66 unsigned long mibs[ICMP_MIB_MAX];
ec733b15 67};
1da177e4 68
96793b48
DS
69#define ICMPMSG_MIB_MAX __ICMPMSG_MIB_MAX
70struct icmpmsg_mib {
71 unsigned long mibs[ICMPMSG_MIB_MAX];
ec733b15 72};
96793b48 73
1da177e4
LT
74/* ICMP6 (IPv6-ICMP) */
75#define ICMP6_MIB_MAX __ICMP6_MIB_MAX
76struct icmpv6_mib {
77 unsigned long mibs[ICMP6_MIB_MAX];
ec733b15 78};
1da177e4 79
14878f75
DS
80#define ICMP6MSG_MIB_MAX __ICMP6MSG_MIB_MAX
81struct icmpv6msg_mib {
82 unsigned long mibs[ICMP6MSG_MIB_MAX];
ec733b15 83};
14878f75
DS
84
85
1da177e4
LT
86/* TCP */
87#define TCP_MIB_MAX __TCP_MIB_MAX
88struct tcp_mib {
89 unsigned long mibs[TCP_MIB_MAX];
ec733b15 90};
1da177e4
LT
91
92/* UDP */
93#define UDP_MIB_MAX __UDP_MIB_MAX
94struct udp_mib {
95 unsigned long mibs[UDP_MIB_MAX];
ec733b15 96};
1da177e4 97
1da177e4
LT
98/* Linux */
99#define LINUX_MIB_MAX __LINUX_MIB_MAX
100struct linux_mib {
101 unsigned long mibs[LINUX_MIB_MAX];
102};
103
558f82ef
MN
104/* Linux Xfrm */
105#define LINUX_MIB_XFRMMAX __LINUX_MIB_XFRMMAX
106struct linux_xfrm_mib {
107 unsigned long mibs[LINUX_MIB_XFRMMAX];
108};
1da177e4
LT
109
110/*
111 * FIXME: On x86 and some other CPUs the split into user and softirq parts
112 * is not needed because addl $1,memory is atomic against interrupts (but
113 * atomic_inc would be overkill because of the lock cycles). Wants new
114 * nonlocked_atomic_inc() primitives -AK
115 */
116#define DEFINE_SNMP_STAT(type, name) \
7d720c3e 117 __typeof__(type) __percpu *name[2]
1da177e4 118#define DECLARE_SNMP_STAT(type, name) \
7d720c3e 119 extern __typeof__(type) __percpu *name[2]
1da177e4
LT
120
121#define SNMP_STAT_BHPTR(name) (name[0])
122#define SNMP_STAT_USRPTR(name) (name[1])
123
4eb41d10
CL
124#define SNMP_INC_STATS_BH(mib, field) \
125 __this_cpu_inc(mib[0]->mibs[field])
126#define SNMP_INC_STATS_USER(mib, field) \
127 this_cpu_inc(mib[1]->mibs[field])
128#define SNMP_INC_STATS(mib, field) \
129 this_cpu_inc(mib[!in_softirq()]->mibs[field])
130#define SNMP_DEC_STATS(mib, field) \
131 this_cpu_dec(mib[!in_softirq()]->mibs[field])
132#define SNMP_ADD_STATS_BH(mib, field, addend) \
133 __this_cpu_add(mib[0]->mibs[field], addend)
134#define SNMP_ADD_STATS_USER(mib, field, addend) \
135 this_cpu_add(mib[1]->mibs[field], addend)
aa2ea058 136#define SNMP_ADD_STATS(mib, field, addend) \
8f1c14b2 137 this_cpu_add(mib[!in_softirq()]->mibs[field], addend)
7d720c3e
TH
138/*
139 * Use "__typeof__(*mib[0]) *ptr" instead of "__typeof__(mib[0]) ptr"
140 * to make @ptr a non-percpu pointer.
141 */
edf391ff
NH
142#define SNMP_UPD_PO_STATS(mib, basefield, addend) \
143 do { \
7d720c3e 144 __typeof__(*mib[0]) *ptr; \
4eb41d10
CL
145 preempt_disable(); \
146 ptr = this_cpu_ptr((mib)[!in_softirq()]); \
edf391ff
NH
147 ptr->mibs[basefield##PKTS]++; \
148 ptr->mibs[basefield##OCTETS] += addend;\
4eb41d10 149 preempt_enable(); \
edf391ff
NH
150 } while (0)
151#define SNMP_UPD_PO_STATS_BH(mib, basefield, addend) \
152 do { \
7d720c3e 153 __typeof__(*mib[0]) *ptr = \
4eb41d10 154 __this_cpu_ptr((mib)[!in_softirq()]); \
edf391ff
NH
155 ptr->mibs[basefield##PKTS]++; \
156 ptr->mibs[basefield##OCTETS] += addend;\
157 } while (0)
1da177e4 158#endif