snmp.h 4.2 KB

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