snmp_agent.txt 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. SNMPv1 agent for lwIP
  2. Author: Christiaan Simons
  3. This is a brief introduction how to use and configure the SNMP agent.
  4. Note the agent uses the raw-API UDP interface so you may also want to
  5. read rawapi.txt to gain a better understanding of the SNMP message handling.
  6. 0 Agent Capabilities
  7. ====================
  8. SNMPv1 per RFC1157
  9. This is an old(er) standard but is still widely supported.
  10. For SNMPv2c and v3 have a greater complexity and need many
  11. more lines of code. IMHO this breaks the idea of "lightweight IP".
  12. Note the S in SNMP stands for "Simple". Note that "Simple" is
  13. relative. SNMP is simple compared to the complex ISO network
  14. management protocols CMIP (Common Management Information Protocol)
  15. and CMOT (CMip Over Tcp).
  16. MIB II per RFC1213
  17. The standard lwIP stack management information base.
  18. This is a required MIB, so this is always enabled.
  19. When builing lwIP without TCP, the mib-2.tcp group is omitted.
  20. The groups EGP, CMOT and transmission are disabled by default.
  21. Most mib-2 objects are not writable except:
  22. sysName, sysLocation, sysContact, snmpEnableAuthenTraps.
  23. Writing to or changing the ARP and IP address and route
  24. tables is not possible.
  25. Note lwIP has a very limited notion of IP routing. It currently
  26. doen't have a route table and doesn't have a notion of the U,G,H flags.
  27. Instead lwIP uses the interface list with only one default interface
  28. acting as a single gateway interface (G) for the default route.
  29. The agent returns a "virtual table" with the default route 0.0.0.0
  30. for the default interface and network routes (no H) for each
  31. network interface in the netif_list.
  32. All routes are considered to be up (U).
  33. Loading additional MIBs
  34. MIBs can only be added in compile-time, not in run-time.
  35. There is no MIB compiler thus additional MIBs must be hand coded.
  36. Large SNMP message support
  37. The packet decoding and encoding routines are designed
  38. to use pbuf-chains. Larger payloads than the minimum
  39. SNMP requirement of 484 octets are supported if the
  40. PBUF_POOL_SIZE and IP_REASS_BUFSIZE are set to match your
  41. local requirement.
  42. 1 Building the Agent
  43. ====================
  44. First of all you'll need to add the following define
  45. to your local lwipopts.h:
  46. #define LWIP_SNMP 1
  47. and add the source files in lwip/src/core/snmp
  48. and some snmp headers in lwip/src/include/lwip to your makefile.
  49. Note you'll might need to adapt you network driver to update
  50. the mib2 variables for your interface.
  51. 2 Running the Agent
  52. ===================
  53. The following function calls must be made in your program to
  54. actually get the SNMP agent running.
  55. Before starting the agent you should supply pointers
  56. to non-volatile memory for sysContact, sysLocation,
  57. and snmpEnableAuthenTraps. You can do this by calling
  58. snmp_set_syscontact()
  59. snmp_set_syslocation()
  60. snmp_set_snmpenableauthentraps()
  61. Additionally you may want to set
  62. snmp_set_sysdescr()
  63. snmp_set_sysobjid() (if you have a private MIB)
  64. snmp_set_sysname()
  65. Also before starting the agent you need to setup
  66. one or more trap destinations using these calls:
  67. snmp_trap_dst_enable();
  68. snmp_trap_dst_ip_set();
  69. In the lwIP initialisation sequence call snmp_init() just after
  70. the call to udp_init().
  71. Exactly every 10 msec the SNMP uptime timestamp must be updated with
  72. snmp_inc_sysuptime(). You should call this from a timer interrupt
  73. or a timer signal handler depending on your runtime environment.
  74. An alternative way to update the SNMP uptime timestamp is to do a call like
  75. snmp_add_sysuptime(100) each 1000ms (which is bigger "step", but call to
  76. a lower frequency). Another one is to not call snmp_inc_sysuptime() or
  77. snmp_add_sysuptime(), and to define the SNMP_GET_SYSUPTIME(sysuptime) macro.
  78. This one is undefined by default in mib2.c. SNMP_GET_SYSUPTIME is called inside
  79. snmp_get_sysuptime(u32_t *value), and enable to change "sysuptime" value only
  80. when it's queried (any function which need "sysuptime" have to call
  81. snmp_get_sysuptime).
  82. 3 Private MIBs
  83. ==============
  84. If want to extend the agent with your own private MIB you'll need to
  85. add the following define to your local lwipopts.h:
  86. #define SNMP_PRIVATE_MIB 1
  87. You must provide the private_mib.h and associated files yourself.
  88. Note we don't have a "MIB compiler" that generates C source from a MIB,
  89. so you're required to do some serious coding if you enable this!
  90. Note the lwIP enterprise ID (26381) is assigned to the lwIP project,
  91. ALL OBJECT IDENTIFIERS LIVING UNDER THIS ID ARE ASSIGNED BY THE lwIP
  92. MAINTAINERS!
  93. If you need to create your own private MIB you'll need
  94. to apply for your own enterprise ID with IANA: http://www.iana.org/numbers.html
  95. You can set it by passing a struct snmp_obj_id to the agent
  96. using snmp_set_sysobjid(&my_object_id), just before snmp_init().
  97. Note the object identifiers for thes MIB-2 and your private MIB
  98. tree must be kept in sorted ascending (lexicographical) order.
  99. This to ensure correct getnext operation.
  100. An example for a private MIB is part of the "minimal Unix" project:
  101. contrib/ports/unix/proj/minimal/lwip_prvmib.c
  102. The next chapter gives a more detailed description of the
  103. MIB-2 tree and the optional private MIB.
  104. 4 The Gory Details
  105. ==================
  106. 4.0 Object identifiers and the MIB tree.
  107. We have three distinct parts for all object identifiers:
  108. The prefix
  109. .iso.org.dod.internet
  110. the middle part
  111. .mgmt.mib-2.ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaPhysAddress
  112. and the index part
  113. .1.192.168.0.1
  114. Objects located above the .internet hierarchy aren't supported.
  115. Currently only the .mgmt sub-tree is available and
  116. when the SNMP_PRIVATE_MIB is enabled the .private tree
  117. becomes available too.
  118. Object identifiers from incoming requests are checked
  119. for a matching prefix, middle part and index part
  120. or are expanded(*) for GetNext requests with short
  121. or inexisting names in the request.
  122. (* we call this "expansion" but this also
  123. resembles the "auto-completion" operation)
  124. The middle part is usually located in ROM (const)
  125. to preserve precious RAM on small microcontrollers.
  126. However RAM location is possible for a dynamically
  127. changing private tree.
  128. The index part is handled by functions which in
  129. turn use dynamically allocated index trees from RAM.
  130. These trees are updated by e.g. the etharp code
  131. when new entries are made or removed form the ARP cache.
  132. /** @todo more gory details */