Blame view

include/net/snmp.h 5.14 KB
2874c5fd2   Thomas Gleixner   treewide: Replace...
1
  /* SPDX-License-Identifier: GPL-2.0-or-later */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
11
  /*
   *
   *		SNMP MIB entries for the IP subsystem.
   *		
   *		Alan Cox <gw4pts@gw4pts.ampr.org>
   *
   *		We don't chose to implement SNMP in the kernel (this would
   *		be silly as SNMP is a pain in the backside in places). We do
   *		however need to collect the MIB statistics and export them
   *		out of /proc (eventually)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
12
13
14
15
16
17
18
   */
   
  #ifndef _SNMP_H
  #define _SNMP_H
  
  #include <linux/cache.h>
  #include <linux/snmp.h>
d647b36a6   Herbert Xu   [SNMP]: Fix SNMP ...
19
  #include <linux/smp.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
21
22
23
24
25
26
27
28
29
  
  /*
   * Mibs are stored in array of unsigned long.
   */
  /*
   * struct snmp_mib{}
   *  - list of entries for particular API (such as /proc/net/snmp)
   *  - name of entries.
   */
  struct snmp_mib {
5833929cc   Alexey Dobriyan   net: constify MIB...
30
  	const char *name;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  	int entry;
  };
  
  #define SNMP_MIB_ITEM(_name,_entry)	{	\
  	.name = _name,				\
  	.entry = _entry,			\
  }
  
  #define SNMP_MIB_SENTINEL {	\
  	.name = NULL,		\
  	.entry = 0,		\
  }
  
  /*
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
45
   * We use unsigned longs for most mibs but u64 for ipstats.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
   */
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
47
  #include <linux/u64_stats_sync.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
