Debian Codegraph @

agent/mibgroup/ip-mib/inetNetToMediaTable/inetNetToMediaTable_data_access.c

raw
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 "inetNetToMediaTable.h"
19
20
21 #include "inetNetToMediaTable_data_access.h"
22
23 netsnmp_feature_require(container_lifo);
24 static netsnmp_arp_access * arp_access = NULL;
25
26 /** @ingroup interface
27 * @addtogroup data_access data_access: Routines to access data
28 *
29 * These routines are used to locate the data used to satisfy
30 * requests.
31 *
32 * @{
33 */
34 /**********************************************************************
35 **********************************************************************
36 ***
37 *** Table inetNetToMediaTable
38 ***
39 **********************************************************************
40 **********************************************************************/
41 /*
42 * IP-MIB::inetNetToMediaTable is subid 35 of ip.
43 * Its status is Current.
44 * OID: .1.3.6.1.2.1.4.35, length: 8
45 */
46
47 /**
48 * initialization for inetNetToMediaTable data access
49 *
50 * This function is called during startup to allow you to
51 * allocate any resources you need for the data table.
52 *
53 * @param inetNetToMediaTable_reg
54 * Pointer to inetNetToMediaTable_registration
55 *
56 * @retval MFD_SUCCESS : success.
57 * @retval MFD_ERROR : unrecoverable error.
58 */
59 int
60 inetNetToMediaTable_init_data(inetNetToMediaTable_registration *
61 inetNetToMediaTable_reg)
62 {
63 DEBUGMSGTL(("verbose:inetNetToMediaTable:inetNetToMediaTable_init_data", "called\n"));
64
65 /*
66 * TODO:303:o: Initialize inetNetToMediaTable data.
67 */
68
69 return MFD_SUCCESS;
70 } /* inetNetToMediaTable_init_data */
71
72 /**
73 * container overview
74 *
75 */
76
77 /**
78 * check entry for update
79 */
80 static void
81 _add_or_update_arp_entry(netsnmp_arp_entry *arp_entry,
82 netsnmp_container *container)
83 {
84 inetNetToMediaTable_rowreq_ctx *rowreq_ctx, *old;
85 int inetAddressType;
86
87 DEBUGTRACE;
88
89 netsnmp_assert(NULL != arp_entry);
90 netsnmp_assert(NULL != container);
91
92 /*
93 * convert the addr len to an inetAddressType
94 */
95 switch (arp_entry->arp_ipaddress_len) {
96 case 4:
97 inetAddressType = INETADDRESSTYPE_IPV4;
98 break;
99
100 case 16:
101 inetAddressType = INETADDRESSTYPE_IPV6;
102 break;
103
104 default:
105 snmp_log(LOG_ERR, "inetNetToMediaTable:_add_or_update_arpentry: unsupported address type, len = %d\n", arp_entry->arp_ipaddress_len);
106 netsnmp_access_arp_entry_free(arp_entry);
107 return;
108 }
109
110 /*
111 * allocate an row context and set the index(es), then try to find it in
112 * the cache.
113 */
114 rowreq_ctx = inetNetToMediaTable_allocate_rowreq_ctx(arp_entry, NULL);
115 if ((NULL != rowreq_ctx) &&
116 (MFD_SUCCESS == inetNetToMediaTable_indexes_set
117 (rowreq_ctx, rowreq_ctx->data->if_index, inetAddressType,
118 (char *) rowreq_ctx->data->arp_ipaddress,
119 rowreq_ctx->data->arp_ipaddress_len))) {
120
121 /* try to find old entry */
122 old = (inetNetToMediaTable_rowreq_ctx*)CONTAINER_FIND(container, rowreq_ctx);
123 if (arp_entry->flags & NETSNMP_ACCESS_ARP_ENTRY_FLAG_DELETE) {
124 /* delete existing entry */
125 if (old != NULL) {
126 CONTAINER_REMOVE(container, old);
127 inetNetToMediaTable_release_rowreq_ctx(old);
128 }
129 inetNetToMediaTable_release_rowreq_ctx(rowreq_ctx);
130 } else if (old != NULL) {
131 /* the entry is already there, update it */
132 netsnmp_access_arp_entry_update(old->data, arp_entry);
133 /* delete the auxiliary context we used to find the entry
134 * (this deletes also arp_entry) */
135 inetNetToMediaTable_release_rowreq_ctx(rowreq_ctx);
136 } else {
137 /* create new entry and add it to the cache*/
138 rowreq_ctx->inetNetToMediaRowStatus = ROWSTATUS_ACTIVE;
139 rowreq_ctx->data->arp_last_updated = netsnmp_get_agent_uptime();
140 CONTAINER_INSERT(container, rowreq_ctx);
141 }
142 } else {
143 if (rowreq_ctx) {
144 snmp_log(LOG_ERR, "error setting index while loading "
145 "inetNetToMediaTable cache.\n");
146 inetNetToMediaTable_release_rowreq_ctx(rowreq_ctx);
147 } else
148 netsnmp_access_arp_entry_free(arp_entry);
149 }
150 }
151
152 static void _arp_hook_update(netsnmp_arp_access *access, netsnmp_arp_entry *entry)
153 {
154 _add_or_update_arp_entry(entry, access->magic);
155 }
156
157 typedef struct {
158 unsigned generation;
159 netsnmp_container *to_delete;
160 } _collect_ctx;
161
162 /**
163 * Put all entries with outdated generation to deletion list.
164 */
165 static void
166 _collect_invalid_arp_ctx(void *p, void *q)
167 {
168 inetNetToMediaTable_rowreq_ctx *ctx = p;
169 _collect_ctx *cctx = q;
170
171 if (ctx->data->generation != cctx->generation)
172 CONTAINER_INSERT(cctx->to_delete, ctx);
173 }
174
175 static void _arp_hook_gc(netsnmp_arp_access *access)
176 {
177 netsnmp_container *container = access->magic;
178 _collect_ctx cctx;
179
180 cctx.to_delete = netsnmp_container_find("lifo");
181 cctx.generation = access->generation;
182
183 CONTAINER_FOR_EACH(container, _collect_invalid_arp_ctx, &cctx);
184
185 while (CONTAINER_SIZE(cctx.to_delete)) {
186 inetNetToMediaTable_rowreq_ctx *ctx = (inetNetToMediaTable_rowreq_ctx*)CONTAINER_FIRST(cctx.to_delete);
187 CONTAINER_REMOVE(container, ctx);
188 inetNetToMediaTable_release_rowreq_ctx(ctx);
189 CONTAINER_REMOVE(cctx.to_delete, NULL);
190 }
191 CONTAINER_FREE(cctx.to_delete);
192 }
193
194 /**
195 * container initialization
196 *
197 * @param container_ptr_ptr A pointer to a container pointer. If you
198 * create a custom container, use this parameter to return it
199 * to the MFD helper. If set to NULL, the MFD helper will
200 * allocate a container for you.
201 * @param cache A pointer to a cache structure. You can set the timeout
202 * and other cache flags using this pointer.
203 *
204 * This function is called at startup to allow you to customize certain
205 * aspects of the access method. For the most part, it is for advanced
206 * users. The default code should suffice for most cases. If no custom
207 * container is allocated, the MFD code will create one for your.
208 *
209 * This is also the place to set up cache behavior. The default, to
210 * simply set the cache timeout, will work well with the default
211 * container. If you are using a custom container, you may want to
212 * look at the cache helper documentation to see if there are any
213 * flags you want to set.
214 *
215 * @remark
216 * This would also be a good place to do any initialization needed
217 * for you data source. For example, opening a connection to another
218 * process that will supply the data, opening a database, etc.
219 */
220 void
221 inetNetToMediaTable_container_init(netsnmp_container **container_ptr_ptr,
222 netsnmp_cache * cache)
223 {
224 DEBUGMSGTL(("verbose:inetNetToMediaTable:inetNetToMediaTable_container_init", "called\n"));
225
226 if (NULL == container_ptr_ptr) {
227 snmp_log(LOG_ERR,
228 "bad container param to inetNetToMediaTable_container_init\n");
229 return;
230 }
231
232 /*
233 * For advanced users, you can use a custom container. If you
234 * do not create one, one will be created for you.
235 */
236 *container_ptr_ptr = NULL;
237
238 if (NULL == cache) {
239 snmp_log(LOG_ERR,
240 "bad cache param to inetNetToMediaTable_container_init\n");
241 return;
242 }
243
244 arp_access = netsnmp_access_arp_create(
245 NETSNMP_ACCESS_ARP_CREATE_NOFLAGS,
246 _arp_hook_update,
247 _arp_hook_gc,
248 &cache->timeout,
249 &cache->flags,
250 &cache->expired);
251 if (arp_access == NULL) {
252 snmp_log(LOG_ERR,
253 "unable to create arp access in inetNetToMediaTable_container_init\n");
254 return;
255 }
256 } /* inetNetToMediaTable_container_init */
257
258 /**
259 * container shutdown
260 *
261 * @param container_ptr A pointer to the container.
262 *
263 * This function is called at shutdown to allow you to customize certain
264 * aspects of the access method. For the most part, it is for advanced
265 * users. The default code should suffice for most cases.
266 *
267 * This function is called before inetNetToMediaTable_container_free().
268 *
269 * @remark
270 * This would also be a good place to do any cleanup needed
271 * for you data source. For example, closing a connection to another
272 * process that supplied the data, closing a database, etc.
273 */
274 void
275 inetNetToMediaTable_container_shutdown(netsnmp_container *container_ptr)
276 {
277 DEBUGMSGTL(("verbose:inetNetToMediaTable:inetNetToMediaTable_container_shutdown", "called\n"));
278
279 if (NULL != arp_access) {
280 netsnmp_access_arp_delete(arp_access);
281 arp_access = NULL;
282 }
283
284 if (NULL == container_ptr) {
285 snmp_log(LOG_ERR,
286 "bad params to inetNetToMediaTable_container_shutdown\n");
287 return;
288 }
289 } /* inetNetToMediaTable_container_shutdown */
290
291 /**
292 * load initial data
293 *
294 * TODO:350:M: Implement inetNetToMediaTable data load
295 * This function will also be called by the cache helper to load
296 * the container again (after the container free function has been
297 * called to free the previous contents).
298 *
299 * @param container container to which items should be inserted
300 *
301 * @retval MFD_SUCCESS : success.
302 * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source
303 * @retval MFD_ERROR : other error.
304 *
305 * This function is called to load the index(es) (and data, optionally)
306 * for the every row in the data set.
307 *
308 * @remark
309 * While loading the data, the only important thing is the indexes.
310 * If access to your data is cheap/fast (e.g. you have a pointer to a
311 * structure in memory), it would make sense to update the data here.
312 * If, however, the accessing the data involves more work (e.g. parsing
313 * some other existing data, or performing calculations to derive the data),
314 * then you can limit yourself to setting the indexes and saving any
315 * information you will need later. Then use the saved information in
316 * inetNetToMediaTable_row_prep() for populating data.
317 *
318 * @note
319 * If you need consistency between rows (like you want statistics
320 * for each row to be from the same time frame), you should set all
321 * data here.
322 *
323 */
324 int
325 inetNetToMediaTable_container_load(netsnmp_container *container)
326 {
327 DEBUGMSGTL(("verbose:inetNetToMediaTable:inetNetToMediaTable_cache_load", "called\n"));
328
329 arp_access->magic = container;
330 if (netsnmp_access_arp_load(arp_access) < 0)
331 return MFD_ERROR;
332
333 return MFD_SUCCESS;
334 } /* inetNetToMediaTable_container_load */
335
336 /**
337 * container clean up
338 *
339 * @param container container with all current items
340 *
341 * This optional callback is called prior to all
342 * item's being removed from the container. If you
343 * need to do any processing before that, do it here.
344 *
345 * @note
346 * The MFD helper will take care of releasing all the row contexts.
347 *
348 */
349 void
350 inetNetToMediaTable_container_free(netsnmp_container *container)
351 {
352 DEBUGMSGTL(("verbose:inetNetToMediaTable:inetNetToMediaTable_container_free", "called\n"));
353
354 if (NULL != arp_access) {
355 netsnmp_access_arp_unload(arp_access);
356 arp_access->magic = NULL;
357 }
358
359 /*
360 * TODO:380:M: Free inetNetToMediaTable container data.
361 */
362 } /* inetNetToMediaTable_container_free */
363
364 /**
365 * prepare row for processing.
366 *
367 * When the agent has located the row for a request, this function is
368 * called to prepare the row for processing. If you fully populated
369 * the data context during the index setup phase, you may not need to
370 * do anything.
371 *
372 * @param rowreq_ctx pointer to a context.
373 *
374 * @retval MFD_SUCCESS : success.
375 * @retval MFD_ERROR : other error.
376 */
377 int
378 inetNetToMediaTable_row_prep(inetNetToMediaTable_rowreq_ctx * rowreq_ctx)
379 {
380 DEBUGMSGTL(("verbose:inetNetToMediaTable:inetNetToMediaTable_row_prep",
381 "called\n"));
382
383 netsnmp_assert(NULL != rowreq_ctx);
384
385 /*
386 * TODO:390:o: Prepare row for request.
387 * If populating row data was delayed, this is the place to
388 * fill in the row for this request.
389 */
390
391 return MFD_SUCCESS;
392 } /* inetNetToMediaTable_row_prep */
393
394 /*
395 * TODO:420:r: Implement inetNetToMediaTable index validation.
396 */
397 /*---------------------------------------------------------------------
398 * IP-MIB::inetNetToMediaEntry.inetNetToMediaIfIndex
399 * inetNetToMediaIfIndex is subid 1 of inetNetToMediaEntry.
400 * Its status is Current, and its access level is NoAccess.
401 * OID: .1.3.6.1.2.1.4.35.1.1
402 * Description:
403 The index value which uniquely identifies the interface to
404 which this entry is applicable. The interface identified by
405 a particular value of this index is the same interface as
406 identified by the same value of the IF-MIB's ifIndex.
407 *
408 * Attributes:
409 * accessible 0 isscalar 0 enums 0 hasdefval 0
410 * readable 0 iscolumn 1 ranges 1 hashint 1
411 * settable 0
412 * hint: d
413 *
414 * Ranges: 1 - 2147483647;
415 *
416 * Its syntax is InterfaceIndex (based on perltype INTEGER32)
417 * The net-snmp type is ASN_INTEGER. The C type decl is long (long)
418 *
419 *
420 *
421 * NOTE: NODE inetNetToMediaIfIndex IS NOT ACCESSIBLE
422 *
423 *
424 */
425 /**
426 * check validity of inetNetToMediaIfIndex index portion
427 *
428 * @retval MFD_SUCCESS : the incoming value is legal
429 * @retval MFD_ERROR : the incoming value is NOT legal
430 *
431 * @note this is not the place to do any checks for the sanity
432 * of multiple indexes. Those types of checks should be done in the
433 * inetNetToMediaTable_validate_index() function.
434 *
435 * @note Also keep in mind that if the index refers to a row in this or
436 * some other table, you can't check for that row here to make
437 * decisions, since that row might not be created yet, but may
438 * be created during the processing this request. If you have
439 * such checks, they should be done in the check_dependencies
440 * function, because any new/deleted/changed rows should be
441 * available then.
442 *
443 * The following checks have already been done for you:
444 * The value is in (one of) the range set(s): 1 - 2147483647
445 *
446 * If there a no other checks you need to do, simply return MFD_SUCCESS.
447 */
448 int
449 inetNetToMediaIfIndex_check_index(inetNetToMediaTable_rowreq_ctx *
450 rowreq_ctx)
451 {
452 DEBUGMSGTL(("verbose:inetNetToMediaTable:inetNetToMediaIfIndex_check_index", "called\n"));
453
454 netsnmp_assert(NULL != rowreq_ctx);
455
456 /*
457 * TODO:426:M: |-> Check inetNetToMediaTable index inetNetToMediaIfIndex.
458 * check that index value in the table context is legal.
459 * (rowreq_ctx->tbl_index.inetNetToMediaIfIndex)
460 */
461
462 return MFD_SUCCESS; /* inetNetToMediaIfIndex index ok */
463 } /* inetNetToMediaIfIndex_check_index */
464
465 /*---------------------------------------------------------------------
466 * IP-MIB::inetNetToMediaEntry.inetNetToMediaNetAddressType
467 * inetNetToMediaNetAddressType is subid 2 of inetNetToMediaEntry.
468 * Its status is Current, and its access level is NoAccess.
469 * OID: .1.3.6.1.2.1.4.35.1.2
470 * Description:
471 The type of inetNetToMediaNetAddress.
472 *
473 * Attributes:
474 * accessible 0 isscalar 0 enums 1 hasdefval 0
475 * readable 0 iscolumn 1 ranges 0 hashint 0
476 * settable 0
477 *
478 * Enum range: 5/8. Values: unknown(0), ipv4(1), ipv6(2), ipv4z(3), ipv6z(4), dns(16)
479 *
480 * Its syntax is InetAddressType (based on perltype INTEGER)
481 * The net-snmp type is ASN_INTEGER. The C type decl is long (u_long)
482 *
483 *
484 *
485 * NOTE: NODE inetNetToMediaNetAddressType IS NOT ACCESSIBLE
486 *
487 *
488 */
489 /**
490 * check validity of inetNetToMediaNetAddressType index portion
491 *
492 * @retval MFD_SUCCESS : the incoming value is legal
493 * @retval MFD_ERROR : the incoming value is NOT legal
494 *
495 * @note this is not the place to do any checks for the sanity
496 * of multiple indexes. Those types of checks should be done in the
497 * inetNetToMediaTable_validate_index() function.
498 *
499 * @note Also keep in mind that if the index refers to a row in this or
500 * some other table, you can't check for that row here to make
501 * decisions, since that row might not be created yet, but may
502 * be created during the processing this request. If you have
503 * such checks, they should be done in the check_dependencies
504 * function, because any new/deleted/changed rows should be
505 * available then.
506 *
507 * The following checks have already been done for you:
508 * The value is one of unknown(0), ipv4(1), ipv6(2), ipv4z(3), ipv6z(4), dns(16)
509 *
510 * If there a no other checks you need to do, simply return MFD_SUCCESS.
511 */
512 int
513 inetNetToMediaNetAddressType_check_index(inetNetToMediaTable_rowreq_ctx *
514 rowreq_ctx)
515 {
516 DEBUGMSGTL(("verbose:inetNetToMediaTable:inetNetToMediaNetAddressType_check_index", "called\n"));
517
518 netsnmp_assert(NULL != rowreq_ctx);
519
520 /*
521 * TODO:426:M: |-> Check inetNetToMediaTable index inetNetToMediaNetAddressType.
522 * check that index value in the table context is legal.
523 * (rowreq_ctx->tbl_index.inetNetToMediaNetAddressType)
524 */
525
526 return MFD_SUCCESS; /* inetNetToMediaNetAddressType index ok */
527 } /* inetNetToMediaNetAddressType_check_index */
528
529 /*---------------------------------------------------------------------
530 * IP-MIB::inetNetToMediaEntry.inetNetToMediaNetAddress
531 * inetNetToMediaNetAddress is subid 3 of inetNetToMediaEntry.
532 * Its status is Current, and its access level is NoAccess.
533 * OID: .1.3.6.1.2.1.4.35.1.3
534 * Description:
535 The IP Address corresponding to the media-dependent
536 `physical' address. The address type of this object is
537 specified in inetNetToMediaAddressType.
538
539
540 Implementors need to be aware that if the size of
541 inetNetToMediaNetAddress exceeds 115 octets then OIDS of
542 instances of columns in this row will have more than 128
543 sub-identifiers and cannot be accessed using SNMPv1, SNMPv2c
544 or SNMPv3.
545 *
546 * Attributes:
547 * accessible 0 isscalar 0 enums 0 hasdefval 0
548 * readable 0 iscolumn 1 ranges 1 hashint 0
549 * settable 0
550 *
551 * Ranges: 0 - 255;
552 *
553 * Its syntax is InetAddress (based on perltype OCTETSTR)
554 * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char)
555 * This data type requires a length. (Max 255)
556 *
557 *
558 *
559 * NOTE: NODE inetNetToMediaNetAddress IS NOT ACCESSIBLE
560 *
561 *
562 */
563 /**
564 * check validity of inetNetToMediaNetAddress index portion
565 *
566 * @retval MFD_SUCCESS : the incoming value is legal
567 * @retval MFD_ERROR : the incoming value is NOT legal
568 *
569 * @note this is not the place to do any checks for the sanity
570 * of multiple indexes. Those types of checks should be done in the
571 * inetNetToMediaTable_validate_index() function.
572 *
573 * @note Also keep in mind that if the index refers to a row in this or
574 * some other table, you can't check for that row here to make
575 * decisions, since that row might not be created yet, but may
576 * be created during the processing this request. If you have
577 * such checks, they should be done in the check_dependencies
578 * function, because any new/deleted/changed rows should be
579 * available then.
580 *
581 * The following checks have already been done for you:
582 * The length is in (one of) the range set(s): 0 - 255
583 *
584 * If there a no other checks you need to do, simply return MFD_SUCCESS.
585 */
586 int
587 inetNetToMediaNetAddress_check_index(inetNetToMediaTable_rowreq_ctx *
588 rowreq_ctx)
589 {
590 DEBUGMSGTL(("verbose:inetNetToMediaTable:inetNetToMediaNetAddress_check_index", "called\n"));
591
592 netsnmp_assert(NULL != rowreq_ctx);
593
594 /*
595 * TODO:426:M: |-> Check inetNetToMediaTable index inetNetToMediaNetAddress.
596 * check that index value in the table context is legal.
597 * (rowreq_ctx->tbl_index.inetNetToMediaNetAddress)
598 */
599
600 return MFD_SUCCESS; /* inetNetToMediaNetAddress index ok */
601 } /* inetNetToMediaNetAddress_check_index */
602
603 /**
604 * verify specified index is valid.
605 *
606 * This check is independent of whether or not the values specified for
607 * the columns of the new row are valid. Column values and row consistency
608 * will be checked later. At this point, only the index values should be
609 * checked.
610 *
611 * All of the individual index validation functions have been called, so this
612 * is the place to make sure they are valid as a whole when combined. If
613 * you only have one index, then you probably don't need to do anything else
614 * here.
615 *
616 * @note Keep in mind that if the indexes refer to a row in this or
617 * some other table, you can't check for that row here to make
618 * decisions, since that row might not be created yet, but may
619 * be created during the processing this request. If you have
620 * such checks, they should be done in the check_dependencies
621 * function, because any new/deleted/changed rows should be
622 * available then.
623 *
624 *
625 * @param inetNetToMediaTable_reg
626 * Pointer to the user registration data
627 * @param rowreq_ctx
628 * Pointer to the users context.
629 * @retval MFD_SUCCESS : success
630 * @retval MFD_CANNOT_CREATE_NOW : index not valid right now
631 * @retval MFD_CANNOT_CREATE_EVER : index never valid
632 */
633 int
634 inetNetToMediaTable_validate_index(inetNetToMediaTable_registration *
635 inetNetToMediaTable_reg,
636 inetNetToMediaTable_rowreq_ctx *
637 rowreq_ctx)
638 {
639 int rc = MFD_SUCCESS;
640
641 DEBUGMSGTL(("verbose:inetNetToMediaTable:inetNetToMediaTable_validate_index", "called\n"));
642
643 /** we should have a non-NULL pointer */
644 netsnmp_assert(NULL != rowreq_ctx);
645
646 /*
647 * TODO:430:M: |-> Validate potential inetNetToMediaTable index.
648 */
649 if (1) {
650 snmp_log(LOG_WARNING, "invalid index for a new row in the "
651 "inetNetToMediaTable table.\n");
652 /*
653 * determine failure type.
654 *
655 * If the index could not ever be created, return MFD_NOT_EVER
656 * If the index can not be created under the present circumstances
657 * (even though it could be created under other circumstances),
658 * return MFD_NOT_NOW.
659 */
660 if (0) {
661 return MFD_CANNOT_CREATE_EVER;
662 } else {
663 return MFD_CANNOT_CREATE_NOW;
664 }
665 }
666
667 return rc;
668 } /* inetNetToMediaTable_validate_index */
669
670 /** @} */