Debian Codegraph @

agent/mibgroup/rmon-mib/etherStatsTable/etherStatsTable_interface.c

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