| 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 "ipv6InterfaceTable.h" |
| 18 |
|
| 19 |
|
| 20 |
#include "ipv6InterfaceTable_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 ipv6InterfaceTable |
| 34 |
*** |
| 35 |
********************************************************************** |
| 36 |
**********************************************************************/ |
| 37 |
/* |
| 38 |
* IP-MIB::ipv6InterfaceTable is subid 30 of ip. |
| 39 |
* Its status is Current. |
| 40 |
* OID: .1.3.6.1.2.1.4.30, length: 8 |
| 41 |
*/ |
| 42 |
|
| 43 |
/** |
| 44 |
* initialization for ipv6InterfaceTable 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 ipv6InterfaceTable_reg |
| 50 |
* Pointer to ipv6InterfaceTable_registration |
| 51 |
* |
| 52 |
* @retval MFD_SUCCESS : success. |
| 53 |
* @retval MFD_ERROR : unrecoverable error. |
| 54 |
*/ |
| 55 |
int |
| 56 |
ipv6InterfaceTable_init_data(ipv6InterfaceTable_registration * |
| 57 |
ipv6InterfaceTable_reg) |
| 58 |
{ |
| 59 |
DEBUGMSGTL(("verbose:ipv6InterfaceTable:ipv6InterfaceTable_init_data", |
| 60 |
"called\n")); |
| 61 |
|
| 62 |
/* |
| 63 |
* TODO:303:o: Initialize ipv6InterfaceTable data. |
| 64 |
*/ |
| 65 |
|
| 66 |
return MFD_SUCCESS; |
| 67 |
} /* ipv6InterfaceTable_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 |
* |
| 82 |
* This function is called at startup to allow you to customize certain |
| 83 |
* aspects of the access method. For the most part, it is for advanced |
| 84 |
* users. The default code should suffice for most cases. If no custom |
| 85 |
* container is allocated, the MFD code will create one for your. |
| 86 |
* |
| 87 |
* @remark |
| 88 |
* This would also be a good place to do any initialization needed |
| 89 |
* for you data source. For example, opening a connection to another |
| 90 |
* process that will supply the data, opening a database, etc. |
| 91 |
*/ |
| 92 |
void |
| 93 |
ipv6InterfaceTable_container_init(netsnmp_container **container_ptr_ptr) |
| 94 |
{ |
| 95 |
DEBUGMSGTL(("verbose:ipv6InterfaceTable:ipv6InterfaceTable_container_init", "called\n")); |
| 96 |
|
| 97 |
if (NULL == container_ptr_ptr) { |
| 98 |
snmp_log(LOG_ERR, |
| 99 |
"bad container param to ipv6InterfaceTable_container_init\n"); |
| 100 |
return; |
| 101 |
} |
| 102 |
|
| 103 |
/* |
| 104 |
* For advanced users, you can use a custom container. If you |
| 105 |
* do not create one, one will be created for you. |
| 106 |
*/ |
| 107 |
*container_ptr_ptr = NULL; |
| 108 |
|
| 109 |
} /* ipv6InterfaceTable_container_init */ |
| 110 |
|
| 111 |
/** |
| 112 |
* @internal |
| 113 |
* determine if we want a ifTable row in our container |
| 114 |
*/ |
| 115 |
void |
| 116 |
ipv6InterfaceTable_check_entry_for_updates(const ifTable_rowreq_ctx * |
| 117 |
ift_rrc, |
| 118 |
netsnmp_interface_entry *entry) |
| 119 |
{ |
| 120 |
netsnmp_container *c = ipv6InterfaceTable_container_get(); |
| 121 |
ifTable_rowreq_ctx *ip6if_rrc; |
| 122 |
int changed = 0; |
| 123 |
|
| 124 |
DEBUGMSGTL(("verbose:ipv6InterfaceTable:check_entry_for_updates", |
| 125 |
"called\n")); |
| 126 |
|
| 127 |
/* |
| 128 |
* do we have a corresponding row? |
| 129 |
*/ |
| 130 |
ip6if_rrc = CONTAINER_FIND(c, ift_rrc); |
| 131 |
if (NULL == ip6if_rrc) { |
| 132 |
/* |
| 133 |
* no corresponding row. should we have one? |
| 134 |
*/ |
| 135 |
if ((NULL != entry) && |
| 136 |
(entry->ns_flags & NETSNMP_INTERFACE_FLAGS_HAS_IPV6)) { |
| 137 |
/* |
| 138 |
* yes. |
| 139 |
*/ |
| 140 |
DEBUGMSGTL(("ipv6InterfaceTable:check_entry_for_updates", |
| 141 |
"inserted row for index %" NETSNMP_PRIo "d\n", entry->index)); |
| 142 |
CONTAINER_INSERT(c, ift_rrc); |
| 143 |
changed = 1; |
| 144 |
} |
| 145 |
} else { |
| 146 |
/* |
| 147 |
* found corresponding row. is it still applicable? |
| 148 |
*/ |
| 149 |
if ((NULL == entry) || |
| 150 |
(0 == (entry->ns_flags & NETSNMP_INTERFACE_FLAGS_HAS_IPV6))) { |
| 151 |
/* |
| 152 |
* no |
| 153 |
*/ |
| 154 |
DEBUGMSGTL(("ipv6InterfaceTable:check_entry_for_updates", |
| 155 |
"removed row for index %" NETSNMP_PRIo "d\n", |
| 156 |
ift_rrc->data.ifentry->index)); |
| 157 |
CONTAINER_REMOVE(c, ift_rrc); |
| 158 |
changed = 1; |
| 159 |
} else { |
| 160 |
/* |
| 161 |
* still applicable. anything changed? |
| 162 |
*/ |
| 163 |
if (/** retransmit */ |
| 164 |
((entry-> |
| 165 |
ns_flags & NETSNMP_INTERFACE_FLAGS_HAS_V6_RETRANSMIT) |
| 166 |
&& (entry->retransmit_v6 != |
| 167 |
ift_rrc->data.ifentry->retransmit_v6)) || |
| 168 |
/** reasm */ |
| 169 |
((entry-> |
| 170 |
ns_flags & NETSNMP_INTERFACE_FLAGS_HAS_V6_REASMMAX) |
| 171 |
&& (entry->reasm_max_v6 != |
| 172 |
ift_rrc->data.ifentry->reasm_max_v6)) || |
| 173 |
/** reachable time */ |
| 174 |
((entry-> |
| 175 |
ns_flags & NETSNMP_INTERFACE_FLAGS_HAS_V6_REACHABLE) |
| 176 |
&& (entry->reachable_time != |
| 177 |
ift_rrc->data.ifentry->reachable_time)) || |
| 178 |
/** if id */ |
| 179 |
((entry->ns_flags & NETSNMP_INTERFACE_FLAGS_HAS_V6_IFID) |
| 180 |
&& |
| 181 |
((entry->v6_if_id_len != |
| 182 |
ift_rrc->data.ifentry->v6_if_id_len) |
| 183 |
|| (0 != |
| 184 |
memcmp(entry->v6_if_id, |
| 185 |
ift_rrc->data.ifentry->v6_if_id, |
| 186 |
entry->v6_if_id_len)))) || |
| 187 |
/** forwarding */ |
| 188 |
((entry-> |
| 189 |
ns_flags & NETSNMP_INTERFACE_FLAGS_HAS_V6_FORWARDING) |
| 190 |
&& (entry->forwarding_v6 != |
| 191 |
ift_rrc->data.ifentry->forwarding_v6))) { |
| 192 |
DEBUGMSGTL(("ipv6InterfaceTable:check_entry_for_updates", |
| 193 |
"row changed for index %" NETSNMP_PRIo "d\n", |
| 194 |
ift_rrc->data.ifentry->index)); |
| 195 |
changed = 1; |
| 196 |
} |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
/* |
| 201 |
* if something changed, update table last changed |
| 202 |
*/ |
| 203 |
if (changed) |
| 204 |
ipv6InterfaceTable_lastChange_set(netsnmp_get_agent_uptime()); |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
/** |
| 209 |
* container shutdown |
| 210 |
* |
| 211 |
* @param container_ptr A pointer to the container. |
| 212 |
* |
| 213 |
* This function is called at shutdown to allow you to customize certain |
| 214 |
* aspects of the access method. For the most part, it is for advanced |
| 215 |
* users. The default code should suffice for most cases. |
| 216 |
* |
| 217 |
* This function is called before ipv6InterfaceTable_container_free(). |
| 218 |
* |
| 219 |
* @remark |
| 220 |
* This would also be a good place to do any cleanup needed |
| 221 |
* for you data source. For example, closing a connection to another |
| 222 |
* process that supplied the data, closing a database, etc. |
| 223 |
*/ |
| 224 |
void |
| 225 |
ipv6InterfaceTable_container_shutdown(netsnmp_container *container_ptr) |
| 226 |
{ |
| 227 |
DEBUGMSGTL(("verbose:ipv6InterfaceTable:ipv6InterfaceTable_container_shutdown", "called\n")); |
| 228 |
|
| 229 |
if (NULL == container_ptr) { |
| 230 |
snmp_log(LOG_ERR, |
| 231 |
"bad params to ipv6InterfaceTable_container_shutdown\n"); |
| 232 |
return; |
| 233 |
} |
| 234 |
|
| 235 |
} /* ipv6InterfaceTable_container_shutdown */ |
| 236 |
|
| 237 |
/** |
| 238 |
* load initial data |
| 239 |
* |
| 240 |
* TODO:350:M: Implement ipv6InterfaceTable data load |
| 241 |
* |
| 242 |
* @param container container to which items should be inserted |
| 243 |
* |
| 244 |
* @retval MFD_SUCCESS : success. |
| 245 |
* @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source |
| 246 |
* @retval MFD_ERROR : other error. |
| 247 |
* |
| 248 |
* This function is called to load the index(es) (and data, optionally) |
| 249 |
* for the every row in the data set. |
| 250 |
* |
| 251 |
* @remark |
| 252 |
* While loading the data, the only important thing is the indexes. |
| 253 |
* If access to your data is cheap/fast (e.g. you have a pointer to a |
| 254 |
* structure in memory), it would make sense to update the data here. |
| 255 |
* If, however, the accessing the data involves more work (e.g. parsing |
| 256 |
* some other existing data, or performing calculations to derive the data), |
| 257 |
* then you can limit yourself to setting the indexes and saving any |
| 258 |
* information you will need later. Then use the saved information in |
| 259 |
* ipv6InterfaceTable_row_prep() for populating data. |
| 260 |
* |
| 261 |
* @note |
| 262 |
* If you need consistency between rows (like you want statistics |
| 263 |
* for each row to be from the same time frame), you should set all |
| 264 |
* data here. |
| 265 |
* |
| 266 |
*/ |
| 267 |
int |
| 268 |
ipv6InterfaceTable_container_load(netsnmp_container *container) |
| 269 |
{ |
| 270 |
ipv6InterfaceTable_rowreq_ctx *rowreq_ctx; |
| 271 |
size_t count = 0; |
| 272 |
|
| 273 |
/* |
| 274 |
* temporary storage for index values |
| 275 |
*/ |
| 276 |
/* |
| 277 |
* ipv6InterfaceIfIndex(1)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H |
| 278 |
*/ |
| 279 |
long ipv6InterfaceIfIndex; |
| 280 |
|
| 281 |
|
| 282 |
DEBUGMSGTL(("verbose:ipv6InterfaceTable:ipv6InterfaceTable_container_load", "called\n")); |
| 283 |
|
| 284 |
/* |
| 285 |
* TODO:351:M: |-> Load/update data in the ipv6InterfaceTable container. |
| 286 |
* loop over your ipv6InterfaceTable data, allocate a rowreq context, |
| 287 |
* set the index(es) [and data, optionally] and insert into |
| 288 |
* the container. |
| 289 |
*/ |
| 290 |
while (1) { |
| 291 |
/* |
| 292 |
* check for end of data; bail out if there is no more data |
| 293 |
*/ |
| 294 |
if (1) |
| 295 |
break; |
| 296 |
|
| 297 |
/* |
| 298 |
* TODO:352:M: | |-> set indexes in new ipv6InterfaceTable rowreq context. |
| 299 |
* data context will be set from the param (unless NULL, |
| 300 |
* in which case a new data context will be allocated) |
| 301 |
*/ |
| 302 |
rowreq_ctx = ipv6InterfaceTable_allocate_rowreq_ctx(NULL); |
| 303 |
if (NULL == rowreq_ctx) { |
| 304 |
snmp_log(LOG_ERR, "memory allocation failed\n"); |
| 305 |
return MFD_RESOURCE_UNAVAILABLE; |
| 306 |
} |
| 307 |
if (MFD_SUCCESS != |
| 308 |
ipv6InterfaceTable_indexes_set(rowreq_ctx, |
| 309 |
ipv6InterfaceIfIndex)) { |
| 310 |
snmp_log(LOG_ERR, |
| 311 |
"error setting index while loading " |
| 312 |
"ipv6InterfaceTable data.\n"); |
| 313 |
ipv6InterfaceTable_release_rowreq_ctx(rowreq_ctx); |
| 314 |
continue; |
| 315 |
} |
| 316 |
|
| 317 |
/* |
| 318 |
* TODO:352:r: | |-> populate ipv6InterfaceTable data context. |
| 319 |
* Populate data context here. (optionally, delay until row prep) |
| 320 |
*/ |
| 321 |
/* |
| 322 |
* non-TRANSIENT data: no need to copy. set pointer to data |
| 323 |
*/ |
| 324 |
|
| 325 |
/* |
| 326 |
* insert into table container |
| 327 |
*/ |
| 328 |
CONTAINER_INSERT(container, rowreq_ctx); |
| 329 |
++count; |
| 330 |
} |
| 331 |
|
| 332 |
DEBUGMSGT(("verbose:ipv6InterfaceTable:ipv6InterfaceTable_container_load", "inserted %d records\n", (int)count)); |
| 333 |
|
| 334 |
return MFD_SUCCESS; |
| 335 |
} /* ipv6InterfaceTable_container_load */ |
| 336 |
|
| 337 |
/** |
| 338 |
* container clean up |
| 339 |
* |
| 340 |
* @param container container with all current items |
| 341 |
* |
| 342 |
* This optional callback is called prior to all |
| 343 |
* item's being removed from the container. If you |
| 344 |
* need to do any processing before that, do it here. |
| 345 |
* |
| 346 |
* @note |
| 347 |
* The MFD helper will take care of releasing all the row contexts. |
| 348 |
* |
| 349 |
*/ |
| 350 |
void |
| 351 |
ipv6InterfaceTable_container_free(netsnmp_container *container) |
| 352 |
{ |
| 353 |
DEBUGMSGTL(("verbose:ipv6InterfaceTable:ipv6InterfaceTable_container_free", "called\n")); |
| 354 |
|
| 355 |
/* |
| 356 |
* TODO:380:M: Free ipv6InterfaceTable container data. |
| 357 |
*/ |
| 358 |
} /* ipv6InterfaceTable_container_free */ |
| 359 |
|
| 360 |
/** |
| 361 |
* prepare row for processing. |
| 362 |
* |
| 363 |
* When the agent has located the row for a request, this function is |
| 364 |
* called to prepare the row for processing. If you fully populated |
| 365 |
* the data context during the index setup phase, you may not need to |
| 366 |
* do anything. |
| 367 |
* |
| 368 |
* @param rowreq_ctx pointer to a context. |
| 369 |
* |
| 370 |
* @retval MFD_SUCCESS : success. |
| 371 |
* @retval MFD_ERROR : other error. |
| 372 |
*/ |
| 373 |
int |
| 374 |
ipv6InterfaceTable_row_prep(ipv6InterfaceTable_rowreq_ctx * rowreq_ctx) |
| 375 |
{ |
| 376 |
DEBUGMSGTL(("verbose:ipv6InterfaceTable:ipv6InterfaceTable_row_prep", |
| 377 |
"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 |
|
| 387 |
return MFD_SUCCESS; |
| 388 |
} /* ipv6InterfaceTable_row_prep */ |
| 389 |
|
| 390 |
/** @} */ |