snmp.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.1.1.1 2007/06/12 07:27:16 eyryu 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. /* ICMP6 (IPv6-ICMP) */
  74. #define ICMP6_MIB_MAX __ICMP6_MIB_MAX
  75. struct icmpv6_mib {
  76. unsigned long mibs[ICMP6_MIB_MAX];
  77. } __SNMP_MIB_ALIGN__;
  78. /* TCP */
  79. #define TCP_MIB_MAX __TCP_MIB_MAX
  80. struct tcp_mib {
  81. unsigned long mibs[TCP_MIB_MAX];
  82. } __SNMP_MIB_ALIGN__;
  83. /* UDP */
  84. #define UDP_MIB_MAX __UDP_MIB_MAX
  85. struct udp_mib {
  86. unsigned long mibs[UDP_MIB_MAX];
  87. } __SNMP_MIB_ALIGN__;
  88. /* Linux */
  89. #define LINUX_MIB_MAX __LINUX_MIB_MAX
  90. struct linux_mib {
  91. unsigned long mibs[LINUX_MIB_MAX];
  92. };
  93. /*
  94. * FIXME: On x86 and some other CPUs the split into user and softirq parts
  95. * is not needed because addl $1,memory is atomic against interrupts (but
  96. * atomic_inc would be overkill because of the lock cycles). Wants new
  97. * nonlocked_atomic_inc() primitives -AK
  98. */
  99. #define DEFINE_SNMP_STAT(type, name) \
  100. __typeof__(type) *name[2]
  101. #define DECLARE_SNMP_STAT(type, name) \
  102. extern __typeof__(type) *name[2]
  103. #define SNMP_STAT_BHPTR(name) (name[0])
  104. #define SNMP_STAT_USRPTR(name) (name[1])
  105. #define SNMP_INC_STATS_BH(mib, field) \
  106. (per_cpu_ptr(mib[0], raw_smp_processor_id())->mibs[field]++)
  107. #define SNMP_INC_STATS_OFFSET_BH(mib, field, offset) \
  108. (per_cpu_ptr(mib[0], raw_smp_processor_id())->mibs[field + (offset)]++)
  109. #define SNMP_INC_STATS_USER(mib, field) \
  110. (per_cpu_ptr(mib[1], raw_smp_processor_id())->mibs[field]++)
  111. #define SNMP_INC_STATS(mib, field) \
  112. (per_cpu_ptr(mib[!in_softirq()], raw_smp_processor_id())->mibs[field]++)
  113. #define SNMP_DEC_STATS(mib, field) \
  114. (per_cpu_ptr(mib[!in_softirq()], raw_smp_processor_id())->mibs[field]--)
  115. #define SNMP_ADD_STATS_BH(mib, field, addend) \
  116. (per_cpu_ptr(mib[0], raw_smp_processor_id())->mibs[field] += addend)
  117. #define SNMP_ADD_STATS_USER(mib, field, addend) \
  118. (per_cpu_ptr(mib[1], raw_smp_processor_id())->mibs[field] += addend)
  119. #endif