Debian Codegraph @

agent/mibgroup/tcp-mib/tcpConnectionTable/tcpConnectionTable_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-includes.h>
12 #include <net-snmp/agent/net-snmp-agent-includes.h>
13
14 /*
15 * include our parent header
16 */
17 #include "tcpConnectionTable.h"
18
19
20 #include "tcpConnectionTable_data_access.h"
21
22 /** @ingroup interface
23 * @addtogroup data_access data_access: Routines to access data
24 *
25 * These routines are used to locate the data used to satisfy
26 * requests.
27 *
28 * @{
29 */
30 /**********************************************************************
31 **********************************************************************
32 ***
33 *** Table tcpConnectionTable
34 ***
35 **********************************************************************
36 **********************************************************************/
37 /*
38 * TCP-MIB::tcpConnectionTable is subid 19 of tcp.
39 * Its status is Current.
40 * OID: .1.3.6.1.2.1.6.19, length: 8
41 */
42
43 /**
44 * initialization for tcpConnectionTable data access
45 *
46 * This function is called during startup to allow you to
47 * allocate any resources you need for the data table.
48 *
49 * @param tcpConnectionTable_reg
50 * Pointer to tcpConnectionTable_registration
51 *
52 * @retval MFD_SUCCESS : success.
53 * @retval MFD_ERROR : unrecoverable error.
54 */
55 int
56 tcpConnectionTable_init_data(tcpConnectionTable_registration *
57 tcpConnectionTable_reg)
58 {
59 DEBUGMSGTL(("verbose:tcpConnectionTable:tcpConnectionTable_init_data",
60 "called\n"));
61
62 /*
63 * TODO:303:o: Initialize tcpConnectionTable data.
64 */
65
66 return MFD_SUCCESS;
67 } /* tcpConnectionTable_init_data */
68
69 /**
70 * container overview
71 *
72 */
73
74 /**
75 * container initialization
76 *
77 * @param container_ptr_ptr A pointer to a container pointer. If you
78 * create a custom container, use this parameter to return it
79 * to the MFD helper. If set to NULL, the MFD helper will
80 * allocate a container for you.
81 * @param cache A pointer to a cache structure. You can set the timeout
82 * and other cache flags using this pointer.
83 *
84 * This function is called at startup to allow you to customize certain
85 * aspects of the access method. For the most part, it is for advanced
86 * users. The default code should suffice for most cases. If no custom
87 * container is allocated, the MFD code will create one for your.
88 *
89 * This is also the place to set up cache behavior. The default, to
90 * simply set the cache timeout, will work well with the default
91 * container. If you are using a custom container, you may want to
92 * look at the cache helper documentation to see if there are any
93 * flags you want to set.
94 *
95 * @remark
96 * This would also be a good place to do any initialization needed
97 * for you data source. For example, opening a connection to another
98 * process that will supply the data, opening a database, etc.
99 */
100 void
101 tcpConnectionTable_container_init(netsnmp_container **container_ptr_ptr,
102 netsnmp_cache * cache)
103 {
104 DEBUGMSGTL(("verbose:tcpConnectionTable:tcpConnectionTable_container_init", "called\n"));
105
106 if (NULL == container_ptr_ptr) {
107 snmp_log(LOG_ERR,
108 "bad container param to tcpConnectionTable_container_init\n");
109 return;
110 }
111
112 /*
113 * For advanced users, you can use a custom container. If you
114 * do not create one, one will be created for you.
115 */
116 *container_ptr_ptr = NULL;
117
118 if (NULL == cache) {
119 snmp_log(LOG_ERR,
120 "bad cache param to tcpConnectionTable_container_init\n");
121 return;
122 }
123
124 /*
125 * TODO:345:A: Set up tcpConnectionTable cache properties.
126 *
127 * Also for advanced users, you can set parameters for the
128 * cache. Do not change the magic pointer, as it is used
129 * by the MFD helper. To completely disable caching, set
130 * cache->enabled to 0.
131 */
132 cache->timeout = TCPCONNECTIONTABLE_CACHE_TIMEOUT; /* seconds */
133 cache->flags |= NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;
134 } /* tcpConnectionTable_container_init */
135
136 /**
137 * container shutdown
138 *
139 * @param container_ptr A pointer to the container.
140 *
141 * This function is called at shutdown to allow you to customize certain
142 * aspects of the access method. For the most part, it is for advanced
143 * users. The default code should suffice for most cases.
144 *
145 * This function is called before tcpConnectionTable_container_free().
146 *
147 * @remark
148 * This would also be a good place to do any cleanup needed
149 * for you data source. For example, closing a connection to another
150 * process that supplied the data, closing a database, etc.
151 */
152 void
153 tcpConnectionTable_container_shutdown(netsnmp_container *container_ptr)
154 {
155 DEBUGMSGTL(("verbose:tcpConnectionTable:tcpConnectionTable_container_shutdown", "called\n"));
156
157 if (NULL == container_ptr) {
158 snmp_log(LOG_ERR,
159 "bad params to tcpConnectionTable_container_shutdown\n");
160 return;
161 }
162
163 } /* tcpConnectionTable_container_shutdown */
164
165 /**
166 * add new entry
167 */
168 static void
169 _add_connection(void *p, void *q)
170 {
171 netsnmp_tcpconn_entry *entry = p;
172 netsnmp_container *container = q;
173 tcpConnectionTable_rowreq_ctx *rowreq_ctx;
174
175 DEBUGMSGTL(("tcpConnectionTable:access", "creating new entry\n"));
176
177 /*
178 * allocate an row context and set the index(es), then add it to
179 * the container
180 */
181 rowreq_ctx = tcpConnectionTable_allocate_rowreq_ctx(entry, NULL);
182 if ((NULL != rowreq_ctx) &&
183 (MFD_SUCCESS == tcpConnectionTable_indexes_set(rowreq_ctx,
184 entry->loc_addr_len,
185 entry->loc_addr,
186 entry->loc_addr_len,
187 entry->loc_port,
188 entry->rmt_addr_len,
189 entry->rmt_addr,
190 entry->rmt_addr_len,
191 entry->rmt_port))) {
192 if (CONTAINER_INSERT(container, rowreq_ctx)) {
193 NETSNMP_LOGONCE((LOG_DEBUG,
194 "Error inserting entry to tcpConnectionTable,"\
195 " entry already exists.\n"));
196 tcpConnectionTable_release_rowreq_ctx(rowreq_ctx);
197 }
198 } else {
199 if (rowreq_ctx) {
200 snmp_log(LOG_ERR, "error setting index while loading "
201 "tcpConnectionTable cache.\n");
202 tcpConnectionTable_release_rowreq_ctx(rowreq_ctx);
203 } else {
204 snmp_log(LOG_ERR, "memory allocation failed while loading "
205 "tcpConnectionTable cache.\n");
206 netsnmp_access_tcpconn_entry_free(entry);
207 }
208 }
209 }
210
211 /**
212 * load initial data
213 *
214 * TODO:350:M: Implement tcpConnectionTable data load
215 * This function will also be called by the cache helper to load
216 * the container again (after the container free function has been
217 * called to free the previous contents).
218 *
219 * @param container container to which items should be inserted
220 *
221 * @retval MFD_SUCCESS : success.
222 * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source
223 * @retval MFD_ERROR : other error.
224 *
225 * This function is called to load the index(es) (and data, optionally)
226 * for the every row in the data set.
227 *
228 * @remark
229 * While loading the data, the only important thing is the indexes.
230 * If access to your data is cheap/fast (e.g. you have a pointer to a
231 * structure in memory), it would make sense to update the data here.
232 * If, however, the accessing the data involves more work (e.g. parsing
233 * some other existing data, or performing calculations to derive the data),
234 * then you can limit yourself to setting the indexes and saving any
235 * information you will need later. Then use the saved information in
236 * tcpConnectionTable_row_prep() for populating data.
237 *
238 * @note
239 * If you need consistency between rows (like you want statistics
240 * for each row to be from the same time frame), you should set all
241 * data here.
242 *
243 */
244 int
245 tcpConnectionTable_container_load(netsnmp_container *container)
246 {
247 netsnmp_container *raw_data =
248 netsnmp_access_tcpconn_container_load(NULL,
249 NETSNMP_ACCESS_TCPCONN_LOAD_NOLISTEN);
250
251 DEBUGMSGTL(("verbose:tcpConnectionTable:tcpConnectionTable_container_load", "called\n"));
252
253 if (NULL == raw_data)
254 return MFD_RESOURCE_UNAVAILABLE; /* msg already logged */
255
256 /*
257 * got all the connections. pull out the active ones.
258 */
259 CONTAINER_FOR_EACH(raw_data, _add_connection, container);
260
261 /*
262 * free the container. we've either claimed each entry, or released it,
263 * so the dal function doesn't need to clear the container.
264 */
265 netsnmp_access_tcpconn_container_free(raw_data,
266 NETSNMP_ACCESS_TCPCONN_FREE_DONT_CLEAR);
267
268 DEBUGMSGT(("verbose:tcpConnectionTable:tcpConnectionTable_cache_load",
269 "%d records\n", (int)CONTAINER_SIZE(container)));
270
271 return MFD_SUCCESS;
272 } /* tcpConnectionTable_container_load */
273
274 /**
275 * container clean up
276 *
277 * @param container container with all current items
278 *
279 * This optional callback is called prior to all
280 * item's being removed from the container. If you
281 * need to do any processing before that, do it here.
282 *
283 * @note
284 * The MFD helper will take care of releasing all the row contexts.
285 *
286 */
287 void
288 tcpConnectionTable_container_free(netsnmp_container *container)
289 {
290 DEBUGMSGTL(("verbose:tcpConnectionTable:tcpConnectionTable_container_free", "called\n"));
291
292 /*
293 * TODO:380:M: Free tcpConnectionTable container data.
294 */
295 } /* tcpConnectionTable_container_free */
296
297 /**
298 * prepare row for processing.
299 *
300 * When the agent has located the row for a request, this function is
301 * called to prepare the row for processing. If you fully populated
302 * the data context during the index setup phase, you may not need to
303 * do anything.
304 *
305 * @param rowreq_ctx pointer to a context.
306 *
307 * @retval MFD_SUCCESS : success.
308 * @retval MFD_ERROR : other error.
309 */
310 int
311 tcpConnectionTable_row_prep(tcpConnectionTable_rowreq_ctx * rowreq_ctx)
312 {
313 DEBUGMSGTL(("verbose:tcpConnectionTable:tcpConnectionTable_row_prep",
314 "called\n"));
315
316 netsnmp_assert(NULL != rowreq_ctx);
317
318 /*
319 * TODO:390:o: Prepare row for request.
320 * If populating row data was delayed, this is the place to
321 * fill in the row for this request.
322 */
323
324 return MFD_SUCCESS;
325 } /* tcpConnectionTable_row_prep */
326
327 /** @} */