50
51
  /* IPstats */
  #define IPSTATS_MIB_MAX	__IPSTATS_MIB_MAX
  struct ipstats_mib {
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
52
53
54
  	/* mibs[] must be first field of struct ipstats_mib */
  	u64		mibs[IPSTATS_MIB_MAX];
  	struct u64_stats_sync syncp;
ec733b15a   Eric Dumazet   net: snmp mib cle...
55
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56
57
  
  /* ICMP */
a9527a3b6   Shan Wei   net: snmp: fix th...
58
  #define ICMP_MIB_MAX	__ICMP_MIB_MAX
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
60
  struct icmp_mib {
  	unsigned long	mibs[ICMP_MIB_MAX];
ec733b15a   Eric Dumazet   net: snmp mib cle...
61
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
62

96793b482   David L Stevens   [IPV4]: Add ICMPM...
63
64
  #define ICMPMSG_MIB_MAX	__ICMPMSG_MIB_MAX
  struct icmpmsg_mib {
acb32ba3d   Eric Dumazet   ipv4: reduce perc...
65
  	atomic_long_t	mibs[ICMPMSG_MIB_MAX];
ec733b15a   Eric Dumazet   net: snmp mib cle...
66
  };
96793b482   David L Stevens   [IPV4]: Add ICMPM...
67

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
68
69
  /* ICMP6 (IPv6-ICMP) */
  #define ICMP6_MIB_MAX	__ICMP6_MIB_MAX
be281e554   Eric Dumazet   ipv6: reduce per ...
70
  /* per network ns counters */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
72
  struct icmpv6_mib {
  	unsigned long	mibs[ICMP6_MIB_MAX];
ec733b15a   Eric Dumazet   net: snmp mib cle...
73
  };
be281e554   Eric Dumazet   ipv6: reduce per ...
74
75
76
77
  /* per device counters, (shared on all cpus) */
  struct icmpv6_mib_device {
  	atomic_long_t	mibs[ICMP6_MIB_MAX];
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78

14878f75a   David L Stevens   [IPV6]: Add ICMPM...
79
  #define ICMP6MSG_MIB_MAX  __ICMP6MSG_MIB_MAX
be281e554   Eric Dumazet   ipv6: reduce per ...
80
  /* per network ns counters */
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
81
  struct icmpv6msg_mib {
2a24444f8   Eric Dumazet   ipv6: reduce perc...
82
  	atomic_long_t	mibs[ICMP6MSG_MIB_MAX];
ec733b15a   Eric Dumazet   net: snmp mib cle...
83
  };
be281e554   Eric Dumazet   ipv6: reduce per ...
84
85
86
87
  /* per device counters, (shared on all cpus) */
  struct icmpv6msg_mib_device {
  	atomic_long_t	mibs[ICMP6MSG_MIB_MAX];
  };
14878f75a   David L Stevens   [IPV6]: Add ICMPM...
88

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
89
90
91
92
  /* TCP */
  #define TCP_MIB_MAX	__TCP_MIB_MAX
  struct tcp_mib {
  	unsigned long	mibs[TCP_MIB_MAX];
ec733b15a   Eric Dumazet   net: snmp mib cle...
93
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94
95
96
97
98
  
  /* UDP */
  #define UDP_MIB_MAX	__UDP_MIB_MAX
  struct udp_mib {
  	unsigned long	mibs[UDP_MIB_MAX];
ec733b15a   Eric Dumazet   net: snmp mib cle...
99
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
101
102
103
104
105
  /* Linux */
  #define LINUX_MIB_MAX	__LINUX_MIB_MAX
  struct linux_mib {
  	unsigned long	mibs[LINUX_MIB_MAX];
  };
558f82ef6   Masahide NAKAMURA   [XFRM]: Define pa...
106
107
108
109
110
  /* Linux Xfrm */
  #define LINUX_MIB_XFRMMAX	__LINUX_MIB_XFRMMAX
  struct linux_xfrm_mib {
  	unsigned long	mibs[LINUX_MIB_XFRMMAX];
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111

d26b698dd   Jakub Kicinski   net/tls: add skel...
112
113
114
115
116
  /* Linux TLS */
  #define LINUX_MIB_TLSMAX	__LINUX_MIB_TLSMAX
  struct linux_tls_mib {
  	unsigned long	mibs[LINUX_MIB_TLSMAX];
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117
  #define DEFINE_SNMP_STAT(type, name)	\
698365fa1   WANG Cong   net: clean up snm...
118
  	__typeof__(type) __percpu *name
be281e554   Eric Dumazet   ipv6: reduce per ...
119
120
  #define DEFINE_SNMP_STAT_ATOMIC(type, name)	\
  	__typeof__(type) *name
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121
  #define DECLARE_SNMP_STAT(type, name)	\
698365fa1   WANG Cong   net: clean up snm...
122
  	extern __typeof__(type) __percpu *name
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123

13415e46c   Eric Dumazet   net: snmp: kill S...
124
  #define __SNMP_INC_STATS(mib, field)	\
698365fa1   WANG Cong   net: clean up snm...
125
  			__this_cpu_inc(mib->mibs[field])
8f0ea0fe3   Eric Dumazet   snmp: reduce perc...
126

be281e554   Eric Dumazet   ipv6: reduce per ...
127
128
  #define SNMP_INC_STATS_ATOMIC_LONG(mib, field)	\
  			atomic_long_inc(&mib->mibs[field])
8f0ea0fe3   Eric Dumazet   snmp: reduce perc...
129

4eb41d10c   Christoph Lameter   this_cpu: Use thi...
130
  #define SNMP_INC_STATS(mib, field)	\
698365fa1   WANG Cong   net: clean up snm...
131
  			this_cpu_inc(mib->mibs[field])
8f0ea0fe3   Eric Dumazet   snmp: reduce perc...
132

4eb41d10c   Christoph Lameter   this_cpu: Use thi...
133
  #define SNMP_DEC_STATS(mib, field)	\
698365fa1   WANG Cong   net: clean up snm...
134
  			this_cpu_dec(mib->mibs[field])
8f0ea0fe3   Eric Dumazet   snmp: reduce perc...
135

13415e46c   Eric Dumazet   net: snmp: kill S...
136
  #define __SNMP_ADD_STATS(mib, field, addend)	\
698365fa1   WANG Cong   net: clean up snm...
137
  			__this_cpu_add(mib->mibs[field], addend)
8f0ea0fe3   Eric Dumazet   snmp: reduce perc...
138

aa2ea0586   Tom Herbert   tcp: fix outsegs ...
139
  #define SNMP_ADD_STATS(mib, field, addend)	\
698365fa1   WANG Cong   net: clean up snm...
140
  			this_cpu_add(mib->mibs[field], addend)
edf391ff1   Neil Horman   snmp: add missing...
141
142
  #define SNMP_UPD_PO_STATS(mib, basefield, addend)	\
  	do { \
54003f119   Sabrina Dubroca   net: fix sparse w...
143
  		__typeof__((mib->mibs) + 0) ptr = mib->mibs;	\
d25398df5   Eric Dumazet   net: avoid reload...
144
145
  		this_cpu_inc(ptr[basefield##PKTS]);		\
  		this_cpu_add(ptr[basefield##OCTETS], addend);	\
edf391ff1   Neil Horman   snmp: add missing...
146
  	} while (0)
13415e46c   Eric Dumazet   net: snmp: kill S...
147
  #define __SNMP_UPD_PO_STATS(mib, basefield, addend)	\
edf391ff1   Neil Horman   snmp: add missing...
148
  	do { \
54003f119   Sabrina Dubroca   net: fix sparse w...
149
  		__typeof__((mib->mibs) + 0) ptr = mib->mibs;	\
d25398df5   Eric Dumazet   net: avoid reload...
150
151
  		__this_cpu_inc(ptr[basefield##PKTS]);		\
  		__this_cpu_add(ptr[basefield##OCTETS], addend);	\
edf391ff1   Neil Horman   snmp: add missing...
152
  	} while (0)
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
153
154
155
  
  
  #if BITS_PER_LONG==32
13415e46c   Eric Dumazet   net: snmp: kill S...
156
  #define __SNMP_ADD_STATS64(mib, field, addend) 				\
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
157
  	do {								\
903ceff7c   Christoph Lameter   net: Replace get_...
158
  		__typeof__(*mib) *ptr = raw_cpu_ptr(mib);		\
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
159
160
161
162
  		u64_stats_update_begin(&ptr->syncp);			\
  		ptr->mibs[field] += addend;				\
  		u64_stats_update_end(&ptr->syncp);			\
  	} while (0)
8f0ea0fe3   Eric Dumazet   snmp: reduce perc...
163

13415e46c   Eric Dumazet   net: snmp: kill S...
164
  #define SNMP_ADD_STATS64(mib, field, addend) 				\
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
165
  	do {								\
ba7863f4d   Eric Dumazet   net: snmp: fix 64...
166
  		local_bh_disable();					\
13415e46c   Eric Dumazet   net: snmp: kill S...
167
  		__SNMP_ADD_STATS64(mib, field, addend);			\
ba7863f4d   Eric Dumazet   net: snmp: fix 64...
168
  		local_bh_enable();				\
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
169
  	} while (0)
8f0ea0fe3   Eric Dumazet   snmp: reduce perc...
170

13415e46c   Eric Dumazet   net: snmp: kill S...
171
  #define __SNMP_INC_STATS64(mib, field) SNMP_ADD_STATS64(mib, field, 1)
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
172
  #define SNMP_INC_STATS64(mib, field) SNMP_ADD_STATS64(mib, field, 1)
13415e46c   Eric Dumazet   net: snmp: kill S...
173
  #define __SNMP_UPD_PO_STATS64(mib, basefield, addend)			\
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
174
  	do {								\
903ceff7c   Christoph Lameter   net: Replace get_...
175
176
  		__typeof__(*mib) *ptr;				\
  		ptr = raw_cpu_ptr((mib));				\
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
177
178
179
180
181
  		u64_stats_update_begin(&ptr->syncp);			\
  		ptr->mibs[basefield##PKTS]++;				\
  		ptr->mibs[basefield##OCTETS] += addend;			\
  		u64_stats_update_end(&ptr->syncp);			\
  	} while (0)
8f0ea0fe3   Eric Dumazet   snmp: reduce perc...
182
183
  #define SNMP_UPD_PO_STATS64(mib, basefield, addend)			\
  	do {								\
ba7863f4d   Eric Dumazet   net: snmp: fix 64...
184
  		local_bh_disable();					\
13415e46c   Eric Dumazet   net: snmp: kill S...
185
  		__SNMP_UPD_PO_STATS64(mib, basefield, addend);		\
ba7863f4d   Eric Dumazet   net: snmp: fix 64...
186
  		local_bh_enable();				\
8f0ea0fe3   Eric Dumazet   snmp: reduce perc...
187
  	} while (0)
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
188
  #else
13415e46c   Eric Dumazet   net: snmp: kill S...
189
  #define __SNMP_INC_STATS64(mib, field)		__SNMP_INC_STATS(mib, field)
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
190
191
  #define SNMP_INC_STATS64(mib, field)		SNMP_INC_STATS(mib, field)
  #define SNMP_DEC_STATS64(mib, field)		SNMP_DEC_STATS(mib, field)
13415e46c   Eric Dumazet   net: snmp: kill S...
192
  #define __SNMP_ADD_STATS64(mib, field, addend)	__SNMP_ADD_STATS(mib, field, addend)
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
193
194
  #define SNMP_ADD_STATS64(mib, field, addend)	SNMP_ADD_STATS(mib, field, addend)
  #define SNMP_UPD_PO_STATS64(mib, basefield, addend) SNMP_UPD_PO_STATS(mib, basefield, addend)
13415e46c   Eric Dumazet   net: snmp: kill S...
195
  #define __SNMP_UPD_PO_STATS64(mib, basefield, addend) __SNMP_UPD_PO_STATS(mib, basefield, addend)
4ce3c183f   Eric Dumazet   snmp: 64bit ipsta...
196
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
197
  #endif