]>
Commit | Line | Data |
---|---|---|
6e6d4a8b JP |
1 | /** |
2 | * @file | |
3 | * SNMP Agent message handling structures. | |
4 | */ | |
5 | ||
6 | /* | |
7 | * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands. | |
8 | * All rights reserved. | |
9 | * | |
10 | * Redistribution and use in source and binary forms, with or without modification, | |
11 | * are permitted provided that the following conditions are met: | |
12 | * | |
13 | * 1. Redistributions of source code must retain the above copyright notice, | |
14 | * this list of conditions and the following disclaimer. | |
15 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
16 | * this list of conditions and the following disclaimer in the documentation | |
17 | * and/or other materials provided with the distribution. | |
18 | * 3. The name of the author may not be used to endorse or promote products | |
19 | * derived from this software without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | |
24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT | |
26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
30 | * OF SUCH DAMAGE. | |
31 | * | |
32 | * Author: Christiaan Simons <christiaan.simons@axon.tv> | |
33 | */ | |
34 | ||
35 | #ifndef __LWIP_SNMP_MSG_H__ | |
36 | #define __LWIP_SNMP_MSG_H__ | |
37 | ||
38 | #include "lwip/opt.h" | |
39 | #include "lwip/snmp.h" | |
40 | #include "lwip/snmp_structs.h" | |
41 | ||
42 | #if SNMP_PRIVATE_MIB | |
43 | #include "private_mib.h" | |
44 | #endif | |
45 | ||
46 | #ifdef __cplusplus | |
47 | extern "C" { | |
48 | #endif | |
49 | ||
50 | /* The listen port of the SNMP agent. Clients have to make their requests to | |
51 | this port. Most standard clients won't work if you change this! */ | |
52 | #ifndef SNMP_IN_PORT | |
53 | #define SNMP_IN_PORT 161 | |
54 | #endif | |
55 | /* The remote port the SNMP agent sends traps to. Most standard trap sinks won't | |
56 | work if you change this! */ | |
57 | #ifndef SNMP_TRAP_PORT | |
58 | #define SNMP_TRAP_PORT 162 | |
59 | #endif | |
60 | ||
61 | #define SNMP_ES_NOERROR 0 | |
62 | #define SNMP_ES_TOOBIG 1 | |
63 | #define SNMP_ES_NOSUCHNAME 2 | |
64 | #define SNMP_ES_BADVALUE 3 | |
65 | #define SNMP_ES_READONLY 4 | |
66 | #define SNMP_ES_GENERROR 5 | |
67 | ||
68 | #define SNMP_GENTRAP_COLDSTART 0 | |
69 | #define SNMP_GENTRAP_WARMSTART 1 | |
70 | #define SNMP_GENTRAP_AUTHFAIL 4 | |
71 | #define SNMP_GENTRAP_ENTERPRISESPC 6 | |
72 | ||
73 | struct snmp_varbind | |
74 | { | |
75 | /* next pointer, NULL for last in list */ | |
76 | struct snmp_varbind *next; | |
77 | /* previous pointer, NULL for first in list */ | |
78 | struct snmp_varbind *prev; | |
79 | ||
80 | /* object identifier length (in s32_t) */ | |
81 | u8_t ident_len; | |
82 | /* object identifier array */ | |
83 | s32_t *ident; | |
84 | ||
85 | /* object value ASN1 type */ | |
86 | u8_t value_type; | |
87 | /* object value length (in u8_t) */ | |
88 | u8_t value_len; | |
89 | /* object value */ | |
90 | void *value; | |
91 | ||
92 | /* encoding varbind seq length length */ | |
93 | u8_t seqlenlen; | |
94 | /* encoding object identifier length length */ | |
95 | u8_t olenlen; | |
96 | /* encoding object value length length */ | |
97 | u8_t vlenlen; | |
98 | /* encoding varbind seq length */ | |
99 | u16_t seqlen; | |
100 | /* encoding object identifier length */ | |
101 | u16_t olen; | |
102 | /* encoding object value length */ | |
103 | u16_t vlen; | |
104 | }; | |
105 | ||
106 | struct snmp_varbind_root | |
107 | { | |
108 | struct snmp_varbind *head; | |
109 | struct snmp_varbind *tail; | |
110 | /* number of variable bindings in list */ | |
111 | u8_t count; | |
112 | /* encoding varbind-list seq length length */ | |
113 | u8_t seqlenlen; | |
114 | /* encoding varbind-list seq length */ | |
115 | u16_t seqlen; | |
116 | }; | |
117 | ||
118 | /** output response message header length fields */ | |
119 | struct snmp_resp_header_lengths | |
120 | { | |
121 | /* encoding error-index length length */ | |
122 | u8_t erridxlenlen; | |
123 | /* encoding error-status length length */ | |
124 | u8_t errstatlenlen; | |
125 | /* encoding request id length length */ | |
126 | u8_t ridlenlen; | |
127 | /* encoding pdu length length */ | |
128 | u8_t pdulenlen; | |
129 | /* encoding community length length */ | |
130 | u8_t comlenlen; | |
131 | /* encoding version length length */ | |
132 | u8_t verlenlen; | |
133 | /* encoding sequence length length */ | |
134 | u8_t seqlenlen; | |
135 | ||
136 | /* encoding error-index length */ | |
137 | u16_t erridxlen; | |
138 | /* encoding error-status length */ | |
139 | u16_t errstatlen; | |
140 | /* encoding request id length */ | |
141 | u16_t ridlen; | |
142 | /* encoding pdu length */ | |
143 | u16_t pdulen; | |
144 | /* encoding community length */ | |
145 | u16_t comlen; | |
146 | /* encoding version length */ | |
147 | u16_t verlen; | |
148 | /* encoding sequence length */ | |
149 | u16_t seqlen; | |
150 | }; | |
151 | ||
152 | /** output response message header length fields */ | |
153 | struct snmp_trap_header_lengths | |
154 | { | |
155 | /* encoding timestamp length length */ | |
156 | u8_t tslenlen; | |
157 | /* encoding specific-trap length length */ | |
158 | u8_t strplenlen; | |
159 | /* encoding generic-trap length length */ | |
160 | u8_t gtrplenlen; | |
161 | /* encoding agent-addr length length */ | |
162 | u8_t aaddrlenlen; | |
163 | /* encoding enterprise-id length length */ | |
164 | u8_t eidlenlen; | |
165 | /* encoding pdu length length */ | |
166 | u8_t pdulenlen; | |
167 | /* encoding community length length */ | |
168 | u8_t comlenlen; | |
169 | /* encoding version length length */ | |
170 | u8_t verlenlen; | |
171 | /* encoding sequence length length */ | |
172 | u8_t seqlenlen; | |
173 | ||
174 | /* encoding timestamp length */ | |
175 | u16_t tslen; | |
176 | /* encoding specific-trap length */ | |
177 | u16_t strplen; | |
178 | /* encoding generic-trap length */ | |
179 | u16_t gtrplen; | |
180 | /* encoding agent-addr length */ | |
181 | u16_t aaddrlen; | |
182 | /* encoding enterprise-id length */ | |
183 | u16_t eidlen; | |
184 | /* encoding pdu length */ | |
185 | u16_t pdulen; | |
186 | /* encoding community length */ | |
187 | u16_t comlen; | |
188 | /* encoding version length */ | |
189 | u16_t verlen; | |
190 | /* encoding sequence length */ | |
191 | u16_t seqlen; | |
192 | }; | |
193 | ||
194 | /* Accepting new SNMP messages. */ | |
195 | #define SNMP_MSG_EMPTY 0 | |
196 | /* Search for matching object for variable binding. */ | |
197 | #define SNMP_MSG_SEARCH_OBJ 1 | |
198 | /* Perform SNMP operation on in-memory object. | |
199 | Pass-through states, for symmetry only. */ | |
200 | #define SNMP_MSG_INTERNAL_GET_OBJDEF 2 | |
201 | #define SNMP_MSG_INTERNAL_GET_VALUE 3 | |
202 | #define SNMP_MSG_INTERNAL_SET_TEST 4 | |
203 | #define SNMP_MSG_INTERNAL_GET_OBJDEF_S 5 | |
204 | #define SNMP_MSG_INTERNAL_SET_VALUE 6 | |
205 | /* Perform SNMP operation on object located externally. | |
206 | In theory this could be used for building a proxy agent. | |
207 | Practical use is for an enterprise spc. app. gateway. */ | |
208 | #define SNMP_MSG_EXTERNAL_GET_OBJDEF 7 | |
209 | #define SNMP_MSG_EXTERNAL_GET_VALUE 8 | |
210 | #define SNMP_MSG_EXTERNAL_SET_TEST 9 | |
211 | #define SNMP_MSG_EXTERNAL_GET_OBJDEF_S 10 | |
212 | #define SNMP_MSG_EXTERNAL_SET_VALUE 11 | |
213 | ||
214 | #define SNMP_COMMUNITY_STR_LEN 64 | |
215 | struct snmp_msg_pstat | |
216 | { | |
217 | /* lwIP local port (161) binding */ | |
218 | struct udp_pcb *pcb; | |
219 | /* source IP address */ | |
220 | struct ip_addr sip; | |
221 | /* source UDP port */ | |
222 | u16_t sp; | |
223 | /* request type */ | |
224 | u8_t rt; | |
225 | /* request ID */ | |
226 | s32_t rid; | |
227 | /* error status */ | |
228 | s32_t error_status; | |
229 | /* error index */ | |
230 | s32_t error_index; | |
231 | /* community name (zero terminated) */ | |
232 | u8_t community[SNMP_COMMUNITY_STR_LEN + 1]; | |
233 | /* community string length (exclusive zero term) */ | |
234 | u8_t com_strlen; | |
235 | /* one out of MSG_EMPTY, MSG_DEMUX, MSG_INTERNAL, MSG_EXTERNAL_x */ | |
236 | u8_t state; | |
237 | /* saved arguments for MSG_EXTERNAL_x */ | |
238 | struct mib_external_node *ext_mib_node; | |
239 | struct snmp_name_ptr ext_name_ptr; | |
240 | struct obj_def ext_object_def; | |
241 | struct snmp_obj_id ext_oid; | |
242 | /* index into input variable binding list */ | |
243 | u8_t vb_idx; | |
244 | /* ptr into input variable binding list */ | |
245 | struct snmp_varbind *vb_ptr; | |
246 | /* list of variable bindings from input */ | |
247 | struct snmp_varbind_root invb; | |
248 | /* list of variable bindings to output */ | |
249 | struct snmp_varbind_root outvb; | |
250 | /* output response lengths used in ASN encoding */ | |
251 | struct snmp_resp_header_lengths rhl; | |
252 | }; | |
253 | ||
254 | struct snmp_msg_trap | |
255 | { | |
256 | /* lwIP local port (161) binding */ | |
257 | struct udp_pcb *pcb; | |
258 | /* destination IP address in network order */ | |
259 | struct ip_addr dip; | |
260 | ||
261 | /* source enterprise ID (sysObjectID) */ | |
262 | struct snmp_obj_id *enterprise; | |
263 | /* source IP address, raw network order format */ | |
264 | u8_t sip_raw[4]; | |
265 | /* generic trap code */ | |
266 | u32_t gen_trap; | |
267 | /* specific trap code */ | |
268 | u32_t spc_trap; | |
269 | /* timestamp */ | |
270 | u32_t ts; | |
271 | /* list of variable bindings to output */ | |
272 | struct snmp_varbind_root outvb; | |
273 | /* output trap lengths used in ASN encoding */ | |
274 | struct snmp_trap_header_lengths thl; | |
275 | }; | |
276 | ||
277 | /** Agent Version constant, 0 = v1 oddity */ | |
278 | extern const s32_t snmp_version; | |
279 | /** Agent default "public" community string */ | |
280 | extern const char snmp_publiccommunity[7]; | |
281 | ||
282 | extern struct snmp_msg_trap trap_msg; | |
283 | ||
284 | /** Agent setup, start listening to port 161. */ | |
285 | void snmp_init(void); | |
286 | void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable); | |
287 | void snmp_trap_dst_ip_set(u8_t dst_idx, struct ip_addr *dst); | |
288 | ||
289 | /** Varbind-list functions. */ | |
290 | struct snmp_varbind* snmp_varbind_alloc(struct snmp_obj_id *oid, u8_t type, u8_t len); | |
291 | void snmp_varbind_free(struct snmp_varbind *vb); | |
292 | void snmp_varbind_list_free(struct snmp_varbind_root *root); | |
293 | void snmp_varbind_tail_add(struct snmp_varbind_root *root, struct snmp_varbind *vb); | |
294 | struct snmp_varbind* snmp_varbind_tail_remove(struct snmp_varbind_root *root); | |
295 | ||
296 | /** Handle an internal (recv) or external (private response) event. */ | |
297 | void snmp_msg_event(u8_t request_id); | |
298 | err_t snmp_send_response(struct snmp_msg_pstat *m_stat); | |
299 | err_t snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap); | |
300 | void snmp_coldstart_trap(void); | |
301 | void snmp_authfail_trap(void); | |
302 | ||
303 | #ifdef __cplusplus | |
304 | } | |
305 | #endif | |
306 | ||
307 | #endif /* __LWIP_SNMP_MSG_H__ */ |