Debian Codegraph @

agent/mibgroup/ip-mib/ipAddressTable/ipAddressTable_interface.c

raw
1 /*
2 * Note: this file originally auto-generated by mib2c using
3 * version : 1.67 $ of : mfd-interface.m2c,v $
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 "ipAddressTable.h"
41
42
43 #include <net-snmp/agent/table_container.h>
44 #include <net-snmp/library/container.h>
45
46 #include "ipAddressTable_interface.h"
47
48 #include <ctype.h>
49
50 netsnmp_feature_child_of(ipAddressTable_external_access, libnetsnmpmibs);
51
52 netsnmp_feature_require(row_merge);
53 netsnmp_feature_require(baby_steps);
54 netsnmp_feature_require(table_container_row_insert);
55 netsnmp_feature_require(check_all_requests_error);
56
57
58 netsnmp_feature_child_of(ipAddressTable_container_size, ipAddressTable_external_access);
59 netsnmp_feature_child_of(ipAddressTable_registration_set, ipAddressTable_external_access);
60 netsnmp_feature_child_of(ipAddressTable_registration_get, ipAddressTable_external_access);
61 netsnmp_feature_child_of(ipAddressTable_container_get, ipAddressTable_external_access);
62
63 /**********************************************************************
64 **********************************************************************
65 ***
66 *** Table ipAddressTable
67 ***
68 **********************************************************************
69 **********************************************************************/
70 /*
71 * IP-MIB::ipAddressTable is subid 34 of ip.
72 * Its status is Current.
73 * OID: .1.3.6.1.2.1.4.34, length: 8
74 */
75 typedef struct ipAddressTable_interface_ctx_s {
76
77 netsnmp_container *container;
78 netsnmp_cache *cache;
79
80 ipAddressTable_registration *user_ctx;
81
82 netsnmp_table_registration_info tbl_info;
83
84 netsnmp_baby_steps_access_methods access_multiplexer;
85
86 u_int table_dirty;
87
88 } ipAddressTable_interface_ctx;
89
90 static ipAddressTable_interface_ctx ipAddressTable_if_ctx;
91
92 static void _ipAddressTable_container_init(ipAddressTable_interface_ctx
93 * if_ctx);
94 static void
95 _ipAddressTable_container_shutdown(ipAddressTable_interface_ctx * if_ctx);
96
97 #ifndef NETSNMP_FEATURE_REMOVE_IPADDRESSTABLE_CONTAINER_GET
98 netsnmp_container *
99 ipAddressTable_container_get(void)
100 {
101 return ipAddressTable_if_ctx.container;
102 }
103 #endif /* NETSNMP_FEATURE_REMOVE_IPADDRESSTABLE_CONTAINER_GET */
104
105 #ifndef NETSNMP_FEATURE_REMOVE_IPADDRESSTABLE_REGISTRATION_GET
106 ipAddressTable_registration *
107 ipAddressTable_registration_get(void)
108 {
109 return ipAddressTable_if_ctx.user_ctx;
110 }
111 #endif /* NETSNMP_FEATURE_REMOVE_IPADDRESSTABLE_REGISTRATION_GET */
112
113 #ifndef NETSNMP_FEATURE_REMOVE_IPADDRESSTABLE_REGISTRATION_SET
114 ipAddressTable_registration *
115 ipAddressTable_registration_set(ipAddressTable_registration * newreg)
116 {
117 ipAddressTable_registration *old = ipAddressTable_if_ctx.user_ctx;
118 ipAddressTable_if_ctx.user_ctx = newreg;
119 return old;
120 }
121 #endif /* NETSNMP_FEATURE_REMOVE_IPADDRESSTABLE_REGISTRATION_SET */
122
123 #ifndef NETSNMP_FEATURE_REMOVE_IPADDRESSTABLE_CONTAINER_SIZE
124 int
125 ipAddressTable_container_size(void)
126 {
127 return CONTAINER_SIZE(ipAddressTable_if_ctx.container);
128 }
129 #endif /* NETSNMP_FEATURE_REMOVE_IPADDRESSTABLE_CONTAINER_SIZE */
130
131 u_int
132 ipAddressTable_dirty_get(void)
133 {
134 return ipAddressTable_if_ctx.table_dirty;
135 }
136
137 void
138 ipAddressTable_dirty_set(u_int status)
139 {
140 DEBUGMSGTL(("ipAddressTable:ipAddressTable_dirty_set",
141 "called. was %d, now %d\n",
142 ipAddressTable_if_ctx.table_dirty, status));
143 ipAddressTable_if_ctx.table_dirty = status;
144 }
145
146 /*
147 * mfd multiplexer modes
148 */
149 static Netsnmp_Node_Handler _mfd_ipAddressTable_pre_request;
150 static Netsnmp_Node_Handler _mfd_ipAddressTable_post_request;
151 static Netsnmp_Node_Handler _mfd_ipAddressTable_object_lookup;
152 static Netsnmp_Node_Handler _mfd_ipAddressTable_get_values;
153 #if !(defined(NETSNMP_NO_WRITE_SUPPORT) || defined(NETSNMP_DISABLE_SET_SUPPORT))
154 static Netsnmp_Node_Handler _mfd_ipAddressTable_check_objects;
155 static Netsnmp_Node_Handler _mfd_ipAddressTable_undo_setup;
156 static Netsnmp_Node_Handler _mfd_ipAddressTable_set_values;
157 static Netsnmp_Node_Handler _mfd_ipAddressTable_undo_cleanup;
158 static Netsnmp_Node_Handler _mfd_ipAddressTable_undo_values;
159 static Netsnmp_Node_Handler _mfd_ipAddressTable_commit;
160 static Netsnmp_Node_Handler _mfd_ipAddressTable_undo_commit;
161 static Netsnmp_Node_Handler _mfd_ipAddressTable_irreversible_commit;
162 static Netsnmp_Node_Handler _mfd_ipAddressTable_check_dependencies;
163
164 NETSNMP_STATIC_INLINE int
165 _ipAddressTable_undo_column(ipAddressTable_rowreq_ctx * rowreq_ctx,
166 netsnmp_variable_list * var,
167 int column);
168 #endif /* NETSNMP_NO_WRITE_SUPPORT || NETSNMP_DISABLE_SET_SUPPORT */
169
170 NETSNMP_STATIC_INLINE int
171 _ipAddressTable_check_indexes(ipAddressTable_rowreq_ctx * rowreq_ctx);
172
173 /**
174 * @internal
175 * Initialize the table ipAddressTable
176 * (Define its contents and how it's structured)
177 */
178 void
179 _ipAddressTable_initialize_interface(ipAddressTable_registration * reg_ptr,
180 u_long flags)
181 {
182 netsnmp_baby_steps_access_methods *access_multiplexer =
183 &ipAddressTable_if_ctx.access_multiplexer;
184 netsnmp_table_registration_info *tbl_info =
185 &ipAddressTable_if_ctx.tbl_info;
186 netsnmp_handler_registration *reginfo;
187 netsnmp_mib_handler *handler;
188 int mfd_modes = 0;
189
190 DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_initialize_interface", "called\n"));
191
192
193 /*************************************************
194 *
195 * save interface context for ipAddressTable
196 */
197 /*
198 * Setting up the table's definition
199 */
200 netsnmp_table_helper_add_indexes(tbl_info, ASN_INTEGER,
201 /** index: ipAddressAddrType */
202 ASN_OCTET_STR,
203 /** index: ipAddressAddr */
204 0);
205
206 /*
207 * Define the minimum and maximum accessible columns. This
208 * optimizes retrieval.
209 */
210 tbl_info->min_column = IPADDRESSTABLE_MIN_COL;
211 tbl_info->max_column = IPADDRESSTABLE_MAX_COL;
212
213 /*
214 * save users context
215 */
216 ipAddressTable_if_ctx.user_ctx = reg_ptr;
217
218 /*
219 * call data access initialization code
220 */
221 ipAddressTable_init_data(reg_ptr);
222
223 /*
224 * set up the container
225 */
226 _ipAddressTable_container_init(&ipAddressTable_if_ctx);
227 if (NULL == ipAddressTable_if_ctx.container) {
228 snmp_log(LOG_ERR,
229 "could not initialize container for ipAddressTable\n");
230 return;
231 }
232
233 /*
234 * access_multiplexer: REQUIRED wrapper for get request handling
235 */
236 access_multiplexer->object_lookup = _mfd_ipAddressTable_object_lookup;
237 access_multiplexer->get_values = _mfd_ipAddressTable_get_values;
238
239 /*
240 * no wrappers yet
241 */
242 access_multiplexer->pre_request = _mfd_ipAddressTable_pre_request;
243 access_multiplexer->post_request = _mfd_ipAddressTable_post_request;
244
245
246 #if !(defined(NETSNMP_NO_WRITE_SUPPORT) || defined(NETSNMP_DISABLE_SET_SUPPORT))
247 /*
248 * REQUIRED wrappers for set request handling
249 */
250 access_multiplexer->object_syntax_checks =
251 _mfd_ipAddressTable_check_objects;
252 access_multiplexer->undo_setup = _mfd_ipAddressTable_undo_setup;
253 access_multiplexer->undo_cleanup = _mfd_ipAddressTable_undo_cleanup;
254 access_multiplexer->set_values = _mfd_ipAddressTable_set_values;
255 access_multiplexer->undo_sets = _mfd_ipAddressTable_undo_values;
256
257 /*
258 * no wrappers yet
259 */
260 access_multiplexer->commit = _mfd_ipAddressTable_commit;
261 access_multiplexer->undo_commit = _mfd_ipAddressTable_undo_commit;
262 access_multiplexer->irreversible_commit =
263 _mfd_ipAddressTable_irreversible_commit;
264
265 /*
266 * REQUIRED for tables with dependencies
267 */
268 access_multiplexer->consistency_checks =
269 _mfd_ipAddressTable_check_dependencies;
270 #endif /* NETSNMP_NO_WRITE_SUPPORT || NETSNMP_DISABLE_SET_SUPPORT */
271
272 /*************************************************
273 *
274 * Create a registration, save our reg data, register table.
275 */
276 DEBUGMSGTL(("ipAddressTable:init_ipAddressTable",
277 "Registering ipAddressTable as a mibs-for-dummies table.\n"));
278 handler =
279 netsnmp_baby_steps_access_multiplexer_get(access_multiplexer);
280 reginfo =
281 netsnmp_handler_registration_create("ipAddressTable", handler,
282 ipAddressTable_oid,
283 ipAddressTable_oid_size,
284 HANDLER_CAN_BABY_STEP |
285 #ifndef NETSNMP_DISABLE_SET_SUPPORT
286 HANDLER_CAN_RWRITE
287 #else
288 HANDLER_CAN_RONLY
289 #endif /* NETSNMP_DISABLE_SET_SUPPORT */
290 );
291 if (NULL == reginfo) {
292 snmp_log(LOG_ERR, "error registering table ipAddressTable\n");
293 return;
294 }
295 reginfo->my_reg_void = &ipAddressTable_if_ctx;
296
297 /*************************************************
298 *
299 * set up baby steps handler, create it and inject it
300 */
301 if (access_multiplexer->object_lookup)
302 mfd_modes |= BABY_STEP_OBJECT_LOOKUP;
303 if (access_multiplexer->pre_request)
304 mfd_modes |= BABY_STEP_PRE_REQUEST;
305 if (access_multiplexer->post_request)
306 mfd_modes |= BABY_STEP_POST_REQUEST;
307
308 #if !(defined(NETSNMP_NO_WRITE_SUPPORT) || defined(NETSNMP_DISABLE_SET_SUPPORT))
309 if (access_multiplexer->set_values)
310 mfd_modes |= BABY_STEP_SET_VALUES;
311 if (access_multiplexer->irreversible_commit)
312 mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT;
313 if (access_multiplexer->object_syntax_checks)
314 mfd_modes |= BABY_STEP_CHECK_OBJECT;
315
316 if (access_multiplexer->undo_setup)
317 mfd_modes |= BABY_STEP_UNDO_SETUP;
318 if (access_multiplexer->undo_cleanup)
319 mfd_modes |= BABY_STEP_UNDO_CLEANUP;
320 if (access_multiplexer->undo_sets)
321 mfd_modes |= BABY_STEP_UNDO_SETS;
322
323 if (access_multiplexer->row_creation)
324 mfd_modes |= BABY_STEP_ROW_CREATE;
325 if (access_multiplexer->consistency_checks)
326 mfd_modes |= BABY_STEP_CHECK_CONSISTENCY;
327 if (access_multiplexer->commit)
328 mfd_modes |= BABY_STEP_COMMIT;
329 if (access_multiplexer->undo_commit)
330 mfd_modes |= BABY_STEP_UNDO_COMMIT;
331 #endif /* NETSNMP_NO_WRITE_SUPPORT || NETSNMP_DISABLE_SET_SUPPORT */
332
333 handler = netsnmp_baby_steps_handler_get(mfd_modes);
334 netsnmp_inject_handler(reginfo, handler);
335
336 /*************************************************
337 *
338 * inject row_merge helper with prefix rootoid_len + 2 (entry.col)
339 */
340 handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2);
341 netsnmp_inject_handler(reginfo, handler);
342
343 /*************************************************
344 *
345 * inject container_table helper
346 */
347 handler =
348 netsnmp_container_table_handler_get(tbl_info,
349 ipAddressTable_if_ctx.
350 container,
351 TABLE_CONTAINER_KEY_NETSNMP_INDEX);
352 netsnmp_inject_handler(reginfo, handler);
353
354 /*************************************************
355 *
356 * inject cache helper
357 */
358 if (NULL != ipAddressTable_if_ctx.cache) {
359 handler = netsnmp_cache_handler_get(ipAddressTable_if_ctx.cache);
360 netsnmp_inject_handler(reginfo, handler);
361 }
362
363 /*
364 * register table
365 */
366 netsnmp_register_table(reginfo, tbl_info);
367
368 } /* _ipAddressTable_initialize_interface */
369
370 /**
371 * @internal
372 * Shutdown the table ipAddressTable
373 */
374 void
375 _ipAddressTable_shutdown_interface(ipAddressTable_registration * reg_ptr)
376 {
377 /*
378 * shutdown the container
379 */
380 _ipAddressTable_container_shutdown(&ipAddressTable_if_ctx);
381 }
382
383 void
384 ipAddressTable_valid_columns_set(netsnmp_column_info *vc)
385 {
386 ipAddressTable_if_ctx.tbl_info.valid_columns = vc;
387 } /* ipAddressTable_valid_columns_set */
388
389 /**
390 * @internal
391 * convert the index component stored in the context to an oid
392 */
393 int
394 ipAddressTable_index_to_oid(netsnmp_index * oid_idx,
395 ipAddressTable_mib_index * mib_idx)
396 {
397 int err = SNMP_ERR_NOERROR;
398
399 /*
400 * temp storage for parsing indexes
401 */
402 /*
403 * ipAddressAddrType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h
404 */
405 netsnmp_variable_list var_ipAddressAddrType;
406 /*
407 * ipAddressAddr(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h
408 */
409 netsnmp_variable_list var_ipAddressAddr;
410
411 /*
412 * set up varbinds
413 */
414 memset(&var_ipAddressAddrType, 0x00, sizeof(var_ipAddressAddrType));
415 var_ipAddressAddrType.type = ASN_INTEGER;
416 memset(&var_ipAddressAddr, 0x00, sizeof(var_ipAddressAddr));
417 var_ipAddressAddr.type = ASN_OCTET_STR;
418
419 /*
420 * chain temp index varbinds together
421 */
422 var_ipAddressAddrType.next_variable = &var_ipAddressAddr;
423 var_ipAddressAddr.next_variable = NULL;
424
425
426 DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_index_to_oid",
427 "called\n"));
428
429 /*
430 * ipAddressAddrType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h
431 */
432 snmp_set_var_value(&var_ipAddressAddrType,
433 (u_char *) & mib_idx->ipAddressAddrType,
434 sizeof(mib_idx->ipAddressAddrType));
435
436 /*
437 * ipAddressAddr(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h
438 */
439 snmp_set_var_value(&var_ipAddressAddr,
440 (u_char *) & mib_idx->ipAddressAddr,
441 mib_idx->ipAddressAddr_len *
442 sizeof(mib_idx->ipAddressAddr[0]));
443
444
445 err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len,
446 NULL, 0, &var_ipAddressAddrType);
447 if (err)
448 snmp_log(LOG_ERR, "error %d converting index to oid\n", err);
449
450 /*
451 * parsing may have allocated memory. free it.
452 */
453 snmp_reset_var_buffers(&var_ipAddressAddrType);
454
455 return err;
456 } /* ipAddressTable_index_to_oid */
457
458 /**
459 * extract ipAddressTable indexes from a netsnmp_index
460 *
461 * @retval SNMP_ERR_NOERROR : no error
462 * @retval SNMP_ERR_GENERR : error
463 */
464 int
465 ipAddressTable_index_from_oid(netsnmp_index * oid_idx,
466 ipAddressTable_mib_index * mib_idx)
467 {
468 int err = SNMP_ERR_NOERROR;
469
470 /*
471 * temp storage for parsing indexes
472 */
473 /*
474 * ipAddressAddrType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h
475 */
476 netsnmp_variable_list var_ipAddressAddrType;
477 /*
478 * ipAddressAddr(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h
479 */
480 netsnmp_variable_list var_ipAddressAddr;
481
482 /*
483 * set up varbinds
484 */
485 memset(&var_ipAddressAddrType, 0x00, sizeof(var_ipAddressAddrType));
486 var_ipAddressAddrType.type = ASN_INTEGER;
487 memset(&var_ipAddressAddr, 0x00, sizeof(var_ipAddressAddr));
488 var_ipAddressAddr.type = ASN_OCTET_STR;
489
490 /*
491 * chain temp index varbinds together
492 */
493 var_ipAddressAddrType.next_variable = &var_ipAddressAddr;
494 var_ipAddressAddr.next_variable = NULL;
495
496
497 DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_index_from_oid",
498 "called\n"));
499
500 /*
501 * parse the oid into the individual index components
502 */
503 err = parse_oid_indexes(oid_idx->oids, oid_idx->len,
504 &var_ipAddressAddrType);
505 if (err == SNMP_ERR_NOERROR) {
506 /*
507 * copy out values
508 */
509 mib_idx->ipAddressAddrType =
510 *((u_long *) var_ipAddressAddrType.val.string);
511 /*
512 * NOTE: val_len is in bytes, ipAddressAddr_len might not be
513 */
514 if (var_ipAddressAddr.val_len > sizeof(mib_idx->ipAddressAddr))
515 err = SNMP_ERR_GENERR;
516 else {
517 memcpy(mib_idx->ipAddressAddr, var_ipAddressAddr.val.string,
518 var_ipAddressAddr.val_len);
519 mib_idx->ipAddressAddr_len =
520 var_ipAddressAddr.val_len /
521 sizeof(mib_idx->ipAddressAddr[0]);
522 }
523
524
525 }
526
527 /*
528 * parsing may have allocated memory. free it.
529 */
530 snmp_reset_var_buffers(&var_ipAddressAddrType);
531
532 return err;
533 } /* ipAddressTable_index_from_oid */
534
535
536 /*
537 *********************************************************************
538 * @internal
539 * allocate resources for a ipAddressTable_rowreq_ctx
540 */
541 ipAddressTable_rowreq_ctx *
542 ipAddressTable_allocate_rowreq_ctx(ipAddressTable_data * data,
543 void *user_init_ctx)
544 {
545 ipAddressTable_rowreq_ctx *rowreq_ctx =
546 SNMP_MALLOC_TYPEDEF(ipAddressTable_rowreq_ctx);
547
548 DEBUGMSGTL(("internal:ipAddressTable:ipAddressTable_allocate_rowreq_ctx", "called\n"));
549
550 if (NULL == rowreq_ctx) {
551 snmp_log(LOG_ERR, "Couldn't allocate memory for a "
552 "ipAddressTable_rowreq_ctx.\n");
553 return NULL;
554 } else {
555 if (NULL != data) {
556 /*
557 * track if we got data from user
558 */
559 rowreq_ctx->rowreq_flags |= MFD_ROW_DATA_FROM_USER;
560 rowreq_ctx->data = data;
561 } else if (NULL ==
562 (rowreq_ctx->data = ipAddressTable_allocate_data())) {
563 SNMP_FREE(rowreq_ctx);
564 return NULL;
565 }
566 }
567
568 /*
569 * undo context will be allocated when needed (in *_undo_setup)
570 */
571
572 rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp;
573
574 rowreq_ctx->ipAddressTable_data_list = NULL;
575
576 /*
577 * if we allocated data, call init routine
578 */
579 if (!(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) {
580 if (SNMPERR_SUCCESS !=
581 ipAddressTable_rowreq_ctx_init(rowreq_ctx, user_init_ctx)) {
582 ipAddressTable_release_rowreq_ctx(rowreq_ctx);
583 rowreq_ctx = NULL;
584 }
585 }
586
587 return rowreq_ctx;
588 } /* ipAddressTable_allocate_rowreq_ctx */
589
590 /*
591 * @internal
592 * release resources for a ipAddressTable_rowreq_ctx
593 */
594 void
595 ipAddressTable_release_rowreq_ctx(ipAddressTable_rowreq_ctx * rowreq_ctx)
596 {
597 DEBUGMSGTL(("internal:ipAddressTable:ipAddressTable_release_rowreq_ctx", "called\n"));
598
599 netsnmp_assert(NULL != rowreq_ctx);
600
601 ipAddressTable_rowreq_ctx_cleanup(rowreq_ctx);
602
603 /*
604 * for non-transient data, don't free data we got from the user
605 */
606 if ((rowreq_ctx->data) &&
607 !(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER))
608 ipAddressTable_release_data(rowreq_ctx->data);
609
610 if (rowreq_ctx->undo)
611 ipAddressTable_release_data(rowreq_ctx->undo);
612
613 /*
614 * free index oid pointer
615 */
616 if (rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp)
617 free(rowreq_ctx->oid_idx.oids);
618
619 SNMP_FREE(rowreq_ctx);
620 } /* ipAddressTable_release_rowreq_ctx */
621
622 /**
623 * @internal
624 * wrapper
625 */
626 static int
627 _mfd_ipAddressTable_pre_request(netsnmp_mib_handler *handler,
628 netsnmp_handler_registration *reginfo,
629 netsnmp_agent_request_info *agtreq_info,
630 netsnmp_request_info *requests)
631 {
632 int rc;
633
634 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_pre_request",
635 "called\n"));
636
637 if (1 != netsnmp_row_merge_status_first(reginfo, agtreq_info)) {
638 DEBUGMSGTL(("internal:ipAddressTable",
639 "skipping additional pre_request\n"));
640 return SNMP_ERR_NOERROR;
641 }
642
643 rc = ipAddressTable_pre_request(ipAddressTable_if_ctx.user_ctx);
644 if (MFD_SUCCESS != rc) {
645 /*
646 * nothing we can do about it but log it
647 */
648 DEBUGMSGTL(("ipAddressTable", "error %d from "
649 "ipAddressTable_pre_request\n", rc));
650 netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
651 }
652
653 return SNMP_ERR_NOERROR;
654 } /* _mfd_ipAddressTable_pre_request */
655
656 /**
657 * @internal
658 * wrapper
659 */
660 static int
661 _mfd_ipAddressTable_post_request(netsnmp_mib_handler *handler,
662 netsnmp_handler_registration *reginfo,
663 netsnmp_agent_request_info *agtreq_info,
664 netsnmp_request_info *requests)
665 {
666 ipAddressTable_rowreq_ctx *rowreq_ctx = (ipAddressTable_rowreq_ctx*)
667 netsnmp_container_table_row_extract(requests);
668 int rc, packet_rc;
669
670 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_post_request",
671 "called\n"));
672
673 /*
674 * release row context, if deleted
675 */
676 if (rowreq_ctx && (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED))
677 ipAddressTable_release_rowreq_ctx(rowreq_ctx);
678
679 /*
680 * wait for last call before calling user
681 */
682 if (1 != netsnmp_row_merge_status_last(reginfo, agtreq_info)) {
683 DEBUGMSGTL(("internal:ipAddressTable",
684 "waiting for last post_request\n"));
685 return SNMP_ERR_NOERROR;
686 }
687
688 packet_rc = netsnmp_check_all_requests_error(agtreq_info->asp, 0);
689 if ((MFD_SUCCESS != packet_rc) && ipAddressTable_dirty_get()) {
690 /*
691 * we shouldn't get here. the undo steps should also clear
692 * the dirty flags.
693 */
694 snmp_log(LOG_WARNING,
695 "ipAddressTable dirty flag set in post_request "
696 "but status != SUCCESS.\n");
697 }
698
699 rc = ipAddressTable_post_request(ipAddressTable_if_ctx.user_ctx,
700 packet_rc);
701 if (MFD_SUCCESS != rc) {
702 /*
703 * nothing we can do about it but log it
704 */
705 DEBUGMSGTL(("ipAddressTable", "error %d from "
706 "ipAddressTable_post_request\n", rc));
707 }
708
709 return SNMP_ERR_NOERROR;
710 } /* _mfd_ipAddressTable_post_request */
711
712
713 /**
714 * @internal
715 * wrapper
716 */
717 static ipAddressTable_rowreq_ctx *
718 _mfd_ipAddressTable_rowreq_from_index(netsnmp_index * oid_idx, int *rc_ptr)
719 {
720 ipAddressTable_rowreq_ctx *rowreq_ctx;
721 ipAddressTable_mib_index mib_idx;
722 int rc;
723
724 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_rowreq_from_index", "called\n"));
725
726 if (NULL == rc_ptr)
727 rc_ptr = &rc;
728 *rc_ptr = MFD_SUCCESS;
729
730 memset(&mib_idx, 0x0, sizeof(mib_idx));
731
732 /*
733 * try to parse oid
734 */
735 *rc_ptr = ipAddressTable_index_from_oid(oid_idx, &mib_idx);
736 if (MFD_SUCCESS != *rc_ptr) {
737 DEBUGMSGT(("ipAddressTable", "error parsing index\n"));
738 return NULL;
739 }
740
741 /*
742 * allocate new context
743 */
744 rowreq_ctx = ipAddressTable_allocate_rowreq_ctx(NULL, NULL);
745 if (NULL == rowreq_ctx) {
746 *rc_ptr = MFD_ERROR;
747 return NULL; /* msg already logged */
748 }
749
750 memcpy(&rowreq_ctx->tbl_idx, &mib_idx, sizeof(mib_idx));
751
752 /*
753 * check indexes
754 */
755 *rc_ptr = _ipAddressTable_check_indexes(rowreq_ctx);
756 if (MFD_SUCCESS != *rc_ptr) {
757 netsnmp_assert((*rc_ptr == SNMP_ERR_NOCREATION) ||
758 (*rc_ptr == SNMP_ERR_INCONSISTENTNAME));
759 ipAddressTable_release_rowreq_ctx(rowreq_ctx);
760 return NULL;
761 }
762
763 /*
764 * copy indexes
765 */
766 rowreq_ctx->oid_idx.len = oid_idx->len;
767 memcpy(rowreq_ctx->oid_idx.oids, oid_idx->oids,
768 oid_idx->len * sizeof(oid));
769
770 return rowreq_ctx;
771 } /* _mfd_ipAddressTable_rowreq_from_index */
772
773
774 /**
775 * @internal
776 * wrapper
777 */
778 static int
779 _mfd_ipAddressTable_object_lookup(netsnmp_mib_handler *handler,
780 netsnmp_handler_registration *reginfo,
781 netsnmp_agent_request_info *agtreq_info,
782 netsnmp_request_info *requests)
783 {
784 int rc = SNMP_ERR_NOERROR;
785 ipAddressTable_rowreq_ctx *rowreq_ctx = (ipAddressTable_rowreq_ctx*)
786 netsnmp_container_table_row_extract(requests);
787
788 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_object_lookup", "called\n"));
789
790 /*
791 * get our context from mfd
792 * ipAddressTable_interface_ctx *if_ctx =
793 * (ipAddressTable_interface_ctx *)reginfo->my_reg_void;
794 */
795
796 if (NULL == rowreq_ctx) {
797 #define NETSNMP_IPADDRESSTABLE_CREATE_SUPPORT 1
798 #ifndef NETSNMP_IPADDRESSTABLE_CREATE_SUPPORT
799 rc = SNMP_ERR_NOCREATION;
800 #else
801 netsnmp_table_request_info *tblreq_info;
802 netsnmp_index oid_idx;
803
804 tblreq_info = netsnmp_extract_table_info(requests);
805 if (NULL == tblreq_info) {
806 snmp_log(LOG_ERR, "request had no table info\n");
807 return MFD_ERROR;
808 }
809
810 /*
811 * try create rowreq
812 */
813 oid_idx.oids = tblreq_info->index_oid;
814 oid_idx.len = tblreq_info->index_oid_len;
815
816 rowreq_ctx = _mfd_ipAddressTable_rowreq_from_index(&oid_idx, &rc);
817 if (MFD_SUCCESS == rc) {
818 netsnmp_assert(NULL != rowreq_ctx);
819 rowreq_ctx->rowreq_flags |= MFD_ROW_CREATED;
820 /*
821 * add rowreq_ctx to request data lists
822 */
823 netsnmp_container_table_row_insert(requests, (netsnmp_index *)
824 rowreq_ctx);
825 }
826 #endif
827 }
828
829 if (MFD_SUCCESS != rc)
830 netsnmp_request_set_error_all(requests, rc);
831 else
832 ipAddressTable_row_prep(rowreq_ctx);
833
834 return SNMP_VALIDATE_ERR(rc);
835 } /* _mfd_ipAddressTable_object_lookup */
836
837 /***********************************************************************
838 *
839 * GET processing
840 *
841 ***********************************************************************/
842 /*
843 * @internal
844 * Retrieve the value for a particular column
845 */
846 NETSNMP_STATIC_INLINE int
847 _ipAddressTable_get_column(ipAddressTable_rowreq_ctx * rowreq_ctx,
848 netsnmp_variable_list * var, int column)
849 {
850 int rc = SNMPERR_SUCCESS;
851
852 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_get_column",
853 "called for %d\n", column));
854
855
856 netsnmp_assert(NULL != rowreq_ctx);
857
858 switch (column) {
859
860 /*
861 * ipAddressIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/W/e/R/d/H
862 */
863 case COLUMN_IPADDRESSIFINDEX:
864 var->val_len = sizeof(long);
865 var->type = ASN_INTEGER;
866 rc = ipAddressIfIndex_get(rowreq_ctx, (long *) var->val.string);
867 break;
868
869 /*
870 * ipAddressType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
871 */
872 case COLUMN_IPADDRESSTYPE:
873 var->val_len = sizeof(u_long);
874 var->type = ASN_INTEGER;
875 rc = ipAddressType_get(rowreq_ctx, (u_long *) var->val.string);
876 break;
877
878 /*
879 * ipAddressPrefix(5)/RowPointer/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/D/h
880 */
881 case COLUMN_IPADDRESSPREFIX:
882 var->type = ASN_OBJECT_ID;
883 rc = ipAddressPrefix_get(rowreq_ctx, (oid **) & var->val.string,
884 &var->val_len);
885 break;
886
887 /*
888 * ipAddressOrigin(6)/IpAddressOriginTC/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h
889 */
890 case COLUMN_IPADDRESSORIGIN:
891 var->val_len = sizeof(u_long);
892 var->type = ASN_INTEGER;
893 rc = ipAddressOrigin_get(rowreq_ctx, (u_long *) var->val.string);
894 break;
895
896 /*
897 * ipAddressStatus(7)/IpAddressStatusTC/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
898 */
899 case COLUMN_IPADDRESSSTATUS:
900 var->val_len = sizeof(u_long);
901 var->type = ASN_INTEGER;
902 rc = ipAddressStatus_get(rowreq_ctx, (u_long *) var->val.string);
903 break;
904
905 /*
906 * ipAddressCreated(8)/TimeStamp/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h
907 */
908 case COLUMN_IPADDRESSCREATED:
909 var->val_len = sizeof(u_long);
910 var->type = ASN_TIMETICKS;
911 rc = ipAddressCreated_get(rowreq_ctx, (u_long *) var->val.string);
912 break;
913
914 /*
915 * ipAddressLastChanged(9)/TimeStamp/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h
916 */
917 case COLUMN_IPADDRESSLASTCHANGED:
918 var->val_len = sizeof(u_long);
919 var->type = ASN_TIMETICKS;
920 rc = ipAddressLastChanged_get(rowreq_ctx,
921 (u_long *) var->val.string);
922 break;
923
924 /*
925 * ipAddressRowStatus(10)/RowStatus/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h
926 */
927 case COLUMN_IPADDRESSROWSTATUS:
928 var->val_len = sizeof(u_long);
929 var->type = ASN_INTEGER;
930 rc = ipAddressRowStatus_get(rowreq_ctx,
931 (u_long *) var->val.string);
932 break;
933
934 /*
935 * ipAddressStorageType(11)/StorageType/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
936 */
937 case COLUMN_IPADDRESSSTORAGETYPE:
938 var->val_len = sizeof(u_long);
939 var->type = ASN_INTEGER;
940 rc = ipAddressStorageType_get(rowreq_ctx,
941 (u_long *) var->val.string);
942 break;
943
944 default:
945 snmp_log(LOG_ERR,
946 "unknown column %d in _ipAddressTable_get_column\n",
947 column);
948 break;
949 }
950
951 return rc;
952 } /* _ipAddressTable_get_column */
953
954 int
955 _mfd_ipAddressTable_get_values(netsnmp_mib_handler *handler,
956 netsnmp_handler_registration *reginfo,
957 netsnmp_agent_request_info *agtreq_info,
958 netsnmp_request_info *requests)
959 {
960 ipAddressTable_rowreq_ctx *rowreq_ctx = (ipAddressTable_rowreq_ctx*)
961 netsnmp_container_table_row_extract(requests);
962 netsnmp_table_request_info *tri;
963 u_char *old_string;
964 void (*dataFreeHook) (void *);
965 int rc;
966
967 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_get_values",
968 "called\n"));
969
970 netsnmp_assert(NULL != rowreq_ctx);
971
972 for (; requests; requests = requests->next) {
973 /*
974 * save old pointer, so we can free it if replaced
975 */
976 old_string = requests->requestvb->val.string;
977 dataFreeHook = requests->requestvb->dataFreeHook;
978 if (NULL == requests->requestvb->val.string) {
979 requests->requestvb->val.string = requests->requestvb->buf;
980 requests->requestvb->val_len =
981 sizeof(requests->requestvb->buf);
982 } else if (requests->requestvb->buf ==
983 requests->requestvb->val.string) {
984 if (requests->requestvb->val_len !=
985 sizeof(requests->requestvb->buf))
986 requests->requestvb->val_len =
987 sizeof(requests->requestvb->buf);
988 }
989
990 /*
991 * get column data
992 */
993 tri = netsnmp_extract_table_info(requests);
994 if (NULL == tri)
995 continue;
996
997 rc = _ipAddressTable_get_column(rowreq_ctx, requests->requestvb,
998 tri->colnum);
999 if (rc) {
1000 if (MFD_SKIP == rc) {
1001 requests->requestvb->type = SNMP_NOSUCHINSTANCE;
1002 rc = SNMP_ERR_NOERROR;
1003 }
1004 } else if (NULL == requests->requestvb->val.string) {
1005 snmp_log(LOG_ERR, "NULL varbind data pointer!\n");
1006 rc = SNMP_ERR_GENERR;
1007 }
1008 if (rc)
1009 netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc));
1010
1011 /*
1012 * if the buffer wasn't used previously for the old data (i.e. it
1013 * was allocated memory) and the get routine replaced the pointer,
1014 * we need to free the previous pointer.
1015 */
1016 if (old_string && (old_string != requests->requestvb->buf) &&
1017 (requests->requestvb->val.string != old_string)) {
1018 if (dataFreeHook)
1019 (*dataFreeHook) (old_string);
1020 else
1021 free(old_string);
1022 }
1023 } /* for results */
1024
1025 return SNMP_ERR_NOERROR;
1026 } /* _mfd_ipAddressTable_get_values */
1027
1028 NETSNMP_STATIC_INLINE int
1029 _ipAddressTable_check_indexes(ipAddressTable_rowreq_ctx * rowreq_ctx)
1030 {
1031 int rc = SNMPERR_SUCCESS;
1032
1033 DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_check_indexes",
1034 "called\n"));
1035
1036 netsnmp_assert(NULL != rowreq_ctx);
1037
1038
1039 /*
1040 * (INDEX) ipAddressAddrType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h
1041 */
1042 /*
1043 * check that the value is one of defined enums
1044 */
1045 if ((SNMPERR_SUCCESS == rc)
1046 && (rowreq_ctx->tbl_idx.ipAddressAddrType !=
1047 INETADDRESSTYPE_UNKNOWN)
1048 && (rowreq_ctx->tbl_idx.ipAddressAddrType != INETADDRESSTYPE_IPV4)
1049 && (rowreq_ctx->tbl_idx.ipAddressAddrType != INETADDRESSTYPE_IPV6)
1050 && (rowreq_ctx->tbl_idx.ipAddressAddrType != INETADDRESSTYPE_IPV4Z)
1051 && (rowreq_ctx->tbl_idx.ipAddressAddrType != INETADDRESSTYPE_IPV6Z)
1052 && (rowreq_ctx->tbl_idx.ipAddressAddrType != INETADDRESSTYPE_DNS)
1053 ) {
1054 rc = SNMP_ERR_WRONGVALUE;
1055 }
1056 if (MFD_SUCCESS != rc)
1057 return rc;
1058 rc = ipAddressAddrType_check_index(rowreq_ctx);
1059 if (MFD_SUCCESS != rc)
1060 return SNMP_ERR_NOCREATION;
1061
1062 /*
1063 * (INDEX) ipAddressAddr(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h
1064 */
1065 /*
1066 * check defined range(s).
1067 */
1068 if (rc == SNMPERR_SUCCESS && rowreq_ctx->tbl_idx.ipAddressAddr_len > 255) {
1069 rc = SNMP_ERR_WRONGLENGTH;
1070 }
1071 if (MFD_SUCCESS != rc)
1072 return rc;
1073 rc = ipAddressAddr_check_index(rowreq_ctx);
1074 if (MFD_SUCCESS != rc)
1075 return SNMP_ERR_NOCREATION;
1076
1077 /*
1078 * if individual parts look ok, check them as a whole
1079 */
1080 return ipAddressTable_validate_index(ipAddressTable_if_ctx.user_ctx,
1081 rowreq_ctx);
1082 } /* _ipAddressTable_check_indexes */
1083
1084 #if !(defined(NETSNMP_NO_WRITE_SUPPORT) || defined(NETSNMP_DISABLE_SET_SUPPORT))
1085 /***********************************************************************
1086 *
1087 * SET processing
1088 *
1089 ***********************************************************************/
1090
1091 /*----------------------------------------------------------------------
1092 *
1093 * SET: Syntax checks
1094 *
1095 *---------------------------------------------------------------------*/
1096 /*
1097 * @internal
1098 * Check the syntax for a particular column
1099 */
1100 NETSNMP_STATIC_INLINE int
1101 _ipAddressTable_check_column(ipAddressTable_rowreq_ctx * rowreq_ctx,
1102 netsnmp_variable_list * var, int column)
1103 {
1104 int rc = SNMPERR_SUCCESS;
1105
1106 DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_check_column",
1107 "called for %d\n", column));
1108
1109 netsnmp_assert(NULL != rowreq_ctx);
1110
1111 switch (column) {
1112 /*
1113 * (INDEX) ipAddressAddrType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h
1114 */
1115 case COLUMN_IPADDRESSADDRTYPE:
1116 rc = SNMP_ERR_NOTWRITABLE; /* can not change index of active row */
1117 break;
1118 /*
1119 * (INDEX) ipAddressAddr(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h
1120 */
1121 case COLUMN_IPADDRESSADDR:
1122 rc = SNMP_ERR_NOTWRITABLE; /* can not change index of active row */
1123 break;
1124
1125 /*
1126 * ipAddressIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/W/e/R/d/H
1127 */
1128 case COLUMN_IPADDRESSIFINDEX:
1129 rc = netsnmp_check_vb_type(var, ASN_INTEGER);
1130 /*
1131 * check defined range(s).
1132 */
1133 if ((SNMPERR_SUCCESS == rc)
1134 && ((*var->val.integer < 1)
1135 || (*var->val.integer > 2147483647))
1136 ) {
1137 rc = SNMP_ERR_WRONGVALUE;
1138 }
1139 if (SNMPERR_SUCCESS != rc) {
1140 DEBUGMSGTL(("ipAddressTable:_ipAddressTable_check_column:ipAddressIfIndex", "varbind validation failed (eg bad type or size)\n"));
1141 } else {
1142 rc = ipAddressIfIndex_check_value(rowreq_ctx,
1143 *((long *) var->val.string));
1144 if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)
1145 && (MFD_NOT_VALID_NOW != rc)) {
1146 snmp_log(LOG_ERR,
1147 "bad rc %d from ipAddressIfIndex_check_value\n",
1148 rc);
1149 rc = SNMP_ERR_GENERR;
1150 }
1151 }
1152 break;
1153
1154 /*
1155 * ipAddressType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
1156 */
1157 case COLUMN_IPADDRESSTYPE:
1158 rc = netsnmp_check_vb_type(var, ASN_INTEGER);
1159 /*
1160 * check that the value is one of defined enums
1161 */
1162 if ((SNMPERR_SUCCESS == rc)
1163 && (*var->val.integer != IPADDRESSTYPE_UNICAST)
1164 && (*var->val.integer != IPADDRESSTYPE_ANYCAST)
1165 && (*var->val.integer != IPADDRESSTYPE_BROADCAST)
1166 ) {
1167 rc = SNMP_ERR_WRONGVALUE;
1168 }
1169 if (SNMPERR_SUCCESS != rc) {
1170 DEBUGMSGTL(("ipAddressTable:_ipAddressTable_check_column:ipAddressType", "varbind validation failed (eg bad type or size)\n"));
1171 } else {
1172 rc = ipAddressType_check_value(rowreq_ctx,
1173 *((u_long *) var->val.string));
1174 if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)
1175 && (MFD_NOT_VALID_NOW != rc)) {
1176 snmp_log(LOG_ERR,
1177 "bad rc %d from ipAddressType_check_value\n", rc);
1178 rc = SNMP_ERR_GENERR;
1179 }
1180 }
1181 break;
1182
1183 /*
1184 * ipAddressPrefix(5)/RowPointer/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/D/h
1185 */
1186 case COLUMN_IPADDRESSPREFIX:
1187 rc = SNMP_ERR_NOTWRITABLE;
1188 break;
1189
1190 /*
1191 * ipAddressOrigin(6)/IpAddressOriginTC/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h
1192 */
1193 case COLUMN_IPADDRESSORIGIN:
1194 rc = SNMP_ERR_NOTWRITABLE;
1195 break;
1196
1197 /*
1198 * ipAddressStatus(7)/IpAddressStatusTC/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
1199 */
1200 case COLUMN_IPADDRESSSTATUS:
1201 rc = netsnmp_check_vb_type(var, ASN_INTEGER);
1202 /*
1203 * check that the value is one of defined enums
1204 */
1205 if ((SNMPERR_SUCCESS == rc)
1206 && (*var->val.integer != IPADDRESSSTATUSTC_PREFERRED)
1207 && (*var->val.integer != IPADDRESSSTATUSTC_INVALID)
1208 && (*var->val.integer != IPADDRESSSTATUSTC_INACCESSIBLE)
1209 && (*var->val.integer != IPADDRESSSTATUSTC_UNKNOWN)
1210 && (*var->val.integer != IPADDRESSSTATUSTC_TENTATIVE)
1211 && (*var->val.integer != IPADDRESSSTATUSTC_DUPLICATE)
1212 ) {
1213 rc = SNMP_ERR_WRONGVALUE;
1214 }
1215 if (SNMPERR_SUCCESS != rc) {
1216 DEBUGMSGTL(("ipAddressTable:_ipAddressTable_check_column:ipAddressStatus", "varbind validation failed (eg bad type or size)\n"));
1217 } else {
1218 rc = ipAddressStatus_check_value(rowreq_ctx,
1219 *((u_long *) var->val.
1220 string));
1221 if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)
1222 && (MFD_NOT_VALID_NOW != rc)) {
1223 snmp_log(LOG_ERR,
1224 "bad rc %d from ipAddressStatus_check_value\n",
1225 rc);
1226 rc = SNMP_ERR_GENERR;
1227 }
1228 }
1229 break;
1230
1231 /*
1232 * ipAddressCreated(8)/TimeStamp/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h
1233 */
1234 case COLUMN_IPADDRESSCREATED:
1235 rc = SNMP_ERR_NOTWRITABLE;
1236 break;
1237
1238 /*
1239 * ipAddressLastChanged(9)/TimeStamp/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h
1240 */
1241 case COLUMN_IPADDRESSLASTCHANGED:
1242 rc = SNMP_ERR_NOTWRITABLE;
1243 break;
1244
1245 /*
1246 * ipAddressRowStatus(10)/RowStatus/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h
1247 */
1248 case COLUMN_IPADDRESSROWSTATUS:
1249 rc = netsnmp_check_vb_rowstatus_value(var);
1250 if (SNMPERR_SUCCESS != rc) {
1251 DEBUGMSGTL(("ipAddressTable:_ipAddressTable_check_column:ipAddressRowStatus", "varbind validation failed (eg bad type or size)\n"));
1252 } else {
1253 rc = ipAddressRowStatus_check_value(rowreq_ctx,
1254 *((u_long *) var->val.
1255 string));
1256 if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)
1257 && (MFD_NOT_VALID_NOW != rc)) {
1258 snmp_log(LOG_ERR,
1259 "bad rc %d from ipAddressRowStatus_check_value\n",
1260 rc);
1261 rc = SNMP_ERR_GENERR;
1262 }
1263 }
1264 break;
1265
1266 /*
1267 * ipAddressStorageType(11)/StorageType/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
1268 */
1269 case COLUMN_IPADDRESSSTORAGETYPE:
1270 rc = netsnmp_check_vb_type(var, ASN_INTEGER);
1271 /*
1272 * check that the value is one of defined enums
1273 */
1274 if ((SNMPERR_SUCCESS == rc)
1275 && (*var->val.integer != STORAGETYPE_OTHER)
1276 && (*var->val.integer != STORAGETYPE_VOLATILE)
1277 && (*var->val.integer != STORAGETYPE_NONVOLATILE)
1278 && (*var->val.integer != STORAGETYPE_PERMANENT)
1279 && (*var->val.integer != STORAGETYPE_READONLY)
1280 ) {
1281 rc = SNMP_ERR_WRONGVALUE;
1282 }
1283 if (SNMPERR_SUCCESS != rc) {
1284 DEBUGMSGTL(("ipAddressTable:_ipAddressTable_check_column:ipAddressStorageType", "varbind validation failed (eg bad type or size)\n"));
1285 } else {
1286 rc = ipAddressStorageType_check_value(rowreq_ctx,
1287 *((u_long *) var->val.
1288 string));
1289 if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)
1290 && (MFD_NOT_VALID_NOW != rc)) {
1291 snmp_log(LOG_ERR,
1292 "bad rc %d from ipAddressStorageType_check_value\n",
1293 rc);
1294 rc = SNMP_ERR_GENERR;
1295 }
1296 }
1297 break;
1298
1299 default: /** We shouldn't get here */
1300 rc = SNMP_ERR_GENERR;
1301 snmp_log(LOG_ERR,
1302 "unknown column %d in _ipAddressTable_check_column\n",
1303 column);
1304 }
1305
1306 return rc;
1307 } /* _ipAddressTable_check_column */
1308
1309 int
1310 _mfd_ipAddressTable_check_objects(netsnmp_mib_handler *handler,
1311 netsnmp_handler_registration *reginfo,
1312 netsnmp_agent_request_info *agtreq_info,
1313 netsnmp_request_info *requests)
1314 {
1315 ipAddressTable_rowreq_ctx *rowreq_ctx = (ipAddressTable_rowreq_ctx*)
1316 netsnmp_container_table_row_extract(requests);
1317 netsnmp_table_request_info *tri;
1318 int rc;
1319
1320 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_check_objects", "called\n"));
1321
1322 netsnmp_assert(NULL != rowreq_ctx);
1323
1324 for (; requests; requests = requests->next) {
1325
1326 /*
1327 * get column number from table request info, and check that column
1328 */
1329 tri = netsnmp_extract_table_info(requests);
1330 if (NULL == tri)
1331 continue;
1332
1333 rc = _ipAddressTable_check_column(rowreq_ctx, requests->requestvb,
1334 tri->colnum);
1335 if (rc) {
1336 netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc));
1337 break;
1338 }
1339
1340 } /* for results */
1341
1342 return SNMP_ERR_NOERROR;
1343 } /* _mfd_ipAddressTable_check_objects */
1344
1345
1346 /*----------------------------------------------------------------------
1347 *
1348 * SET: check dependencies
1349 *
1350 *---------------------------------------------------------------------*/
1351 /*
1352 * @internal
1353 * Check dependencies wrapper
1354 */
1355 static int
1356 _mfd_ipAddressTable_check_dependencies(netsnmp_mib_handler *handler, netsnmp_handler_registration
1357 *reginfo, netsnmp_agent_request_info
1358 *agtreq_info,
1359 netsnmp_request_info *requests)
1360 {
1361 int rc;
1362 ipAddressTable_rowreq_ctx *rowreq_ctx = (ipAddressTable_rowreq_ctx*)
1363 netsnmp_container_table_row_extract(requests);
1364 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_check_dependencies", "called\n"));
1365
1366 netsnmp_assert(NULL != rowreq_ctx);
1367
1368 rc = ipAddressTable_check_dependencies(rowreq_ctx);
1369 if (rc) {
1370 DEBUGMSGTL(("ipAddressTable:mfd", "error %d from "
1371 "ipAddressTable_check_dependencies\n", rc));
1372 netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
1373 }
1374
1375 return SNMP_ERR_NOERROR;
1376 } /* _mfd_ipAddressTable_check_dependencies */
1377
1378 /*----------------------------------------------------------------------
1379 *
1380 * SET: Undo setup
1381 *
1382 *---------------------------------------------------------------------*/
1383 /*
1384 * @internal
1385 * Set the value for a particular column
1386 */
1387 NETSNMP_STATIC_INLINE int
1388 _ipAddressTable_undo_setup_column(ipAddressTable_rowreq_ctx * rowreq_ctx,
1389 int column)
1390 {
1391 int rc = SNMPERR_SUCCESS;
1392
1393 DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_undo_setup_column", "called for %d\n", column));
1394
1395 netsnmp_assert(NULL != rowreq_ctx);
1396
1397 switch (column) {
1398
1399 /*
1400 * ipAddressIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/W/e/R/d/H
1401 */
1402 case COLUMN_IPADDRESSIFINDEX:
1403 rowreq_ctx->column_set_flags |= COLUMN_IPADDRESSIFINDEX_FLAG;
1404 rc = ipAddressIfIndex_undo_setup(rowreq_ctx);
1405 break;
1406
1407 /*
1408 * ipAddressType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
1409 */
1410 case COLUMN_IPADDRESSTYPE:
1411 rowreq_ctx->column_set_flags |= COLUMN_IPADDRESSTYPE_FLAG;
1412 rc = ipAddressType_undo_setup(rowreq_ctx);
1413 break;
1414
1415 /*
1416 * ipAddressStatus(7)/IpAddressStatusTC/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
1417 */
1418 case COLUMN_IPADDRESSSTATUS:
1419 rowreq_ctx->column_set_flags |= COLUMN_IPADDRESSSTATUS_FLAG;
1420 rc = ipAddressStatus_undo_setup(rowreq_ctx);
1421 break;
1422
1423 /*
1424 * ipAddressRowStatus(10)/RowStatus/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h
1425 */
1426 case COLUMN_IPADDRESSROWSTATUS:
1427 rowreq_ctx->column_set_flags |= COLUMN_IPADDRESSROWSTATUS_FLAG;
1428 rc = ipAddressRowStatus_undo_setup(rowreq_ctx);
1429 break;
1430
1431 /*
1432 * ipAddressStorageType(11)/StorageType/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
1433 */
1434 case COLUMN_IPADDRESSSTORAGETYPE:
1435 rowreq_ctx->column_set_flags |= COLUMN_IPADDRESSSTORAGETYPE_FLAG;
1436 rc = ipAddressStorageType_undo_setup(rowreq_ctx);
1437 break;
1438
1439 default:
1440 snmp_log(LOG_ERR,
1441 "unknown column %d in _ipAddressTable_undo_setup_column\n",
1442 column);
1443 break;
1444 }
1445
1446 return rc;
1447 } /* _ipAddressTable_undo_setup_column */
1448
1449
1450 /**
1451 * @internal
1452 * undo setup
1453 */
1454 int
1455 _mfd_ipAddressTable_undo_setup(netsnmp_mib_handler *handler,
1456 netsnmp_handler_registration *reginfo,
1457 netsnmp_agent_request_info *agtreq_info,
1458 netsnmp_request_info *requests)
1459 {
1460 int rc;
1461 ipAddressTable_rowreq_ctx *rowreq_ctx = (ipAddressTable_rowreq_ctx*)
1462 netsnmp_container_table_row_extract(requests);
1463
1464 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_undo_setup",
1465 "called\n"));
1466
1467 netsnmp_assert(NULL != rowreq_ctx);
1468
1469 /*
1470 * allocate undo context
1471 */
1472 rowreq_ctx->undo = ipAddressTable_allocate_data();
1473 if (NULL == rowreq_ctx->undo) {
1474 /** msg already logged */
1475 netsnmp_request_set_error_all(requests,
1476 SNMP_ERR_RESOURCEUNAVAILABLE);
1477 return SNMP_ERR_NOERROR;
1478 }
1479
1480 /*
1481 * row undo setup
1482 */
1483 rowreq_ctx->column_set_flags = 0;
1484 rc = ipAddressTable_undo_setup(rowreq_ctx);
1485 if (MFD_SUCCESS != rc) {
1486 DEBUGMSGTL(("ipAddressTable:mfd", "error %d from "
1487 "ipAddressTable_undo_setup\n", rc));
1488 netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
1489 } else {
1490 /*
1491 * column undo setup
1492 */
1493 netsnmp_table_request_info *tri;
1494 for (; requests; requests = requests->next) {
1495 /*
1496 * set column data
1497 */
1498 tri = netsnmp_extract_table_info(requests);
1499 if (NULL == tri)
1500 continue;
1501
1502 rc = _ipAddressTable_undo_setup_column(rowreq_ctx,
1503 tri->colnum);
1504 if (MFD_SUCCESS != rc) {
1505 DEBUGMSGTL(("ipAddressTable:mfd", "error %d from "
1506 "ipAddressTable_undo_setup_column\n", rc));
1507 netsnmp_set_request_error(agtreq_info, requests,
1508 SNMP_VALIDATE_ERR(rc));
1509 }
1510 } /* for results */
1511 }
1512
1513 return SNMP_ERR_NOERROR;
1514 } /* _mfd_ipAddressTable_undo_setup */
1515
1516 /**
1517 * @internal
1518 * undo setup
1519 */
1520 int
1521 _mfd_ipAddressTable_undo_cleanup(netsnmp_mib_handler *handler,
1522 netsnmp_handler_registration *reginfo,
1523 netsnmp_agent_request_info *agtreq_info,
1524 netsnmp_request_info *requests)
1525 {
1526 ipAddressTable_rowreq_ctx *rowreq_ctx = (ipAddressTable_rowreq_ctx*)
1527 netsnmp_container_table_row_extract(requests);
1528 int rc;
1529
1530 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_undo_cleanup",
1531 "called\n"));
1532
1533 /*
1534 * failed row create in early stages has no rowreq_ctx
1535 */
1536 if (NULL == rowreq_ctx)
1537 return MFD_SUCCESS;
1538
1539 /*
1540 * call user cleanup
1541 */
1542 rc = ipAddressTable_undo_cleanup(rowreq_ctx);
1543 if (MFD_SUCCESS != rc) {
1544 /*
1545 * nothing we can do about it but log it
1546 */
1547 DEBUGMSGTL(("ipAddressTable:mfd", "error %d from "
1548 "ipAddressTable_undo_cleanup\n", rc));
1549 }
1550
1551 /*
1552 * release undo context, if needed
1553 */
1554 if (rowreq_ctx->undo) {
1555 ipAddressTable_release_data(rowreq_ctx->undo);
1556 rowreq_ctx->undo = NULL;
1557 }
1558
1559
1560 return SNMP_ERR_NOERROR;
1561 } /* _mfd_ipAddressTable_undo_cleanup */
1562
1563 /*----------------------------------------------------------------------
1564 *
1565 * SET: Set values
1566 *
1567 *---------------------------------------------------------------------*/
1568 /*
1569 * @internal
1570 * Set the value for a particular column
1571 */
1572 NETSNMP_STATIC_INLINE int
1573 _ipAddressTable_set_column(ipAddressTable_rowreq_ctx * rowreq_ctx,
1574 netsnmp_variable_list * var, int column)
1575 {
1576 int rc = SNMPERR_SUCCESS;
1577
1578 DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_set_column",
1579 "called for %d\n", column));
1580
1581 netsnmp_assert(NULL != rowreq_ctx);
1582
1583 switch (column) {
1584
1585 /*
1586 * ipAddressIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/W/e/R/d/H
1587 */
1588 case COLUMN_IPADDRESSIFINDEX:
1589 rowreq_ctx->column_set_flags |= COLUMN_IPADDRESSIFINDEX_FLAG;
1590 rc = ipAddressIfIndex_set(rowreq_ctx, *((long *) var->val.string));
1591 break;
1592
1593 /*
1594 * ipAddressType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
1595 */
1596 case COLUMN_IPADDRESSTYPE:
1597 rowreq_ctx->column_set_flags |= COLUMN_IPADDRESSTYPE_FLAG;
1598 rc = ipAddressType_set(rowreq_ctx, *((u_long *) var->val.string));
1599 break;
1600
1601 /*
1602 * ipAddressStatus(7)/IpAddressStatusTC/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
1603 */
1604 case COLUMN_IPADDRESSSTATUS:
1605 rowreq_ctx->column_set_flags |= COLUMN_IPADDRESSSTATUS_FLAG;
1606 rc = ipAddressStatus_set(rowreq_ctx,
1607 *((u_long *) var->val.string));
1608 break;
1609
1610 /*
1611 * ipAddressRowStatus(10)/RowStatus/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h
1612 */
1613 case COLUMN_IPADDRESSROWSTATUS:
1614 rowreq_ctx->column_set_flags |= COLUMN_IPADDRESSROWSTATUS_FLAG;
1615 rc = ipAddressRowStatus_set(rowreq_ctx,
1616 *((u_long *) var->val.string));
1617 break;
1618
1619 /*
1620 * ipAddressStorageType(11)/StorageType/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
1621 */
1622 case COLUMN_IPADDRESSSTORAGETYPE:
1623 rowreq_ctx->column_set_flags |= COLUMN_IPADDRESSSTORAGETYPE_FLAG;
1624 rc = ipAddressStorageType_set(rowreq_ctx,
1625 *((u_long *) var->val.string));
1626 break;
1627
1628 default:
1629 snmp_log(LOG_ERR,
1630 "unknown column %d in _ipAddressTable_set_column\n",
1631 column);
1632 rc = SNMP_ERR_GENERR;
1633 break;
1634 }
1635
1636 return rc;
1637 } /* _ipAddressTable_set_column */
1638
1639 int
1640 _mfd_ipAddressTable_set_values(netsnmp_mib_handler *handler,
1641 netsnmp_handler_registration *reginfo,
1642 netsnmp_agent_request_info *agtreq_info,
1643 netsnmp_request_info *requests)
1644 {
1645 ipAddressTable_rowreq_ctx *rowreq_ctx = (ipAddressTable_rowreq_ctx*)
1646 netsnmp_container_table_row_extract(requests);
1647 netsnmp_table_request_info *tri;
1648 int rc = SNMP_ERR_NOERROR;
1649
1650 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_set_values",
1651 "called\n"));
1652
1653 netsnmp_assert(NULL != rowreq_ctx);
1654
1655 rowreq_ctx->column_set_flags = 0;
1656 for (; requests; requests = requests->next) {
1657 /*
1658 * set column data
1659 */
1660 tri = netsnmp_extract_table_info(requests);
1661 if (NULL == tri)
1662 continue;
1663
1664 rc = _ipAddressTable_set_column(rowreq_ctx,
1665 requests->requestvb, tri->colnum);
1666 if (MFD_SUCCESS != rc) {
1667 DEBUGMSGTL(("ipAddressTable:mfd", "error %d from "
1668 "ipAddressTable_set_column\n", rc));
1669 netsnmp_set_request_error(agtreq_info, requests,
1670 SNMP_VALIDATE_ERR(rc));
1671 }
1672 } /* for results */
1673
1674 return SNMP_ERR_NOERROR;
1675 } /* _mfd_ipAddressTable_set_values */
1676
1677 /*----------------------------------------------------------------------
1678 *
1679 * SET: commit
1680 *
1681 *---------------------------------------------------------------------*/
1682 /**
1683 * @internal
1684 * commit the values
1685 */
1686 int
1687 _mfd_ipAddressTable_commit(netsnmp_mib_handler *handler,
1688 netsnmp_handler_registration *reginfo,
1689 netsnmp_agent_request_info *agtreq_info,
1690 netsnmp_request_info *requests)
1691 {
1692 int rc;
1693 ipAddressTable_rowreq_ctx *rowreq_ctx = (ipAddressTable_rowreq_ctx*)
1694 netsnmp_container_table_row_extract(requests);
1695
1696 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_commit",
1697 "called\n"));
1698
1699 netsnmp_assert(NULL != rowreq_ctx);
1700
1701 rc = ipAddressTable_commit(rowreq_ctx);
1702 if (MFD_SUCCESS != rc) {
1703 DEBUGMSGTL(("ipAddressTable:mfd", "error %d from "
1704 "ipAddressTable_commit\n", rc));
1705 netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
1706 }
1707
1708 if (rowreq_ctx->rowreq_flags & MFD_ROW_DIRTY) {
1709 /*
1710 * if we successfully committed this row, set the dirty flag. Use the
1711 * current value + 1 (i.e. dirty = # rows changed).
1712 * this is checked in post_request...
1713 */
1714 ipAddressTable_dirty_set(ipAddressTable_dirty_get() + 1); /* set table dirty flag */
1715 }
1716
1717 return SNMP_ERR_NOERROR;
1718 }
1719
1720 int
1721 _mfd_ipAddressTable_undo_commit(netsnmp_mib_handler *handler,
1722 netsnmp_handler_registration *reginfo,
1723 netsnmp_agent_request_info *agtreq_info,
1724 netsnmp_request_info *requests)
1725 {
1726 int rc;
1727 ipAddressTable_rowreq_ctx *rowreq_ctx = (ipAddressTable_rowreq_ctx*)
1728 netsnmp_container_table_row_extract(requests);
1729
1730 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_undo_commit",
1731 "called\n"));
1732
1733 netsnmp_assert(NULL != rowreq_ctx);
1734
1735 if (rowreq_ctx->rowreq_flags & MFD_ROW_DIRTY) {
1736 u_int d = ipAddressTable_dirty_get();
1737
1738 netsnmp_assert(d != 0);
1739 if (d)
1740 ipAddressTable_dirty_set(d - 1);
1741 }
1742
1743 rc = ipAddressTable_undo_commit(rowreq_ctx);
1744 if (MFD_SUCCESS != rc) {
1745 /*
1746 * nothing we can do about it but log it
1747 */
1748 DEBUGMSGTL(("ipAddressTable:mfd", "error %d from "
1749 "ipAddressTable_undo_commit\n", rc));
1750 }
1751
1752 if (rowreq_ctx->rowreq_flags & MFD_ROW_DIRTY) {
1753 snmp_log(LOG_WARNING,
1754 "ipAddressTable row dirty flag still set after undo_commit\n");
1755 rowreq_ctx->rowreq_flags &= ~MFD_ROW_DIRTY;
1756 }
1757
1758 return SNMP_ERR_NOERROR;
1759 } /* _mfd_ipAddressTable_commit */
1760
1761 /*----------------------------------------------------------------------
1762 *
1763 * SET: Undo
1764 *
1765 *---------------------------------------------------------------------*/
1766 /**
1767 * @internal
1768 * undo the value for a particular column
1769 */
1770 NETSNMP_STATIC_INLINE int
1771 _ipAddressTable_undo_column(ipAddressTable_rowreq_ctx * rowreq_ctx,
1772 netsnmp_variable_list * var, int column)
1773 {
1774 int rc = SNMPERR_SUCCESS;
1775
1776 DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_undo_column",
1777 "called for %d\n", column));
1778
1779 netsnmp_assert(NULL != rowreq_ctx);
1780
1781 switch (column) {
1782
1783 /*
1784 * ipAddressIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/W/e/R/d/H
1785 */
1786 case COLUMN_IPADDRESSIFINDEX:
1787 rc = ipAddressIfIndex_undo(rowreq_ctx);
1788 break;
1789
1790 /*
1791 * ipAddressType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
1792 */
1793 case COLUMN_IPADDRESSTYPE:
1794 rc = ipAddressType_undo(rowreq_ctx);
1795 break;
1796
1797 /*
1798 * ipAddressStatus(7)/IpAddressStatusTC/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
1799 */
1800 case COLUMN_IPADDRESSSTATUS:
1801 rc = ipAddressStatus_undo(rowreq_ctx);
1802 break;
1803
1804 /*
1805 * ipAddressRowStatus(10)/RowStatus/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h
1806 */
1807 case COLUMN_IPADDRESSROWSTATUS:
1808 rc = ipAddressRowStatus_undo(rowreq_ctx);
1809 break;
1810
1811 /*
1812 * ipAddressStorageType(11)/StorageType/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h
1813 */
1814 case COLUMN_IPADDRESSSTORAGETYPE:
1815 rc = ipAddressStorageType_undo(rowreq_ctx);
1816 break;
1817
1818 default:
1819 snmp_log(LOG_ERR,
1820 "unknown column %d in _ipAddressTable_undo_column\n",
1821 column);
1822 break;
1823 }
1824
1825 return rc;
1826 } /* _ipAddressTable_undo_column */
1827
1828 int
1829 _mfd_ipAddressTable_undo_values(netsnmp_mib_handler *handler,
1830 netsnmp_handler_registration *reginfo,
1831 netsnmp_agent_request_info *agtreq_info,
1832 netsnmp_request_info *requests)
1833 {
1834 int rc;
1835 ipAddressTable_rowreq_ctx *rowreq_ctx = (ipAddressTable_rowreq_ctx*)
1836 netsnmp_container_table_row_extract(requests);
1837 netsnmp_table_request_info *tri;
1838
1839 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_undo_values",
1840 "called\n"));
1841
1842 netsnmp_assert(NULL != rowreq_ctx);
1843
1844 rc = ipAddressTable_undo(rowreq_ctx);
1845 if (MFD_SUCCESS != rc) {
1846 /*
1847 * nothing we can do about it but log it
1848 */
1849 DEBUGMSGTL(("ipAddressTable:mfd", "error %d from "
1850 "ipAddressTable_undo\n", rc));
1851 }
1852
1853 for (; requests; requests = requests->next) {
1854 /*
1855 * set column data
1856 */
1857 tri = netsnmp_extract_table_info(requests);
1858 if (NULL == tri)
1859 continue;
1860
1861 rc = _ipAddressTable_undo_column(rowreq_ctx, requests->requestvb,
1862 tri->colnum);
1863 if (MFD_SUCCESS != rc) {
1864 /*
1865 * nothing we can do about it but log it
1866 */
1867 DEBUGMSGTL(("ipAddressTable:mfd", "error %d from "
1868 "ipAddressTable_undo_column\n", rc));
1869 }
1870 } /* for results */
1871
1872 return SNMP_ERR_NOERROR;
1873 } /* _mfd_ipAddressTable_undo_values */
1874
1875 /*----------------------------------------------------------------------
1876 *
1877 * SET: irreversible commit
1878 *
1879 *---------------------------------------------------------------------*/
1880 /**
1881 * @internal
1882 * commit irreversible actions
1883 */
1884 int
1885 _mfd_ipAddressTable_irreversible_commit(netsnmp_mib_handler *handler, netsnmp_handler_registration
1886 *reginfo, netsnmp_agent_request_info
1887 *agtreq_info,
1888 netsnmp_request_info *requests)
1889 {
1890 ipAddressTable_rowreq_ctx *rowreq_ctx = (ipAddressTable_rowreq_ctx*)
1891 netsnmp_container_table_row_extract(requests);
1892
1893 DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_irreversible:commit", "called\n"));
1894
1895 netsnmp_assert(NULL != rowreq_ctx);
1896
1897 /*
1898 * check for and handle row creation/deletion
1899 * and update column exist flags...
1900 */
1901 if (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED) {
1902 if (!(rowreq_ctx->rowreq_flags & MFD_ROW_CREATED))
1903 CONTAINER_REMOVE(ipAddressTable_if_ctx.container, rowreq_ctx);
1904 } else {
1905 if (rowreq_ctx->column_set_flags) {
1906 rowreq_ctx->column_set_flags = 0;
1907 }
1908 if (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED) {
1909 rowreq_ctx->rowreq_flags &= ~MFD_ROW_CREATED;
1910 CONTAINER_INSERT(ipAddressTable_if_ctx.container, rowreq_ctx);
1911 }
1912 }
1913
1914 return SNMP_ERR_NOERROR;
1915 } /* _mfd_ipAddressTable_irreversible_commit */
1916 #endif /* NETSNMP_NO_WRITE_SUPPORT || NETSNMP_DISABLE_SET_SUPPORT */
1917
1918 /***********************************************************************
1919 *
1920 * DATA ACCESS
1921 *
1922 ***********************************************************************/
1923 static void _container_free(netsnmp_container *container);
1924
1925 /**
1926 * @internal
1927 */
1928 static int
1929 _cache_load(netsnmp_cache * cache, void *vmagic)
1930 {
1931 DEBUGMSGTL(("internal:ipAddressTable:_cache_load", "called\n"));
1932
1933 if ((NULL == cache) || (NULL == cache->magic)) {
1934 snmp_log(LOG_ERR, "invalid cache for ipAddressTable_cache_load\n");
1935 return -1;
1936 }
1937
1938 /** should only be called for an invalid or expired cache */
1939 netsnmp_assert((0 == cache->valid) || (1 == cache->expired));
1940
1941 /*
1942 * call user code
1943 */
1944 return ipAddressTable_container_load((netsnmp_container *) cache->
1945 magic);
1946 } /* _cache_load */
1947
1948 /**
1949 * @internal
1950 */
1951 static void
1952 _cache_free(netsnmp_cache * cache, void *magic)
1953 {
1954 netsnmp_container *container;
1955
1956 DEBUGMSGTL(("internal:ipAddressTable:_cache_free", "called\n"));
1957
1958 if ((NULL == cache) || (NULL == cache->magic)) {
1959 snmp_log(LOG_ERR, "invalid cache in ipAddressTable_cache_free\n");
1960 return;
1961 }
1962
1963 container = (netsnmp_container *) cache->magic;
1964
1965 _container_free(container);
1966 } /* _cache_free */
1967
1968 /**
1969 * @internal
1970 */
1971 static void
1972 _container_item_free(void *rowreq_ctx, void *context)
1973 {
1974 DEBUGMSGTL(("internal:ipAddressTable:_container_item_free",
1975 "called\n"));
1976
1977 if (NULL == rowreq_ctx)
1978 return;
1979
1980 ipAddressTable_release_rowreq_ctx(rowreq_ctx);
1981 } /* _container_item_free */
1982
1983 /**
1984 * @internal
1985 */
1986 static void
1987 _container_free(netsnmp_container *container)
1988 {
1989 DEBUGMSGTL(("internal:ipAddressTable:_container_free", "called\n"));
1990
1991 if (!container)
1992 return;
1993
1994 /*
1995 * call user code
1996 */
1997 ipAddressTable_container_free(container);
1998
1999 /*
2000 * free all items. inefficient, but easy.
2001 */
2002 CONTAINER_CLEAR(container, _container_item_free, NULL);
2003 } /* _container_free */
2004
2005 /**
2006 * @internal
2007 * initialize the container with functions or wrappers
2008 */
2009 void
2010 _ipAddressTable_container_init(ipAddressTable_interface_ctx * if_ctx)
2011 {
2012 DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_container_init",
2013 "called\n"));
2014
2015 /*
2016 * cache init
2017 */
2018 if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */
2019 _cache_load, _cache_free,
2020 ipAddressTable_oid,
2021 ipAddressTable_oid_size);
2022
2023 if (NULL == if_ctx->cache) {
2024 snmp_log(LOG_ERR, "error creating cache for ipAddressTable\n");
2025 return;
2026 }
2027
2028 if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;
2029
2030 ipAddressTable_container_init(&if_ctx->container, if_ctx->cache);
2031 if (NULL == if_ctx->container)
2032 if_ctx->container =
2033 netsnmp_container_find("ipAddressTable:table_container");
2034 if (NULL == if_ctx->container) {
2035 snmp_log(LOG_ERR, "error creating container in "
2036 "ipAddressTable_container_init\n");
2037 return;
2038 }
2039
2040 if (NULL != if_ctx->cache)
2041 if_ctx->cache->magic = (void *) if_ctx->container;
2042 } /* _ipAddressTable_container_init */
2043
2044 /**
2045 * @internal
2046 * shutdown the container with functions or wrappers
2047 */
2048 void
2049 _ipAddressTable_container_shutdown(ipAddressTable_interface_ctx * if_ctx)
2050 {
2051 DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_container_shutdown", "called\n"));
2052
2053 ipAddressTable_container_shutdown(if_ctx->container);
2054
2055 _container_free(if_ctx->container);
2056
2057 } /* _ipAddressTable_container_shutdown */
2058
2059
2060 #ifndef NETSNMP_FEATURE_REMOVE_IPADDRESSTABLE_EXTERNAL_ACCESS
2061 ipAddressTable_rowreq_ctx *
2062 ipAddressTable_row_find_by_mib_index(ipAddressTable_mib_index * mib_idx)
2063 {
2064 ipAddressTable_rowreq_ctx *rowreq_ctx;
2065 oid oid_tmp[MAX_OID_LEN];
2066 netsnmp_index oid_idx;
2067 int rc;
2068
2069 /*
2070 * set up storage for OID
2071 */
2072 oid_idx.oids = oid_tmp;
2073 oid_idx.len = sizeof(oid_tmp) / sizeof(oid);
2074
2075 /*
2076 * convert
2077 */
2078 rc = ipAddressTable_index_to_oid(&oid_idx, mib_idx);
2079 if (MFD_SUCCESS != rc)
2080 return NULL;
2081
2082 rowreq_ctx = (ipAddressTable_rowreq_ctx*)CONTAINER_FIND(ipAddressTable_if_ctx.container, &oid_idx);
2083
2084 return rowreq_ctx;
2085 }
2086 #endif /* NETSNMP_FEATURE_REMOVE_IPADDRESSTABLE_EXTERNAL_ACCESS */