Linux Audio

Check our new training course

Loading...
v4.6
  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_MAX	__ICMP_MIB_MAX
 64struct icmp_mib {
 65	unsigned long	mibs[ICMP_MIB_MAX];
 66};
 67
 68#define ICMPMSG_MIB_MAX	__ICMPMSG_MIB_MAX
 69struct icmpmsg_mib {
 70	atomic_long_t	mibs[ICMPMSG_MIB_MAX];
 71};
 72
 73/* ICMP6 (IPv6-ICMP) */
 74#define ICMP6_MIB_MAX	__ICMP6_MIB_MAX
 75/* per network ns counters */
 76struct icmpv6_mib {
 77	unsigned long	mibs[ICMP6_MIB_MAX];
 78};
 79/* per device counters, (shared on all cpus) */
 80struct icmpv6_mib_device {
 81	atomic_long_t	mibs[ICMP6_MIB_MAX];
 82};
 83
 84#define ICMP6MSG_MIB_MAX  __ICMP6MSG_MIB_MAX
 85/* per network ns counters */
 86struct icmpv6msg_mib {
 87	atomic_long_t	mibs[ICMP6MSG_MIB_MAX];
 88};
 89/* per device counters, (shared on all cpus) */
 90struct icmpv6msg_mib_device {
 91	atomic_long_t	mibs[ICMP6MSG_MIB_MAX];
 92};
 93
 94
 95/* TCP */
 96#define TCP_MIB_MAX	__TCP_MIB_MAX
 97struct tcp_mib {
 98	unsigned long	mibs[TCP_MIB_MAX];
 99};
