1 /*
2 * Note: this file originally auto-generated by mib2c using
3 * version : 1.17 $ of : mfd-data-access.m2c,v $
4 *
5 * $Id$
6 */
7 /*
8 * standard Net-SNMP includes
9 */
10 #include <net-snmp/net-snmp-config.h>
11 #include <net-snmp/net-snmp-features.h>
12 #include <net-snmp/net-snmp-includes.h>
13 #include <net-snmp/agent/net-snmp-agent-includes.h>
14
15 /*
16 * include our parent header
17 */
18 #include "ipAddressTable.h"
19
20
21 #include "ipAddressTable_data_access.h"
22
23 #include <sys/ioctl.h>
24 #include <errno.h>
25
26 netsnmp_feature_require(container_lifo);
27 netsnmp_feature_require(ipaddress_entry_update);
28
29 /** @ingroup interface
30 * @addtogroup data_access data_access: Routines to access data
31 *
32 * These routines are used to locate the data used to satisfy
33 * requests.
34 *
35 * @{
36 */
37 /**********************************************************************
38 **********************************************************************
39 ***
40 *** Table ipAddressTable
41 ***
42 **********************************************************************
43 **********************************************************************/
44 /*
45 * IP-MIB::ipAddressTable is subid 34 of ip.
46 * Its status is Current.
47 * OID: .1.3.6.1.2.1.4.34, length: 8
48 */
49
50 /**
51 * initialization for ipAddressTable data access
52 *
53 * This function is called during startup to allow you to
54 * allocate any resources you need for the data table.
55 *
56 * @param ipAddressTable_reg
57 * Pointer to ipAddressTable_registration
58 *
59 * @retval MFD_SUCCESS : success.
60 * @retval MFD_ERROR : unrecoverable error.
61 */
62 int
ipAddressTable_init_data(ipAddressTable_registration * ipAddressTable_reg)63 ipAddressTable_init_data(ipAddressTable_registration * ipAddressTable_reg)
64 {
65 DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_init_data",
66 "called\n"));
67
68 /*
69 * TODO:303:o: Initialize ipAddressTable data.
70 */
71
72 return MFD_SUCCESS;
73 } /* ipAddressTable_init_data */
74
75 /**
76 * container overview
77 *
78 */
79 /**
80 * check entry for update
81 */
82 static void
_clear_times(ipAddressTable_rowreq_ctx * rowreq_ctx,void * magic)83 _clear_times(ipAddressTable_rowreq_ctx * rowreq_ctx, void *magic)
84 {
85 rowreq_ctx->ipAddressLastChanged = rowreq_ctx->ipAddressCreated = 0;
86 }
87
88 /**
89 * container initialization
90 *
91 * @param container_ptr_ptr A pointer to a container pointer. If you
92 * create a custom container, use this parameter to return it
93 * to the MFD helper. If set to NULL, the MFD helper will
94 * allocate a container for you.
95 * @param cache A pointer to a cache structure. You can set the timeout
96 * and other cache flags using this pointer.
97 *
98 * This function is called at startup to allow you to customize certain
99 * aspects of the access method. For the most part, it is for advanced
100 * users. The default code should suffice for most cases. If no custom
101 * container is allocated, the MFD code will create one for your.
102 *
103 * This is also the place to set up cache behavior. The default, to
104 * simply set the cache timeout, will work well with the default
105 * container. If you are using a custom container, you may want to
106 * look at the cache helper documentation to see if there are any
107 * flags you want to set.
108 *
109 * @remark
110 * This would also be a good place to do any initialization needed
111 * for you data source. For example, opening a connection to another
112 * process that will supply the data, opening a database, etc.
113 */
114 void
ipAddressTable_container_init(netsnmp_container ** container_ptr_ptr,netsnmp_cache * cache)115 ipAddressTable_container_init(netsnmp_container **container_ptr_ptr,
116 netsnmp_cache * cache)
117 {
118 DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_container_init",
119 "called\n"));
120
121 if (NULL == container_ptr_ptr) {
122 snmp_log(LOG_ERR,
123 "bad container param to ipAddressTable_container_init\n");
124 return;
125 }
126
127 /*
128 * For advanced users, you can use a custom container. If you
129 * do not create one, one will be created for you.
130 */
131 /*
132 * We create a custom container here so we can pre-load it, which
133 * will result in all new entries with last changed values. we need
134 * to clear those... We also need to make sure ifIndexes have been
135 * assigned...
136 */
137 *container_ptr_ptr =
138 netsnmp_container_find("ipAddressTable:table_container");
139 if (NULL != *container_ptr_ptr) {
140 /*
141 * The container has ALLOW_DUPLICATES flag to speed up CONTAINER_INSERT
142 * operations (it does not need to check for duplicates), however we
143 * (manually) ensure that we won't insert any duplicates there.
144 */
145 (*container_ptr_ptr)->flags = CONTAINER_KEY_ALLOW_DUPLICATES;
146 (*container_ptr_ptr)->container_name = strdup("ipAddressTable");
147 ipAddressTable_container_load(*container_ptr_ptr);
148 CONTAINER_FOR_EACH(*container_ptr_ptr,
149 (netsnmp_container_obj_func *) _clear_times,
150 NULL);
151 }
152
153 if (NULL == cache) {
154 snmp_log(LOG_ERR,
155 "bad cache param to ipAddressTable_container_init\n");
156 return;
157 }
158
159 /*
160 * TODO:345:A: Set up ipAddressTable cache properties.
161 *
162 * Also for advanced users, you can set parameters for the
163 * cache. Do not change the magic pointer, as it is used
164 * by the MFD helper. To completely disable caching, set
165 * cache->enabled to 0.
166 */
167
168 /*
169 * basically, turn off all automatic cache handling except autoload.
170 */
171 cache->flags |=
172 (NETSNMP_CACHE_DONT_AUTO_RELEASE | NETSNMP_CACHE_DONT_FREE_EXPIRED
173 | NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD | NETSNMP_CACHE_AUTO_RELOAD
174 | NETSNMP_CACHE_DONT_INVALIDATE_ON_SET);
175 } /* ipAddressTable_container_init */
176
177 /**
178 * container shutdown
179 *
180 * @param container_ptr A pointer to the container.
181 *
182 * This function is called at shutdown to allow you to customize certain
183 * aspects of the access method. For the most part, it is for advanced
184 * users. The default code should suffice for most cases.
185 *
186 * This function is called before ipAddressTable_container_free().
187 *
188 * @remark
189 * This would also be a good place to do any cleanup needed
190 * for you data source. For example, closing a connection to another
191 * process that supplied the data, closing a database, etc.
192 */
193 void
ipAddressTable_container_shutdown(netsnmp_container * container_ptr)194 ipAddressTable_container_shutdown(netsnmp_container *container_ptr)
195 {
196 DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_container_shutdown",
197 "called\n"));
198
199 if (NULL == container_ptr) {
200 snmp_log(LOG_ERR,
201 "bad params to ipAddressTable_container_shutdown\n");
202 return;
203 }
204
205 } /* ipAddressTable_container_shutdown */
206
207 /**
208 * check entry for update
209 */
210 static void
_check_entry_for_updates(ipAddressTable_rowreq_ctx * rowreq_ctx,void ** magic)211 _check_entry_for_updates(ipAddressTable_rowreq_ctx * rowreq_ctx,
212 void **magic)
213 {
214 netsnmp_container *ipaddress_container = (netsnmp_container*)magic[0];
215 netsnmp_container *to_delete = (netsnmp_container*)magic[1];
216 netsnmp_container *to_ignore = (netsnmp_container*)magic[2];
217
218 /*
219 * check for matching entry using secondary index.
220 */
221 netsnmp_ipaddress_entry *ipaddress_entry = (netsnmp_ipaddress_entry*)
222 CONTAINER_FIND(ipaddress_container, rowreq_ctx->data);
223 if (NULL == ipaddress_entry) {
224 DEBUGMSGTL(("ipAddressTable:access", "removing missing entry\n"));
225
226 if (NULL == to_delete) {
227 magic[1] = to_delete = netsnmp_container_find("lifo");
228 if (NULL == to_delete)
229 snmp_log(LOG_ERR, "couldn't create delete container\n");
230 }
231 if (NULL != to_delete)
232 CONTAINER_INSERT(to_delete, rowreq_ctx);
233 } else {
234 DEBUGMSGTL(("ipAddressTable:access", "updating existing entry\n"));
235
236 /*
237 * Check for changes & update
238 */
239 if (netsnmp_access_ipaddress_entry_update(rowreq_ctx->data,
240 ipaddress_entry) > 0)
241 rowreq_ctx->ipAddressLastChanged = netsnmp_get_agent_uptime();
242
243 /*
244 * Remember not to add this entry from 'ipaddress_container' to 'container' later.
245 * Simple CONTAINER_REMOVE(ipaddress_container, ..) would be slow.
246 */
247 if (NULL == to_ignore) {
248 magic[2] = to_ignore = netsnmp_container_find("access_ipaddress:table_container");
249 if (NULL == to_ignore) {
250 snmp_log(LOG_ERR, "couldn't create ignore container\n");
251 } else {
252 /* to speed up insertion */
253 to_ignore->flags = CONTAINER_KEY_ALLOW_DUPLICATES;
254 }
255 }
256 if (NULL != to_ignore)
257 CONTAINER_INSERT(to_ignore, ipaddress_entry);
258 }
259 }
260
261 /**
262 * add new entry
263 */
264 static void
_add_new_entry(netsnmp_ipaddress_entry * ipaddress_entry,void ** magic)265 _add_new_entry(netsnmp_ipaddress_entry *ipaddress_entry,
266 void **magic)
267 {
268 netsnmp_container *container = magic[0];
269 netsnmp_container *to_ignore = magic[2];
270
271 ipAddressTable_rowreq_ctx *rowreq_ctx;
272
273 DEBUGMSGTL(("ipAddressTable:access", "creating new entry\n"));
274
275 netsnmp_assert(NULL != ipaddress_entry);
276 netsnmp_assert(NULL != container);
277
278 if (to_ignore && CONTAINER_FIND(to_ignore, ipaddress_entry)) {
279 /* this entry already is in 'container', skip it */
280 return;
281 }
282 /*
283 * allocate an row context and set the index(es)
284 */
285 rowreq_ctx = ipAddressTable_allocate_rowreq_ctx(ipaddress_entry, NULL);
286 if ((NULL != rowreq_ctx) &&
287 (MFD_SUCCESS ==
288 ipAddressTable_indexes_set(rowreq_ctx,
289 ipaddress_entry->ia_address_len,
290 ipaddress_entry->ia_address,
291 ipaddress_entry->ia_address_len))) {
292 if (CONTAINER_INSERT(container, rowreq_ctx) < 0) {
293 DEBUGMSGTL (("ipAddressTable:access","container insert failed for new entry\n"));
294 ipAddressTable_release_rowreq_ctx(rowreq_ctx);
295 return;
296 }
297 rowreq_ctx->ipAddressLastChanged =
298 rowreq_ctx->ipAddressCreated = netsnmp_get_agent_uptime();
299 } else {
300 if (NULL != rowreq_ctx) {
301 snmp_log(LOG_ERR, "error setting index while loading "
302 "ipAddressTable cache.\n");
303 ipAddressTable_release_rowreq_ctx(rowreq_ctx);
304 } else {
305 snmp_log(LOG_ERR, "memory allocation failed while loading "
306 "ipAddressTable cache.\n");
307 netsnmp_access_ipaddress_entry_free(ipaddress_entry);
308 }
309
310 return;
311 }
312
313 /*-------------------------------------------------------------------
314 * handle data that isn't part of the data_access ipaddress structure
315 */
316 rowreq_ctx->ipAddressRowStatus = ROWSTATUS_ACTIVE;
317 }
318
319 /**
320 * load initial data
321 *
322 * TODO:350:M: Implement ipAddressTable data load
323 * This function will also be called by the cache helper to load
324 * the container again (after the container free function has been
325 * called to free the previous contents).
326 *
327 * @param container container to which items should be inserted
328 *
329 * @retval MFD_SUCCESS : success.
330 * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source
331 * @retval MFD_ERROR : other error.
332 *
333 * This function is called to load the index(es) (and data, optionally)
334 * for the every row in the data set.
335 *
336 * @remark
337 * While loading the data, the only important thing is the indexes.
338 * If access to your data is cheap/fast (e.g. you have a pointer to a
339 * structure in memory), it would make sense to update the data here.
340 * If, however, the accessing the data invovles more work (e.g. parsing
341 * some other existing data, or peforming calculations to derive the data),
342 * then you can limit yourself to setting the indexes and saving any
343 * information you will need later. Then use the saved information in
344 * ipAddressTable_row_prep() for populating data.
345 *
346 * @note
347 * If you need consistency between rows (like you want statistics
348 * for each row to be from the same time frame), you should set all
349 * data here.
350 *
351 */
352 int
ipAddressTable_container_load(netsnmp_container * container)353 ipAddressTable_container_load(netsnmp_container *container)
354 {
355 netsnmp_container *ipaddress_container;
356 void *tmp_ptr[3];
357
358 DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_cache_load",
359 "called\n"));
360
361 /*
362 * Load/update data in the ipAddressTable container.
363 * loop over your ipAddressTable data, allocate a rowreq context,
364 * set the index(es) [and data, optionally] and insert into
365 * the container.
366 */
367 /*
368 * netsnmp_access_ipaddress_container_load makes sure that
369 * ipaddress_container does not contain any duplicate entries,
370 */
371 ipaddress_container =
372 netsnmp_access_ipaddress_container_load(NULL,
373 NETSNMP_ACCESS_IPADDRESS_LOAD_ADDL_IDX_BY_ADDR);
374 /*
375 * we just got a fresh copy of interface data. compare it to
376 * what we've already got, and make any adjustments, saving
377 * missing addresses to be deleted. Also, prune interfaces in
378 * ipaddress_container, so only the new interfaces remain.
379 */
380 tmp_ptr[0] = ipaddress_container->next;
381 tmp_ptr[1] = NULL; /* list of interfaces to be removed from 'container' */
382 tmp_ptr[2] = NULL; /* list of interfaces to be ignored in ipaddress_container */
383 CONTAINER_FOR_EACH(container, (netsnmp_container_obj_func *)
384 _check_entry_for_updates, tmp_ptr);
385
386 /*
387 * now add any new interfaces
388 */
389 tmp_ptr[0] = container;
390 CONTAINER_FOR_EACH(ipaddress_container,
391 (netsnmp_container_obj_func *) _add_new_entry,
392 tmp_ptr);
393
394 /*
395 * free the container. we've either claimed each entry, or released it,
396 * so the access function doesn't need to clear the container.
397 */
398 netsnmp_access_ipaddress_container_free(ipaddress_container,
399 NETSNMP_ACCESS_IPADDRESS_FREE_DONT_CLEAR);
400
401 /*
402 * remove deleted addresses from table container
403 */
404 if (NULL != tmp_ptr[1]) {
405 netsnmp_container *tmp_container =
406 (netsnmp_container *) tmp_ptr[1];
407 ipAddressTable_rowreq_ctx *tmp_ctx;
408
409 /*
410 * this works because the tmp_container is a linked list,
411 * which can be used like a stack...
412 */
413 while (CONTAINER_SIZE(tmp_container)) {
414 /*
415 * get from delete list
416 */
417 tmp_ctx = (ipAddressTable_rowreq_ctx*)CONTAINER_FIRST(tmp_container);
418
419 /*
420 * release context, delete from table container
421 */
422 CONTAINER_REMOVE(container, tmp_ctx);
423 ipAddressTable_release_rowreq_ctx(tmp_ctx);
424
425 /*
426 * pop off delete list
427 */
428 CONTAINER_REMOVE(tmp_container, NULL);
429 }
430 CONTAINER_FREE(tmp_container);
431 }
432
433 if (NULL != tmp_ptr[2]) {
434 /* list of interfaces to be ignored in ipaddress_container - free it */
435 netsnmp_container *to_ignore = (netsnmp_container *) tmp_ptr[2];
436 netsnmp_ipaddress_entry *ipaddress_entry;
437 while (CONTAINER_SIZE(to_ignore)) {
438 ipaddress_entry = (netsnmp_ipaddress_entry*)CONTAINER_FIRST(to_ignore);
439 CONTAINER_REMOVE(to_ignore, ipaddress_entry);
440 netsnmp_access_ipaddress_entry_free(ipaddress_entry);
441 }
442 CONTAINER_FREE(to_ignore);
443 }
444
445 DEBUGMSGT(("verbose:ipAddressTable:ipAddressTable_cache_load",
446 "%lu records\n", (unsigned long)CONTAINER_SIZE(container)));
447
448 return MFD_SUCCESS;
449 }
450
451 /**
452 * container clean up
453 *
454 * @param container container with all current items
455 *
456 * This optional callback is called prior to all
457 * item's being removed from the container. If you
458 * need to do any processing before that, do it here.
459 *
460 * @note
461 * The MFD helper will take care of releasing all the row contexts.
462 *
463 */
464 void
ipAddressTable_container_free(netsnmp_container * container)465 ipAddressTable_container_free(netsnmp_container *container)
466 {
467 DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_container_free",
468 "called\n"));
469
470 /*
471 * TODO:380:M: Free ipAddressTable container data.
472 */
473 } /* ipAddressTable_container_free */
474
475 /**
476 * prepare row for processing.
477 *
478 * When the agent has located the row for a request, this function is
479 * called to prepare the row for processing. If you fully populated
480 * the data context during the index setup phase, you may not need to
481 * do anything.
482 *
483 * @param rowreq_ctx pointer to a context.
484 *
485 * @retval MFD_SUCCESS : success.
486 * @retval MFD_ERROR : other error.
487 */
488 int
ipAddressTable_row_prep(ipAddressTable_rowreq_ctx * rowreq_ctx)489 ipAddressTable_row_prep(ipAddressTable_rowreq_ctx * rowreq_ctx)
490 {
491 DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_row_prep",
492 "called\n"));
493
494 netsnmp_assert(NULL != rowreq_ctx);
495
496 /*
497 * TODO:390:o: Prepare row for request.
498 * If populating row data was delayed, this is the place to
499 * fill in the row for this request.
500 */
501
502 return MFD_SUCCESS;
503 } /* ipAddressTable_row_prep */
504
505 /*
506 * TODO:420:r: Implement ipAddressTable index validation.
507 */
508 /*---------------------------------------------------------------------
509 * IP-MIB::ipAddressEntry.ipAddressAddrType
510 * ipAddressAddrType is subid 1 of ipAddressEntry.
511 * Its status is Current, and its access level is NoAccess.
512 * OID: .1.3.6.1.2.1.4.34.1.1
513 * Description:
514 The address type of ipAddressAddr.
515 *
516 * Attributes:
517 * accessible 0 isscalar 0 enums 1 hasdefval 0
518 * readable 0 iscolumn 1 ranges 0 hashint 0
519 * settable 0
520 *
521 * Enum range: 5/8. Values: unknown(0), ipv4(1), ipv6(2), ipv4z(3), ipv6z(4), dns(16)
522 *
523 * Its syntax is InetAddressType (based on perltype INTEGER)
524 * The net-snmp type is ASN_INTEGER. The C type decl is long (u_long)
525 *
526 *
527 *
528 * NOTE: NODE ipAddressAddrType IS NOT ACCESSIBLE
529 *
530 *
531 */
532 /**
533 * check validity of ipAddressAddrType index portion
534 *
535 * @retval MFD_SUCCESS : the incoming value is legal
536 * @retval MFD_ERROR : the incoming value is NOT legal
537 *
538 * @note this is not the place to do any checks for the sanity
539 * of multiple indexes. Those types of checks should be done in the
540 * ipAddressTable_validate_index() function.
541 *
542 * @note Also keep in mind that if the index refers to a row in this or
543 * some other table, you can't check for that row here to make
544 * decisions, since that row might not be created yet, but may
545 * be created during the processing this request. If you have
546 * such checks, they should be done in the check_dependencies
547 * function, because any new/deleted/changed rows should be
548 * available then.
549 *
550 * The following checks have already been done for you:
551 * The value is one of unknown(0), ipv4(1), ipv6(2), ipv4z(3), ipv6z(4), dns(16)
552 *
553 * If there a no other checks you need to do, simply return MFD_SUCCESS.
554 */
555 int
ipAddressAddrType_check_index(ipAddressTable_rowreq_ctx * rowreq_ctx)556 ipAddressAddrType_check_index(ipAddressTable_rowreq_ctx * rowreq_ctx)
557 {
558 DEBUGMSGTL(("verbose:ipAddressTable:ipAddressAddrType_check_index",
559 "called\n"));
560
561 netsnmp_assert(NULL != rowreq_ctx);
562
563 /*
564 * TODO:426:M: |-> Check ipAddressTable index ipAddressAddrType.
565 * check that index value in the table context is legal.
566 * (rowreq_ctx->tbl_index.ipAddressAddrType)
567 */
568 switch (rowreq_ctx->tbl_idx.ipAddressAddrType) {
569
570 case INETADDRESSTYPE_IPV4:
571 case INETADDRESSTYPE_IPV6:
572 break;
573
574 default:
575 DEBUGMSGT(("ipAddressTable", "illegal addr type\n"));
576 return MFD_ERROR;
577 }
578
579
580 return MFD_SUCCESS; /* ipAddressAddrType index ok */
581 } /* ipAddressAddrType_check_index */
582
583 /*---------------------------------------------------------------------
584 * IP-MIB::ipAddressEntry.ipAddressAddr
585 * ipAddressAddr is subid 2 of ipAddressEntry.
586 * Its status is Current, and its access level is NoAccess.
587 * OID: .1.3.6.1.2.1.4.34.1.2
588 * Description:
589 The IP address to which this entry's addressing information
590 pertains. The address type of this object is specified in
591 ipAddressAddrType.
592
593
594 Implementors need to be aware that if the size of
595 ipAddressAddr exceeds 116 octets then OIDS of instances of
596 columns in this row will have more than 128 sub-identifiers
597 and cannot be accessed using SNMPv1, SNMPv2c or SNMPv3.
598 *
599 * Attributes:
600 * accessible 0 isscalar 0 enums 0 hasdefval 0
601 * readable 0 iscolumn 1 ranges 1 hashint 0
602 * settable 0
603 *
604 * Ranges: 0 - 255;
605 *
606 * Its syntax is InetAddress (based on perltype OCTETSTR)
607 * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char)
608 * This data type requires a length. (Max 255)
609 *
610 *
611 *
612 * NOTE: NODE ipAddressAddr IS NOT ACCESSIBLE
613 *
614 *
615 */
616 /**
617 * check validity of ipAddressAddr index portion
618 *
619 * @retval MFD_SUCCESS : the incoming value is legal
620 * @retval MFD_ERROR : the incoming value is NOT legal
621 *
622 * @note this is not the place to do any checks for the sanity
623 * of multiple indexes. Those types of checks should be done in the
624 * ipAddressTable_validate_index() function.
625 *
626 * @note Also keep in mind that if the index refers to a row in this or
627 * some other table, you can't check for that row here to make
628 * decisions, since that row might not be created yet, but may
629 * be created during the processing this request. If you have
630 * such checks, they should be done in the check_dependencies
631 * function, because any new/deleted/changed rows should be
632 * available then.
633 *
634 * The following checks have already been done for you:
635 * The length is in (one of) the range set(s): 0 - 255
636 *
637 * If there a no other checks you need to do, simply return MFD_SUCCESS.
638 */
639 int
ipAddressAddr_check_index(ipAddressTable_rowreq_ctx * rowreq_ctx)640 ipAddressAddr_check_index(ipAddressTable_rowreq_ctx * rowreq_ctx)
641 {
642 DEBUGMSGTL(("verbose:ipAddressTable:ipAddressAddr_check_index",
643 "called\n"));
644
645 netsnmp_assert(NULL != rowreq_ctx);
646
647 /*
648 * TODO:426:M: |-> Check ipAddressTable index ipAddressAddr.
649 * check that index value in the table context is legal.
650 * (rowreq_ctx->tbl_index.ipAddressAddr)
651 */
652 switch (rowreq_ctx->tbl_idx.ipAddressAddrType) {
653
654 case INETADDRESSTYPE_IPV4:
655 if (4 != rowreq_ctx->tbl_idx.ipAddressAddr_len) {
656 DEBUGMSGT(("ipAddressTable", "bad addr len\n"));
657 return MFD_ERROR;
658 }
659 break;
660
661 case INETADDRESSTYPE_IPV6:
662 /** xxx-rks: allow 20? */
663 if (16 != rowreq_ctx->tbl_idx.ipAddressAddr_len) {
664 DEBUGMSGT(("ipAddressTable", "bad addr len\n"));
665 return MFD_ERROR;
666 }
667 break;
668
669 default:
670 return MFD_ERROR;
671 }
672
673 return MFD_SUCCESS; /* ipAddressAddr index ok */
674 } /* ipAddressAddr_check_index */
675
676 /**
677 * verify specified index is valid.
678 *
679 * This check is independent of whether or not the values specified for
680 * the columns of the new row are valid. Column values and row consistency
681 * will be checked later. At this point, only the index values should be
682 * checked.
683 *
684 * All of the individual index validation functions have been called, so this
685 * is the place to make sure they are valid as a whole when combined. If
686 * you only have one index, then you probably don't need to do anything else
687 * here.
688 *
689 * @note Keep in mind that if the indexes refer to a row in this or
690 * some other table, you can't check for that row here to make
691 * decisions, since that row might not be created yet, but may
692 * be created during the processing this request. If you have
693 * such checks, they should be done in the check_dependencies
694 * function, because any new/deleted/changed rows should be
695 * available then.
696 *
697 *
698 * @param ipAddressTable_reg
699 * Pointer to the user registration data
700 * @param rowreq_ctx
701 * Pointer to the users context.
702 * @retval MFD_SUCCESS : success
703 * @retval MFD_CANNOT_CREATE_NOW : index not valid right now
704 * @retval MFD_CANNOT_CREATE_EVER : index never valid
705 */
706 int
ipAddressTable_validate_index(ipAddressTable_registration * ipAddressTable_reg,ipAddressTable_rowreq_ctx * rowreq_ctx)707 ipAddressTable_validate_index(ipAddressTable_registration *
708 ipAddressTable_reg,
709 ipAddressTable_rowreq_ctx * rowreq_ctx)
710 {
711 int rc = MFD_SUCCESS;
712
713 DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_validate_index",
714 "called\n"));
715
716 /** we should have a non-NULL pointer */
717 netsnmp_assert(NULL != rowreq_ctx);
718
719 /*
720 * TODO:430:M: |-> Validate potential ipAddressTable index.
721 *
722 *
723 */
724 if ((4 != rowreq_ctx->tbl_idx.ipAddressAddr_len)
725 && (16 != rowreq_ctx->tbl_idx.ipAddressAddr_len)) {
726 snmp_log(LOG_WARNING, "invalid index for a new row in the "
727 "ipAddressTable table.\n");
728 /*
729 * determine failure type.
730 *
731 * If the index could not ever be created, return MFD_NOT_EVER
732 * If the index can not be created under the present circumstances
733 * (even though it could be created under other circumstances),
734 * return MFD_NOT_NOW.
735 */
736 if (0) {
737 return MFD_CANNOT_CREATE_EVER;
738 } else {
739 return MFD_CANNOT_CREATE_NOW;
740 }
741 } else {
742 memcpy(rowreq_ctx->data->ia_address, rowreq_ctx->tbl_idx.ipAddressAddr,
743 rowreq_ctx->tbl_idx.ipAddressAddr_len);
744 rowreq_ctx->data->ia_address_len = rowreq_ctx->tbl_idx.ipAddressAddr_len;
745 }
746
747 return rc;
748 } /* ipAddressTable_validate_index */
749
750 /** @} */
751