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