1 /*
2 * Note: this file originally auto-generated by mib2c using
3 * version : 14170 $ of $
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 "ipDefaultRouterTable.h"
19
20
21 #include "ipDefaultRouterTable_data_access.h"
22
23 netsnmp_feature_require(container_lifo);
24
25 /** @ingroup interface
26 * @addtogroup data_access data_access: Routines to access data
27 *
28 * These routines are used to locate the data used to satisfy
29 * requests.
30 *
31 * @{
32 */
33 /**********************************************************************
34 **********************************************************************
35 ***
36 *** Table ipDefaultRouterTable
37 ***
38 **********************************************************************
39 **********************************************************************/
40 /*
41 * IP-MIB::ipDefaultRouterTable is subid 37 of ip.
42 * Its status is Current.
43 * OID: .1.3.6.1.2.1.4.37, length: 8
44 */
45
46 /**
47 * initialization for ipDefaultRouterTable data access
48 *
49 * This function is called during startup to allow you to
50 * allocate any resources you need for the data table.
51 *
52 * @param ipDefaultRouterTable_reg
53 * Pointer to ipDefaultRouterTable_registration
54 *
55 * @retval MFD_SUCCESS : success.
56 * @retval MFD_ERROR : unrecoverable error.
57 */
58 int
ipDefaultRouterTable_init_data(ipDefaultRouterTable_registration * ipDefaultRouterTable_reg)59 ipDefaultRouterTable_init_data(ipDefaultRouterTable_registration *
60 ipDefaultRouterTable_reg)
61 {
62 DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_init_data", "called\n"));
63
64 /*
65 * TODO:303:o: Initialize ipDefaultRouterTable data.
66 */
67
68 return MFD_SUCCESS;
69 } /* ipDefaultRouterTable_init_data */
70
71 /**
72 * container overview
73 *
74 */
75
76 /**
77 * container initialization
78 *
79 * @param container_ptr_ptr A pointer to a container pointer. If you
80 * create a custom container, use this parameter to return it
81 * to the MFD helper. If set to NULL, the MFD helper will
82 * allocate a container for you.
83 * @param cache A pointer to a cache structure. You can set the timeout
84 * and other cache flags using this pointer.
85 *
86 * This function is called at startup to allow you to customize certain
87 * aspects of the access method. For the most part, it is for advanced
88 * users. The default code should suffice for most cases. If no custom
89 * container is allocated, the MFD code will create one for your.
90 *
91 * This is also the place to set up cache behavior. The default, to
92 * simply set the cache timeout, will work well with the default
93 * container. If you are using a custom container, you may want to
94 * look at the cache helper documentation to see if there are any
95 * flags you want to set.
96 *
97 * @remark
98 * This would also be a good place to do any initialization needed
99 * for you data source. For example, opening a connection to another
100 * process that will supply the data, opening a database, etc.
101 */
102 void
ipDefaultRouterTable_container_init(netsnmp_container ** container_ptr_ptr,netsnmp_cache * cache)103 ipDefaultRouterTable_container_init(netsnmp_container ** container_ptr_ptr,
104 netsnmp_cache * cache)
105 {
106 DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_container_init", "called\n"));
107
108 if (NULL == container_ptr_ptr) {
109 snmp_log(LOG_ERR,
110 "bad container param to ipDefaultRouterTable_container_init\n");
111 return;
112 }
113
114 /*
115 * For advanced users, you can use a custom container. If you
116 * do not create one, one will be created for you.
117 */
118 *container_ptr_ptr = NULL;
119
120 if (NULL == cache) {
121 snmp_log(LOG_ERR,
122 "bad cache param to ipDefaultRouterTable_container_init\n");
123 return;
124 }
125
126 /*
127 * TODO:345:A: Set up ipDefaultRouterTable cache properties.
128 *
129 * Also for advanced users, you can set parameters for the
130 * cache. Do not change the magic pointer, as it is used
131 * by the MFD helper. To completely disable caching, set
132 * cache->enabled to 0.
133 */
134 cache->timeout = IPDEFAULTROUTERTABLE_CACHE_TIMEOUT; /* seconds */
135 } /* ipDefaultRouterTable_container_init */
136
137 /**
138 * container shutdown
139 *
140 * @param container_ptr A pointer to the container.
141 *
142 * This function is called at shutdown to allow you to customize certain
143 * aspects of the access method. For the most part, it is for advanced
144 * users. The default code should suffice for most cases.
145 *
146 * This function is called before ipDefaultRouterTable_container_free().
147 *
148 * @remark
149 * This would also be a good place to do any cleanup needed
150 * for you data source. For example, closing a connection to another
151 * process that supplied the data, closing a database, etc.
152 */
153 void
ipDefaultRouterTable_container_shutdown(netsnmp_container * container_ptr)154 ipDefaultRouterTable_container_shutdown(netsnmp_container * container_ptr)
155 {
156 DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_container_shutdown", "called\n"));
157
158 if (NULL == container_ptr) {
159 snmp_log(LOG_ERR,
160 "bad params to ipDefaultRouterTable_container_shutdown\n");
161 return;
162 }
163
164 } /* ipDefaultRouterTable_container_shutdown */
165
166 /**
167 * check entry for update
168 */
169 static void
_check_entry_for_updates(ipDefaultRouterTable_rowreq_ctx * rowreq_ctx,void ** magic)170 _check_entry_for_updates(ipDefaultRouterTable_rowreq_ctx * rowreq_ctx,
171 void **magic)
172 {
173 netsnmp_container *defaultrouter_container = magic[0];
174 netsnmp_container *to_delete = (netsnmp_container *) magic[1];
175
176 /*
177 * check for matching entry using secondary index.
178 */
179 netsnmp_defaultrouter_entry *defaultrouter_entry =
180 CONTAINER_FIND(defaultrouter_container, rowreq_ctx->data);
181 if (NULL == defaultrouter_entry) {
182 DEBUGMSGTL(("ipDefaultRouterTable:access", "removing missing entry\n"));
183
184 if (NULL == to_delete) {
185 magic[1] = to_delete = netsnmp_container_find("lifo");
186 if (NULL == to_delete)
187 snmp_log(LOG_ERR, "couldn't create delete container\n");
188 }
189 if (NULL != to_delete)
190 CONTAINER_INSERT(to_delete, rowreq_ctx);
191 } else {
192 DEBUGMSGTL(("ipDefaultRouterTable:access", "updating existing entry\n"));
193
194 /*
195 * Check for changes & update
196 */
197 netsnmp_access_defaultrouter_entry_update(rowreq_ctx->data,
198 defaultrouter_entry);
199
200 /*
201 * remove entry from ifcontainer
202 */
203 CONTAINER_REMOVE(defaultrouter_container, defaultrouter_entry);
204 netsnmp_access_defaultrouter_entry_free(defaultrouter_entry);
205 }
206 }
207
208 /**
209 * add new entry
210 */
211 static void
_add_new_entry(netsnmp_defaultrouter_entry * defaultrouter_entry,netsnmp_container * container)212 _add_new_entry(netsnmp_defaultrouter_entry *defaultrouter_entry,
213 netsnmp_container *container)
214 {
215 ipDefaultRouterTable_rowreq_ctx *rowreq_ctx;
216
217 DEBUGMSGTL(("ipDefaultRouterTable:access", "creating new entry\n"));
218
219 netsnmp_assert(NULL != defaultrouter_entry);
220 netsnmp_assert(NULL != container);
221
222 /*
223 * allocate an row context and set the index(es)
224 */
225 rowreq_ctx = ipDefaultRouterTable_allocate_rowreq_ctx(defaultrouter_entry,
226 NULL);
227 if ((NULL != rowreq_ctx) &&
228 (MFD_SUCCESS ==
229 ipDefaultRouterTable_indexes_set(rowreq_ctx,
230 defaultrouter_entry->dr_addresstype,
231 defaultrouter_entry->dr_address,
232 defaultrouter_entry->dr_address_len,
233 defaultrouter_entry->dr_if_index))) {
234 if (CONTAINER_INSERT(container, rowreq_ctx) < 0) {
235 DEBUGMSGTL(("ipAddressTable:access",
236 "container insert failed for new entry\n"));
237 ipDefaultRouterTable_release_rowreq_ctx(rowreq_ctx);
238 return;
239 }
240 } else {
241 if (NULL != rowreq_ctx) {
242 snmp_log(LOG_ERR, "error setting index while loading "
243 "ipDefaultRouterTable cache.\n");
244 ipDefaultRouterTable_release_rowreq_ctx(rowreq_ctx);
245 } else {
246 snmp_log(LOG_ERR, "memory allocation failed while loading "
247 "ipDefaultRouterTable cache.\n");
248 netsnmp_access_defaultrouter_entry_free(defaultrouter_entry);
249 }
250
251 return;
252 }
253 }
254
255 /**
256 * load initial data
257 *
258 * TODO:350:M: Implement ipDefaultRouterTable data load
259 * This function will also be called by the cache helper to load
260 * the container again (after the container free function has been
261 * called to free the previous contents).
262 *
263 * @param container container to which items should be inserted
264 *
265 * @retval MFD_SUCCESS : success.
266 * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source
267 * @retval MFD_ERROR : other error.
268 *
269 * This function is called to load the index(es) (and data, optionally)
270 * for the every row in the data set.
271 *
272 * @remark
273 * While loading the data, the only important thing is the indexes.
274 * If access to your data is cheap/fast (e.g. you have a pointer to a
275 * structure in memory), it would make sense to update the data here.
276 * If, however, the accessing the data invovles more work (e.g. parsing
277 * some other existing data, or peforming calculations to derive the data),
278 * then you can limit yourself to setting the indexes and saving any
279 * information you will need later. Then use the saved information in
280 * ipDefaultRouterTable_row_prep() for populating data.
281 *
282 * @note
283 * If you need consistency between rows (like you want statistics
284 * for each row to be from the same time frame), you should set all
285 * data here.
286 *
287 */
288 int
ipDefaultRouterTable_container_load(netsnmp_container * container)289 ipDefaultRouterTable_container_load(netsnmp_container * container)
290 {
291 netsnmp_container *defaultrouter_container;
292 void *tmp_ptr[2];
293
294 DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_container_load", "called\n"));
295
296 /*
297 * TODO:351:M: |-> Load/update data in the ipDefaultRouterTable container.
298 * loop over your ipDefaultRouterTable data, allocate a rowreq context,
299 * set the index(es) [and data, optionally] and insert into
300 * the container.
301 */
302 defaultrouter_container =
303 netsnmp_access_defaultrouter_container_load(NULL,
304 NETSNMP_ACCESS_DEFAULTROUTER_LOAD_ADDL_IDX_BY_ADDR);
305
306 if (NULL == defaultrouter_container)
307 return MFD_RESOURCE_UNAVAILABLE; /* msg already logged */
308
309 /*
310 * we just got a fresh copy of interface data. compare it to
311 * what we've already got, and make any adjustments, saving
312 * missing addresses to be deleted.
313 */
314 tmp_ptr[0] = defaultrouter_container->next;
315 tmp_ptr[1] = NULL;
316 CONTAINER_FOR_EACH(container,
317 (netsnmp_container_obj_func *) _check_entry_for_updates,
318 tmp_ptr);
319
320 /*
321 * now add any new interfaces
322 */
323 CONTAINER_FOR_EACH(defaultrouter_container,
324 (netsnmp_container_obj_func *) _add_new_entry,
325 container);
326
327 /*
328 * free the container. we've either claimed each entry, or released it,
329 * so the access function doesn't need to clear the container.
330 */
331 netsnmp_access_defaultrouter_container_free(defaultrouter_container,
332 NETSNMP_ACCESS_DEFAULTROUTER_FREE_DONT_CLEAR);
333
334 /*
335 * remove deleted addresses from table container
336 */
337 if (NULL != tmp_ptr[1]) {
338 netsnmp_container *tmp_container =
339 (netsnmp_container *) tmp_ptr[1];
340 ipDefaultRouterTable_rowreq_ctx *tmp_ctx;
341
342 /*
343 * this works because the tmp_container is a linked list,
344 * which can be used like a stack...
345 */
346 while (CONTAINER_SIZE(tmp_container)) {
347 /*
348 * get from delete list
349 */
350 tmp_ctx = CONTAINER_FIRST(tmp_container);
351
352 /*
353 * release context, delete from table container
354 */
355 CONTAINER_REMOVE(container, tmp_ctx);
356 ipDefaultRouterTable_release_rowreq_ctx(tmp_ctx);
357
358 /*
359 * pop off delete list
360 */
361 CONTAINER_REMOVE(tmp_container, NULL);
362 }
363 }
364
365 DEBUGMSGT(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_container_load",
366 "%" NETSNMP_PRIz "d records\n", CONTAINER_SIZE(container)));
367
368 return MFD_SUCCESS;
369 }
370
371 /**
372 * container clean up
373 *
374 * @param container container with all current items
375 *
376 * This optional callback is called prior to all
377 * item's being removed from the container. If you
378 * need to do any processing before that, do it here.
379 *
380 * @note
381 * The MFD helper will take care of releasing all the row contexts.
382 *
383 */
384 void
ipDefaultRouterTable_container_free(netsnmp_container * container)385 ipDefaultRouterTable_container_free(netsnmp_container * container)
386 {
387 DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_container_free", "called\n"));
388
389 /*
390 * TODO:380:M: Free ipDefaultRouterTable container data.
391 */
392 } /* ipDefaultRouterTable_container_free */
393
394 /**
395 * prepare row for processing.
396 *
397 * When the agent has located the row for a request, this function is
398 * called to prepare the row for processing. If you fully populated
399 * the data context during the index setup phase, you may not need to
400 * do anything.
401 *
402 * @param rowreq_ctx pointer to a context.
403 *
404 * @retval MFD_SUCCESS : success.
405 * @retval MFD_ERROR : other error.
406 */
407 int
ipDefaultRouterTable_row_prep(ipDefaultRouterTable_rowreq_ctx * rowreq_ctx)408 ipDefaultRouterTable_row_prep(ipDefaultRouterTable_rowreq_ctx * rowreq_ctx)
409 {
410 DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_row_prep", "called\n"));
411
412 netsnmp_assert(NULL != rowreq_ctx);
413
414 /*
415 * TODO:390:o: Prepare row for request.
416 * If populating row data was delayed, this is the place to
417 * fill in the row for this request.
418 */
419
420 return MFD_SUCCESS;
421 } /* ipDefaultRouterTable_row_prep */
422
423 /** @} */
424