| 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 "ipAddressPrefixTable.h" |
| 19 |
|
| 20 |
|
| 21 |
#include "ipAddressPrefixTable_data_access.h" |
| 22 |
|
| 23 |
#include "ip-mib/ipAddressTable/ipAddressTable.h" |
| 24 |
|
| 25 |
netsnmp_feature_require(ipAddressTable_container_get); |
| 26 |
netsnmp_feature_require(ipaddress_common_copy_utilities); |
| 27 |
netsnmp_feature_require(ipaddress_prefix_copy); |
| 28 |
|
| 29 |
/** @ingroup interface |
| 30 |
* @addtogroup data_access data_access: Routines to access data |
| 31 |
* |
| 32 |
* These routines are used to locate the data used to satisfy |
| 33 |
* requests. |
| 34 |
* |
| 35 |
* @{ |
| 36 |
*/ |
| 37 |
/********************************************************************** |
| 38 |
********************************************************************** |
| 39 |
*** |
| 40 |
*** Table ipAddressPrefixTable |
| 41 |
*** |
| 42 |
********************************************************************** |
| 43 |
**********************************************************************/ |
| 44 |
/* |
| 45 |
* IP-MIB::ipAddressPrefixTable is subid 32 of ip. |
| 46 |
* Its status is Current. |
| 47 |
* OID: .1.3.6.1.2.1.4.32, length: 8 |
| 48 |
*/ |
| 49 |
|
| 50 |
/** |
| 51 |
* initialization for ipAddressPrefixTable data access |
| 52 |
* |
| 53 |
* This function is called during startup to allow you to |
| 54 |
* allocate any resources you need for the data table. |
| 55 |
* |
| 56 |
* @param ipAddressPrefixTable_reg |
| 57 |
* Pointer to ipAddressPrefixTable_registration |
| 58 |
* |
| 59 |
* @retval MFD_SUCCESS : success. |
| 60 |
* @retval MFD_ERROR : unrecoverable error. |
| 61 |
*/ |
| 62 |
int |
| 63 |
ipAddressPrefixTable_init_data(ipAddressPrefixTable_registration * |
| 64 |
ipAddressPrefixTable_reg) |
| 65 |
{ |
| 66 |
DEBUGMSGTL(("verbose:ipAddressPrefixTable:ipAddressPrefixTable_init_data", "called\n")); |
| 67 |
|
| 68 |
/* |
| 69 |
* TODO:303:o: Initialize ipAddressPrefixTable data. |
| 70 |
*/ |
| 71 |
|
| 72 |
return MFD_SUCCESS; |
| 73 |
} /* ipAddressPrefixTable_init_data */ |
| 74 |
|
| 75 |
/** |
| 76 |
* container overview |
| 77 |
* |
| 78 |
*/ |
| 79 |
|
| 80 |
/** |
| 81 |
* container initialization |
| 82 |
* |
| 83 |
* @param container_ptr_ptr A pointer to a container pointer. If you |
| 84 |
* create a custom container, use this parameter to return it |
| 85 |
* to the MFD helper. If set to NULL, the MFD helper will |
| 86 |
* allocate a container for you. |
| 87 |
* @param cache A pointer to a cache structure. You can set the timeout |
| 88 |
* and other cache flags using this pointer. |
| 89 |
* |
| 90 |
* This function is called at startup to allow you to customize certain |
| 91 |
* aspects of the access method. For the most part, it is for advanced |
| 92 |
* users. The default code should suffice for most cases. If no custom |
| 93 |
* container is allocated, the MFD code will create one for your. |
| 94 |
* |
| 95 |
* This is also the place to set up cache behavior. The default, to |
| 96 |
* simply set the cache timeout, will work well with the default |
| 97 |
* container. If you are using a custom container, you may want to |
| 98 |
* look at the cache helper documentation to see if there are any |
| 99 |
* flags you want to set. |
| 100 |
* |
| 101 |
* @remark |
| 102 |
* This would also be a good place to do any initialization needed |
| 103 |
* for you data source. For example, opening a connection to another |
| 104 |
* process that will supply the data, opening a database, etc. |
| 105 |
*/ |
| 106 |
void |
| 107 |
ipAddressPrefixTable_container_init(netsnmp_container **container_ptr_ptr, |
| 108 |
netsnmp_cache * cache) |
| 109 |
{ |
| 110 |
DEBUGMSGTL(("verbose:ipAddressPrefixTable:ipAddressPrefixTable_container_init", "called\n")); |
| 111 |
|
| 112 |
if (NULL == container_ptr_ptr) { |
| 113 |
snmp_log(LOG_ERR, |
| 114 |
"bad container param to ipAddressPrefixTable_container_init\n"); |
| 115 |
return; |
| 116 |
} |
| 117 |
|
| 118 |
/* |
| 119 |
* For advanced users, you can use a custom container. If you |
| 120 |
* do not create one, one will be created for you. |
| 121 |
*/ |
| 122 |
*container_ptr_ptr = NULL; |
| 123 |
|
| 124 |
if (NULL == cache) { |
| 125 |
snmp_log(LOG_ERR, |
| 126 |
"bad cache param to ipAddressPrefixTable_container_init\n"); |
| 127 |
return; |
| 128 |
} |
| 129 |
|
| 130 |
/* |
| 131 |
* TODO:345:A: Set up ipAddressPrefixTable cache properties. |
| 132 |
* |
| 133 |
* Also for advanced users, you can set parameters for the |
| 134 |
* cache. Do not change the magic pointer, as it is used |
| 135 |
* by the MFD helper. To completely disable caching, set |
| 136 |
* cache->enabled to 0. |
| 137 |
*/ |
| 138 |
cache->timeout = IPADDRESSPREFIXTABLE_CACHE_TIMEOUT; /* seconds */ |
| 139 |
} /* ipAddressPrefixTable_container_init */ |
| 140 |
|
| 141 |
/** |
| 142 |
* container shutdown |
| 143 |
* |
| 144 |
* @param container_ptr A pointer to the container. |
| 145 |
* |
| 146 |
* This function is called at shutdown to allow you to customize certain |
| 147 |
* aspects of the access method. For the most part, it is for advanced |
| 148 |
* users. The default code should suffice for most cases. |
| 149 |
* |
| 150 |
* This function is called before ipAddressPrefixTable_container_free(). |
| 151 |
* |
| 152 |
* @remark |
| 153 |
* This would also be a good place to do any cleanup needed |
| 154 |
* for you data source. For example, closing a connection to another |
| 155 |
* process that supplied the data, closing a database, etc. |
| 156 |
*/ |
| 157 |
void |
| 158 |
ipAddressPrefixTable_container_shutdown(netsnmp_container *container_ptr) |
| 159 |
{ |
| 160 |
DEBUGMSGTL(("verbose:ipAddressPrefixTable:ipAddressPrefixTable_container_shutdown", "called\n")); |
| 161 |
|
| 162 |
if (NULL == container_ptr) { |
| 163 |
snmp_log(LOG_ERR, |
| 164 |
"bad params to ipAddressPrefixTable_container_shutdown\n"); |
| 165 |
return; |
| 166 |
} |
| 167 |
|
| 168 |
} /* ipAddressPrefixTable_container_shutdown */ |
| 169 |
|
| 170 |
/** |
| 171 |
* load initial data |
| 172 |
* |
| 173 |
* TODO:350:M: Implement ipAddressPrefixTable data load |
| 174 |
* This function will also be called by the cache helper to load |
| 175 |
* the container again (after the container free function has been |
| 176 |
* called to free the previous contents). |
| 177 |
* |
| 178 |
* @param container container to which items should be inserted |
| 179 |
* |
| 180 |
* @retval MFD_SUCCESS : success. |
| 181 |
* @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source |
| 182 |
* @retval MFD_ERROR : other error. |
| 183 |
* |
| 184 |
* This function is called to load the index(es) (and data, optionally) |
| 185 |
* for the every row in the data set. |
| 186 |
* |
| 187 |
* @remark |
| 188 |
* While loading the data, the only important thing is the indexes. |
| 189 |
* If access to your data is cheap/fast (e.g. you have a pointer to a |
| 190 |
* structure in memory), it would make sense to update the data here. |
| 191 |
* If, however, the accessing the data involves more work (e.g. parsing |
| 192 |
* some other existing data, or performing calculations to derive the data), |
| 193 |
* then you can limit yourself to setting the indexes and saving any |
| 194 |
* information you will need later. Then use the saved information in |
| 195 |
* ipAddressPrefixTable_row_prep() for populating data. |
| 196 |
* |
| 197 |
* @note |
| 198 |
* If you need consistency between rows (like you want statistics |
| 199 |
* for each row to be from the same time frame), you should set all |
| 200 |
* data here. |
| 201 |
* |
| 202 |
*/ |
| 203 |
int |
| 204 |
ipAddressPrefixTable_container_load(netsnmp_container *container) |
| 205 |
{ |
| 206 |
ipAddressPrefixTable_rowreq_ctx *rowreq_ctx = NULL, *tmp_rowreq_ctx; |
| 207 |
ipAddressTable_rowreq_ctx *addr_rowreq_ctx; |
| 208 |
netsnmp_container *addr_container; |
| 209 |
netsnmp_iterator *addr_it; |
| 210 |
int count = 0; |
| 211 |
u_char tmp_pfx[NETSNMP_ACCESS_IPADDRESS_BUF_SIZE]; |
| 212 |
|
| 213 |
DEBUGMSGTL(("verbose:ipAddressPrefixTable:ipAddressPrefixTable_container_load", "called\n")); |
| 214 |
|
| 215 |
addr_container = ipAddressTable_container_get(); |
| 216 |
if (NULL == addr_container) { |
| 217 |
DEBUGMSGTL(("ipAddressPrefixTable:container_load", |
| 218 |
"couldn't get ipAddress container\n")); |
| 219 |
return MFD_RESOURCE_UNAVAILABLE; |
| 220 |
} |
| 221 |
|
| 222 |
addr_it = CONTAINER_ITERATOR(addr_container); |
| 223 |
if (NULL == addr_container) { |
| 224 |
DEBUGMSGTL(("ipAddressPrefixTable:container_load", |
| 225 |
"couldn't get ipAddress iterator\n")); |
| 226 |
return MFD_RESOURCE_UNAVAILABLE; |
| 227 |
} |
| 228 |
|
| 229 |
/* |
| 230 |
* TODO:351:M: |-> Load/update data in the ipAddressPrefixTable container. |
| 231 |
* loop over your ipAddressPrefixTable data, allocate a rowreq context, |
| 232 |
* set the index(es) [and data, optionally] and insert into |
| 233 |
* the container. |
| 234 |
*/ |
| 235 |
for (addr_rowreq_ctx = ITERATOR_FIRST(addr_it); |
| 236 |
addr_rowreq_ctx; addr_rowreq_ctx = ITERATOR_NEXT(addr_it)) { |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
/* |
| 241 |
* TODO:352:M: | |-> set indexes in new ipAddressPrefixTable rowreq context. |
| 242 |
* data context will be set from the param (unless NULL, |
| 243 |
* in which case a new data context will be allocated) |
| 244 |
*/ |
| 245 |
if (NULL == rowreq_ctx) { |
| 246 |
rowreq_ctx = ipAddressPrefixTable_allocate_rowreq_ctx(NULL); |
| 247 |
if (NULL == rowreq_ctx) { |
| 248 |
snmp_log(LOG_ERR, "memory allocation failed\n"); |
| 249 |
ITERATOR_RELEASE(addr_it); |
| 250 |
return MFD_RESOURCE_UNAVAILABLE; |
| 251 |
} |
| 252 |
} |
| 253 |
netsnmp_ipaddress_prefix_copy(tmp_pfx, |
| 254 |
addr_rowreq_ctx->tbl_idx. |
| 255 |
ipAddressAddr, |
| 256 |
addr_rowreq_ctx->data-> |
| 257 |
ia_address_len, |
| 258 |
addr_rowreq_ctx->data-> |
| 259 |
ia_prefix_len); |
| 260 |
netsnmp_ipaddress_flags_copy(&rowreq_ctx->data. |
| 261 |
ipAddressPrefixAdvPreferredLifetime, |
| 262 |
&rowreq_ctx->data. |
| 263 |
ipAddressPrefixAdvValidLifetime, |
| 264 |
&rowreq_ctx->data. |
| 265 |
ipAddressPrefixOnLinkFlag, |
| 266 |
&rowreq_ctx->data. |
| 267 |
ipAddressPrefixAutonomousFlag, |
| 268 |
&addr_rowreq_ctx->data-> |
| 269 |
ia_prefered_lifetime, |
| 270 |
&addr_rowreq_ctx->data-> |
| 271 |
ia_valid_lifetime, |
| 272 |
&addr_rowreq_ctx->data-> |
| 273 |
ia_onlink_flag, |
| 274 |
&addr_rowreq_ctx->data-> |
| 275 |
ia_autonomous_flag); |
| 276 |
|
| 277 |
if (MFD_SUCCESS != |
| 278 |
ipAddressPrefixTable_indexes_set(rowreq_ctx, |
| 279 |
addr_rowreq_ctx->data-> |
| 280 |
if_index, |
| 281 |
addr_rowreq_ctx->tbl_idx. |
| 282 |
ipAddressAddrType, tmp_pfx, |
| 283 |
addr_rowreq_ctx->data-> |
| 284 |
ia_address_len, |
| 285 |
addr_rowreq_ctx->data-> |
| 286 |
ia_prefix_len)) { |
| 287 |
snmp_log(LOG_ERR, |
| 288 |
"error setting index while loading " |
| 289 |
"ipAddressPrefixTable data.\n"); |
| 290 |
ipAddressPrefixTable_release_rowreq_ctx(rowreq_ctx); |
| 291 |
rowreq_ctx = NULL; |
| 292 |
continue; |
| 293 |
} |
| 294 |
|
| 295 |
/** do we already have this prefix? */ |
| 296 |
tmp_rowreq_ctx = CONTAINER_FIND(container, rowreq_ctx); |
| 297 |
if (NULL != tmp_rowreq_ctx) |
| 298 |
continue; |
| 299 |
|
| 300 |
/* |
| 301 |
* TODO:352:r: | |-> populate ipAddressPrefixTable data context. |
| 302 |
* Populate data context here. (optionally, delay until row prep) |
| 303 |
*/ |
| 304 |
netsnmp_ipaddress_prefix_origin_copy(&rowreq_ctx->data. |
| 305 |
ipAddressPrefixOrigin, |
| 306 |
addr_rowreq_ctx->data-> |
| 307 |
ia_origin, |
| 308 |
addr_rowreq_ctx->data-> |
| 309 |
flags, |
| 310 |
addr_rowreq_ctx->tbl_idx. |
| 311 |
ipAddressAddrType); |
| 312 |
|
| 313 |
/** defer the rest til row prep */ |
| 314 |
|
| 315 |
/* |
| 316 |
* insert into table container, clear ptr so we reallocate |
| 317 |
*/ |
| 318 |
if (CONTAINER_INSERT(container, rowreq_ctx) == 0) { |
| 319 |
rowreq_ctx = NULL; |
| 320 |
++count; |
| 321 |
} |
| 322 |
} |
| 323 |
ITERATOR_RELEASE(addr_it); |
| 324 |
|
| 325 |
/* |
| 326 |
* clean up if "do we already have this prefix?" was true and no |
| 327 |
* CONTAINER_INSERT happened afterwards |
| 328 |
*/ |
| 329 |
if (rowreq_ctx) { |
| 330 |
ipAddressPrefixTable_release_rowreq_ctx(rowreq_ctx); |
| 331 |
} |
| 332 |
|
| 333 |
DEBUGMSGT(("verbose:ipAddressPrefixTable:ipAddressPrefixTable_container_load", "inserted %d records\n", count)); |
| 334 |
|
| 335 |
return MFD_SUCCESS; |
| 336 |
} /* ipAddressPrefixTable_container_load */ |
| 337 |
|
| 338 |
/** |
| 339 |
* container clean up |
| 340 |
* |
| 341 |
* @param container container with all current items |
| 342 |
* |
| 343 |
* This optional callback is called prior to all |
| 344 |
* item's being removed from the container. If you |
| 345 |
* need to do any processing before that, do it here. |
| 346 |
* |
| 347 |
* @note |
| 348 |
* The MFD helper will take care of releasing all the row contexts. |
| 349 |
* |
| 350 |
*/ |
| 351 |
void |
| 352 |
ipAddressPrefixTable_container_free(netsnmp_container *container) |
| 353 |
{ |
| 354 |
DEBUGMSGTL(("verbose:ipAddressPrefixTable:ipAddressPrefixTable_container_free", "called\n")); |
| 355 |
|
| 356 |
/* |
| 357 |
* TODO:380:M: Free ipAddressPrefixTable container data. |
| 358 |
*/ |
| 359 |
} /* ipAddressPrefixTable_container_free */ |
| 360 |
|
| 361 |
/** |
| 362 |
* prepare row for processing. |
| 363 |
* |
| 364 |
* When the agent has located the row for a request, this function is |
| 365 |
* called to prepare the row for processing. If you fully populated |
| 366 |
* the data context during the index setup phase, you may not need to |
| 367 |
* do anything. |
| 368 |
* |
| 369 |
* @param rowreq_ctx pointer to a context. |
| 370 |
* |
| 371 |
* @retval MFD_SUCCESS : success. |
| 372 |
* @retval MFD_ERROR : other error. |
| 373 |
*/ |
| 374 |
int |
| 375 |
ipAddressPrefixTable_row_prep(ipAddressPrefixTable_rowreq_ctx * rowreq_ctx) |
| 376 |
{ |
| 377 |
DEBUGMSGTL(("verbose:ipAddressPrefixTable:ipAddressPrefixTable_row_prep", "called\n")); |
| 378 |
|
| 379 |
netsnmp_assert(NULL != rowreq_ctx); |
| 380 |
|
| 381 |
/* |
| 382 |
* TODO:390:o: Prepare row for request. |
| 383 |
* If populating row data was delayed, this is the place to |
| 384 |
* fill in the row for this request. |
| 385 |
*/ |
| 386 |
if (INETADDRESSTYPE_IPV6 == rowreq_ctx->tbl_idx.ipAddressPrefixType) { |
| 387 |
|
| 388 |
} |
| 389 |
|
| 390 |
return MFD_SUCCESS; |
| 391 |
} /* ipAddressPrefixTable_row_prep */ |
| 392 |
|
| 393 |
/** @} */ |