Debian Codegraph @

agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_access.c

raw
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
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
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
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
170 _check_entry_for_updates(void *p, void *q)
171 {
172 ipDefaultRouterTable_rowreq_ctx *rowreq_ctx = p;
173 void **magic = q;
174 netsnmp_container *defaultrouter_container = magic[0];
175 netsnmp_container *to_delete = (netsnmp_container *) magic[1];
176
177 /*
178 * check for matching entry using secondary index.
179 */
180 netsnmp_defaultrouter_entry *defaultrouter_entry =
181 CONTAINER_FIND(defaultrouter_container, rowreq_ctx->data);
182 if (NULL == defaultrouter_entry) {
183 DEBUGMSGTL(("ipDefaultRouterTable:access", "removing missing entry\n"));
184
185 if (NULL == to_delete) {
186 magic[1] = to_delete = netsnmp_container_find("lifo");
187 if (NULL == to_delete)
188 snmp_log(LOG_ERR, "couldn't create delete container\n");
189 }
190 if (NULL != to_delete)
191 CONTAINER_INSERT(to_delete, rowreq_ctx);
192 } else {
193 DEBUGMSGTL(("ipDefaultRouterTable:access", "updating existing entry\n"));
194
195 /*
196 * Check for changes & update
197 */
198 netsnmp_access_defaultrouter_entry_update(rowreq_ctx->data,
199 defaultrouter_entry);
200
201 /*
202 * remove entry from ifcontainer
203 */
204 CONTAINER_REMOVE(defaultrouter_container, defaultrouter_entry);
205 netsnmp_access_defaultrouter_entry_free(defaultrouter_entry);
206 }
207 }
208
209 /**
210 * add new entry
211 */
212 static void
213 _add_new_entry(void *p, void *q)
214 {
215 netsnmp_defaultrouter_entry *defaultrouter_entry = p;
216 netsnmp_container *container = q;
217 ipDefaultRouterTable_rowreq_ctx *rowreq_ctx;
218
219 DEBUGMSGTL(("ipDefaultRouterTable:access", "creating new entry\n"));
220
221 netsnmp_assert(NULL != defaultrouter_entry);
222 netsnmp_assert(NULL != container);
223
224 /*
225 * allocate an row context and set the index(es)
226 */
227 rowreq_ctx = ipDefaultRouterTable_allocate_rowreq_ctx(defaultrouter_entry,
228 NULL);
229 if ((NULL != rowreq_ctx) &&
230 (MFD_SUCCESS ==
231 ipDefaultRouterTable_indexes_set(rowreq_ctx,
232 defaultrouter_entry->dr_addresstype,
233 defaultrouter_entry->dr_address,
234 defaultrouter_entry->dr_address_len,
235 defaultrouter_entry->dr_if_index))) {
236 if (CONTAINER_INSERT(container, rowreq_ctx) < 0) {
237 DEBUGMSGTL(("ipAddressTable:access",
238 "container insert failed for new entry\n"));
239 ipDefaultRouterTable_release_rowreq_ctx(rowreq_ctx);
240 return;
241 }
242 } else {
243 if (NULL != rowreq_ctx) {
244 snmp_log(LOG_ERR, "error setting index while loading "
245 "ipDefaultRouterTable cache.\n");
246 ipDefaultRouterTable_release_rowreq_ctx(rowreq_ctx);
247 } else {
248 snmp_log(LOG_ERR, "memory allocation failed while loading "
249 "ipDefaultRouterTable cache.\n");
250 netsnmp_access_defaultrouter_entry_free(defaultrouter_entry);
251 }
252
253 return;
254 }
255 }
256
257 /**
258 * load initial data
259 *
260 * TODO:350:M: Implement ipDefaultRouterTable data load
261 * This function will also be called by the cache helper to load
262 * the container again (after the container free function has been
263 * called to free the previous contents).
264 *
265 * @param container container to which items should be inserted
266 *
267 * @retval MFD_SUCCESS : success.
268 * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source
269 * @retval MFD_ERROR : other error.
270 *
271 * This function is called to load the index(es) (and data, optionally)
272 * for the every row in the data set.
273 *
274 * @remark
275 * While loading the data, the only important thing is the indexes.
276 * If access to your data is cheap/fast (e.g. you have a pointer to a
277 * structure in memory), it would make sense to update the data here.
278 * If, however, the accessing the data involves more work (e.g. parsing
279 * some other existing data, or performing calculations to derive the data),
280 * then you can limit yourself to setting the indexes and saving any
281 * information you will need later. Then use the saved information in
282 * ipDefaultRouterTable_row_prep() for populating data.
283 *
284 * @note
285 * If you need consistency between rows (like you want statistics
286 * for each row to be from the same time frame), you should set all
287 * data here.
288 *
289 */
290 int
291 ipDefaultRouterTable_container_load(netsnmp_container * container)
292 {
293 netsnmp_container *defaultrouter_container;
294 void *tmp_ptr[2];
295
296 DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_container_load", "called\n"));
297
298 /*
299 * TODO:351:M: |-> Load/update data in the ipDefaultRouterTable container.
300 * loop over your ipDefaultRouterTable data, allocate a rowreq context,
301 * set the index(es) [and data, optionally] and insert into
302 * the container.
303 */
304 defaultrouter_container =
305 netsnmp_access_defaultrouter_container_load(NULL,
306 NETSNMP_ACCESS_DEFAULTROUTER_LOAD_ADDL_IDX_BY_ADDR);
307
308 if (NULL == defaultrouter_container)
309 return MFD_RESOURCE_UNAVAILABLE; /* msg already logged */
310
311 /*
312 * we just got a fresh copy of interface data. compare it to
313 * what we've already got, and make any adjustments, saving
314 * missing addresses to be deleted.
315 */
316 tmp_ptr[0] = defaultrouter_container->next;
317 tmp_ptr[1] = NULL;
318 CONTAINER_FOR_EACH(container, _check_entry_for_updates, tmp_ptr);
319
320 /*
321 * now add any new interfaces
322 */
323 CONTAINER_FOR_EACH(defaultrouter_container, _add_new_entry, container);
324
325 /*
326 * free the container. we've either claimed each entry, or released it,
327 * so the access function doesn't need to clear the container.
328 */
329 netsnmp_access_defaultrouter_container_free(defaultrouter_container,
330 NETSNMP_ACCESS_DEFAULTROUTER_FREE_DONT_CLEAR);
331
332 /*
333 * remove deleted addresses from table container
334 */
335 if (NULL != tmp_ptr[1]) {
336 netsnmp_container *tmp_container =
337 (netsnmp_container *) tmp_ptr[1];
338 ipDefaultRouterTable_rowreq_ctx *tmp_ctx;
339
340 /*
341 * this works because the tmp_container is a linked list,
342 * which can be used like a stack...
343 */
344 while (CONTAINER_SIZE(tmp_container)) {
345 /*
346 * get from delete list
347 */
348 tmp_ctx = CONTAINER_FIRST(tmp_container);
349
350 /*
351 * release context, delete from table container
352 */
353 CONTAINER_REMOVE(container, tmp_ctx);
354 ipDefaultRouterTable_release_rowreq_ctx(tmp_ctx);
355
356 /*
357 * pop off delete list
358 */
359 CONTAINER_REMOVE(tmp_container, NULL);
360 }
361 }
362
363 DEBUGMSGT(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_container_load",
364 "%" NETSNMP_PRIz "d records\n", CONTAINER_SIZE(container)));
365
366 return MFD_SUCCESS;
367 }
368
369 /**
370 * container clean up
371 *
372 * @param container container with all current items
373 *
374 * This optional callback is called prior to all
375 * item's being removed from the container. If you
376 * need to do any processing before that, do it here.
377 *
378 * @note
379 * The MFD helper will take care of releasing all the row contexts.
380 *
381 */
382 void
383 ipDefaultRouterTable_container_free(netsnmp_container * container)
384 {
385 DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_container_free", "called\n"));
386
387 /*
388 * TODO:380:M: Free ipDefaultRouterTable container data.
389 */
390 } /* ipDefaultRouterTable_container_free */
391
392 /**
393 * prepare row for processing.
394 *
395 * When the agent has located the row for a request, this function is
396 * called to prepare the row for processing. If you fully populated
397 * the data context during the index setup phase, you may not need to
398 * do anything.
399 *
400 * @param rowreq_ctx pointer to a context.
401 *
402 * @retval MFD_SUCCESS : success.
403 * @retval MFD_ERROR : other error.
404 */
405 int
406 ipDefaultRouterTable_row_prep(ipDefaultRouterTable_rowreq_ctx * rowreq_ctx)
407 {
408 DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_row_prep", "called\n"));
409
410 netsnmp_assert(NULL != rowreq_ctx);
411
412 /*
413 * TODO:390:o: Prepare row for request.
414 * If populating row data was delayed, this is the place to
415 * fill in the row for this request.
416 */
417
418 return MFD_SUCCESS;
419 } /* ipDefaultRouterTable_row_prep */
420
421 /** @} */