blob: 35512ac6dcfb186884a84a207c5ebab251c2b2db [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18
19#ifndef _SNMP_H
20#define _SNMP_H
21
22#include <linux/cache.h>
23#include <linux/snmp.h>
Herbert Xud647b362007-12-20 04:13:21 -080024#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
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 {
Alexey Dobriyan58339292010-01-22 10:17:26 +000035 const char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 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/*
Eric Dumazet4ce3c182010-06-30 13:31:19 -070050 * We use unsigned longs for most mibs but u64 for ipstats.
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 */
Eric Dumazet4ce3c182010-06-30 13:31:19 -070052#include <linux/u64_stats_sync.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Linus Torvalds1da177e2005-04-16 15:20:36 -070054/* IPstats */
55#define IPSTATS_MIB_MAX __IPSTATS_MIB_MAX
56struct ipstats_mib {
Eric Dumazet4ce3c182010-06-30 13:31:19 -070057 /* mibs[] must be first field of struct ipstats_mib */
58 u64 mibs[IPSTATS_MIB_MAX];
59 struct u64_stats_sync syncp;
Eric Dumazetec733b152010-03-18 20:36:06 +000060};
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62/* ICMP */
Shan Weia9527a32010-12-01 18:04:43 +000063#define ICMP_MIB_MAX __ICMP_MIB_MAX
Linus Torvalds1da177e2005-04-16 15:20:36 -070064struct icmp_mib {
65 unsigned long mibs[ICMP_MIB_MAX];
Eric Dumazetec733b152010-03-18 20:36:06 +000066};
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
David L Stevens96793b42007-09-17 09:57:33 -070068#define ICMPMSG_MIB_MAX __ICMPMSG_MIB_MAX
69struct icmpmsg_mib {
Eric Dumazetacb32ba2011-11-08 13:04:43 +000070 atomic_long_t mibs[ICMPMSG_MIB_MAX];
Eric Dumazetec733b152010-03-18 20:36:06 +000071};
David L Stevens96793b42007-09-17 09:57:33 -070072
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/* ICMP6 (IPv6-ICMP) */
74#define ICMP6_MIB_MAX __ICMP6_MIB_MAX
Eric Dumazetbe281e52011-05-19 01:14:23 +000075/* per network ns counters */
Linus Torvalds1da177e2005-04-16 15:20:36 -070076struct icmpv6_mib {
77 unsigned long mibs[ICMP6_MIB_MAX];
Eric Dumazetec733b152010-03-18 20:36:06 +000078};
Eric Dumazetbe281e52011-05-19 01:14:23 +000079/* per device counters, (shared on all cpus) */
80struct icmpv6_mib_device {
81 atomic_long_t mibs[ICMP6_MIB_MAX];
82};
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
David L Stevens14878f72007-09-16 16:52:35 -070084#define ICMP6MSG_MIB_MAX __ICMP6MSG_MIB_MAX
Eric Dumazetbe281e52011-05-19 01:14:23 +000085/* per network ns counters */
David L Stevens14878f72007-09-16 16:52:35 -070086struct icmpv6msg_mib {
Eric Dumazet2a244442011-11-13 01:24:04 +000087 atomic_long_t mibs[ICMP6MSG_MIB_MAX];
Eric Dumazetec733b152010-03-18 20:36:06 +000088};
Eric Dumazetbe281e52011-05-19 01:14:23 +000089/* per device counters, (shared on all cpus) */
90struct icmpv6msg_mib_device {
91 atomic_long_t mibs[ICMP6MSG_MIB_MAX];
92};
David L Stevens14878f72007-09-16 16:52:35 -070093
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095/* TCP */
96#define TCP_MIB_MAX __TCP_MIB_MAX
97struct tcp_mib {
98 unsigned long mibs[TCP_MIB_MAX];
Eric Dumazetec733b152010-03-18 20:36:06 +000099};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101/* UDP */
102#define UDP_MIB_MAX __UDP_MIB_MAX
103struct udp_mib {
104 unsigned long mibs[UDP_MIB_MAX];
Eric Dumazetec733b152010-03-18 20:36:06 +0000105};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/* Linux */
108#define LINUX_MIB_MAX __LINUX_MIB_MAX
109struct linux_mib {
110 unsigned long mibs[LINUX_MIB_MAX];
111};
112
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -0800113/* Linux Xfrm */
114#define LINUX_MIB_XFRMMAX __LINUX_MIB_XFRMMAX
115struct linux_xfrm_mib {
116 unsigned long mibs[LINUX_MIB_XFRMMAX];
117};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#define DEFINE_SNMP_STAT(type, name) \
WANG Cong698365f2014-05-05 15:55:55 -0700120 __typeof__(type) __percpu *name
Eric Dumazetbe281e52011-05-19 01:14:23 +0000121#define DEFINE_SNMP_STAT_ATOMIC(type, name) \
122 __typeof__(type) *name
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#define DECLARE_SNMP_STAT(type, name) \
WANG Cong698365f2014-05-05 15:55:55 -0700124 extern __typeof__(type) __percpu *name
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Christoph Lameter4eb41d12009-10-03 19:48:22 +0900126#define SNMP_INC_STATS_BH(mib, field) \
WANG Cong698365f2014-05-05 15:55:55 -0700127 __this_cpu_inc(mib->mibs[field])
Eric Dumazet8f0ea0f2011-06-10 19:45:51 +0000128
Christoph Lameter4eb41d12009-10-03 19:48:22 +0900129#define SNMP_INC_STATS_USER(mib, field) \
WANG Cong698365f2014-05-05 15:55:55 -0700130 this_cpu_inc(mib->mibs[field])
Eric Dumazet8f0ea0f2011-06-10 19:45:51 +0000131
Eric Dumazetbe281e52011-05-19 01:14:23 +0000132#define SNMP_INC_STATS_ATOMIC_LONG(mib, field) \
133 atomic_long_inc(&mib->mibs[field])
Eric Dumazet8f0ea0f2011-06-10 19:45:51 +0000134
Christoph Lameter4eb41d12009-10-03 19:48:22 +0900135#define SNMP_INC_STATS(mib, field) \
WANG Cong698365f2014-05-05 15:55:55 -0700136 this_cpu_inc(mib->mibs[field])
Eric Dumazet8f0ea0f2011-06-10 19:45:51 +0000137
Christoph Lameter4eb41d12009-10-03 19:48:22 +0900138#define SNMP_DEC_STATS(mib, field) \
WANG Cong698365f2014-05-05 15:55:55 -0700139 this_cpu_dec(mib->mibs[field])
Eric Dumazet8f0ea0f2011-06-10 19:45:51 +0000140
Christoph Lameter4eb41d12009-10-03 19:48:22 +0900141#define SNMP_ADD_STATS_BH(mib, field, addend) \
WANG Cong698365f2014-05-05 15:55:55 -0700142 __this_cpu_add(mib->mibs[field], addend)
Eric Dumazet8f0ea0f2011-06-10 19:45:51 +0000143
Christoph Lameter4eb41d12009-10-03 19:48:22 +0900144#define SNMP_ADD_STATS_USER(mib, field, addend) \
WANG Cong698365f2014-05-05 15:55:55 -0700145 this_cpu_add(mib->mibs[field], addend)
Eric Dumazet8f0ea0f2011-06-10 19:45:51 +0000146
Tom Herbertaa2ea052010-04-22 07:00:24 +0000147#define SNMP_ADD_STATS(mib, field, addend) \
WANG Cong698365f2014-05-05 15:55:55 -0700148 this_cpu_add(mib->mibs[field], addend)
Neil Hormanedf391f2009-04-27 02:45:02 -0700149#define SNMP_UPD_PO_STATS(mib, basefield, addend) \
150 do { \
Sabrina Dubroca54003f12014-09-17 23:23:12 +0200151 __typeof__((mib->mibs) + 0) ptr = mib->mibs; \
Eric Dumazetd25398d2012-08-04 20:26:13 +0000152 this_cpu_inc(ptr[basefield##PKTS]); \
153 this_cpu_add(ptr[basefield##OCTETS], addend); \
Neil Hormanedf391f2009-04-27 02:45:02 -0700154 } while (0)
155#define SNMP_UPD_PO_STATS_BH(mib, basefield, addend) \
156 do { \
Sabrina Dubroca54003f12014-09-17 23:23:12 +0200157 __typeof__((mib->mibs) + 0) ptr = mib->mibs; \
Eric Dumazetd25398d2012-08-04 20:26:13 +0000158 __this_cpu_inc(ptr[basefield##PKTS]); \
159 __this_cpu_add(ptr[basefield##OCTETS], addend); \
Neil Hormanedf391f2009-04-27 02:45:02 -0700160 } while (0)
Eric Dumazet4ce3c182010-06-30 13:31:19 -0700161
162
163#if BITS_PER_LONG==32
164
165#define SNMP_ADD_STATS64_BH(mib, field, addend) \
166 do { \
Christoph Lameter903ceff2014-08-17 12:30:35 -0500167 __typeof__(*mib) *ptr = raw_cpu_ptr(mib); \
Eric Dumazet4ce3c182010-06-30 13:31:19 -0700168 u64_stats_update_begin(&ptr->syncp); \
169 ptr->mibs[field] += addend; \
170 u64_stats_update_end(&ptr->syncp); \
171 } while (0)
Eric Dumazet8f0ea0f2011-06-10 19:45:51 +0000172
Eric Dumazet4ce3c182010-06-30 13:31:19 -0700173#define SNMP_ADD_STATS64_USER(mib, field, addend) \
174 do { \
Eric Dumazet8f0ea0f2011-06-10 19:45:51 +0000175 local_bh_disable(); \
176 SNMP_ADD_STATS64_BH(mib, field, addend); \
177 local_bh_enable(); \
Eric Dumazet4ce3c182010-06-30 13:31:19 -0700178 } while (0)
Eric Dumazet8f0ea0f2011-06-10 19:45:51 +0000179
Eric Dumazet4ce3c182010-06-30 13:31:19 -0700180#define SNMP_ADD_STATS64(mib, field, addend) \
Eric Dumazet8f0ea0f2011-06-10 19:45:51 +0000181 SNMP_ADD_STATS64_USER(mib, field, addend)
182
Eric Dumazet4ce3c182010-06-30 13:31:19 -0700183#define SNMP_INC_STATS64_BH(mib, field) SNMP_ADD_STATS64_BH(mib, field, 1)
184#define SNMP_INC_STATS64_USER(mib, field) SNMP_ADD_STATS64_USER(mib, field, 1)
185#define SNMP_INC_STATS64(mib, field) SNMP_ADD_STATS64(mib, field, 1)
Eric Dumazet4ce3c182010-06-30 13:31:19 -0700186#define SNMP_UPD_PO_STATS64_BH(mib, basefield, addend) \
187 do { \
Christoph Lameter903ceff2014-08-17 12:30:35 -0500188 __typeof__(*mib) *ptr; \
189 ptr = raw_cpu_ptr((mib)); \
Eric Dumazet4ce3c182010-06-30 13:31:19 -0700190 u64_stats_update_begin(&ptr->syncp); \
191 ptr->mibs[basefield##PKTS]++; \
192 ptr->mibs[basefield##OCTETS] += addend; \
193 u64_stats_update_end(&ptr->syncp); \
194 } while (0)
Eric Dumazet8f0ea0f2011-06-10 19:45:51 +0000195#define SNMP_UPD_PO_STATS64(mib, basefield, addend) \
196 do { \
197 local_bh_disable(); \
198 SNMP_UPD_PO_STATS64_BH(mib, basefield, addend); \
199 local_bh_enable(); \
200 } while (0)
Eric Dumazet4ce3c182010-06-30 13:31:19 -0700201#else
202#define SNMP_INC_STATS64_BH(mib, field) SNMP_INC_STATS_BH(mib, field)
203#define SNMP_INC_STATS64_USER(mib, field) SNMP_INC_STATS_USER(mib, field)
204#define SNMP_INC_STATS64(mib, field) SNMP_INC_STATS(mib, field)
205#define SNMP_DEC_STATS64(mib, field) SNMP_DEC_STATS(mib, field)
206#define SNMP_ADD_STATS64_BH(mib, field, addend) SNMP_ADD_STATS_BH(mib, field, addend)
207#define SNMP_ADD_STATS64_USER(mib, field, addend) SNMP_ADD_STATS_USER(mib, field, addend)
208#define SNMP_ADD_STATS64(mib, field, addend) SNMP_ADD_STATS(mib, field, addend)
209#define SNMP_UPD_PO_STATS64(mib, basefield, addend) SNMP_UPD_PO_STATS(mib, basefield, addend)
210#define SNMP_UPD_PO_STATS64_BH(mib, basefield, addend) SNMP_UPD_PO_STATS_BH(mib, basefield, addend)
211#endif
212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213#endif