~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/net/snmp.h

Version: ~ [ linux-5.14-rc3 ] ~ [ linux-5.13.5 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.53 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.135 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.198 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.240 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.276 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.276 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0-or-later */
  2 /*
  3  *
  4  *              SNMP MIB entries for the IP subsystem.
  5  *              
  6  *              Alan Cox <gw4pts@gw4pts.ampr.org>
  7  *
  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)
 12  */
 13  
 14 #ifndef _SNMP_H
 15 #define _SNMP_H
 16 
 17 #include <linux/cache.h>
 18 #include <linux/snmp.h>
 19 #include <linux/smp.h>
 20 
 21 /*
 22  * Mibs are stored in array of unsigned long.
 23  */
 24 /*
 25  * struct snmp_mib{}
 26  *  - list of entries for particular API (such as /proc/net/snmp)
 27  *  - name of entries.
 28  */
 29 struct snmp_mib {
 30         const char *name;
 31         int entry;
 32 };
 33 
 34 #define SNMP_MIB_ITEM(_name,_entry)     {       \
 35         .name = _name,                          \
 36         .entry = _entry,                        \
 37 }
 38 
 39 #define SNMP_MIB_SENTINEL {     \
 40         .name = NULL,           \
 41         .entry = 0,             \
 42 }
 43 
 44 /*
 45  * We use unsigned longs for most mibs but u64 for ipstats.
 46  */
 47 #include <linux/u64_stats_sync.h>
 48 
 49 /* IPstats */
 50 #define IPSTATS_MIB_MAX __IPSTATS_MIB_MAX
 51 struct ipstats_mib {
 52         /* mibs[] must be first field of struct ipstats_mib */
 53         u64             mibs[IPSTATS_MIB_MAX];
 54         struct u64_stats_sync syncp;
 55 };
 56 
 57 /* ICMP */
 58 #define ICMP_MIB_MAX    __ICMP_MIB_MAX
 59 struct icmp_mib {
 60         unsigned long   mibs[ICMP_MIB_MAX];
 61 };
 62 
 63 #define ICMPMSG_MIB_MAX __ICMPMSG_MIB_MAX
 64 struct icmpmsg_mib {
 65         atomic_long_t   mibs[ICMPMSG_MIB_MAX];
 66 };
 67 
 68 /* ICMP6 (IPv6-ICMP) */
 69 #define ICMP6_MIB_MAX   __ICMP6_MIB_MAX
 70 /* per network ns counters */
 71 struct icmpv6_mib {
 72         unsigned long   mibs[ICMP6_MIB_MAX];
 73 };
 74 /* per device counters, (shared on all cpus) */
 75 struct icmpv6_mib_device {
 76         atomic_long_t   mibs[ICMP6_MIB_MAX];
 77 };
 78 
 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];
 83 };
 84 /* per device counters, (shared on all cpus) */
 85 struct icmpv6msg_mib_device {
 86         atomic_long_t   mibs[ICMP6MSG_MIB_MAX];
 87 };
 88 
 89 
 90 /* TCP */
 91 #define TCP_MIB_MAX     __TCP_MIB_MAX
 92 struct tcp_mib {
 93         unsigned long   mibs[TCP_MIB_MAX];
 94 };
 95 
 96 /* UDP */
 97 #define UDP_MIB_MAX     __UDP_MIB_MAX
 98 struct udp_mib {
 99         unsigned long   mibs[UDP_MIB_MAX];
100 };
101 
102 /* Linux */
103 #define LINUX_MIB_MAX   __LINUX_MIB_MAX
104 struct linux_mib {
105         unsigned long   mibs[LINUX_MIB_MAX];
106 };
107 
108 /* Linux Xfrm */
109 #define LINUX_MIB_XFRMMAX       __LINUX_MIB_XFRMMAX
110 struct linux_xfrm_mib {
111         unsigned long   mibs[LINUX_MIB_XFRMMAX];
112 };
113 
114 /* Linux TLS */
115 #define LINUX_MIB_TLSMAX        __LINUX_MIB_TLSMAX
116 struct linux_tls_mib {
117         unsigned long   mibs[LINUX_MIB_TLSMAX];
118 };
119 
120 #define DEFINE_SNMP_STAT(type, name)    \
121         __typeof__(type) __percpu *name
122 #define DEFINE_SNMP_STAT_ATOMIC(type, name)     \
123         __typeof__(type) *name
124 #define DECLARE_SNMP_STAT(type, name)   \
125         extern __typeof__(type) __percpu *name
126 
127 #define __SNMP_INC_STATS(mib, field)    \
128                         __this_cpu_inc(mib->mibs[field])
129 
130 #define SNMP_INC_STATS_ATOMIC_LONG(mib, field)  \
131                         atomic_long_inc(&mib->mibs[field])
132 
133 #define SNMP_INC_STATS(mib, field)      \
134                         this_cpu_inc(mib->mibs[field])
135 
136 #define SNMP_DEC_STATS(mib, field)      \
137                         this_cpu_dec(mib->mibs[field])
138 
139 #define __SNMP_ADD_STATS(mib, field, addend)    \
140                         __this_cpu_add(mib->mibs[field], addend)
141 
142 #define SNMP_ADD_STATS(mib, field, addend)      \
143                         this_cpu_add(mib->mibs[field], addend)
144 #define SNMP_UPD_PO_STATS(mib, basefield, addend)       \
145         do { \
146                 __typeof__((mib->mibs) + 0) ptr = mib->mibs;    \
147                 this_cpu_inc(ptr[basefield##PKTS]);             \
148                 this_cpu_add(ptr[basefield##OCTETS], addend);   \
149         } while (0)
150 #define __SNMP_UPD_PO_STATS(mib, basefield, addend)     \
151         do { \
152                 __typeof__((mib->mibs) + 0) ptr = mib->mibs;    \
153                 __this_cpu_inc(ptr[basefield##PKTS]);           \
154                 __this_cpu_add(ptr[basefield##OCTETS], addend); \
155         } while (0)
156 
157 
158 #if BITS_PER_LONG==32
159 
160 #define __SNMP_ADD_STATS64(mib, field, addend)                          \
161         do {                                                            \
162                 __typeof__(*mib) *ptr = raw_cpu_ptr(mib);               \
163                 u64_stats_update_begin(&ptr->syncp);                    \
164                 ptr->mibs[field] += addend;                             \
165                 u64_stats_update_end(&ptr->syncp);                      \
166         } while (0)
167 
168 #define SNMP_ADD_STATS64(mib, field, addend)                            \
169         do {                                                            \
170                 local_bh_disable();                                     \
171                 __SNMP_ADD_STATS64(mib, field, addend);                 \
172                 local_bh_enable();                              \
173         } while (0)
174 
175 #define __SNMP_INC_STATS64(mib, field) SNMP_ADD_STATS64(mib, field, 1)
176 #define SNMP_INC_STATS64(mib, field) SNMP_ADD_STATS64(mib, field, 1)
177 #define __SNMP_UPD_PO_STATS64(mib, basefield, addend)                   \
178         do {                                                            \
179                 __typeof__(*mib) *ptr;                          \
180                 ptr = raw_cpu_ptr((mib));                               \
181                 u64_stats_update_begin(&ptr->syncp);                    \
182                 ptr->mibs[basefield##PKTS]++;                           \
183                 ptr->mibs[basefield##OCTETS] += addend;                 \
184                 u64_stats_update_end(&ptr->syncp);                      \
185         } while (0)
186 #define SNMP_UPD_PO_STATS64(mib, basefield, addend)                     \
187         do {                                                            \
188                 local_bh_disable();                                     \
189                 __SNMP_UPD_PO_STATS64(mib, basefield, addend);          \
190                 local_bh_enable();                              \
191         } while (0)
192 #else
193 #define __SNMP_INC_STATS64(mib, field)          __SNMP_INC_STATS(mib, field)
194 #define SNMP_INC_STATS64(mib, field)            SNMP_INC_STATS(mib, field)
195 #define SNMP_DEC_STATS64(mib, field)            SNMP_DEC_STATS(mib, field)
196 #define __SNMP_ADD_STATS64(mib, field, addend)  __SNMP_ADD_STATS(mib, field, addend)
197 #define SNMP_ADD_STATS64(mib, field, addend)    SNMP_ADD_STATS(mib, field, addend)
198 #define SNMP_UPD_PO_STATS64(mib, basefield, addend) SNMP_UPD_PO_STATS(mib, basefield, addend)
199 #define __SNMP_UPD_PO_STATS64(mib, basefield, addend) __SNMP_UPD_PO_STATS(mib, basefield, addend)
200 #endif
201 
202 #endif
203 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp