1 /*
2 * Note: this file originally auto-generated by mib2c using
3 * version : 15899 $ of $
4 *
5 * $Id:$
6 */
7 /*
8 * *********************************************************************
9 * *********************************************************************
10 * *********************************************************************
11 * *** ***
12 * *** NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE ***
13 * *** ***
14 * *** ***
15 * *** THIS FILE DOES NOT CONTAIN ANY USER EDITABLE CODE. ***
16 * *** ***
17 * *** ***
18 * *** THE GENERATED CODE IS INTERNAL IMPLEMENTATION, AND ***
19 * *** ***
20 * *** ***
21 * *** IS SUBJECT TO CHANGE WITHOUT WARNING IN FUTURE RELEASES. ***
22 * *** ***
23 * *** ***
24 * *********************************************************************
25 * *********************************************************************
26 * *********************************************************************
27 */
28
29 /*
30 * standard Net-SNMP includes
31 */
32 #include <net-snmp/net-snmp-config.h>
33 #include <net-snmp/net-snmp-features.h>
34 #include <net-snmp/net-snmp-includes.h>
35 #include <net-snmp/agent/net-snmp-agent-includes.h>
36
37 /*
38 * include our parent header
39 */
40 #include "ipDefaultRouterTable.h"
41
42
43 #include <net-snmp/agent/table_container.h>
44 #include <net-snmp/library/container.h>
45
46 #include "ipDefaultRouterTable_interface.h"
47
48 #include <ctype.h>
49
50 netsnmp_feature_require(row_merge);
51 netsnmp_feature_require(baby_steps);
52 netsnmp_feature_require(check_all_requests_error);
53
54 /**********************************************************************
55 **********************************************************************
56 ***
57 *** Table ipDefaultRouterTable
58 ***
59 **********************************************************************
60 **********************************************************************/
61 /*
62 * IP-MIB::ipDefaultRouterTable is subid 37 of ip.
63 * Its status is Current.
64 * OID: .1.3.6.1.2.1.4.37, length: 8
65 */
66 typedef struct ipDefaultRouterTable_interface_ctx_s {
67
68 netsnmp_container *container;
69 netsnmp_cache *cache;
70
71 ipDefaultRouterTable_registration *user_ctx;
72
73 netsnmp_table_registration_info tbl_info;
74
75 netsnmp_baby_steps_access_methods access_multiplexer;
76
77 } ipDefaultRouterTable_interface_ctx;
78
79 static ipDefaultRouterTable_interface_ctx ipDefaultRouterTable_if_ctx;
80
81 static void
82 _ipDefaultRouterTable_container_init(ipDefaultRouterTable_interface_ctx *
83 if_ctx);
84 static void
85 _ipDefaultRouterTable_container_shutdown(ipDefaultRouterTable_interface_ctx
86 * if_ctx);
87
88
89 netsnmp_container *
ipDefaultRouterTable_container_get(void)90 ipDefaultRouterTable_container_get(void)
91 {
92 return ipDefaultRouterTable_if_ctx.container;
93 }
94
95 ipDefaultRouterTable_registration *
ipDefaultRouterTable_registration_get(void)96 ipDefaultRouterTable_registration_get(void)
97 {
98 return ipDefaultRouterTable_if_ctx.user_ctx;
99 }
100
101 ipDefaultRouterTable_registration *
ipDefaultRouterTable_registration_set(ipDefaultRouterTable_registration * newreg)102 ipDefaultRouterTable_registration_set(ipDefaultRouterTable_registration *
103 newreg)
104 {
105 ipDefaultRouterTable_registration *old =
106 ipDefaultRouterTable_if_ctx.user_ctx;
107 ipDefaultRouterTable_if_ctx.user_ctx = newreg;
108 return old;
109 }
110
111 int
ipDefaultRouterTable_container_size(void)112 ipDefaultRouterTable_container_size(void)
113 {
114 return CONTAINER_SIZE(ipDefaultRouterTable_if_ctx.container);
115 }
116
117 /*
118 * mfd multiplexer modes
119 */
120 static Netsnmp_Node_Handler _mfd_ipDefaultRouterTable_pre_request;
121 static Netsnmp_Node_Handler _mfd_ipDefaultRouterTable_post_request;
122 static Netsnmp_Node_Handler _mfd_ipDefaultRouterTable_object_lookup;
123 static Netsnmp_Node_Handler _mfd_ipDefaultRouterTable_get_values;
124 /**
125 * @internal
126 * Initialize the table ipDefaultRouterTable
127 * (Define its contents and how it's structured)
128 */
129 void
_ipDefaultRouterTable_initialize_interface(ipDefaultRouterTable_registration * reg_ptr,u_long flags)130 _ipDefaultRouterTable_initialize_interface
131 (ipDefaultRouterTable_registration * reg_ptr, u_long flags)
132 {
133 netsnmp_baby_steps_access_methods *access_multiplexer =
134 &ipDefaultRouterTable_if_ctx.access_multiplexer;
135 netsnmp_table_registration_info *tbl_info =
136 &ipDefaultRouterTable_if_ctx.tbl_info;
137 netsnmp_handler_registration *reginfo;
138 netsnmp_mib_handler *handler;
139 int mfd_modes = 0;
140
141 DEBUGMSGTL(("internal:ipDefaultRouterTable:_ipDefaultRouterTable_initialize_interface", "called\n"));
142
143
144 /*************************************************
145 *
146 * save interface context for ipDefaultRouterTable
147 */
148 /*
149 * Setting up the table's definition
150 */
151 netsnmp_table_helper_add_indexes(tbl_info, ASN_INTEGER,
152 /** index: ipDefaultRouterAddressType */
153 ASN_OCTET_STR,
154 /** index: ipDefaultRouterAddress */
155 ASN_INTEGER,
156 /** index: ipDefaultRouterIfIndex */
157 0);
158
159 /*
160 * Define the minimum and maximum accessible columns. This
161 * optimizes retrieval.
162 */
163 tbl_info->min_column = IPDEFAULTROUTERTABLE_MIN_COL;
164 tbl_info->max_column = IPDEFAULTROUTERTABLE_MAX_COL;
165
166 /*
167 * save users context
168 */
169 ipDefaultRouterTable_if_ctx.user_ctx = reg_ptr;
170
171 /*
172 * call data access initialization code
173 */
174 ipDefaultRouterTable_init_data(reg_ptr);
175
176 /*
177 * set up the container
178 */
179 _ipDefaultRouterTable_container_init(&ipDefaultRouterTable_if_ctx);
180 if (NULL == ipDefaultRouterTable_if_ctx.container) {
181 snmp_log(LOG_ERR,
182 "could not initialize container for ipDefaultRouterTable\n");
183 return;
184 }
185
186 /*
187 * access_multiplexer: REQUIRED wrapper for get request handling
188 */
189 access_multiplexer->object_lookup =
190 _mfd_ipDefaultRouterTable_object_lookup;
191 access_multiplexer->get_values = _mfd_ipDefaultRouterTable_get_values;
192
193 /*
194 * no wrappers yet
195 */
196 access_multiplexer->pre_request =
197 _mfd_ipDefaultRouterTable_pre_request;
198 access_multiplexer->post_request =
199 _mfd_ipDefaultRouterTable_post_request;
200
201
202 /*************************************************
203 *
204 * Create a registration, save our reg data, register table.
205 */
206 DEBUGMSGTL(("ipDefaultRouterTable:init_ipDefaultRouterTable",
207 "Registering ipDefaultRouterTable as a mibs-for-dummies table.\n"));
208 handler =
209 netsnmp_baby_steps_access_multiplexer_get(access_multiplexer);
210 reginfo =
211 netsnmp_handler_registration_create("ipDefaultRouterTable",
212 handler,
213 ipDefaultRouterTable_oid,
214 ipDefaultRouterTable_oid_size,
215 HANDLER_CAN_BABY_STEP |
216 HANDLER_CAN_RONLY);
217 if (NULL == reginfo) {
218 snmp_log(LOG_ERR,
219 "error registering table ipDefaultRouterTable\n");
220 return;
221 }
222 reginfo->my_reg_void = &ipDefaultRouterTable_if_ctx;
223
224 /*************************************************
225 *
226 * set up baby steps handler, create it and inject it
227 */
228 if (access_multiplexer->object_lookup)
229 mfd_modes |= BABY_STEP_OBJECT_LOOKUP;
230 if (access_multiplexer->pre_request)
231 mfd_modes |= BABY_STEP_PRE_REQUEST;
232 if (access_multiplexer->post_request)
233 mfd_modes |= BABY_STEP_POST_REQUEST;
234
235 #if !(defined(NETSNMP_NO_WRITE_SUPPORT) || defined(NETSNMP_DISABLE_SET_SUPPORT))
236 /* XXX - are these actually necessary? */
237 if (access_multiplexer->set_values)
238 mfd_modes |= BABY_STEP_SET_VALUES;
239 if (access_multiplexer->irreversible_commit)
240 mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT;
241 if (access_multiplexer->object_syntax_checks)
242 mfd_modes |= BABY_STEP_CHECK_OBJECT;
243
244 if (access_multiplexer->undo_setup)
245 mfd_modes |= BABY_STEP_UNDO_SETUP;
246 if (access_multiplexer->undo_cleanup)
247 mfd_modes |= BABY_STEP_UNDO_CLEANUP;
248 if (access_multiplexer->undo_sets)
249 mfd_modes |= BABY_STEP_UNDO_SETS;
250
251 if (access_multiplexer->row_creation)
252 mfd_modes |= BABY_STEP_ROW_CREATE;
253 if (access_multiplexer->consistency_checks)
254 mfd_modes |= BABY_STEP_CHECK_CONSISTENCY;
255 if (access_multiplexer->commit)
256 mfd_modes |= BABY_STEP_COMMIT;
257 if (access_multiplexer->undo_commit)
258 mfd_modes |= BABY_STEP_UNDO_COMMIT;
259 #endif /* NETSNMP_NO_WRITE_SUPPORT || NETSNMP_DISABLE_SET_SUPPORT */
260
261 handler = netsnmp_baby_steps_handler_get(mfd_modes);
262 netsnmp_inject_handler(reginfo, handler);
263
264 /*************************************************
265 *
266 * inject row_merge helper with prefix rootoid_len + 2 (entry.col)
267 */
268 handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2);
269 netsnmp_inject_handler(reginfo, handler);
270
271 /*************************************************
272 *
273 * inject container_table helper
274 */
275 handler =
276 netsnmp_container_table_handler_get(tbl_info,
277 ipDefaultRouterTable_if_ctx.
278 container,
279 TABLE_CONTAINER_KEY_NETSNMP_INDEX);
280 netsnmp_inject_handler(reginfo, handler);
281
282 /*************************************************
283 *
284 * inject cache helper
285 */
286 if (NULL != ipDefaultRouterTable_if_ctx.cache) {
287 handler =
288 netsnmp_cache_handler_get(ipDefaultRouterTable_if_ctx.cache);
289 netsnmp_inject_handler(reginfo, handler);
290 }
291
292 /*
293 * register table
294 */
295 netsnmp_register_table(reginfo, tbl_info);
296
297 } /* _ipDefaultRouterTable_initialize_interface */
298
299 /**
300 * @internal
301 * Shutdown the table ipDefaultRouterTable
302 */
303 void
_ipDefaultRouterTable_shutdown_interface(ipDefaultRouterTable_registration * reg_ptr)304 _ipDefaultRouterTable_shutdown_interface(ipDefaultRouterTable_registration
305 * reg_ptr)
306 {
307 /*
308 * shutdown the container
309 */
310 _ipDefaultRouterTable_container_shutdown(&ipDefaultRouterTable_if_ctx);
311 }
312
313 void
ipDefaultRouterTable_valid_columns_set(netsnmp_column_info * vc)314 ipDefaultRouterTable_valid_columns_set(netsnmp_column_info *vc)
315 {
316 ipDefaultRouterTable_if_ctx.tbl_info.valid_columns = vc;
317 } /* ipDefaultRouterTable_valid_columns_set */
318
319 /**
320 * @internal
321 * convert the index component stored in the context to an oid
322 */
323 int
ipDefaultRouterTable_index_to_oid(netsnmp_index * oid_idx,ipDefaultRouterTable_mib_index * mib_idx)324 ipDefaultRouterTable_index_to_oid(netsnmp_index * oid_idx,
325 ipDefaultRouterTable_mib_index * mib_idx)
326 {
327 int err = SNMP_ERR_NOERROR;
328
329 /*
330 * temp storage for parsing indexes
331 */
332 /*
333 * ipDefaultRouterAddressType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h
334 */
335 netsnmp_variable_list var_ipDefaultRouterAddressType;
336 /*
337 * ipDefaultRouterAddress(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h
338 */
339 netsnmp_variable_list var_ipDefaultRouterAddress;
340 /*
341 * ipDefaultRouterIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H
342 */
343 netsnmp_variable_list var_ipDefaultRouterIfIndex;
344
345 /*
346 * set up varbinds
347 */
348 memset(&var_ipDefaultRouterAddressType, 0x00,
349 sizeof(var_ipDefaultRouterAddressType));
350 var_ipDefaultRouterAddressType.type = ASN_INTEGER;
351 memset(&var_ipDefaultRouterAddress, 0x00,
352 sizeof(var_ipDefaultRouterAddress));
353 var_ipDefaultRouterAddress.type = ASN_OCTET_STR;
354 memset(&var_ipDefaultRouterIfIndex, 0x00,
355 sizeof(var_ipDefaultRouterIfIndex));
356 var_ipDefaultRouterIfIndex.type = ASN_INTEGER;
357
358 /*
359 * chain temp index varbinds together
360 */
361 var_ipDefaultRouterAddressType.next_variable =
362 &var_ipDefaultRouterAddress;
363 var_ipDefaultRouterAddress.next_variable = &var_ipDefaultRouterIfIndex;
364 var_ipDefaultRouterIfIndex.next_variable = NULL;
365
366
367 DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_index_to_oid", "called\n"));
368
369 /*
370 * ipDefaultRouterAddressType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h
371 */
372 snmp_set_var_value(&var_ipDefaultRouterAddressType,
373 (u_char *) & mib_idx->ipDefaultRouterAddressType,
374 sizeof(mib_idx->ipDefaultRouterAddressType));
375
376 /*
377 * ipDefaultRouterAddress(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h
378 */
379 snmp_set_var_value(&var_ipDefaultRouterAddress,
380 (u_char *) & mib_idx->ipDefaultRouterAddress,
381 mib_idx->ipDefaultRouterAddress_len *
382 sizeof(mib_idx->ipDefaultRouterAddress[0]));
383
384 /*
385 * ipDefaultRouterIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H
386 */
387 snmp_set_var_value(&var_ipDefaultRouterIfIndex,
388 (u_char *) & mib_idx->ipDefaultRouterIfIndex,
389 sizeof(mib_idx->ipDefaultRouterIfIndex));
390
391
392 err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len,
393 NULL, 0, &var_ipDefaultRouterAddressType);
394 if (err)
395 snmp_log(LOG_ERR, "error %d converting index to oid\n", err);
396
397 /*
398 * parsing may have allocated memory. free it.
399 */
400 snmp_reset_var_buffers(&var_ipDefaultRouterAddressType);
401
402 return err;
403 } /* ipDefaultRouterTable_index_to_oid */
404
405 /**
406 * extract ipDefaultRouterTable indexes from a netsnmp_index
407 *
408 * @retval SNMP_ERR_NOERROR : no error
409 * @retval SNMP_ERR_GENERR : error
410 */
411 int
ipDefaultRouterTable_index_from_oid(netsnmp_index * oid_idx,ipDefaultRouterTable_mib_index * mib_idx)412 ipDefaultRouterTable_index_from_oid(netsnmp_index * oid_idx,
413 ipDefaultRouterTable_mib_index *
414 mib_idx)
415 {
416 int err = SNMP_ERR_NOERROR;
417
418 /*
419 * temp storage for parsing indexes
420 */
421 /*
422 * ipDefaultRouterAddressType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h
423 */
424 netsnmp_variable_list var_ipDefaultRouterAddressType;
425 /*
426 * ipDefaultRouterAddress(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h
427 */
428 netsnmp_variable_list var_ipDefaultRouterAddress;
429 /*
430 * ipDefaultRouterIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H
431 */
432 netsnmp_variable_list var_ipDefaultRouterIfIndex;
433
434 /*
435 * set up varbinds
436 */
437 memset(&var_ipDefaultRouterAddressType, 0x00,
438 sizeof(var_ipDefaultRouterAddressType));
439 var_ipDefaultRouterAddressType.type = ASN_INTEGER;
440 memset(&var_ipDefaultRouterAddress, 0x00,
441 sizeof(var_ipDefaultRouterAddress));
442 var_ipDefaultRouterAddress.type = ASN_OCTET_STR;
443 memset(&var_ipDefaultRouterIfIndex, 0x00,
444 sizeof(var_ipDefaultRouterIfIndex));
445 var_ipDefaultRouterIfIndex.type = ASN_INTEGER;
446
447 /*
448 * chain temp index varbinds together
449 */
450 var_ipDefaultRouterAddressType.next_variable =
451 &var_ipDefaultRouterAddress;
452 var_ipDefaultRouterAddress.next_variable = &var_ipDefaultRouterIfIndex;
453 var_ipDefaultRouterIfIndex.next_variable = NULL;
454
455
456 DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_index_from_oid", "called\n"));
457
458 /*
459 * parse the oid into the individual index components
460 */
461 err = parse_oid_indexes(oid_idx->oids, oid_idx->len,
462 &var_ipDefaultRouterAddressType);
463 if (err == SNMP_ERR_NOERROR) {
464 /*
465 * copy out values
466 */
467 mib_idx->ipDefaultRouterAddressType =
468 *((u_long *) var_ipDefaultRouterAddressType.val.string);
469 /*
470 * NOTE: val_len is in bytes, ipDefaultRouterAddress_len might not be
471 */
472 if (var_ipDefaultRouterAddress.val_len >
473 sizeof(mib_idx->ipDefaultRouterAddress))
474 err = SNMP_ERR_GENERR;
475 else {
476 memcpy(mib_idx->ipDefaultRouterAddress,
477 var_ipDefaultRouterAddress.val.string,
478 var_ipDefaultRouterAddress.val_len);
479 mib_idx->ipDefaultRouterAddress_len =
480 var_ipDefaultRouterAddress.val_len /
481 sizeof(mib_idx->ipDefaultRouterAddress[0]);
482 }
483 mib_idx->ipDefaultRouterIfIndex =
484 *((long *) var_ipDefaultRouterIfIndex.val.string);
485
486
487 }
488
489 /*
490 * parsing may have allocated memory. free it.
491 */
492 snmp_reset_var_buffers(&var_ipDefaultRouterAddressType);
493
494 return err;
495 } /* ipDefaultRouterTable_index_from_oid */
496
497
498 /*
499 *********************************************************************
500 * @internal
501 * allocate resources for a ipDefaultRouterTable_rowreq_ctx
502 */
503 ipDefaultRouterTable_rowreq_ctx *
ipDefaultRouterTable_allocate_rowreq_ctx(ipDefaultRouterTable_data * data,void * user_init_ctx)504 ipDefaultRouterTable_allocate_rowreq_ctx(ipDefaultRouterTable_data * data,
505 void *user_init_ctx)
506 {
507 ipDefaultRouterTable_rowreq_ctx *rowreq_ctx =
508 SNMP_MALLOC_TYPEDEF(ipDefaultRouterTable_rowreq_ctx);
509
510 DEBUGMSGTL(("internal:ipDefaultRouterTable:ipDefaultRouterTable_allocate_rowreq_ctx", "called\n"));
511
512 if (NULL == rowreq_ctx) {
513 snmp_log(LOG_ERR, "Couldn't allocate memory for a "
514 "ipDefaultRouterTable_rowreq_ctx.\n");
515 return NULL;
516 } else {
517 if (NULL != data) {
518 /*
519 * track if we got data from user
520 */
521 rowreq_ctx->rowreq_flags |= MFD_ROW_DATA_FROM_USER;
522 rowreq_ctx->data = data;
523 } else if (NULL ==
524 (rowreq_ctx->data =
525 ipDefaultRouterTable_allocate_data())) {
526 SNMP_FREE(rowreq_ctx);
527 return NULL;
528 }
529 }
530
531 /*
532 * undo context will be allocated when needed (in *_undo_setup)
533 */
534
535 rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp;
536
537 rowreq_ctx->ipDefaultRouterTable_data_list = NULL;
538
539 /*
540 * if we allocated data, call init routine
541 */
542 if (!(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) {
543 if (SNMPERR_SUCCESS !=
544 ipDefaultRouterTable_rowreq_ctx_init(rowreq_ctx,
545 user_init_ctx)) {
546 ipDefaultRouterTable_release_rowreq_ctx(rowreq_ctx);
547 rowreq_ctx = NULL;
548 }
549 }
550
551 return rowreq_ctx;
552 } /* ipDefaultRouterTable_allocate_rowreq_ctx */
553
554 /*
555 * @internal
556 * release resources for a ipDefaultRouterTable_rowreq_ctx
557 */
558 void
ipDefaultRouterTable_release_rowreq_ctx(ipDefaultRouterTable_rowreq_ctx * rowreq_ctx)559 ipDefaultRouterTable_release_rowreq_ctx(ipDefaultRouterTable_rowreq_ctx *
560 rowreq_ctx)
561 {
562 DEBUGMSGTL(("internal:ipDefaultRouterTable:ipDefaultRouterTable_release_rowreq_ctx", "called\n"));
563
564 netsnmp_assert(NULL != rowreq_ctx);
565
566 ipDefaultRouterTable_rowreq_ctx_cleanup(rowreq_ctx);
567
568 /*
569 * for non-transient data, don't free data we got from the user
570 */
571 if ((rowreq_ctx->data) &&
572 !(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER))
573 ipDefaultRouterTable_release_data(rowreq_ctx->data);
574
575 /*
576 * free index oid pointer
577 */
578 if (rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp)
579 free(rowreq_ctx->oid_idx.oids);
580
581 SNMP_FREE(rowreq_ctx);
582 } /* ipDefaultRouterTable_release_rowreq_ctx */
583
584 /**
585 * @internal
586 * wrapper
587 */
588 static int
_mfd_ipDefaultRouterTable_pre_request(netsnmp_mib_handler * handler,netsnmp_handler_registration * reginfo,netsnmp_agent_request_info * agtreq_info,netsnmp_request_info * requests)589 _mfd_ipDefaultRouterTable_pre_request(netsnmp_mib_handler *handler,
590 netsnmp_handler_registration
591 *reginfo,
592 netsnmp_agent_request_info
593 *agtreq_info,
594 netsnmp_request_info *requests)
595 {
596 int rc;
597
598 DEBUGMSGTL(("internal:ipDefaultRouterTable:_mfd_ipDefaultRouterTable_pre_request", "called\n"));
599
600 if (1 != netsnmp_row_merge_status_first(reginfo, agtreq_info)) {
601 DEBUGMSGTL(("internal:ipDefaultRouterTable",
602 "skipping additional pre_request\n"));
603 return SNMP_ERR_NOERROR;
604 }
605
606 rc = ipDefaultRouterTable_pre_request(ipDefaultRouterTable_if_ctx.
607 user_ctx);
608 if (MFD_SUCCESS != rc) {
609 /*
610 * nothing we can do about it but log it
611 */
612 DEBUGMSGTL(("ipDefaultRouterTable", "error %d from "
613 "ipDefaultRouterTable_pre_request\n", rc));
614 netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
615 }
616
617 return SNMP_ERR_NOERROR;
618 } /* _mfd_ipDefaultRouterTable_pre_request */
619
620 /**
621 * @internal
622 * wrapper
623 */
624 static int
_mfd_ipDefaultRouterTable_post_request(netsnmp_mib_handler * handler,netsnmp_handler_registration * reginfo,netsnmp_agent_request_info * agtreq_info,netsnmp_request_info * requests)625 _mfd_ipDefaultRouterTable_post_request(netsnmp_mib_handler *handler,
626 netsnmp_handler_registration
627 *reginfo,
628 netsnmp_agent_request_info
629 *agtreq_info,
630 netsnmp_request_info *requests)
631 {
632 ipDefaultRouterTable_rowreq_ctx *rowreq_ctx =
633 netsnmp_container_table_row_extract(requests);
634 int rc, packet_rc;
635
636 DEBUGMSGTL(("internal:ipDefaultRouterTable:_mfd_ipDefaultRouterTable_post_request", "called\n"));
637
638 /*
639 * release row context, if deleted
640 */
641 if (rowreq_ctx && (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED))
642 ipDefaultRouterTable_release_rowreq_ctx(rowreq_ctx);
643
644 /*
645 * wait for last call before calling user
646 */
647 if (1 != netsnmp_row_merge_status_last(reginfo, agtreq_info)) {
648 DEBUGMSGTL(("internal:ipDefaultRouterTable",
649 "waiting for last post_request\n"));
650 return SNMP_ERR_NOERROR;
651 }
652
653 packet_rc = netsnmp_check_all_requests_error(agtreq_info->asp, 0);
654 rc = ipDefaultRouterTable_post_request(ipDefaultRouterTable_if_ctx.
655 user_ctx, packet_rc);
656 if (MFD_SUCCESS != rc) {
657 /*
658 * nothing we can do about it but log it
659 */
660 DEBUGMSGTL(("ipDefaultRouterTable", "error %d from "
661 "ipDefaultRouterTable_post_request\n", rc));
662 }
663
664 return SNMP_ERR_NOERROR;
665 } /* _mfd_ipDefaultRouterTable_post_request */
666
667 /**
668 * @internal
669 * wrapper
670 */
671 static int
_mfd_ipDefaultRouterTable_object_lookup(netsnmp_mib_handler * handler,netsnmp_handler_registration * reginfo,netsnmp_agent_request_info * agtreq_info,netsnmp_request_info * requests)672 _mfd_ipDefaultRouterTable_object_lookup(netsnmp_mib_handler *handler,
673 netsnmp_handler_registration
674 *reginfo,
675 netsnmp_agent_request_info
676 *agtreq_info,
677 netsnmp_request_info *requests)
678 {
679 int rc = SNMP_ERR_NOERROR;
680 ipDefaultRouterTable_rowreq_ctx *rowreq_ctx =
681 netsnmp_container_table_row_extract(requests);
682
683 DEBUGMSGTL(("internal:ipDefaultRouterTable:_mfd_ipDefaultRouterTable_object_lookup", "called\n"));
684
685 /*
686 * get our context from mfd
687 * ipDefaultRouterTable_interface_ctx *if_ctx =
688 * (ipDefaultRouterTable_interface_ctx *)reginfo->my_reg_void;
689 */
690
691 if (NULL == rowreq_ctx) {
692 rc = SNMP_ERR_NOCREATION;
693 }
694
695 if (MFD_SUCCESS != rc)
696 netsnmp_request_set_error_all(requests, rc);
697 else
698 ipDefaultRouterTable_row_prep(rowreq_ctx);
699
700 return SNMP_VALIDATE_ERR(rc);
701 } /* _mfd_ipDefaultRouterTable_object_lookup */
702
703 /***********************************************************************
704 *
705 * GET processing
706 *
707 ***********************************************************************/
708 /*
709 * @internal
710 * Retrieve the value for a particular column
711 */
712 NETSNMP_STATIC_INLINE int
_ipDefaultRouterTable_get_column(ipDefaultRouterTable_rowreq_ctx * rowreq_ctx,netsnmp_variable_list * var,int column)713 _ipDefaultRouterTable_get_column(ipDefaultRouterTable_rowreq_ctx *
714 rowreq_ctx, netsnmp_variable_list * var,
715 int column)
716 {
717 int rc = SNMPERR_SUCCESS;
718
719 DEBUGMSGTL(("internal:ipDefaultRouterTable:_mfd_ipDefaultRouterTable_get_column", "called for %d\n", column));
720
721
722 netsnmp_assert(NULL != rowreq_ctx);
723
724 switch (column) {
725
726 /*
727 * ipDefaultRouterLifetime(4)/UNSIGNED32/ASN_UNSIGNED/u_long(u_long)//l/A/w/e/R/d/h
728 */
729 case COLUMN_IPDEFAULTROUTERLIFETIME:
730 var->val_len = sizeof(u_long);
731 var->type = ASN_UNSIGNED;
732 rc = ipDefaultRouterLifetime_get(rowreq_ctx,
733 (u_long *) var->val.string);
734 break;
735
736 /*
737 * ipDefaultRouterPreference(5)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h
738 */
739 case COLUMN_IPDEFAULTROUTERPREFERENCE:
740 var->val_len = sizeof(u_long);
741 var->type = ASN_INTEGER;
742 rc = ipDefaultRouterPreference_get(rowreq_ctx,
743 (u_long *) var->val.string);
744 break;
745
746 default:
747 if (IPDEFAULTROUTERTABLE_MIN_COL <= column
748 && column <= IPDEFAULTROUTERTABLE_MAX_COL) {
749 DEBUGMSGTL(("internal:ipDefaultRouterTable:_mfd_ipDefaultRouterTable_get_column", "assume column %d is reserved\n", column));
750 rc = MFD_SKIP;
751 } else {
752 snmp_log(LOG_ERR,
753 "unknown column %d in _ipDefaultRouterTable_get_column\n",
754 column);
755 }
756 break;
757 }
758
759 return rc;
760 } /* _ipDefaultRouterTable_get_column */
761
762 int
_mfd_ipDefaultRouterTable_get_values(netsnmp_mib_handler * handler,netsnmp_handler_registration * reginfo,netsnmp_agent_request_info * agtreq_info,netsnmp_request_info * requests)763 _mfd_ipDefaultRouterTable_get_values(netsnmp_mib_handler *handler,
764 netsnmp_handler_registration *reginfo,
765 netsnmp_agent_request_info
766 *agtreq_info,
767 netsnmp_request_info *requests)
768 {
769 ipDefaultRouterTable_rowreq_ctx *rowreq_ctx =
770 netsnmp_container_table_row_extract(requests);
771 netsnmp_table_request_info *tri;
772 u_char *old_string;
773 void (*dataFreeHook) (void *);
774 int rc;
775
776 DEBUGMSGTL(("internal:ipDefaultRouterTable:_mfd_ipDefaultRouterTable_get_values", "called\n"));
777
778 netsnmp_assert(NULL != rowreq_ctx);
779
780 for (; requests; requests = requests->next) {
781 /*
782 * save old pointer, so we can free it if replaced
783 */
784 old_string = requests->requestvb->val.string;
785 dataFreeHook = requests->requestvb->dataFreeHook;
786 if (NULL == requests->requestvb->val.string) {
787 requests->requestvb->val.string = requests->requestvb->buf;
788 requests->requestvb->val_len =
789 sizeof(requests->requestvb->buf);
790 } else if (requests->requestvb->buf ==
791 requests->requestvb->val.string) {
792 if (requests->requestvb->val_len !=
793 sizeof(requests->requestvb->buf))
794 requests->requestvb->val_len =
795 sizeof(requests->requestvb->buf);
796 }
797
798 /*
799 * get column data
800 */
801 tri = netsnmp_extract_table_info(requests);
802 if (NULL == tri)
803 continue;
804
805 rc = _ipDefaultRouterTable_get_column(rowreq_ctx,
806 requests->requestvb,
807 tri->colnum);
808 if (rc) {
809 if (MFD_SKIP == rc) {
810 requests->requestvb->type = SNMP_NOSUCHINSTANCE;
811 rc = SNMP_ERR_NOERROR;
812 }
813 } else if (NULL == requests->requestvb->val.string) {
814 snmp_log(LOG_ERR, "NULL varbind data pointer!\n");
815 rc = SNMP_ERR_GENERR;
816 }
817 if (rc)
818 netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc));
819
820 /*
821 * if the buffer wasn't used previously for the old data (i.e. it
822 * was allcoated memory) and the get routine replaced the pointer,
823 * we need to free the previous pointer.
824 */
825 if (old_string && (old_string != requests->requestvb->buf) &&
826 (requests->requestvb->val.string != old_string)) {
827 if (dataFreeHook)
828 (*dataFreeHook) (old_string);
829 else
830 free(old_string);
831 }
832 } /* for results */
833
834 return SNMP_ERR_NOERROR;
835 } /* _mfd_ipDefaultRouterTable_get_values */
836
837
838 /***********************************************************************
839 *
840 * SET processing
841 *
842 ***********************************************************************/
843
844 /*
845 * SET PROCESSING NOT APPLICABLE (per MIB or user setting)
846 */
847 /***********************************************************************
848 *
849 * DATA ACCESS
850 *
851 ***********************************************************************/
852 static void _container_free(netsnmp_container * container);
853
854 /**
855 * @internal
856 */
857 static int
_cache_load(netsnmp_cache * cache,void * vmagic)858 _cache_load(netsnmp_cache * cache, void *vmagic)
859 {
860 DEBUGMSGTL(("internal:ipDefaultRouterTable:_cache_load", "called\n"));
861
862 if ((NULL == cache) || (NULL == cache->magic)) {
863 snmp_log(LOG_ERR,
864 "invalid cache for ipDefaultRouterTable_cache_load\n");
865 return -1;
866 }
867
868 /** should only be called for an invalid or expired cache */
869 netsnmp_assert((0 == cache->valid) || (1 == cache->expired));
870
871 /*
872 * call user code
873 */
874 return ipDefaultRouterTable_container_load((netsnmp_container *)
875 cache->magic);
876 } /* _cache_load */
877
878 /**
879 * @internal
880 */
881 static void
_cache_free(netsnmp_cache * cache,void * magic)882 _cache_free(netsnmp_cache * cache, void *magic)
883 {
884 netsnmp_container *container;
885
886 DEBUGMSGTL(("internal:ipDefaultRouterTable:_cache_free", "called\n"));
887
888 if ((NULL == cache) || (NULL == cache->magic)) {
889 snmp_log(LOG_ERR,
890 "invalid cache in ipDefaultRouterTable_cache_free\n");
891 return;
892 }
893
894 container = (netsnmp_container *) cache->magic;
895
896 _container_free(container);
897 } /* _cache_free */
898
899 /**
900 * @internal
901 */
902 static void
_container_item_free(ipDefaultRouterTable_rowreq_ctx * rowreq_ctx,void * context)903 _container_item_free(ipDefaultRouterTable_rowreq_ctx * rowreq_ctx,
904 void *context)
905 {
906 DEBUGMSGTL(("internal:ipDefaultRouterTable:_container_item_free",
907 "called\n"));
908
909 if (NULL == rowreq_ctx)
910 return;
911
912 ipDefaultRouterTable_release_rowreq_ctx(rowreq_ctx);
913 } /* _container_item_free */
914
915 /**
916 * @internal
917 */
918 static void
_container_free(netsnmp_container * container)919 _container_free(netsnmp_container * container)
920 {
921 DEBUGMSGTL(("internal:ipDefaultRouterTable:_container_free",
922 "called\n"));
923
924 if (NULL == container) {
925 snmp_log(LOG_ERR,
926 "invalid container in ipDefaultRouterTable_container_free\n");
927 return;
928 }
929
930 /*
931 * call user code
932 */
933 ipDefaultRouterTable_container_free(container);
934
935 /*
936 * free all items. inefficient, but easy.
937 */
938 CONTAINER_CLEAR(container,
939 (netsnmp_container_obj_func *) _container_item_free,
940 NULL);
941 } /* _container_free */
942
943 /**
944 * @internal
945 * initialize the container with functions or wrappers
946 */
947 void
_ipDefaultRouterTable_container_init(ipDefaultRouterTable_interface_ctx * if_ctx)948 _ipDefaultRouterTable_container_init(ipDefaultRouterTable_interface_ctx *
949 if_ctx)
950 {
951 DEBUGMSGTL(("internal:ipDefaultRouterTable:_ipDefaultRouterTable_container_init", "called\n"));
952
953 /*
954 * cache init
955 */
956 if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */
957 _cache_load, _cache_free,
958 ipDefaultRouterTable_oid,
959 ipDefaultRouterTable_oid_size);
960
961 if (NULL == if_ctx->cache) {
962 snmp_log(LOG_ERR,
963 "error creating cache for ipDefaultRouterTable\n");
964 return;
965 }
966
967 if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;
968
969 ipDefaultRouterTable_container_init(&if_ctx->container, if_ctx->cache);
970 if (NULL == if_ctx->container)
971 if_ctx->container =
972 netsnmp_container_find("ipDefaultRouterTable:table_container");
973 if (NULL == if_ctx->container) {
974 snmp_log(LOG_ERR, "error creating container in "
975 "ipDefaultRouterTable_container_init\n");
976 return;
977 }
978
979 if (NULL != if_ctx->cache)
980 if_ctx->cache->magic = (void *) if_ctx->container;
981 } /* _ipDefaultRouterTable_container_init */
982
983 /**
984 * @internal
985 * shutdown the container with functions or wrappers
986 */
987 void
_ipDefaultRouterTable_container_shutdown(ipDefaultRouterTable_interface_ctx * if_ctx)988 _ipDefaultRouterTable_container_shutdown(ipDefaultRouterTable_interface_ctx
989 * if_ctx)
990 {
991 DEBUGMSGTL(("internal:ipDefaultRouterTable:_ipDefaultRouterTable_container_shutdown", "called\n"));
992
993 ipDefaultRouterTable_container_shutdown(if_ctx->container);
994
995 _container_free(if_ctx->container);
996
997 } /* _ipDefaultRouterTable_container_shutdown */
998
999
1000 ipDefaultRouterTable_rowreq_ctx *
ipDefaultRouterTable_row_find_by_mib_index(ipDefaultRouterTable_mib_index * mib_idx)1001 ipDefaultRouterTable_row_find_by_mib_index(ipDefaultRouterTable_mib_index *
1002 mib_idx)
1003 {
1004 ipDefaultRouterTable_rowreq_ctx *rowreq_ctx;
1005 oid oid_tmp[MAX_OID_LEN];
1006 netsnmp_index oid_idx;
1007 int rc;
1008
1009 /*
1010 * set up storage for OID
1011 */
1012 oid_idx.oids = oid_tmp;
1013 oid_idx.len = sizeof(oid_tmp) / sizeof(oid);
1014
1015 /*
1016 * convert
1017 */
1018 rc = ipDefaultRouterTable_index_to_oid(&oid_idx, mib_idx);
1019 if (MFD_SUCCESS != rc)
1020 return NULL;
1021
1022 rowreq_ctx =
1023 CONTAINER_FIND(ipDefaultRouterTable_if_ctx.container, &oid_idx);
1024
1025 return rowreq_ctx;
1026 }
1027