Debian Codegraph @

agent/mibgroup/sctp-mib/sctpAssocTable.c

raw
1 /*
2 * Note: this file originally auto-generated by mib2c using
3 * mib2c -c mib2c.container.conf
4 */
5
6 #include <net-snmp/net-snmp-config.h>
7 #include <net-snmp/net-snmp-includes.h>
8 #include <net-snmp/agent/net-snmp-agent-includes.h>
9 #include <net-snmp/agent/table_container.h>
10 #include "sctpAssocTable.h"
11
12 static void _cache_free(netsnmp_cache * cache, void *magic);
13 static int _cache_load(netsnmp_cache * cache, void *vmagic);
14
15 /*
16 * content of the sctpAssocTable
17 */
18 static netsnmp_container *sctpAssocTable_container;
19 static netsnmp_table_registration_info *table_info;
20
21 /** Initializes the sctpAssocTable module */
22 void
23 init_sctpAssocTable(void)
24 {
25 /*
26 * here we initialize all the tables we're planning on supporting
27 */
28 initialize_table_sctpAssocTable();
29 }
30
31 void
32 shutdown_sctpAssocTable(void)
33 {
34 shutdown_table_sctpAssocTable();
35 }
36
37 /** Initialize the sctpAssocTable table by defining its contents and how it's structured */
38 void
39 initialize_table_sctpAssocTable(void)
40 {
41 static oid sctpAssocTable_oid[] = { 1, 3, 6, 1, 2, 1, 104, 1, 3 };
42 size_t sctpAssocTable_oid_len =
43 OID_LENGTH(sctpAssocTable_oid);
44 netsnmp_handler_registration *reg = NULL;
45 netsnmp_mib_handler *handler = NULL;
46 netsnmp_container *container = NULL;
47 netsnmp_cache *cache = NULL;
48
49 reg =
50 netsnmp_create_handler_registration("sctpAssocTable",
51 sctpAssocTable_handler,
52 sctpAssocTable_oid,
53 sctpAssocTable_oid_len,
54 HANDLER_CAN_RWRITE);
55 if (NULL == reg) {
56 snmp_log(LOG_ERR,
57 "error creating handler registration for sctpAssocTable\n");
58 goto bail;
59 }
60 /** should a set on a non-existent row create a new one? */
61 /** reg->modes |= HANDLER_CAN_NOT_CREATE; */
62
63 container = netsnmp_container_find("sctpAssocTable:table_container");
64 if (NULL == container) {
65 snmp_log(LOG_ERR, "error creating container for sctpAssocTable\n");
66 goto bail;
67 }
68 sctpAssocTable_container = container;
69
70 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
71 if (NULL == table_info) {
72 snmp_log(LOG_ERR,
73 "error allocating table registration for sctpAssocTable\n");
74 goto bail;
75 }
76 netsnmp_table_helper_add_indexes(table_info, ASN_UNSIGNED, /* index: sctpAssocId */
77 0);
78 table_info->min_column = COLUMN_SCTPASSOCREMHOSTNAME;
79 table_info->max_column = COLUMN_SCTPASSOCDISCONTINUITYTIME;
80
81 /*************************************************
82 *
83 * inject container_table helper
84 */
85 handler = netsnmp_container_table_handler_get(table_info, container,
86 TABLE_CONTAINER_KEY_NETSNMP_INDEX);
87 if (NULL == handler) {
88 snmp_log(LOG_ERR,
89 "error allocating table registration for sctpAssocTable\n");
90 goto bail;
91 }
92 if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
93 snmp_log(LOG_ERR,
94 "error injecting container_table handler for sctpAssocTable\n");
95 goto bail;
96 }
97 handler = NULL; /* reg has it, will reuse below */
98
99 /*************************************************
100 *
101 * inject cache helper
102 */
103 cache = netsnmp_cache_create(SCTP_TABLES_CACHE_TIMEOUT, /* timeout in seconds */
104 _cache_load, _cache_free,
105 sctpAssocTable_oid,
106 sctpAssocTable_oid_len);
107
108 if (NULL == cache) {
109 snmp_log(LOG_ERR, "error creating cache for sctpAssocTable\n");
110 goto bail;
111 }
112 cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET
113 | NETSNMP_CACHE_AUTO_RELOAD | NETSNMP_CACHE_PRELOAD;
114 cache->magic = container;
115
116 handler = netsnmp_cache_handler_get(cache);
117 if (NULL == handler) {
118 snmp_log(LOG_ERR,
119 "error creating cache handler for sctpAssocTable\n");
120 goto bail;
121 }
122
123 netsnmp_cache_handler_owns_cache(handler);
124
125 if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
126 snmp_log(LOG_ERR,
127 "error injecting cache handler for sctpAssocTable\n");
128 goto bail;
129 }
130 handler = NULL; /* reg has it */
131
132 /*
133 * register the table
134 */
135 if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
136 snmp_log(LOG_ERR,
137 "error registering table handler for sctpAssocTable\n");
138 reg = NULL; /* it was freed inside netsnmp_register_table */
139 goto bail;
140 }
141
142 /*
143 * Initialise the contents of the table here
144 */
145
146
147 return; /* ok */
148
149 /*
150 * Some error occurred during registration. Clean up and bail.
151 */
152 bail: /* not ok */
153
154 if (handler)
155 netsnmp_handler_free(handler);
156
157 if (cache)
158 netsnmp_cache_free(cache);
159
160 if (table_info)
161 netsnmp_table_registration_info_free(table_info);
162
163 if (container)
164 CONTAINER_FREE(container);
165
166 if (reg)
167 netsnmp_handler_registration_free(reg);
168 }
169
170 void
171 shutdown_table_sctpAssocTable(void)
172 {
173 if (table_info) {
174 netsnmp_table_registration_info_free(table_info);
175 table_info = NULL;
176 }
177 if (sctpAssocTable_container)
178 sctpAssocTable_container_clear(sctpAssocTable_container);
179 }
180
181
182 /** handles requests for the sctpAssocTable table */
183 int
184 sctpAssocTable_handler(netsnmp_mib_handler *handler,
185 netsnmp_handler_registration *reginfo,
186 netsnmp_agent_request_info *reqinfo,
187 netsnmp_request_info *requests)
188 {
189 netsnmp_request_info *request;
190 netsnmp_table_request_info *table_info;
191 sctpAssocTable_entry *table_entry;
192
193 switch (reqinfo->mode) {
194 /*
195 * Read-support (also covers GetNext requests)
196 */
197 case MODE_GET:
198 for (request = requests; request; request = request->next) {
199 if (request->processed)
200 continue;
201 table_entry = (sctpAssocTable_entry *)
202 netsnmp_container_table_extract_context(request);
203 table_info = netsnmp_extract_table_info(request);
204 if ((NULL == table_entry) || (NULL == table_info)) {
205 snmp_log(LOG_ERR,
206 "could not extract table entry or info for sctpAssocTable\n");
207 snmp_set_var_typed_value(request->requestvb,
208 SNMP_ERR_GENERR, NULL, 0);
209 continue;
210 }
211
212 switch (table_info->colnum) {
213 case COLUMN_SCTPASSOCREMHOSTNAME:
214 if (!table_entry) {
215 netsnmp_set_request_error(reqinfo, request,
216 SNMP_NOSUCHINSTANCE);
217 continue;
218 }
219 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
220 (u_char *)
221 table_entry->sctpAssocRemHostName,
222 table_entry->sctpAssocRemHostName_len);
223 break;
224 case COLUMN_SCTPASSOCLOCALPORT:
225 if (!table_entry) {
226 netsnmp_set_request_error(reqinfo, request,
227 SNMP_NOSUCHINSTANCE);
228 continue;
229 }
230 snmp_set_var_typed_integer(request->requestvb,
231 ASN_UNSIGNED,
232 table_entry->sctpAssocLocalPort);
233 break;
234 case COLUMN_SCTPASSOCREMPORT:
235 if (!table_entry) {
236 netsnmp_set_request_error(reqinfo, request,
237 SNMP_NOSUCHINSTANCE);
238 continue;
239 }
240 snmp_set_var_typed_integer(request->requestvb,
241 ASN_UNSIGNED,
242 table_entry->sctpAssocRemPort);
243 break;
244 case COLUMN_SCTPASSOCREMPRIMADDRTYPE:
245 if (!table_entry) {
246 netsnmp_set_request_error(reqinfo, request,
247 SNMP_NOSUCHINSTANCE);
248 continue;
249 }
250 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
251 table_entry->sctpAssocRemPrimAddrType);
252 break;
253 case COLUMN_SCTPASSOCREMPRIMADDR:
254 if (!table_entry) {
255 netsnmp_set_request_error(reqinfo, request,
256 SNMP_NOSUCHINSTANCE);
257 continue;
258 }
259 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
260 (u_char *)
261 table_entry->sctpAssocRemPrimAddr,
262 table_entry->sctpAssocRemPrimAddr_len);
263 break;
264 case COLUMN_SCTPASSOCHEARTBEATINTERVAL:
265 if (!table_entry) {
266 netsnmp_set_request_error(reqinfo, request,
267 SNMP_NOSUCHINSTANCE);
268 continue;
269 }
270 snmp_set_var_typed_integer(request->requestvb,
271 ASN_UNSIGNED,
272 table_entry->sctpAssocHeartBeatInterval);
273 break;
274 case COLUMN_SCTPASSOCSTATE:
275 if (!table_entry) {
276 netsnmp_set_request_error(reqinfo, request,
277 SNMP_NOSUCHINSTANCE);
278 continue;
279 }
280 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
281 table_entry->sctpAssocState);
282 break;
283 case COLUMN_SCTPASSOCINSTREAMS:
284 if (!table_entry) {
285 netsnmp_set_request_error(reqinfo, request,
286 SNMP_NOSUCHINSTANCE);
287 continue;
288 }
289 snmp_set_var_typed_integer(request->requestvb,
290 ASN_UNSIGNED,
291 table_entry->sctpAssocInStreams);
292 break;
293 case COLUMN_SCTPASSOCOUTSTREAMS:
294 if (!table_entry) {
295 netsnmp_set_request_error(reqinfo, request,
296 SNMP_NOSUCHINSTANCE);
297 continue;
298 }
299 snmp_set_var_typed_integer(request->requestvb,
300 ASN_UNSIGNED,
301 table_entry->sctpAssocOutStreams);
302 break;
303 case COLUMN_SCTPASSOCMAXRETR:
304 if (!table_entry) {
305 netsnmp_set_request_error(reqinfo, request,
306 SNMP_NOSUCHINSTANCE);
307 continue;
308 }
309 snmp_set_var_typed_integer(request->requestvb,
310 ASN_UNSIGNED,
311 table_entry->sctpAssocMaxRetr);
312 break;
313 case COLUMN_SCTPASSOCPRIMPROCESS:
314 if (!table_entry) {
315 netsnmp_set_request_error(reqinfo, request,
316 SNMP_NOSUCHINSTANCE);
317 continue;
318 }
319 snmp_set_var_typed_integer(request->requestvb,
320 ASN_UNSIGNED,
321 table_entry->sctpAssocPrimProcess);
322 break;
323 case COLUMN_SCTPASSOCT1EXPIREDS:
324 if (!table_entry) {
325 netsnmp_set_request_error(reqinfo, request,
326 SNMP_NOSUCHINSTANCE);
327 continue;
328 }
329 snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
330 table_entry->sctpAssocT1expireds);
331 break;
332 case COLUMN_SCTPASSOCT2EXPIREDS:
333 if (!table_entry) {
334 netsnmp_set_request_error(reqinfo, request,
335 SNMP_NOSUCHINSTANCE);
336 continue;
337 }
338 snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
339 table_entry->sctpAssocT2expireds);
340 break;
341 case COLUMN_SCTPASSOCRTXCHUNKS:
342 if (!table_entry) {
343 netsnmp_set_request_error(reqinfo, request,
344 SNMP_NOSUCHINSTANCE);
345 continue;
346 }
347 snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
348 table_entry->sctpAssocRtxChunks);
349 break;
350 case COLUMN_SCTPASSOCSTARTTIME:
351 if (!table_entry) {
352 netsnmp_set_request_error(reqinfo, request,
353 SNMP_NOSUCHINSTANCE);
354 continue;
355 }
356 snmp_set_var_typed_integer(request->requestvb,
357 ASN_TIMETICKS,
358 table_entry->sctpAssocStartTime);
359 break;
360 case COLUMN_SCTPASSOCDISCONTINUITYTIME:
361 if (!table_entry) {
362 netsnmp_set_request_error(reqinfo, request,
363 SNMP_NOSUCHINSTANCE);
364 continue;
365 }
366 snmp_set_var_typed_integer(request->requestvb,
367 ASN_TIMETICKS,
368 table_entry->sctpAssocDiscontinuityTime);
369 break;
370 default:
371 netsnmp_set_request_error(reqinfo, request,
372 SNMP_NOSUCHOBJECT);
373 break;
374 }
375 }
376 break;
377
378 /*
379 * Write-support
380 */
381 case MODE_SET_RESERVE1:
382 for (request = requests; request; request = request->next) {
383 if (request->processed)
384 continue;
385 netsnmp_set_request_error(reqinfo, request,
386 SNMP_ERR_NOTWRITABLE);
387 }
388 break;
389
390 case MODE_SET_RESERVE2:
391 case MODE_SET_FREE:
392 case MODE_SET_ACTION:
393 case MODE_SET_UNDO:
394 case MODE_SET_COMMIT:
395 break;
396 }
397 return SNMP_ERR_NOERROR;
398 }
399
400 /**
401 * @internal
402 */
403 static int
404 _cache_load(netsnmp_cache * cache, void *vmagic)
405 {
406 DEBUGMSGTL(("internal:sctpAssocTable:_cache_load", "called\n"));
407
408 if ((NULL == cache) || (NULL == cache->magic)) {
409 snmp_log(LOG_ERR, "invalid cache for sctpAssocTable_cache_load\n");
410 return -1;
411 }
412 /** should only be called for an invalid or expired cache */
413 netsnmp_assert((0 == cache->valid) || (1 == cache->expired));
414
415 return sctpTables_load();
416 } /* _cache_load */
417
418 /**
419 * @Internal
420 */
421 /** remove a row from the table */
422 static void
423 sctpAssocTable_freeEntry_cb(void *entry, void *magic)
424 {
425 sctpAssocTable_entry_free(entry);
426 }
427
428 /**
429 * @internal
430 */
431 static void
432 _cache_free(netsnmp_cache * cache, void *magic)
433 {
434 netsnmp_container *container;
435
436 DEBUGMSGTL(("internal:sctpAssocTable:_cache_free", "called\n"));
437
438 if ((NULL == cache) || (NULL == cache->magic)) {
439 snmp_log(LOG_ERR, "invalid cache in sctpAssocTable_cache_free\n");
440 return;
441 }
442 container = (netsnmp_container *) cache->magic;
443
444 /*
445 * empty (but don't free) cache here
446 */
447 CONTAINER_CLEAR(container, sctpAssocTable_freeEntry_cb, NULL);
448 } /* _cache_free */
449
450 sctpAssocTable_entry *
451 sctpAssocTable_entry_create(void)
452 {
453 sctpAssocTable_entry *entry =
454 SNMP_MALLOC_TYPEDEF(sctpAssocTable_entry);
455 if (entry != NULL) {
456 entry->oid_index.len = SCTP_ASSOC_TABLE_INDEX_SIZE;
457 entry->oid_index.oids = entry->oid_tmp;
458 }
459
460 return entry;
461 }
462
463 int
464 sctpAssocTable_entry_update_index(sctpAssocTable_entry * entry)
465 {
466 netsnmp_variable_list var_sctpAssocId;
467 int err = 0;
468
469 /*
470 * prepare the value to be converted
471 */
472 memset(&var_sctpAssocId, 0, sizeof(var_sctpAssocId));
473 var_sctpAssocId.type = ASN_UNSIGNED;
474 var_sctpAssocId.next_variable = NULL;
475 snmp_set_var_value(&var_sctpAssocId, (u_char *) & entry->sctpAssocId,
476 sizeof(entry->sctpAssocId));
477
478 /*
479 * convert it
480 */
481 err =
482 build_oid_noalloc(entry->oid_index.oids, entry->oid_index.len,
483 &entry->oid_index.len, NULL, 0,
484 &var_sctpAssocId);
485 if (err)
486 snmp_log(LOG_ERR, "error %d converting index to oid\n", err);
487
488 /*
489 * release any memory allocated during the conversion
490 */
491 snmp_reset_var_buffers(&var_sctpAssocId);
492
493 return err;
494 }
495
496 void
497 sctpAssocTable_entry_copy(sctpAssocTable_entry * from,
498 sctpAssocTable_entry * to)
499 {
500 memcpy(to, from, sizeof(sctpAssocTable_entry));
501 to->oid_index.oids = to->oid_tmp;
502 }
503
504
505 void
506 sctpAssocTable_entry_free(sctpAssocTable_entry * entry)
507 {
508 SNMP_FREE(entry);
509 }
510
511 netsnmp_container *
512 sctpAssocTable_get_container(void)
513 {
514 return sctpAssocTable_container;
515 }
516
517 static void
518 sctpAssocTable_entry_clear(void *what, void *magic)
519 {
520 sctpAssocTable_entry_free(what);
521 }
522
523 void
524 sctpAssocTable_container_clear(netsnmp_container *container)
525 {
526 CONTAINER_CLEAR(container, sctpAssocTable_entry_clear, NULL);
527 }