]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - include/net/snmp.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 * SNMP MIB entries for the IP subsystem.
6 * Alan Cox <gw4pts@gw4pts.ampr.org>
8 * We don't chose to implement SNMP in the kernel (this would
9 * be silly as SNMP is a pain in the backside in places). We do
10 * however need to collect the MIB statistics and export them
11 * out of /proc (eventually)
17 #include <linux/cache.h>
18 #include <linux/snmp.h>
19 #include <linux/smp.h>
22 * Mibs are stored in array of unsigned long.
26 * - list of entries for particular API (such as /proc/net/snmp)
34 #define SNMP_MIB_ITEM(_name,_entry) { \
39 #define SNMP_MIB_SENTINEL { \
45 * We use unsigned longs for most mibs but u64 for ipstats.
47 #include <linux/u64_stats_sync.h>
50 #define IPSTATS_MIB_MAX __IPSTATS_MIB_MAX
52 /* mibs[] must be first field of struct ipstats_mib */
53 u64 mibs
[IPSTATS_MIB_MAX
];
54 struct u64_stats_sync syncp
;
58 #define ICMP_MIB_MAX __ICMP_MIB_MAX
60 unsigned long mibs
[ICMP_MIB_MAX
];
63 #define ICMPMSG_MIB_MAX __ICMPMSG_MIB_MAX
65 atomic_long_t mibs
[ICMPMSG_MIB_MAX
];
68 /* ICMP6 (IPv6-ICMP) */
69 #define ICMP6_MIB_MAX __ICMP6_MIB_MAX
70 /* per network ns counters */
72 unsigned long mibs
[ICMP6_MIB_MAX
];
74 /* per device counters, (shared on all cpus) */
75 struct icmpv6_mib_device
{
76 atomic_long_t mibs
[ICMP6_MIB_MAX
];
79 #define ICMP6MSG_MIB_MAX __ICMP6MSG_MIB_MAX
80 /* per network ns counters */
81 struct icmpv6msg_mib
{
82 atomic_long_t mibs
[ICMP6MSG_MIB_MAX
];
84 /* per device counters, (shared on all cpus) */
85 struct icmpv6msg_mib_device
{
86 atomic_long_t mibs
[ICMP6MSG_MIB_MAX
];
91 #define TCP_MIB_MAX __TCP_MIB_MAX
93 unsigned long mibs
[TCP_MIB_MAX
];
97 #define UDP_MIB_MAX __UDP_MIB_MAX
99 unsigned long mibs
[UDP_MIB_MAX
];
103 #define LINUX_MIB_MAX __LINUX_MIB_MAX
105 unsigned long mibs
[LINUX_MIB_MAX
];
109 #define LINUX_MIB_XFRMMAX __LINUX_MIB_XFRMMAX
110 struct linux_xfrm_mib
{
111 unsigned long mibs
[LINUX_MIB_XFRMMAX
];
114 #define DEFINE_SNMP_STAT(type, name) \
115 __typeof__(type) __percpu *name
116 #define DEFINE_SNMP_STAT_ATOMIC(type, name) \
117 __typeof__(type) *name
118 #define DECLARE_SNMP_STAT(type, name) \
119 extern __typeof__(type) __percpu *name
121 #define __SNMP_INC_STATS(mib, field) \
122 __this_cpu_inc(mib->mibs[field])
124 #define SNMP_INC_STATS_ATOMIC_LONG(mib, field) \
125 atomic_long_inc(&mib->mibs[field])
127 #define SNMP_INC_STATS(mib, field) \
128 this_cpu_inc(mib->mibs[field])
130 #define SNMP_DEC_STATS(mib, field) \
131 this_cpu_dec(mib->mibs[field])
133 #define __SNMP_ADD_STATS(mib, field, addend) \
134 __this_cpu_add(mib->mibs[field], addend)
136 #define SNMP_ADD_STATS(mib, field, addend) \
137 this_cpu_add(mib->mibs[field], addend)
138 #define SNMP_UPD_PO_STATS(mib, basefield, addend) \
140 __typeof__((mib->mibs) + 0) ptr = mib->mibs; \
141 this_cpu_inc(ptr[basefield##PKTS]); \
142 this_cpu_add(ptr[basefield##OCTETS], addend); \
144 #define __SNMP_UPD_PO_STATS(mib, basefield, addend) \
146 __typeof__((mib->mibs) + 0) ptr = mib->mibs; \
147 __this_cpu_inc(ptr[basefield##PKTS]); \
148 __this_cpu_add(ptr[basefield##OCTETS], addend); \
152 #if BITS_PER_LONG==32
154 #define __SNMP_ADD_STATS64(mib, field, addend) \
156 __typeof__(*mib) *ptr = raw_cpu_ptr(mib); \
157 u64_stats_update_begin(&ptr->syncp); \
158 ptr->mibs[field] += addend; \
159 u64_stats_update_end(&ptr->syncp); \
162 #define SNMP_ADD_STATS64(mib, field, addend) \
164 local_bh_disable(); \
165 __SNMP_ADD_STATS64(mib, field, addend); \
169 #define __SNMP_INC_STATS64(mib, field) SNMP_ADD_STATS64(mib, field, 1)
170 #define SNMP_INC_STATS64(mib, field) SNMP_ADD_STATS64(mib, field, 1)
171 #define __SNMP_UPD_PO_STATS64(mib, basefield, addend) \
173 __typeof__(*mib) *ptr; \
174 ptr = raw_cpu_ptr((mib)); \
175 u64_stats_update_begin(&ptr->syncp); \
176 ptr->mibs[basefield##PKTS]++; \
177 ptr->mibs[basefield##OCTETS] += addend; \
178 u64_stats_update_end(&ptr->syncp); \
180 #define SNMP_UPD_PO_STATS64(mib, basefield, addend) \
182 local_bh_disable(); \
183 __SNMP_UPD_PO_STATS64(mib, basefield, addend); \
187 #define __SNMP_INC_STATS64(mib, field) __SNMP_INC_STATS(mib, field)
188 #define SNMP_INC_STATS64(mib, field) SNMP_INC_STATS(mib, field)
189 #define SNMP_DEC_STATS64(mib, field) SNMP_DEC_STATS(mib, field)
190 #define __SNMP_ADD_STATS64(mib, field, addend) __SNMP_ADD_STATS(mib, field, addend)
191 #define SNMP_ADD_STATS64(mib, field, addend) SNMP_ADD_STATS(mib, field, addend)
192 #define SNMP_UPD_PO_STATS64(mib, basefield, addend) SNMP_UPD_PO_STATS(mib, basefield, addend)
193 #define __SNMP_UPD_PO_STATS64(mib, basefield, addend) __SNMP_UPD_PO_STATS(mib, basefield, addend)