100
101/* UDP */
102#define UDP_MIB_MAX	__UDP_MIB_MAX
103struct udp_mib {
104	unsigned long	mibs[UDP_MIB_MAX];
105};
106
107/* Linux */
108#define LINUX_MIB_MAX	__LINUX_MIB_MAX
109struct linux_mib {
110	unsigned long	mibs[LINUX_MIB_MAX];
111};
112
113/* Linux Xfrm */
114#define LINUX_MIB_XFRMMAX	__LINUX_MIB_XFRMMAX
115struct linux_xfrm_mib {
116	unsigned long	mibs[LINUX_MIB_XFRMMAX];
117};
118
119#define DEFINE_SNMP_STAT(type, name)	\
120	__typeof__(type) __percpu *name
121#define DEFINE_SNMP_STAT_ATOMIC(type, name)	\
122	__typeof__(type) *name
123#define DECLARE_SNMP_STAT(type, name)	\
124	extern __typeof__(type) __percpu *name
125
126#define SNMP_INC_STATS_BH(mib, field)	\
127			__this_cpu_inc(mib->mibs[field])
128
129#define SNMP_INC_STATS_USER(mib, field)	\
130			this_cpu_inc(mib->mibs[field])
131
132#define SNMP_INC_STATS_ATOMIC_LONG(mib, field)	\
133			atomic_long_inc(&mib->mibs[field])
134
135#define SNMP_INC_STATS(mib, field)	\
136			this_cpu_inc(mib->mibs[field])
137
138#define SNMP_DEC_STATS(mib, field)	\
139			this_cpu_dec(mib->mibs[field])
140
141#define SNMP_ADD_STATS_BH(mib, field, addend)	\
142			__this_cpu_add(mib->mibs[field], addend)
143
144#define SNMP_ADD_STATS_USER(mib, field, addend)	\
145			this_cpu_add(mib->mibs[field], addend)
146
147#define SNMP_ADD_STATS(mib, field, addend)	\
148			this_cpu_add(mib->mibs[field], addend)
149#define SNMP_UPD_PO_STATS(mib, basefield, addend)	\
150	do { \
151		__typeof__((mib->mibs) + 0) ptr = mib->mibs;	\
152		this_cpu_inc(ptr[basefield##PKTS]);		\
153		this_cpu_add(ptr[basefield##OCTETS], addend);	\
154	} while (0)
155#define SNMP_UPD_PO_STATS_BH(mib, basefield, addend)	\
156	do { \
157		__typeof__((mib->mibs) + 0) ptr = mib->mibs;	\
158		__this_cpu_inc(ptr[basefield##PKTS]);		\
159		__this_cpu_add(ptr[basefield##OCTETS], addend);	\
160	} while (0)
161
162
163#if BITS_PER_LONG==32
164
165#define SNMP_ADD_STATS64_BH(mib, field, addend) 			\
166	do {								\
167		__typeof__(*mib) *ptr = raw_cpu_ptr(mib);		\
168		u64_stats_update_begin(&ptr->syncp);			\
169		ptr->mibs[field] += addend;				\
170		u64_stats_update_end(&ptr->syncp);			\
171	} while (0)
172
173#define SNMP_ADD_STATS64_USER(mib, field, addend) 			\
174	do {								\
175		local_bh_disable();					\
176		SNMP_ADD_STATS64_BH(mib, field, addend);		\
177		local_bh_enable();					\
178	} while (0)
179
180#define SNMP_ADD_STATS64(mib, field, addend)				\
181		SNMP_ADD_STATS64_USER(mib, field, addend)
182
183#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)
186#define SNMP_UPD_PO_STATS64_BH(mib, basefield, addend)			\
187	do {								\
188		__typeof__(*mib) *ptr;				\
189		ptr = raw_cpu_ptr((mib));				\
190		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)
195#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)
201#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
213#endif
v4.17
  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_MAX	__ICMP_MIB_MAX
 64struct icmp_mib {
 65	unsigned long	mibs[ICMP_MIB_MAX];
 66};
 67
 68#define ICMPMSG_MIB_MAX	__ICMPMSG_MIB_MAX
 69struct icmpmsg_mib {
 70	atomic_long_t	mibs[ICMPMSG_MIB_MAX];
 71};
 72
 73/* ICMP6 (IPv6-ICMP) */
 74#define ICMP6_MIB_MAX	__ICMP6_MIB_MAX
 75/* per network ns counters */
 76struct icmpv6_mib {
 77	unsigned long	mibs[ICMP6_MIB_MAX];
 78};
 79/* per device counters, (shared on all cpus) */
 80struct icmpv6_mib_device {
 81	atomic_long_t	mibs[ICMP6_MIB_MAX];
 82};
 83
 84#define ICMP6MSG_MIB_MAX  __ICMP6MSG_MIB_MAX
 85/* per network ns counters */
 86struct icmpv6msg_mib {
 87	atomic_long_t	mibs[ICMP6MSG_MIB_MAX];
 88};
 89/* per device counters, (shared on all cpus) */
 90struct icmpv6msg_mib_device {
 91	atomic_long_t	mibs[ICMP6MSG_MIB_MAX];
 92};
 93
 94
 95/* TCP */
 96#define TCP_MIB_MAX	__TCP_MIB_MAX
 97struct tcp_mib {
 98	unsigned long	mibs[TCP_MIB_MAX];
 99};
100
101/* UDP */
102#define UDP_MIB_MAX	__UDP_MIB_MAX
103struct udp_mib {
104	unsigned long	mibs[UDP_MIB_MAX];
105};
106
107/* Linux */
108#define LINUX_MIB_MAX	__LINUX_MIB_MAX
109struct linux_mib {
110	unsigned long	mibs[LINUX_MIB_MAX];
111};
112
113/* Linux Xfrm */
114#define LINUX_MIB_XFRMMAX	__LINUX_MIB_XFRMMAX
115struct linux_xfrm_mib {
116	unsigned long	mibs[LINUX_MIB_XFRMMAX];
117};
118
119#define DEFINE_SNMP_STAT(type, name)	\
120	__typeof__(type) __percpu *name
121#define DEFINE_SNMP_STAT_ATOMIC(type, name)	\
122	__typeof__(type) *name
123#define DECLARE_SNMP_STAT(type, name)	\
124	extern __typeof__(type) __percpu *name
125
126#define __SNMP_INC_STATS(mib, field)	\
127			__this_cpu_inc(mib->mibs[field])
128
 
 
 
129#define SNMP_INC_STATS_ATOMIC_LONG(mib, field)	\
130			atomic_long_inc(&mib->mibs[field])
131
132#define SNMP_INC_STATS(mib, field)	\
133			this_cpu_inc(mib->mibs[field])
134
135#define SNMP_DEC_STATS(mib, field)	\
136			this_cpu_dec(mib->mibs[field])
137
138#define __SNMP_ADD_STATS(mib, field, addend)	\
139			__this_cpu_add(mib->mibs[field], addend)
140
 
 
 
141#define SNMP_ADD_STATS(mib, field, addend)	\
142			this_cpu_add(mib->mibs[field], addend)
143#define SNMP_UPD_PO_STATS(mib, basefield, addend)	\
144	do { \
145		__typeof__((mib->mibs) + 0) ptr = mib->mibs;	\
146		this_cpu_inc(ptr[basefield##PKTS]);		\
147		this_cpu_add(ptr[basefield##OCTETS], addend);	\
148	} while (0)
149#define __SNMP_UPD_PO_STATS(mib, basefield, addend)	\
150	do { \
151		__typeof__((mib->mibs) + 0) ptr = mib->mibs;	\
152		__this_cpu_inc(ptr[basefield##PKTS]);		\
153		__this_cpu_add(ptr[basefield##OCTETS], addend);	\
154	} while (0)
155
156
157#if BITS_PER_LONG==32
158
159#define __SNMP_ADD_STATS64(mib, field, addend) 				\
160	do {								\
161		__typeof__(*mib) *ptr = raw_cpu_ptr(mib);		\
162		u64_stats_update_begin(&ptr->syncp);			\
163		ptr->mibs[field] += addend;				\
164		u64_stats_update_end(&ptr->syncp);			\
165	} while (0)
166
167#define SNMP_ADD_STATS64(mib, field, addend) 				\
168	do {								\
169		local_bh_disable();					\
170		__SNMP_ADD_STATS64(mib, field, addend);			\
171		local_bh_enable();				\
172	} while (0)
173
174#define __SNMP_INC_STATS64(mib, field) SNMP_ADD_STATS64(mib, field, 1)
 
 
 
 
175#define SNMP_INC_STATS64(mib, field) SNMP_ADD_STATS64(mib, field, 1)
176#define __SNMP_UPD_PO_STATS64(mib, basefield, addend)			\
177	do {								\
178		__typeof__(*mib) *ptr;				\
179		ptr = raw_cpu_ptr((mib));				\
180		u64_stats_update_begin(&ptr->syncp);			\
181		ptr->mibs[basefield##PKTS]++;				\
182		ptr->mibs[basefield##OCTETS] += addend;			\
183		u64_stats_update_end(&ptr->syncp);			\
184	} while (0)
185#define SNMP_UPD_PO_STATS64(mib, basefield, addend)			\
186	do {								\
187		local_bh_disable();					\
188		__SNMP_UPD_PO_STATS64(mib, basefield, addend);		\
189		local_bh_enable();				\
190	} while (0)
191#else
192#define __SNMP_INC_STATS64(mib, field)		__SNMP_INC_STATS(mib, field)
 
193#define SNMP_INC_STATS64(mib, field)		SNMP_INC_STATS(mib, field)
194#define SNMP_DEC_STATS64(mib, field)		SNMP_DEC_STATS(mib, field)
195#define __SNMP_ADD_STATS64(mib, field, addend)	__SNMP_ADD_STATS(mib, field, addend)
 
196#define SNMP_ADD_STATS64(mib, field, addend)	SNMP_ADD_STATS(mib, field, addend)
197#define SNMP_UPD_PO_STATS64(mib, basefield, addend) SNMP_UPD_PO_STATS(mib, basefield, addend)
198#define __SNMP_UPD_PO_STATS64(mib, basefield, addend) __SNMP_UPD_PO_STATS(mib, basefield, addend)
199#endif
200
201#endif