| 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 "ipAddressTable.h" |
| 19 |
|
| 20 |
|
| 21 |
#include "ipAddressTable_data_access.h" |
| 22 |
|
| 23 |
#include <sys/ioctl.h> |
| 24 |
#include <errno.h> |
| 25 |
|
| 26 |
netsnmp_feature_require(container_lifo); |
| 27 |
netsnmp_feature_require(ipaddress_entry_update); |
| 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 ipAddressTable |
| 41 |
*** |
| 42 |
********************************************************************** |
| 43 |
**********************************************************************/ |
| 44 |
/* |
| 45 |
* IP-MIB::ipAddressTable is subid 34 of ip. |
| 46 |
* Its status is Current. |
| 47 |
* OID: .1.3.6.1.2.1.4.34, length: 8 |
| 48 |
*/ |
| 49 |
|
| 50 |
/** |
| 51 |
* initialization for ipAddressTable 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 ipAddressTable_reg |
| 57 |
* Pointer to ipAddressTable_registration |
| 58 |
* |
| 59 |
* @retval MFD_SUCCESS : success. |
| 60 |
* @retval MFD_ERROR : unrecoverable error. |
| 61 |
*/ |
| 62 |
int |
| 63 |
ipAddressTable_init_data(ipAddressTable_registration * ipAddressTable_reg) |
| 64 |
{ |
| 65 |
DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_init_data", |
| 66 |
"called\n")); |
| 67 |
|
| 68 |
/* |
| 69 |
* TODO:303:o: Initialize ipAddressTable data. |
| 70 |
*/ |
| 71 |
|
| 72 |
return MFD_SUCCESS; |
| 73 |
} /* ipAddressTable_init_data */ |
| 74 |
|
| 75 |
/** |
| 76 |
* container overview |
| 77 |
* |
| 78 |
*/ |
| 79 |
/** |
| 80 |
* check entry for update |
| 81 |
*/ |
| 82 |
static void |
| 83 |
_clear_times(void *p, void *magic) |
| 84 |
{ |
| 85 |
ipAddressTable_rowreq_ctx *rowreq_ctx = p; |
| 86 |
|
| 87 |
rowreq_ctx->ipAddressLastChanged = rowreq_ctx->ipAddressCreated = 0; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* container initialization |
| 92 |
* |
| 93 |
* @param container_ptr_ptr A pointer to a container pointer. If you |
| 94 |
* create a custom container, use this parameter to return it |
| 95 |
* to the MFD helper. If set to NULL, the MFD helper will |
| 96 |
* allocate a container for you. |
| 97 |
* @param cache A pointer to a cache structure. You can set the timeout |
| 98 |
* and other cache flags using this pointer. |
| 99 |
* |
| 100 |
* This function is called at startup to allow you to customize certain |
| 101 |
* aspects of the access method. For the most part, it is for advanced |
| 102 |
* users. The default code should suffice for most cases. If no custom |
| 103 |
* container is allocated, the MFD code will create one for your. |
| 104 |
* |
| 105 |
* This is also the place to set up cache behavior. The default, to |
| 106 |
* simply set the cache timeout, will work well with the default |
| 107 |
* container. If you are using a custom container, you may want to |
| 108 |
* look at the cache helper documentation to see if there are any |
| 109 |
* flags you want to set. |
| 110 |
* |
| 111 |
* @remark |
| 112 |
* This would also be a good place to do any initialization needed |
| 113 |
* for you data source. For example, opening a connection to another |
| 114 |
* process that will supply the data, opening a database, etc. |
| 115 |
*/ |
| 116 |
void |
| 117 |
ipAddressTable_container_init(netsnmp_container **container_ptr_ptr, |
| 118 |
netsnmp_cache * cache) |
| 119 |
{ |
| 120 |
DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_container_init", |
| 121 |
"called\n")); |
| 122 |
|
| 123 |
if (NULL == container_ptr_ptr) { |
| 124 |
snmp_log(LOG_ERR, |
| 125 |
"bad container param to ipAddressTable_container_init\n"); |
| 126 |
return; |
| 127 |
} |
| 128 |
|
| 129 |
/* |
| 130 |
* For advanced users, you can use a custom container. If you |
| 131 |
* do not create one, one will be created for you. |
| 132 |
*/ |
| 133 |
/* |
| 134 |
* We create a custom container here so we can pre-load it, which |
| 135 |
* will result in all new entries with last changed values. we need |
| 136 |
* to clear those... We also need to make sure ifIndexes have been |
| 137 |
* assigned... |
| 138 |
*/ |
| 139 |
*container_ptr_ptr = |
| 140 |
netsnmp_container_find("ipAddressTable:table_container"); |
| 141 |
if (NULL != *container_ptr_ptr) { |
| 142 |
/* |
| 143 |
* The container has ALLOW_DUPLICATES flag to speed up CONTAINER_INSERT |
| 144 |
* operations (it does not need to check for duplicates), however we |
| 145 |
* (manually) ensure that we won't insert any duplicates there. |
| 146 |
*/ |
| 147 |
(*container_ptr_ptr)->flags = CONTAINER_KEY_ALLOW_DUPLICATES; |
| 148 |
(*container_ptr_ptr)->container_name = strdup("ipAddressTable"); |
| 149 |
ipAddressTable_container_load(*container_ptr_ptr); |
| 150 |
CONTAINER_FOR_EACH(*container_ptr_ptr, _clear_times, NULL); |
| 151 |
} |
| 152 |
|
| 153 |
if (NULL == cache) { |
| 154 |
snmp_log(LOG_ERR, |
| 155 |
"bad cache param to ipAddressTable_container_init\n"); |
| 156 |
return; |
| 157 |
} |
| 158 |
|
| 159 |
/* |
| 160 |
* TODO:345:A: Set up ipAddressTable cache properties. |
| 161 |
* |
| 162 |
* Also for advanced users, you can set parameters for the |
| 163 |
* cache. Do not change the magic pointer, as it is used |
| 164 |
* by the MFD helper. To completely disable caching, set |
| 165 |
* cache->enabled to 0. |
| 166 |
*/ |
| 167 |
|
| 168 |
/* |
| 169 |
* basically, turn off all automatic cache handling except autoload. |
| 170 |
*/ |
| 171 |
cache->flags |= |
| 172 |
(NETSNMP_CACHE_DONT_AUTO_RELEASE | NETSNMP_CACHE_DONT_FREE_EXPIRED |
| 173 |
| NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD | NETSNMP_CACHE_AUTO_RELOAD |
| 174 |
| NETSNMP_CACHE_DONT_INVALIDATE_ON_SET); |
| 175 |
} /* ipAddressTable_container_init */ |
| 176 |
|
| 177 |
/** |
| 178 |
* container shutdown |
| 179 |
* |
| 180 |
* @param container_ptr A pointer to the container. |
| 181 |
* |
| 182 |
* This function is called at shutdown to allow you to customize certain |
| 183 |
* aspects of the access method. For the most part, it is for advanced |
| 184 |
* users. The default code should suffice for most cases. |
| 185 |
* |
| 186 |
* This function is called before ipAddressTable_container_free(). |
| 187 |
* |
| 188 |
* @remark |
| 189 |
* This would also be a good place to do any cleanup needed |
| 190 |
* for you data source. For example, closing a connection to another |
| 191 |
* process that supplied the data, closing a database, etc. |
| 192 |
*/ |
| 193 |
void |
| 194 |
ipAddressTable_container_shutdown(netsnmp_container *container_ptr) |
| 195 |
{ |
| 196 |
DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_container_shutdown", |
| 197 |
"called\n")); |
| 198 |
} /* ipAddressTable_container_shutdown */ |
| 199 |
|
| 200 |
/** |
| 201 |
* check entry for update |
| 202 |
*/ |
| 203 |
static void |
| 204 |
_check_entry_for_updates(void *p, void *q) |
| 205 |
{ |
| 206 |
ipAddressTable_rowreq_ctx *rowreq_ctx = p; |
| 207 |
void **magic = q; |
| 208 |
netsnmp_container *ipaddress_container = magic[0]; |
| 209 |
netsnmp_container *to_delete = magic[1]; |
| 210 |
netsnmp_container *to_ignore = magic[2]; |
| 211 |
|
| 212 |
/* |
| 213 |
* check for matching entry using secondary index. |
| 214 |
*/ |
| 215 |
netsnmp_ipaddress_entry *ipaddress_entry = (netsnmp_ipaddress_entry*) |
| 216 |
CONTAINER_FIND(ipaddress_container, rowreq_ctx->data); |
| 217 |
if (NULL == ipaddress_entry) { |
| 218 |
DEBUGMSGTL(("ipAddressTable:access", "removing missing entry\n")); |
| 219 |
|
| 220 |
if (NULL == to_delete) { |
| 221 |
magic[1] = to_delete = netsnmp_container_find("lifo"); |
| 222 |
if (NULL == to_delete) |
| 223 |
snmp_log(LOG_ERR, "couldn't create delete container\n"); |
| 224 |
} |
| 225 |
if (NULL != to_delete) |
| 226 |
CONTAINER_INSERT(to_delete, rowreq_ctx); |
| 227 |
} else { |
| 228 |
DEBUGMSGTL(("ipAddressTable:access", "updating existing entry\n")); |
| 229 |
|
| 230 |
/* |
| 231 |
* Check for changes & update |
| 232 |
*/ |
| 233 |
if (netsnmp_access_ipaddress_entry_update(rowreq_ctx->data, |
| 234 |
ipaddress_entry) > 0) |
| 235 |
rowreq_ctx->ipAddressLastChanged = netsnmp_get_agent_uptime(); |
| 236 |
|
| 237 |
/* |
| 238 |
* Remember not to add this entry from 'ipaddress_container' to 'container' later. |
| 239 |
* Simple CONTAINER_REMOVE(ipaddress_container, ..) would be slow. |
| 240 |
*/ |
| 241 |
if (NULL == to_ignore) { |
| 242 |
magic[2] = to_ignore = netsnmp_container_find("access_ipaddress:table_container"); |
| 243 |
if (NULL == to_ignore) { |
| 244 |
snmp_log(LOG_ERR, "couldn't create ignore container\n"); |
| 245 |
} else { |
| 246 |
/* to speed up insertion */ |
| 247 |
to_ignore->flags = CONTAINER_KEY_ALLOW_DUPLICATES; |
| 248 |
} |
| 249 |
} |
| 250 |
if (NULL != to_ignore) |
| 251 |
CONTAINER_INSERT(to_ignore, ipaddress_entry); |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
/** |
| 256 |
* add new entry |
| 257 |
*/ |
| 258 |
static void |
| 259 |
_add_new_entry(void *p, void *q) |
| 260 |
{ |
| 261 |
netsnmp_ipaddress_entry *ipaddress_entry = p; |
| 262 |
void **magic = q; |
| 263 |
netsnmp_container *container = magic[0]; |
| 264 |
netsnmp_container *to_ignore = magic[2]; |
| 265 |
|
| 266 |
ipAddressTable_rowreq_ctx *rowreq_ctx; |
| 267 |
|
| 268 |
DEBUGMSGTL(("ipAddressTable:access", "creating new entry\n")); |
| 269 |
|
| 270 |
netsnmp_assert(NULL != ipaddress_entry); |
| 271 |
netsnmp_assert(NULL != container); |
| 272 |
|
| 273 |
if (to_ignore && CONTAINER_FIND(to_ignore, ipaddress_entry)) { |
| 274 |
/* this entry already is in 'container', skip it */ |
| 275 |
return; |
| 276 |
} |
| 277 |
/* |
| 278 |
* allocate an row context and set the index(es) |
| 279 |
*/ |
| 280 |
rowreq_ctx = ipAddressTable_allocate_rowreq_ctx(ipaddress_entry, NULL); |
| 281 |
if ((NULL != rowreq_ctx) && |
| 282 |
(MFD_SUCCESS == |
| 283 |
ipAddressTable_indexes_set(rowreq_ctx, |
| 284 |
ipaddress_entry->ia_address_len, |
| 285 |
ipaddress_entry->ia_address, |
| 286 |
ipaddress_entry->ia_address_len))) { |
| 287 |
if (CONTAINER_INSERT(container, rowreq_ctx) < 0) { |
| 288 |
DEBUGMSGTL (("ipAddressTable:access","container insert failed for new entry\n")); |
| 289 |
ipAddressTable_release_rowreq_ctx(rowreq_ctx); |
| 290 |
return; |
| 291 |
} |
| 292 |
rowreq_ctx->ipAddressLastChanged = |
| 293 |
rowreq_ctx->ipAddressCreated = netsnmp_get_agent_uptime(); |
| 294 |
} else { |
| 295 |
if (NULL != rowreq_ctx) { |
| 296 |
snmp_log(LOG_ERR, "error setting index while loading " |
| 297 |
"ipAddressTable cache.\n"); |
| 298 |
ipAddressTable_release_rowreq_ctx(rowreq_ctx); |
| 299 |
} else { |
| 300 |
snmp_log(LOG_ERR, "memory allocation failed while loading " |
| 301 |
"ipAddressTable cache.\n"); |
| 302 |
netsnmp_access_ipaddress_entry_free(ipaddress_entry); |
| 303 |
} |
| 304 |
|
| 305 |
return; |
| 306 |
} |
| 307 |
|
| 308 |
/*------------------------------------------------------------------- |
| 309 |
* handle data that isn't part of the data_access ipaddress structure |
| 310 |
*/ |
| 311 |
rowreq_ctx->ipAddressRowStatus = ROWSTATUS_ACTIVE; |
| 312 |
} |
| 313 |
|
| 314 |
/** |
| 315 |
* load initial data |
| 316 |
* |
| 317 |
* TODO:350:M: Implement ipAddressTable data load |
| 318 |
* This function will also be called by the cache helper to load |
| 319 |
* the container again (after the container free function has been |
| 320 |
* called to free the previous contents). |
| 321 |
* |
| 322 |
* @param container container to which items should be inserted |
| 323 |
* |
| 324 |
* @retval MFD_SUCCESS : success. |
| 325 |
* @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source |
| 326 |
* @retval MFD_ERROR : other error. |
| 327 |
* |
| 328 |
* This function is called to load the index(es) (and data, optionally) |
| 329 |
* for the every row in the data set. |
| 330 |
* |
| 331 |
* @remark |
| 332 |
* While loading the data, the only important thing is the indexes. |
| 333 |
* If access to your data is cheap/fast (e.g. you have a pointer to a |
| 334 |
* structure in memory), it would make sense to update the data here. |
| 335 |
* If, however, the accessing the data involves more work (e.g. parsing |
| 336 |
* some other existing data, or performing calculations to derive the data), |
| 337 |
* then you can limit yourself to setting the indexes and saving any |
| 338 |
* information you will need later. Then use the saved information in |
| 339 |
* ipAddressTable_row_prep() for populating data. |
| 340 |
* |
| 341 |
* @note |
| 342 |
* If you need consistency between rows (like you want statistics |
| 343 |
* for each row to be from the same time frame), you should set all |
| 344 |
* data here. |
| 345 |
* |
| 346 |
*/ |
| 347 |
int |
| 348 |
ipAddressTable_container_load(netsnmp_container *container) |
| 349 |
{ |
| 350 |
netsnmp_container *ipaddress_container; |
| 351 |
void *tmp_ptr[3]; |
| 352 |
|
| 353 |
DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_cache_load", |
| 354 |
"called\n")); |
| 355 |
|
| 356 |
/* |
| 357 |
* Load/update data in the ipAddressTable container. |
| 358 |
* loop over your ipAddressTable data, allocate a rowreq context, |
| 359 |
* set the index(es) [and data, optionally] and insert into |
| 360 |
* the container. |
| 361 |
*/ |
| 362 |
/* |
| 363 |
* netsnmp_access_ipaddress_container_load makes sure that |
| 364 |
* ipaddress_container does not contain any duplicate entries, |
| 365 |
*/ |
| 366 |
ipaddress_container = |
| 367 |
netsnmp_access_ipaddress_container_load(NULL, |
| 368 |
NETSNMP_ACCESS_IPADDRESS_LOAD_ADDL_IDX_BY_ADDR); |
| 369 |
/* |
| 370 |
* we just got a fresh copy of interface data. compare it to |
| 371 |
* what we've already got, and make any adjustments, saving |
| 372 |
* missing addresses to be deleted. Also, prune interfaces in |
| 373 |
* ipaddress_container, so only the new interfaces remain. |
| 374 |
*/ |
| 375 |
tmp_ptr[0] = ipaddress_container->next; |
| 376 |
tmp_ptr[1] = NULL; /* list of interfaces to be removed from 'container' */ |
| 377 |
tmp_ptr[2] = NULL; /* list of interfaces to be ignored in ipaddress_container */ |
| 378 |
CONTAINER_FOR_EACH(container, _check_entry_for_updates, tmp_ptr); |
| 379 |
|
| 380 |
/* |
| 381 |
* now add any new interfaces |
| 382 |
*/ |
| 383 |
tmp_ptr[0] = container; |
| 384 |
CONTAINER_FOR_EACH(ipaddress_container, _add_new_entry, tmp_ptr); |
| 385 |
|
| 386 |
/* |
| 387 |
* free the container. we've either claimed each entry, or released it, |
| 388 |
* so the access function doesn't need to clear the container. |
| 389 |
*/ |
| 390 |
netsnmp_access_ipaddress_container_free(ipaddress_container, |
| 391 |
NETSNMP_ACCESS_IPADDRESS_FREE_DONT_CLEAR); |
| 392 |
|
| 393 |
/* |
| 394 |
* remove deleted addresses from table container |
| 395 |
*/ |
| 396 |
if (NULL != tmp_ptr[1]) { |
| 397 |
netsnmp_container *tmp_container = |
| 398 |
(netsnmp_container *) tmp_ptr[1]; |
| 399 |
ipAddressTable_rowreq_ctx *tmp_ctx; |
| 400 |
|
| 401 |
/* |
| 402 |
* this works because the tmp_container is a linked list, |
| 403 |
* which can be used like a stack... |
| 404 |
*/ |
| 405 |
while (CONTAINER_SIZE(tmp_container)) { |
| 406 |
/* |
| 407 |
* get from delete list |
| 408 |
*/ |
| 409 |
tmp_ctx = (ipAddressTable_rowreq_ctx*)CONTAINER_FIRST(tmp_container); |
| 410 |
|
| 411 |
/* |
| 412 |
* release context, delete from table container |
| 413 |
*/ |
| 414 |
CONTAINER_REMOVE(container, tmp_ctx); |
| 415 |
ipAddressTable_release_rowreq_ctx(tmp_ctx); |
| 416 |
|
| 417 |
/* |
| 418 |
* pop off delete list |
| 419 |
*/ |
| 420 |
CONTAINER_REMOVE(tmp_container, NULL); |
| 421 |
} |
| 422 |
CONTAINER_FREE(tmp_container); |
| 423 |
} |
| 424 |
|
| 425 |
if (NULL != tmp_ptr[2]) { |
| 426 |
/* list of interfaces to be ignored in ipaddress_container - free it */ |
| 427 |
netsnmp_container *to_ignore = (netsnmp_container *) tmp_ptr[2]; |
| 428 |
netsnmp_ipaddress_entry *ipaddress_entry; |
| 429 |
while (CONTAINER_SIZE(to_ignore)) { |
| 430 |
ipaddress_entry = (netsnmp_ipaddress_entry*)CONTAINER_FIRST(to_ignore); |
| 431 |
CONTAINER_REMOVE(to_ignore, ipaddress_entry); |
| 432 |
netsnmp_access_ipaddress_entry_free(ipaddress_entry); |
| 433 |
} |
| 434 |
CONTAINER_FREE(to_ignore); |
| 435 |
} |
| 436 |
|
| 437 |
DEBUGMSGT(("verbose:ipAddressTable:ipAddressTable_cache_load", |
| 438 |
"%lu records\n", (unsigned long)CONTAINER_SIZE(container))); |
| 439 |
|
| 440 |
return MFD_SUCCESS; |
| 441 |
} |
| 442 |
|
| 443 |
/** |
| 444 |
* container clean up |
| 445 |
* |
| 446 |
* @param container container with all current items |
| 447 |
* |
| 448 |
* This optional callback is called prior to all |
| 449 |
* item's being removed from the container. If you |
| 450 |
* need to do any processing before that, do it here. |
| 451 |
* |
| 452 |
* @note |
| 453 |
* The MFD helper will take care of releasing all the row contexts. |
| 454 |
* |
| 455 |
*/ |
| 456 |
void |
| 457 |
ipAddressTable_container_free(netsnmp_container *container) |
| 458 |
{ |
| 459 |
DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_container_free", |
| 460 |
"called\n")); |
| 461 |
|
| 462 |
/* |
| 463 |
* TODO:380:M: Free ipAddressTable container data. |
| 464 |
*/ |
| 465 |
} /* ipAddressTable_container_free */ |
| 466 |
|
| 467 |
/** |
| 468 |
* prepare row for processing. |
| 469 |
* |
| 470 |
* When the agent has located the row for a request, this function is |
| 471 |
* called to prepare the row for processing. If you fully populated |
| 472 |
* the data context during the index setup phase, you may not need to |
| 473 |
* do anything. |
| 474 |
* |
| 475 |
* @param rowreq_ctx pointer to a context. |
| 476 |
* |
| 477 |
* @retval MFD_SUCCESS : success. |
| 478 |
* @retval MFD_ERROR : other error. |
| 479 |
*/ |
| 480 |
int |
| 481 |
ipAddressTable_row_prep(ipAddressTable_rowreq_ctx * rowreq_ctx) |
| 482 |
{ |
| 483 |
DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_row_prep", |
| 484 |
"called\n")); |
| 485 |
|
| 486 |
netsnmp_assert(NULL != rowreq_ctx); |
| 487 |
|
| 488 |
/* |
| 489 |
* TODO:390:o: Prepare row for request. |
| 490 |
* If populating row data was delayed, this is the place to |
| 491 |
* fill in the row for this request. |
| 492 |
*/ |
| 493 |
|
| 494 |
return MFD_SUCCESS; |
| 495 |
} /* ipAddressTable_row_prep */ |
| 496 |
|
| 497 |
/* |
| 498 |
* TODO:420:r: Implement ipAddressTable index validation. |
| 499 |
*/ |
| 500 |
/*--------------------------------------------------------------------- |
| 501 |
* IP-MIB::ipAddressEntry.ipAddressAddrType |
| 502 |
* ipAddressAddrType is subid 1 of ipAddressEntry. |
| 503 |
* Its status is Current, and its access level is NoAccess. |
| 504 |
* OID: .1.3.6.1.2.1.4.34.1.1 |
| 505 |
* Description: |
| 506 |
The address type of ipAddressAddr. |
| 507 |
* |
| 508 |
* Attributes: |
| 509 |
* accessible 0 isscalar 0 enums 1 hasdefval 0 |
| 510 |
* readable 0 iscolumn 1 ranges 0 hashint 0 |
| 511 |
* settable 0 |
| 512 |
* |
| 513 |
* Enum range: 5/8. Values: unknown(0), ipv4(1), ipv6(2), ipv4z(3), ipv6z(4), dns(16) |
| 514 |
* |
| 515 |
* Its syntax is InetAddressType (based on perltype INTEGER) |
| 516 |
* The net-snmp type is ASN_INTEGER. The C type decl is long (u_long) |
| 517 |
* |
| 518 |
* |
| 519 |
* |
| 520 |
* NOTE: NODE ipAddressAddrType IS NOT ACCESSIBLE |
| 521 |
* |
| 522 |
* |
| 523 |
*/ |
| 524 |
/** |
| 525 |
* check validity of ipAddressAddrType index portion |
| 526 |
* |
| 527 |
* @retval MFD_SUCCESS : the incoming value is legal |
| 528 |
* @retval MFD_ERROR : the incoming value is NOT legal |
| 529 |
* |
| 530 |
* @note this is not the place to do any checks for the sanity |
| 531 |
* of multiple indexes. Those types of checks should be done in the |
| 532 |
* ipAddressTable_validate_index() function. |
| 533 |
* |
| 534 |
* @note Also keep in mind that if the index refers to a row in this or |
| 535 |
* some other table, you can't check for that row here to make |
| 536 |
* decisions, since that row might not be created yet, but may |
| 537 |
* be created during the processing this request. If you have |
| 538 |
* such checks, they should be done in the check_dependencies |
| 539 |
* function, because any new/deleted/changed rows should be |
| 540 |
* available then. |
| 541 |
* |
| 542 |
* The following checks have already been done for you: |
| 543 |
* The value is one of unknown(0), ipv4(1), ipv6(2), ipv4z(3), ipv6z(4), dns(16) |
| 544 |
* |
| 545 |
* If there a no other checks you need to do, simply return MFD_SUCCESS. |
| 546 |
*/ |
| 547 |
int |
| 548 |
ipAddressAddrType_check_index(ipAddressTable_rowreq_ctx * rowreq_ctx) |
| 549 |
{ |
| 550 |
DEBUGMSGTL(("verbose:ipAddressTable:ipAddressAddrType_check_index", |
| 551 |
"called\n")); |
| 552 |
|
| 553 |
netsnmp_assert(NULL != rowreq_ctx); |
| 554 |
|
| 555 |
/* |
| 556 |
* TODO:426:M: |-> Check ipAddressTable index ipAddressAddrType. |
| 557 |
* check that index value in the table context is legal. |
| 558 |
* (rowreq_ctx->tbl_index.ipAddressAddrType) |
| 559 |
*/ |
| 560 |
switch (rowreq_ctx->tbl_idx.ipAddressAddrType) { |
| 561 |
|
| 562 |
case INETADDRESSTYPE_IPV4: |
| 563 |
case INETADDRESSTYPE_IPV6: |
| 564 |
break; |
| 565 |
|
| 566 |
default: |
| 567 |
DEBUGMSGT(("ipAddressTable", "illegal addr type\n")); |
| 568 |
return MFD_ERROR; |
| 569 |
} |
| 570 |
|
| 571 |
|
| 572 |
return MFD_SUCCESS; /* ipAddressAddrType index ok */ |
| 573 |
} /* ipAddressAddrType_check_index */ |
| 574 |
|
| 575 |
/*--------------------------------------------------------------------- |
| 576 |
* IP-MIB::ipAddressEntry.ipAddressAddr |
| 577 |
* ipAddressAddr is subid 2 of ipAddressEntry. |
| 578 |
* Its status is Current, and its access level is NoAccess. |
| 579 |
* OID: .1.3.6.1.2.1.4.34.1.2 |
| 580 |
* Description: |
| 581 |
The IP address to which this entry's addressing information |
| 582 |
pertains. The address type of this object is specified in |
| 583 |
ipAddressAddrType. |
| 584 |
|
| 585 |
|
| 586 |
Implementors need to be aware that if the size of |
| 587 |
ipAddressAddr exceeds 116 octets then OIDS of instances of |
| 588 |
columns in this row will have more than 128 sub-identifiers |
| 589 |
and cannot be accessed using SNMPv1, SNMPv2c or SNMPv3. |
| 590 |
* |
| 591 |
* Attributes: |
| 592 |
* accessible 0 isscalar 0 enums 0 hasdefval 0 |
| 593 |
* readable 0 iscolumn 1 ranges 1 hashint 0 |
| 594 |
* settable 0 |
| 595 |
* |
| 596 |
* Ranges: 0 - 255; |
| 597 |
* |
| 598 |
* Its syntax is InetAddress (based on perltype OCTETSTR) |
| 599 |
* The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) |
| 600 |
* This data type requires a length. (Max 255) |
| 601 |
* |
| 602 |
* |
| 603 |
* |
| 604 |
* NOTE: NODE ipAddressAddr IS NOT ACCESSIBLE |
| 605 |
* |
| 606 |
* |
| 607 |
*/ |
| 608 |
/** |
| 609 |
* check validity of ipAddressAddr index portion |
| 610 |
* |
| 611 |
* @retval MFD_SUCCESS : the incoming value is legal |
| 612 |
* @retval MFD_ERROR : the incoming value is NOT legal |
| 613 |
* |
| 614 |
* @note this is not the place to do any checks for the sanity |
| 615 |
* of multiple indexes. Those types of checks should be done in the |
| 616 |
* ipAddressTable_validate_index() function. |
| 617 |
* |
| 618 |
* @note Also keep in mind that if the index refers to a row in this or |
| 619 |
* some other table, you can't check for that row here to make |
| 620 |
* decisions, since that row might not be created yet, but may |
| 621 |
* be created during the processing this request. If you have |
| 622 |
* such checks, they should be done in the check_dependencies |
| 623 |
* function, because any new/deleted/changed rows should be |
| 624 |
* available then. |
| 625 |
* |
| 626 |
* The following checks have already been done for you: |
| 627 |
* The length is in (one of) the range set(s): 0 - 255 |
| 628 |
* |
| 629 |
* If there a no other checks you need to do, simply return MFD_SUCCESS. |
| 630 |
*/ |
| 631 |
int |
| 632 |
ipAddressAddr_check_index(ipAddressTable_rowreq_ctx * rowreq_ctx) |
| 633 |
{ |
| 634 |
DEBUGMSGTL(("verbose:ipAddressTable:ipAddressAddr_check_index", |
| 635 |
"called\n")); |
| 636 |
|
| 637 |
netsnmp_assert(NULL != rowreq_ctx); |
| 638 |
|
| 639 |
/* |
| 640 |
* TODO:426:M: |-> Check ipAddressTable index ipAddressAddr. |
| 641 |
* check that index value in the table context is legal. |
| 642 |
* (rowreq_ctx->tbl_index.ipAddressAddr) |
| 643 |
*/ |
| 644 |
switch (rowreq_ctx->tbl_idx.ipAddressAddrType) { |
| 645 |
|
| 646 |
case INETADDRESSTYPE_IPV4: |
| 647 |
if (4 != rowreq_ctx->tbl_idx.ipAddressAddr_len) { |
| 648 |
DEBUGMSGT(("ipAddressTable", "bad addr len\n")); |
| 649 |
return MFD_ERROR; |
| 650 |
} |
| 651 |
break; |
| 652 |
|
| 653 |
case INETADDRESSTYPE_IPV6: |
| 654 |
/** xxx-rks: allow 20? */ |
| 655 |
if (16 != rowreq_ctx->tbl_idx.ipAddressAddr_len) { |
| 656 |
DEBUGMSGT(("ipAddressTable", "bad addr len\n")); |
| 657 |
return MFD_ERROR; |
| 658 |
} |
| 659 |
break; |
| 660 |
|
| 661 |
default: |
| 662 |
return MFD_ERROR; |
| 663 |
} |
| 664 |
|
| 665 |
return MFD_SUCCESS; /* ipAddressAddr index ok */ |
| 666 |
} /* ipAddressAddr_check_index */ |
| 667 |
|
| 668 |
/** |
| 669 |
* verify specified index is valid. |
| 670 |
* |
| 671 |
* This check is independent of whether or not the values specified for |
| 672 |
* the columns of the new row are valid. Column values and row consistency |
| 673 |
* will be checked later. At this point, only the index values should be |
| 674 |
* checked. |
| 675 |
* |
| 676 |
* All of the individual index validation functions have been called, so this |
| 677 |
* is the place to make sure they are valid as a whole when combined. If |
| 678 |
* you only have one index, then you probably don't need to do anything else |
| 679 |
* here. |
| 680 |
* |
| 681 |
* @note Keep in mind that if the indexes refer to a row in this or |
| 682 |
* some other table, you can't check for that row here to make |
| 683 |
* decisions, since that row might not be created yet, but may |
| 684 |
* be created during the processing this request. If you have |
| 685 |
* such checks, they should be done in the check_dependencies |
| 686 |
* function, because any new/deleted/changed rows should be |
| 687 |
* available then. |
| 688 |
* |
| 689 |
* |
| 690 |
* @param ipAddressTable_reg |
| 691 |
* Pointer to the user registration data |
| 692 |
* @param rowreq_ctx |
| 693 |
* Pointer to the users context. |
| 694 |
* @retval MFD_SUCCESS : success |
| 695 |
* @retval MFD_CANNOT_CREATE_NOW : index not valid right now |
| 696 |
* @retval MFD_CANNOT_CREATE_EVER : index never valid |
| 697 |
*/ |
| 698 |
int |
| 699 |
ipAddressTable_validate_index(ipAddressTable_registration * |
| 700 |
ipAddressTable_reg, |
| 701 |
ipAddressTable_rowreq_ctx * rowreq_ctx) |
| 702 |
{ |
| 703 |
int rc = MFD_SUCCESS; |
| 704 |
|
| 705 |
DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_validate_index", |
| 706 |
"called\n")); |
| 707 |
|
| 708 |
/** we should have a non-NULL pointer */ |
| 709 |
netsnmp_assert(NULL != rowreq_ctx); |
| 710 |
|
| 711 |
/* |
| 712 |
* TODO:430:M: |-> Validate potential ipAddressTable index. |
| 713 |
* |
| 714 |
* |
| 715 |
*/ |
| 716 |
if ((4 != rowreq_ctx->tbl_idx.ipAddressAddr_len) |
| 717 |
&& (16 != rowreq_ctx->tbl_idx.ipAddressAddr_len)) { |
| 718 |
snmp_log(LOG_WARNING, "invalid index for a new row in the " |
| 719 |
"ipAddressTable table.\n"); |
| 720 |
/* |
| 721 |
* determine failure type. |
| 722 |
* |
| 723 |
* If the index could not ever be created, return MFD_NOT_EVER |
| 724 |
* If the index can not be created under the present circumstances |
| 725 |
* (even though it could be created under other circumstances), |
| 726 |
* return MFD_NOT_NOW. |
| 727 |
*/ |
| 728 |
if (0) { |
| 729 |
return MFD_CANNOT_CREATE_EVER; |
| 730 |
} else { |
| 731 |
return MFD_CANNOT_CREATE_NOW; |
| 732 |
} |
| 733 |
} else { |
| 734 |
memcpy(rowreq_ctx->data->ia_address, rowreq_ctx->tbl_idx.ipAddressAddr, |
| 735 |
rowreq_ctx->tbl_idx.ipAddressAddr_len); |
| 736 |
rowreq_ctx->data->ia_address_len = rowreq_ctx->tbl_idx.ipAddressAddr_len; |
| 737 |
} |
| 738 |
|
| 739 |
return rc; |
| 740 |
} /* ipAddressTable_validate_index */ |
| 741 |
|
| 742 |
/** @} */ |