snmp.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. * $Id: snmp.h,v 1.19 2001/06/14 13:40:46 davem Exp $
  18. *
  19. */
  20. #ifndef _SNMP_H
  21. #define _SNMP_H
  22. #include <linux/cache.h>
  23. #include <linux/snmp.h>
  24. #include <linux/smp.h>
  25. /*
  26. * Mibs are stored in array of unsigned long.
  27. */
  28. /*
  29. * struct snmp_mib{}
  30. * - list of entries for particular API (such as /proc/net/snmp)
  31. * - name of entries.
  32. */
  33. struct snmp_mib {
  34. char *name;
  35. int entry;
  36. };
  37. #define SNMP_MIB_ITEM(_name,_entry) { \
  38. .name = _name, \
  39. .entry = _entry, \
  40. }
  41. #define SNMP_MIB_SENTINEL { \
  42. .name = NULL, \
  43. .entry = 0, \
  44. }
  45. /*
  46. * We use all unsigned longs. Linux will soon be so reliable that even
  47. * these will rapidly get too small 8-). Seriously consider the IpInReceives
  48. * count on the 20Gb/s + networks people expect in a few years time!
  49. */
  50. /*
  51. * The rule for padding:
  52. * Best is power of two because then the right structure can be found by a
  53. * simple shift. The structure should be always cache line aligned.
  54. * gcc needs n=alignto(cachelinesize, popcnt(sizeof(bla_mib))) shift/add
  55. * instructions to emulate multiply in case it is not power-of-two.
  56. * Currently n is always <=3 for all sizes so simple cache line alignment
  57. * is enough.
  58. *
  59. * The best solution would be a global CPU local area , especially on 64
  60. * and 128byte cacheline machine it makes a *lot* of sense -AK
  61. */
  62. #define __SNMP_MIB_ALIGN__ ____cacheline_aligned
  63. /* IPstats */
  64. #define IPSTATS_MIB_MAX __IPSTATS_MIB_MAX
  65. struct ipstats_mib {
  66. unsigned long mibs[IPSTATS_MIB_MAX];
  67. } __SNMP_MIB_ALIGN__;
  68. /* ICMP */
  69. #define ICMP_MIB_DUMMY __ICMP_MIB_MAX
  70. #define ICMP_MIB_MAX (__ICMP_MIB_MAX + 1)
  71. struct icmp_mib {
  72. unsigned long mibs[ICMP_MIB_MAX];
  73. } __SNMP_MIB_ALIGN__;
  74. #define ICMPMSG_MIB_MAX __ICMPMSG_MIB_MAX
  75. struct icmpmsg_mib {
  76. unsigned long mibs[ICMPMSG_MIB_MAX];
  77. } __SNMP_MIB_ALIGN__;
  78. /* ICMP6 (IPv6-ICMP) */
  79. #define ICMP6_MIB_MAX __ICMP6_MIB_MAX
  80. struct icmpv6_mib {
  81. unsigned long mibs[ICMP6_MIB_MAX];
  82. } __SNMP_MIB_ALIGN__;
  83. #define ICMP6MSG_MIB_MAX __ICMP6MSG_MIB_MAX
  84. struct icmpv6msg_mib {
  85. unsigned long mibs[ICMP6MSG_MIB_MAX];
  86. } __SNMP_MIB_ALIGN__;
  87. /* TCP */
  88. #define TCP_MIB_MAX __TCP_MIB_MAX
  89. struct tcp_mib {
  90. unsigned long mibs[TCP_MIB_MAX];
  91. } __SNMP_MIB_ALIGN__;
  92. /* UDP */
  93. #define UDP_MIB_MAX __UDP_MIB_MAX
  94. struct udp_mib {
  95. unsigned long mibs[UDP_MIB_MAX];
  96. } __SNMP_MIB_ALIGN__;
  97. /* Linux */
  98. #define LINUX_MIB_MAX __LINUX_MIB_MAX
  99. struct linux_mib {
  100. unsigned long mibs[LINUX_MIB_MAX];
  101. };
  102. /* Linux Xfrm */
  103. #define LINUX_MIB_XFRMMAX __LINUX_MIB_XFRMMAX
  104. struct linux_xfrm_mib {
  105. unsigned long mibs[LINUX_MIB_XFRMMAX];
  106. };
  107. /*
  108. * FIXME: On x86 and some other CPUs the split into user and softirq parts
  109. * is not needed because addl $1,memory is atomic against interrupts (but
  110. * atomic_inc would be overkill because of the lock cycles). Wants new
  111. * nonlocked_atomic_inc() primitives -AK
  112. */
  113. #define DEFINE_SNMP_STAT(type, name) \
  114. __typeof__(type) *name[2]
  115. #define DECLARE_SNMP_STAT(type, name) \
  116. extern __typeof__(type) *name[2]
  117. #define SNMP_STAT_BHPTR(name) (name[0])
  118. #define SNMP_STAT_USRPTR(name) (name[1])
  119. #define SNMP_INC_STATS_BH(mib, field) \
  120. (per_cpu_ptr(mib[0], raw_smp_processor_id())->mibs[field]++)
  121. #define SNMP_INC_STATS_USER(mib, field) \
  122. do { \
  123. per_cpu_ptr(mib[1], get_cpu())->mibs[field]++; \
  124. put_cpu(); \
  125. } while (0)
  126. #define SNMP_INC_STATS(mib, field) \
  127. do { \
  128. per_cpu_ptr(mib[!in_softirq()], get_cpu())->mibs[field]++; \
  129. put_cpu(); \
  130. } while (0)
  131. #define SNMP_DEC_STATS(mib, field) \
  132. do { \
  133. per_cpu_ptr(mib[!in_softirq()], get_cpu())->mibs[field]--; \
  134. put_cpu(); \
  135. } while (0)
  136. #define SNMP_ADD_STATS_BH(mib, field, addend) \
  137. (per_cpu_ptr(mib[0], raw_smp_processor_id())->mibs[field] += addend)
  138. #define SNMP_ADD_STATS_USER(mib, field, addend) \
  139. do { \
  140. per_cpu_ptr(mib[1], get_cpu())->mibs[field] += addend; \
  141. put_cpu(); \
  142. } while (0)
  143. #endif