| 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 |
#include <net-snmp/data_access/ipaddress.h> |
| 14 |
#include <net-snmp/data_access/udp_endpoint.h> |
| 15 |
|
| 16 |
/* |
| 17 |
* include our parent header |
| 18 |
*/ |
| 19 |
#include "udpEndpointTable.h" |
| 20 |
|
| 21 |
|
| 22 |
#include "udpEndpointTable_data_access.h" |
| 23 |
|
| 24 |
/** @ingroup interface |
| 25 |
* @addtogroup data_access data_access: Routines to access data |
| 26 |
* |
| 27 |
* These routines are used to locate the data used to satisfy |
| 28 |
* requests. |
| 29 |
* |
| 30 |
* @{ |
| 31 |
*/ |
| 32 |
/********************************************************************** |
| 33 |
********************************************************************** |
| 34 |
*** |
| 35 |
*** Table udpEndpointTable |
| 36 |
*** |
| 37 |
********************************************************************** |
| 38 |
**********************************************************************/ |
| 39 |
/* |
| 40 |
* UDP-MIB::udpEndpointTable is subid 7 of udp. |
| 41 |
* Its status is Current. |
| 42 |
* OID: .1.3.6.1.2.1.7.7, length: 8 |
| 43 |
*/ |
| 44 |
|
| 45 |
/** |
| 46 |
* initialization for udpEndpointTable data access |
| 47 |
* |
| 48 |
* This function is called during startup to allow you to |
| 49 |
* allocate any resources you need for the data table. |
| 50 |
* |
| 51 |
* @param udpEndpointTable_reg |
| 52 |
* Pointer to udpEndpointTable_registration |
| 53 |
* |
| 54 |
* @retval MFD_SUCCESS : success. |
| 55 |
* @retval MFD_ERROR : unrecoverable error. |
| 56 |
*/ |
| 57 |
int |
| 58 |
udpEndpointTable_init_data(udpEndpointTable_registration * |
| 59 |
udpEndpointTable_reg) |
| 60 |
{ |
| 61 |
DEBUGMSGTL(("verbose:udpEndpointTable:udpEndpointTable_init_data", |
| 62 |
"called\n")); |
| 63 |
|
| 64 |
/* |
| 65 |
* TODO:303:o: Initialize udpEndpointTable data. |
| 66 |
*/ |
| 67 |
|
| 68 |
return MFD_SUCCESS; |
| 69 |
} /* udpEndpointTable_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 |
udpEndpointTable_container_init(netsnmp_container **container_ptr_ptr, |
| 104 |
netsnmp_cache * cache) |
| 105 |
{ |
| 106 |
DEBUGMSGTL(("verbose:udpEndpointTable:udpEndpointTable_container_init", |
| 107 |
"called\n")); |
| 108 |
|
| 109 |
if (NULL == container_ptr_ptr) { |
| 110 |
snmp_log(LOG_ERR, |
| 111 |
"bad container param to udpEndpointTable_container_init\n"); |
| 112 |
return; |
| 113 |
} |
| 114 |
|
| 115 |
/* |
| 116 |
* For advanced users, you can use a custom container. If you |
| 117 |
* do not create one, one will be created for you. |
| 118 |
*/ |
| 119 |
*container_ptr_ptr = NULL; |
| 120 |
|
| 121 |
if (NULL == cache) { |
| 122 |
snmp_log(LOG_ERR, |
| 123 |
"bad cache param to udpEndpointTable_container_init\n"); |
| 124 |
return; |
| 125 |
} |
| 126 |
|
| 127 |
/* |
| 128 |
* TODO:345:A: Set up udpEndpointTable cache properties. |
| 129 |
* |
| 130 |
* Also for advanced users, you can set parameters for the |
| 131 |
* cache. Do not change the magic pointer, as it is used |
| 132 |
* by the MFD helper. To completely disable caching, set |
| 133 |
* cache->enabled to 0. |
| 134 |
*/ |
| 135 |
cache->timeout = UDPENDPOINTTABLE_CACHE_TIMEOUT; /* seconds */ |
| 136 |
} /* udpEndpointTable_container_init */ |
| 137 |
|
| 138 |
/** |
| 139 |
* container shutdown |
| 140 |
* |
| 141 |
* @param container_ptr A pointer to the container. |
| 142 |
* |
| 143 |
* This function is called at shutdown to allow you to customize certain |
| 144 |
* aspects of the access method. For the most part, it is for advanced |
| 145 |
* users. The default code should suffice for most cases. |
| 146 |
* |
| 147 |
* This function is called before udpEndpointTable_container_free(). |
| 148 |
* |
| 149 |
* @remark |
| 150 |
* This would also be a good place to do any cleanup needed |
| 151 |
* for you data source. For example, closing a connection to another |
| 152 |
* process that supplied the data, closing a database, etc. |
| 153 |
*/ |
| 154 |
void |
| 155 |
udpEndpointTable_container_shutdown(netsnmp_container *container_ptr) |
| 156 |
{ |
| 157 |
DEBUGMSGTL(("verbose:udpEndpointTable:udpEndpointTable_container_shutdown", "called\n")); |
| 158 |
|
| 159 |
if (NULL == container_ptr) { |
| 160 |
snmp_log(LOG_ERR, |
| 161 |
"bad params to udpEndpointTable_container_shutdown\n"); |
| 162 |
return; |
| 163 |
} |
| 164 |
|
| 165 |
} /* udpEndpointTable_container_shutdown */ |
| 166 |
|
| 167 |
/** |
| 168 |
* load initial data |
| 169 |
* |
| 170 |
* TODO:350:M: Implement udpEndpointTable data load |
| 171 |
* This function will also be called by the cache helper to load |
| 172 |
* the container again (after the container free function has been |
| 173 |
* called to free the previous contents). |
| 174 |
* |
| 175 |
* @param container container to which items should be inserted |
| 176 |
* |
| 177 |
* @retval MFD_SUCCESS : success. |
| 178 |
* @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source |
| 179 |
* @retval MFD_ERROR : other error. |
| 180 |
* |
| 181 |
* This function is called to load the index(es) (and data, optionally) |
| 182 |
* for the every row in the data set. |
| 183 |
* |
| 184 |
* @remark |
| 185 |
* While loading the data, the only important thing is the indexes. |
| 186 |
* If access to your data is cheap/fast (e.g. you have a pointer to a |
| 187 |
* structure in memory), it would make sense to update the data here. |
| 188 |
* If, however, the accessing the data involves more work (e.g. parsing |
| 189 |
* some other existing data, or performing calculations to derive the data), |
| 190 |
* then you can limit yourself to setting the indexes and saving any |
| 191 |
* information you will need later. Then use the saved information in |
| 192 |
* udpEndpointTable_row_prep() for populating data. |
| 193 |
* |
| 194 |
* @note |
| 195 |
* If you need consistency between rows (like you want statistics |
| 196 |
* for each row to be from the same time frame), you should set all |
| 197 |
* data here. |
| 198 |
* |
| 199 |
*/ |
| 200 |
static u_long |
| 201 |
_address_type_from_len(int addrlen) { |
| 202 |
switch (addrlen) { |
| 203 |
case 4: |
| 204 |
return INETADDRESSTYPE_IPV4; |
| 205 |
case 16: |
| 206 |
return INETADDRESSTYPE_IPV6; |
| 207 |
case 0: |
| 208 |
return INETADDRESSTYPE_UNKNOWN; |
| 209 |
default: |
| 210 |
/* To get same behavior as before */ |
| 211 |
return INETADDRESSTYPE_IPV4; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
int |
| 216 |
udpEndpointTable_container_load(netsnmp_container *container) |
| 217 |
{ |
| 218 |
udpEndpointTable_rowreq_ctx *rowreq_ctx; |
| 219 |
netsnmp_container *ep_c; |
| 220 |
netsnmp_iterator *ep_it; |
| 221 |
netsnmp_udp_endpoint_entry *ep; |
| 222 |
|
| 223 |
/* |
| 224 |
* temporary storage for index values |
| 225 |
*/ |
| 226 |
u_long udpEndpointLocalAddressType; |
| 227 |
u_long udpEndpointRemoteAddressType; |
| 228 |
|
| 229 |
DEBUGMSGTL(("verbose:udpEndpointTable:udpEndpointTable_container_load", |
| 230 |
"called\n")); |
| 231 |
|
| 232 |
/* |
| 233 |
* TODO:351:M: |-> Load/update data in the udpEndpointTable container. |
| 234 |
* loop over your udpEndpointTable data, allocate a rowreq context, |
| 235 |
* set the index(es) [and data, optionally] and insert into |
| 236 |
* the container. |
| 237 |
*/ |
| 238 |
ep_c = netsnmp_access_udp_endpoint_container_load(NULL, 0); |
| 239 |
if (NULL == ep_c) |
| 240 |
return MFD_RESOURCE_UNAVAILABLE; |
| 241 |
ep_it = CONTAINER_ITERATOR(ep_c); |
| 242 |
if (NULL == ep_it) { |
| 243 |
netsnmp_access_udp_endpoint_container_free(ep_c, 0); |
| 244 |
return MFD_RESOURCE_UNAVAILABLE; |
| 245 |
} |
| 246 |
for (ep = (netsnmp_udp_endpoint_entry*)ITERATOR_FIRST(ep_it); ep; |
| 247 |
ep = (netsnmp_udp_endpoint_entry*)ITERATOR_NEXT (ep_it)) { |
| 248 |
|
| 249 |
/* |
| 250 |
* TODO:352:M: | |-> set indexes in new udpEndpointTable rowreq context. |
| 251 |
*/ |
| 252 |
rowreq_ctx = udpEndpointTable_allocate_rowreq_ctx(); |
| 253 |
if (NULL == rowreq_ctx) { |
| 254 |
snmp_log(LOG_ERR, "memory allocation failed\n"); |
| 255 |
return MFD_RESOURCE_UNAVAILABLE; |
| 256 |
} |
| 257 |
udpEndpointLocalAddressType = _address_type_from_len(ep->loc_addr_len); |
| 258 |
udpEndpointRemoteAddressType = _address_type_from_len(ep->rmt_addr_len); |
| 259 |
if (MFD_SUCCESS != |
| 260 |
udpEndpointTable_indexes_set(rowreq_ctx, |
| 261 |
udpEndpointLocalAddressType, |
| 262 |
(char *) ep->loc_addr, |
| 263 |
ep->loc_addr_len, |
| 264 |
ep->loc_port, |
| 265 |
udpEndpointRemoteAddressType, |
| 266 |
(char *) ep->rmt_addr, |
| 267 |
ep->rmt_addr_len, |
| 268 |
ep->rmt_port, |
| 269 |
ep->instance, |
| 270 |
ep->pid)) { |
| 271 |
snmp_log(LOG_ERR, |
| 272 |
"error setting index while loading " |
| 273 |
"udpEndpointTable data.\n"); |
| 274 |
udpEndpointTable_release_rowreq_ctx(rowreq_ctx); |
| 275 |
continue; |
| 276 |
} |
| 277 |
|
| 278 |
/* |
| 279 |
* TODO:352:r: | |-> populate udpEndpointTable data context. |
| 280 |
* Populate data context here. (optionally, delay until row prep) |
| 281 |
*/ |
| 282 |
/* |
| 283 |
* non-TRANSIENT data: no need to copy. set pointer to data |
| 284 |
*/ |
| 285 |
|
| 286 |
/* |
| 287 |
* insert into table container |
| 288 |
*/ |
| 289 |
if (CONTAINER_INSERT(container, rowreq_ctx)) |
| 290 |
udpEndpointTable_release_rowreq_ctx(rowreq_ctx); |
| 291 |
} |
| 292 |
|
| 293 |
ITERATOR_RELEASE(ep_it); |
| 294 |
|
| 295 |
netsnmp_access_udp_endpoint_container_free(ep_c, 0); |
| 296 |
|
| 297 |
|
| 298 |
DEBUGMSGT(("verbose:udpEndpointTable:udpEndpointTable_container_load", |
| 299 |
"inserted %d records\n", (int)CONTAINER_SIZE(container))); |
| 300 |
|
| 301 |
return MFD_SUCCESS; |
| 302 |
} /* udpEndpointTable_container_load */ |
| 303 |
|
| 304 |
/** |
| 305 |
* container clean up |
| 306 |
* |
| 307 |
* @param container container with all current items |
| 308 |
* |
| 309 |
* This optional callback is called prior to all |
| 310 |
* item's being removed from the container. If you |
| 311 |
* need to do any processing before that, do it here. |
| 312 |
* |
| 313 |
* @note |
| 314 |
* The MFD helper will take care of releasing all the row contexts. |
| 315 |
* |
| 316 |
*/ |
| 317 |
void |
| 318 |
udpEndpointTable_container_free(netsnmp_container *container) |
| 319 |
{ |
| 320 |
DEBUGMSGTL(("verbose:udpEndpointTable:udpEndpointTable_container_free", |
| 321 |
"called\n")); |
| 322 |
|
| 323 |
/* |
| 324 |
* TODO:380:M: Free udpEndpointTable container data. |
| 325 |
*/ |
| 326 |
} /* udpEndpointTable_container_free */ |
| 327 |
|
| 328 |
/** |
| 329 |
* prepare row for processing. |
| 330 |
* |
| 331 |
* When the agent has located the row for a request, this function is |
| 332 |
* called to prepare the row for processing. If you fully populated |
| 333 |
* the data context during the index setup phase, you may not need to |
| 334 |
* do anything. |
| 335 |
* |
| 336 |
* @param rowreq_ctx pointer to a context. |
| 337 |
* |
| 338 |
* @retval MFD_SUCCESS : success. |
| 339 |
* @retval MFD_ERROR : other error. |
| 340 |
*/ |
| 341 |
int |
| 342 |
udpEndpointTable_row_prep(udpEndpointTable_rowreq_ctx * rowreq_ctx) |
| 343 |
{ |
| 344 |
DEBUGMSGTL(("verbose:udpEndpointTable:udpEndpointTable_row_prep", |
| 345 |
"called\n")); |
| 346 |
|
| 347 |
netsnmp_assert(NULL != rowreq_ctx); |
| 348 |
|
| 349 |
/* |
| 350 |
* TODO:390:o: Prepare row for request. |
| 351 |
* If populating row data was delayed, this is the place to |
| 352 |
* fill in the row for this request. |
| 353 |
*/ |
| 354 |
|
| 355 |
return MFD_SUCCESS; |
| 356 |
} /* udpEndpointTable_row_prep */ |
| 357 |
|
| 358 |
/** @} */ |