| 1 |
/* |
| 2 |
* Note: this file originally auto-generated by mib2c using |
| 3 |
* version : 1.67 $ of : mfd-interface.m2c,v $ |
| 4 |
* |
| 5 |
* $Id$ |
| 6 |
*/ |
| 7 |
/* |
| 8 |
* ********************************************************************* |
| 9 |
* ********************************************************************* |
| 10 |
* ********************************************************************* |
| 11 |
* *** *** |
| 12 |
* *** NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE *** |
| 13 |
* *** *** |
| 14 |
* *** *** |
| 15 |
* *** THIS FILE DOES NOT CONTAIN ANY USER EDITABLE CODE. *** |
| 16 |
* *** *** |
| 17 |
* *** *** |
| 18 |
* *** THE GENERATED CODE IS INTERNAL IMPLEMENTATION, AND *** |
| 19 |
* *** *** |
| 20 |
* *** *** |
| 21 |
* *** IS SUBJECT TO CHANGE WITHOUT WARNING IN FUTURE RELEASES. *** |
| 22 |
* *** *** |
| 23 |
* *** *** |
| 24 |
* ********************************************************************* |
| 25 |
* ********************************************************************* |
| 26 |
* ********************************************************************* |
| 27 |
*/ |
| 28 |
|
| 29 |
/* |
| 30 |
* standard Net-SNMP includes |
| 31 |
*/ |
| 32 |
#include <net-snmp/net-snmp-config.h> |
| 33 |
#include <net-snmp/net-snmp-features.h> |
| 34 |
#include <net-snmp/net-snmp-features.h> |
| 35 |
#include <net-snmp/net-snmp-includes.h> |
| 36 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 37 |
|
| 38 |
/* |
| 39 |
* include our parent header |
| 40 |
*/ |
| 41 |
#include "ifXTable.h" |
| 42 |
|
| 43 |
|
| 44 |
#include <net-snmp/agent/table_container.h> |
| 45 |
#include <net-snmp/library/container.h> |
| 46 |
|
| 47 |
#include "ifXTable_interface.h" |
| 48 |
#include "if-mib/ifTable/ifTable_interface.h" |
| 49 |
#include "if-mib/ifTable/ifTable_defs.h" |
| 50 |
|
| 51 |
#include <ctype.h> |
| 52 |
|
| 53 |
netsnmp_feature_child_of(ifXTable_external_access, libnetsnmpmibs); |
| 54 |
|
| 55 |
netsnmp_feature_require(row_merge); |
| 56 |
netsnmp_feature_require(cache_find_by_oid); |
| 57 |
netsnmp_feature_require(baby_steps); |
| 58 |
netsnmp_feature_require(check_all_requests_error); |
| 59 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 60 |
netsnmp_feature_require(check_vb_type_and_max_size); |
| 61 |
#endif /* NETSNMP_NO_WRITE_SUPPORT */ |
| 62 |
|
| 63 |
/********************************************************************** |
| 64 |
********************************************************************** |
| 65 |
*** |
| 66 |
*** Table ifXTable |
| 67 |
*** |
| 68 |
********************************************************************** |
| 69 |
**********************************************************************/ |
| 70 |
/* |
| 71 |
* IF-MIB::ifXTable is subid 1 of ifMIBObjects. |
| 72 |
* Its status is Current. |
| 73 |
* OID: .1.3.6.1.2.1.31.1.1, length: 9 |
| 74 |
*/ |
| 75 |
typedef struct ifXTable_interface_ctx_s { |
| 76 |
|
| 77 |
netsnmp_container *container; |
| 78 |
netsnmp_cache *cache; |
| 79 |
|
| 80 |
ifXTable_registration *user_ctx; |
| 81 |
|
| 82 |
netsnmp_table_registration_info tbl_info; |
| 83 |
|
| 84 |
netsnmp_baby_steps_access_methods access_multiplexer; |
| 85 |
|
| 86 |
u_int table_dirty; |
| 87 |
|
| 88 |
} ifXTable_interface_ctx; |
| 89 |
|
| 90 |
static ifXTable_interface_ctx ifXTable_if_ctx; |
| 91 |
|
| 92 |
static void _ifXTable_container_init(ifXTable_interface_ctx * if_ctx); |
| 93 |
static void _ifXTable_container_shutdown(ifXTable_interface_ctx * |
| 94 |
if_ctx); |
| 95 |
|
| 96 |
#ifndef NETSNMP_FEATURE_REMOVE_IFXTABLE_CONTAINER_GET |
| 97 |
netsnmp_container * |
| 98 |
ifXTable_container_get(void) |
| 99 |
{ |
| 100 |
return ifXTable_if_ctx.container; |
| 101 |
} |
| 102 |
#endif /* NETSNMP_FEATURE_REMOVE_IFXTABLE_CONTAINER_GET */ |
| 103 |
|
| 104 |
#ifndef NETSNMP_FEATURE_REMOVE_IFXTABLE_REGISTRATION_GET |
| 105 |
ifXTable_registration * |
| 106 |
ifXTable_registration_get(void) |
| 107 |
{ |
| 108 |
return ifXTable_if_ctx.user_ctx; |
| 109 |
} |
| 110 |
#endif /* NETSNMP_FEATURE_REMOVE_IFXTABLE_REGISTRATION_GET */ |
| 111 |
|
| 112 |
#ifndef NETSNMP_FEATURE_REMOVE_IFXTABLE_REGISTRATION_SET |
| 113 |
ifXTable_registration * |
| 114 |
ifXTable_registration_set(ifXTable_registration * newreg) |
| 115 |
{ |
| 116 |
ifXTable_registration *old = ifXTable_if_ctx.user_ctx; |
| 117 |
ifXTable_if_ctx.user_ctx = newreg; |
| 118 |
return old; |
| 119 |
} |
| 120 |
#endif /* NETSNMP_FEATURE_REMOVE_IFXTABLE_REGISTRATION_SET */ |
| 121 |
|
| 122 |
#ifndef NETSNMP_FEATURE_REMOVE_IFXTABLE_CONTAINER_SIZE |
| 123 |
int |
| 124 |
ifXTable_container_size(void) |
| 125 |
{ |
| 126 |
return CONTAINER_SIZE(ifXTable_if_ctx.container); |
| 127 |
} |
| 128 |
#endif /* NETSNMP_FEATURE_REMOVE_IFXTABLE_CONTAINER_SIZE */ |
| 129 |
|
| 130 |
u_int |
| 131 |
ifXTable_dirty_get(void) |
| 132 |
{ |
| 133 |
return ifXTable_if_ctx.table_dirty; |
| 134 |
} |
| 135 |
|
| 136 |
void |
| 137 |
ifXTable_dirty_set(u_int status) |
| 138 |
{ |
| 139 |
DEBUGMSGTL(("ifXTable:ifXTable_dirty_set", |
| 140 |
"called. was %d, now %d\n", |
| 141 |
ifXTable_if_ctx.table_dirty, status)); |
| 142 |
ifXTable_if_ctx.table_dirty = status; |
| 143 |
} |
| 144 |
|
| 145 |
/* |
| 146 |
* mfd multiplexer modes |
| 147 |
*/ |
| 148 |
static Netsnmp_Node_Handler _mfd_ifXTable_pre_request; |
| 149 |
static Netsnmp_Node_Handler _mfd_ifXTable_post_request; |
| 150 |
static Netsnmp_Node_Handler _mfd_ifXTable_object_lookup; |
| 151 |
static Netsnmp_Node_Handler _mfd_ifXTable_get_values; |
| 152 |
#if !(defined(NETSNMP_NO_WRITE_SUPPORT) || defined(NETSNMP_DISABLE_SET_SUPPORT)) |
| 153 |
static Netsnmp_Node_Handler _mfd_ifXTable_check_objects; |
| 154 |
static Netsnmp_Node_Handler _mfd_ifXTable_undo_setup; |
| 155 |
static Netsnmp_Node_Handler _mfd_ifXTable_set_values; |
| 156 |
static Netsnmp_Node_Handler _mfd_ifXTable_undo_cleanup; |
| 157 |
static Netsnmp_Node_Handler _mfd_ifXTable_undo_values; |
| 158 |
static Netsnmp_Node_Handler _mfd_ifXTable_commit; |
| 159 |
static Netsnmp_Node_Handler _mfd_ifXTable_undo_commit; |
| 160 |
static Netsnmp_Node_Handler _mfd_ifXTable_irreversible_commit; |
| 161 |
static Netsnmp_Node_Handler _mfd_ifXTable_check_dependencies; |
| 162 |
|
| 163 |
NETSNMP_STATIC_INLINE int _ifXTable_undo_column(ifXTable_rowreq_ctx * |
| 164 |
rowreq_ctx, |
| 165 |
netsnmp_variable_list * |
| 166 |
var, int column); |
| 167 |
#endif /* NETSNMP_NO_WRITE_SUPPORT || NETSNMP_DISABLE_SET_SUPPORT */ |
| 168 |
|
| 169 |
ifXTable_data *ifXTable_allocate_data(void); |
| 170 |
|
| 171 |
/** |
| 172 |
* @internal |
| 173 |
* Initialize the table ifXTable |
| 174 |
* (Define its contents and how it's structured) |
| 175 |
*/ |
| 176 |
void |
| 177 |
_ifXTable_initialize_interface(ifXTable_registration * reg_ptr, |
| 178 |
u_long flags) |
| 179 |
{ |
| 180 |
netsnmp_baby_steps_access_methods *access_multiplexer = |
| 181 |
&ifXTable_if_ctx.access_multiplexer; |
| 182 |
netsnmp_table_registration_info *tbl_info = &ifXTable_if_ctx.tbl_info; |
| 183 |
netsnmp_handler_registration *reginfo; |
| 184 |
netsnmp_mib_handler *handler; |
| 185 |
int mfd_modes = 0; |
| 186 |
|
| 187 |
DEBUGMSGTL(("internal:ifXTable:_ifXTable_initialize_interface", |
| 188 |
"called\n")); |
| 189 |
|
| 190 |
/* |
| 191 |
* make sure the ifTable container has been initialized, since |
| 192 |
* we use its container, and we can't guarantee that it has |
| 193 |
* already been initialized. |
| 194 |
*/ |
| 195 |
(void) if_mib_container_init(); |
| 196 |
|
| 197 |
/************************************************* |
| 198 |
* |
| 199 |
* save interface context for ifXTable |
| 200 |
*/ |
| 201 |
/* |
| 202 |
* Setting up the table's definition |
| 203 |
*/ |
| 204 |
netsnmp_table_helper_add_indexes(tbl_info, ASN_INTEGER, |
| 205 |
/** index: ifIndex */ |
| 206 |
0); |
| 207 |
|
| 208 |
/* |
| 209 |
* Define the minimum and maximum accessible columns. This |
| 210 |
* optimizes retrieval. |
| 211 |
*/ |
| 212 |
tbl_info->min_column = IFXTABLE_MIN_COL; |
| 213 |
tbl_info->max_column = IFXTABLE_MAX_COL; |
| 214 |
|
| 215 |
/* |
| 216 |
* save users context |
| 217 |
*/ |
| 218 |
ifXTable_if_ctx.user_ctx = reg_ptr; |
| 219 |
|
| 220 |
/* |
| 221 |
* call data access initialization code |
| 222 |
*/ |
| 223 |
ifXTable_init_data(reg_ptr); |
| 224 |
|
| 225 |
/* |
| 226 |
* set up the container |
| 227 |
*/ |
| 228 |
_ifXTable_container_init(&ifXTable_if_ctx); |
| 229 |
if (NULL == ifXTable_if_ctx.container) |
| 230 |
return; /* msg already logged */ |
| 231 |
|
| 232 |
/* |
| 233 |
* access_multiplexer: REQUIRED wrapper for get request handling |
| 234 |
*/ |
| 235 |
access_multiplexer->object_lookup = _mfd_ifXTable_object_lookup; |
| 236 |
access_multiplexer->get_values = _mfd_ifXTable_get_values; |
| 237 |
|
| 238 |
/* |
| 239 |
* no wrappers yet |
| 240 |
*/ |
| 241 |
access_multiplexer->pre_request = _mfd_ifXTable_pre_request; |
| 242 |
access_multiplexer->post_request = _mfd_ifXTable_post_request; |
| 243 |
|
| 244 |
|
| 245 |
#if !(defined(NETSNMP_NO_WRITE_SUPPORT) || defined(NETSNMP_DISABLE_SET_SUPPORT)) |
| 246 |
/* |
| 247 |
* REQUIRED wrappers for set request handling |
| 248 |
*/ |
| 249 |
access_multiplexer->object_syntax_checks = _mfd_ifXTable_check_objects; |
| 250 |
access_multiplexer->undo_setup = _mfd_ifXTable_undo_setup; |
| 251 |
access_multiplexer->undo_cleanup = _mfd_ifXTable_undo_cleanup; |
| 252 |
access_multiplexer->set_values = _mfd_ifXTable_set_values; |
| 253 |
access_multiplexer->undo_sets = _mfd_ifXTable_undo_values; |
| 254 |
|
| 255 |
/* |
| 256 |
* no wrappers yet |
| 257 |
*/ |
| 258 |
access_multiplexer->commit = _mfd_ifXTable_commit; |
| 259 |
access_multiplexer->undo_commit = _mfd_ifXTable_undo_commit; |
| 260 |
access_multiplexer->irreversible_commit = |
| 261 |
_mfd_ifXTable_irreversible_commit; |
| 262 |
|
| 263 |
/* |
| 264 |
* REQUIRED for tables with dependencies |
| 265 |
*/ |
| 266 |
access_multiplexer->consistency_checks = |
| 267 |
_mfd_ifXTable_check_dependencies; |
| 268 |
#endif /* NETSNMP_NO_WRITE_SUPPORT || NETSNMP_DISABLE_SET_SUPPORT */ |
| 269 |
|
| 270 |
/************************************************* |
| 271 |
* |
| 272 |
* Create a registration, save our reg data, register table. |
| 273 |
*/ |
| 274 |
DEBUGMSGTL(("ifXTable:init_ifXTable", |
| 275 |
"Registering ifXTable as a mibs-for-dummies table.\n")); |
| 276 |
handler = |
| 277 |
netsnmp_baby_steps_access_multiplexer_get(access_multiplexer); |
| 278 |
reginfo = |
| 279 |
netsnmp_handler_registration_create("ifXTable", handler, |
| 280 |
ifXTable_oid, |
| 281 |
ifXTable_oid_size, |
| 282 |
HANDLER_CAN_BABY_STEP | |
| 283 |
#if !(defined(NETSNMP_NO_WRITE_SUPPORT) || defined(NETSNMP_DISABLE_SET_SUPPORT)) |
| 284 |
HANDLER_CAN_RWRITE |
| 285 |
#else |
| 286 |
HANDLER_CAN_RONLY |
| 287 |
#endif /* NETSNMP_NO_WRITE_SUPPORT || NETSNMP_DISABLE_SET_SUPPORT */ |
| 288 |
); |
| 289 |
|
| 290 |
if (NULL == reginfo) { |
| 291 |
snmp_log(LOG_ERR, "error registering table ifXTable\n"); |
| 292 |
return; |
| 293 |
} |
| 294 |
reginfo->my_reg_void = &ifXTable_if_ctx; |
| 295 |
|
| 296 |
/************************************************* |
| 297 |
* |
| 298 |
* set up baby steps handler, create it and inject it |
| 299 |
*/ |
| 300 |
if (access_multiplexer->object_lookup) |
| 301 |
mfd_modes |= BABY_STEP_OBJECT_LOOKUP; |
| 302 |
if (access_multiplexer->pre_request) |
| 303 |
mfd_modes |= BABY_STEP_PRE_REQUEST; |
| 304 |
if (access_multiplexer->post_request) |
| 305 |
mfd_modes |= BABY_STEP_POST_REQUEST; |
| 306 |
|
| 307 |
#if !(defined(NETSNMP_NO_WRITE_SUPPORT) || defined(NETSNMP_DISABLE_SET_SUPPORT)) |
| 308 |
if (access_multiplexer->set_values) |
| 309 |
mfd_modes |= BABY_STEP_SET_VALUES; |
| 310 |
if (access_multiplexer->irreversible_commit) |
| 311 |
mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT; |
| 312 |
if (access_multiplexer->object_syntax_checks) |
| 313 |
mfd_modes |= BABY_STEP_CHECK_OBJECT; |
| 314 |
|
| 315 |
if (access_multiplexer->undo_setup) |
| 316 |
mfd_modes |= BABY_STEP_UNDO_SETUP; |
| 317 |
if (access_multiplexer->undo_cleanup) |
| 318 |
mfd_modes |= BABY_STEP_UNDO_CLEANUP; |
| 319 |
if (access_multiplexer->undo_sets) |
| 320 |
mfd_modes |= BABY_STEP_UNDO_SETS; |
| 321 |
|
| 322 |
if (access_multiplexer->row_creation) |
| 323 |
mfd_modes |= BABY_STEP_ROW_CREATE; |
| 324 |
if (access_multiplexer->consistency_checks) |
| 325 |
mfd_modes |= BABY_STEP_CHECK_CONSISTENCY; |
| 326 |
if (access_multiplexer->commit) |
| 327 |
mfd_modes |= BABY_STEP_COMMIT; |
| 328 |
if (access_multiplexer->undo_commit) |
| 329 |
mfd_modes |= BABY_STEP_UNDO_COMMIT; |
| 330 |
#endif /* NETSNMP_NO_WRITE_SUPPORT || NETSNMP_DISABLE_SET_SUPPORT */ |
| 331 |
|
| 332 |
handler = netsnmp_baby_steps_handler_get(mfd_modes); |
| 333 |
netsnmp_inject_handler(reginfo, handler); |
| 334 |
|
| 335 |
/************************************************* |
| 336 |
* |
| 337 |
* inject row_merge helper with prefix rootoid_len + 2 (entry.col) |
| 338 |
*/ |
| 339 |
handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2); |
| 340 |
netsnmp_inject_handler(reginfo, handler); |
| 341 |
|
| 342 |
/************************************************* |
| 343 |
* |
| 344 |
* inject container_table helper |
| 345 |
*/ |
| 346 |
handler = |
| 347 |
netsnmp_container_table_handler_get(tbl_info, |
| 348 |
ifXTable_if_ctx.container, |
| 349 |
TABLE_CONTAINER_KEY_NETSNMP_INDEX); |
| 350 |
netsnmp_inject_handler(reginfo, handler); |
| 351 |
|
| 352 |
/************************************************* |
| 353 |
* |
| 354 |
* inject cache helper |
| 355 |
*/ |
| 356 |
if (NULL != ifXTable_if_ctx.cache) { |
| 357 |
handler = netsnmp_cache_handler_get(ifXTable_if_ctx.cache); |
| 358 |
netsnmp_inject_handler(reginfo, handler); |
| 359 |
} |
| 360 |
|
| 361 |
/* |
| 362 |
* register table |
| 363 |
*/ |
| 364 |
netsnmp_register_table(reginfo, tbl_info); |
| 365 |
|
| 366 |
/* |
| 367 |
* register config/persistence callbacks |
| 368 |
*/ |
| 369 |
ifXTable_container_init_persistence(ifXTable_if_ctx.container); |
| 370 |
|
| 371 |
} /* _ifXTable_initialize_interface */ |
| 372 |
|
| 373 |
/** |
| 374 |
* @internal |
| 375 |
* Shutdown the table ifXTable |
| 376 |
*/ |
| 377 |
#ifndef NETSNMP_FEATURE_REMOVE_IFXTABLE_SHUTDOWN_INTERFACE |
| 378 |
void |
| 379 |
_ifXTable_shutdown_interface(ifXTable_registration * reg_ptr) |
| 380 |
{ |
| 381 |
/* |
| 382 |
* shutdown the container |
| 383 |
*/ |
| 384 |
_ifXTable_container_shutdown(&ifXTable_if_ctx); |
| 385 |
} |
| 386 |
#endif /* NETSNMP_FEATURE_REMOVE_IFXTABLE_SHUTDOWN_INTERFACE */ |
| 387 |
|
| 388 |
void |
| 389 |
ifXTable_valid_columns_set(netsnmp_column_info *vc) |
| 390 |
{ |
| 391 |
ifXTable_if_ctx.tbl_info.valid_columns = vc; |
| 392 |
} /* ifXTable_valid_columns_set */ |
| 393 |
|
| 394 |
/** |
| 395 |
* @internal |
| 396 |
* convert the index component stored in the context to an oid |
| 397 |
*/ |
| 398 |
int |
| 399 |
ifXTable_index_to_oid(netsnmp_index * oid_idx, |
| 400 |
ifXTable_mib_index * mib_idx) |
| 401 |
{ |
| 402 |
int err = SNMP_ERR_NOERROR; |
| 403 |
|
| 404 |
/* |
| 405 |
* temp storage for parsing indexes |
| 406 |
*/ |
| 407 |
/* |
| 408 |
* ifIndex(1)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/w/e/R/d/H |
| 409 |
*/ |
| 410 |
netsnmp_variable_list var_ifIndex; |
| 411 |
|
| 412 |
/* |
| 413 |
* set up varbinds |
| 414 |
*/ |
| 415 |
memset(&var_ifIndex, 0x00, sizeof(var_ifIndex)); |
| 416 |
var_ifIndex.type = ASN_INTEGER; |
| 417 |
|
| 418 |
/* |
| 419 |
* chain temp index varbinds together |
| 420 |
*/ |
| 421 |
var_ifIndex.next_variable = NULL; |
| 422 |
|
| 423 |
|
| 424 |
DEBUGMSGTL(("verbose:ifXTable:ifXTable_index_to_oid", "called\n")); |
| 425 |
|
| 426 |
/* |
| 427 |
* ifIndex(1)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/w/e/R/d/H |
| 428 |
*/ |
| 429 |
snmp_set_var_value(&var_ifIndex, (u_char *) & mib_idx->ifIndex, |
| 430 |
sizeof(mib_idx->ifIndex)); |
| 431 |
|
| 432 |
|
| 433 |
err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, |
| 434 |
NULL, 0, &var_ifIndex); |
| 435 |
if (err) |
| 436 |
snmp_log(LOG_ERR, "error %d converting index to oid\n", err); |
| 437 |
|
| 438 |
/* |
| 439 |
* parsing may have allocated memory. free it. |
| 440 |
*/ |
| 441 |
snmp_reset_var_buffers(&var_ifIndex); |
| 442 |
|
| 443 |
return err; |
| 444 |
} /* ifXTable_index_to_oid */ |
| 445 |
|
| 446 |
/** |
| 447 |
* extract ifXTable indexes from a netsnmp_index |
| 448 |
* |
| 449 |
* @retval SNMP_ERR_NOERROR : no error |
| 450 |
* @retval SNMP_ERR_GENERR : error |
| 451 |
*/ |
| 452 |
int |
| 453 |
ifXTable_index_from_oid(netsnmp_index * oid_idx, |
| 454 |
ifXTable_mib_index * mib_idx) |
| 455 |
{ |
| 456 |
int err = SNMP_ERR_NOERROR; |
| 457 |
|
| 458 |
/* |
| 459 |
* temp storage for parsing indexes |
| 460 |
*/ |
| 461 |
/* |
| 462 |
* ifIndex(1)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/w/e/R/d/H |
| 463 |
*/ |
| 464 |
netsnmp_variable_list var_ifIndex; |
| 465 |
|
| 466 |
/* |
| 467 |
* set up varbinds |
| 468 |
*/ |
| 469 |
memset(&var_ifIndex, 0x00, sizeof(var_ifIndex)); |
| 470 |
var_ifIndex.type = ASN_INTEGER; |
| 471 |
|
| 472 |
/* |
| 473 |
* chain temp index varbinds together |
| 474 |
*/ |
| 475 |
var_ifIndex.next_variable = NULL; |
| 476 |
|
| 477 |
|
| 478 |
DEBUGMSGTL(("verbose:ifXTable:ifXTable_index_from_oid", "called\n")); |
| 479 |
|
| 480 |
/* |
| 481 |
* parse the oid into the individual index components |
| 482 |
*/ |
| 483 |
err = parse_oid_indexes(oid_idx->oids, oid_idx->len, &var_ifIndex); |
| 484 |
if (err == SNMP_ERR_NOERROR) { |
| 485 |
/* |
| 486 |
* copy out values |
| 487 |
*/ |
| 488 |
mib_idx->ifIndex = *((long *) var_ifIndex.val.string); |
| 489 |
|
| 490 |
|
| 491 |
} |
| 492 |
|
| 493 |
/* |
| 494 |
* parsing may have allocated memory. free it. |
| 495 |
*/ |
| 496 |
snmp_reset_var_buffers(&var_ifIndex); |
| 497 |
|
| 498 |
return err; |
| 499 |
} /* ifXTable_index_from_oid */ |
| 500 |
|
| 501 |
|
| 502 |
/* |
| 503 |
* ifXTable_allocate_data |
| 504 |
* |
| 505 |
* Purpose: create new ifXTable_data. |
| 506 |
*/ |
| 507 |
ifXTable_data * |
| 508 |
ifXTable_allocate_data(void) |
| 509 |
{ |
| 510 |
ifXTable_data *rtn = SNMP_MALLOC_TYPEDEF(ifXTable_data); |
| 511 |
|
| 512 |
DEBUGMSGTL(("verbose:ifXTable:ifXTable_allocate_data", "called\n")); |
| 513 |
|
| 514 |
if (NULL == rtn) { |
| 515 |
snmp_log(LOG_ERR, "unable to malloc memory for new " |
| 516 |
"ifXTable_data.\n"); |
| 517 |
} |
| 518 |
|
| 519 |
return rtn; |
| 520 |
} /* ifXTable_allocate_data */ |
| 521 |
|
| 522 |
/* |
| 523 |
* ifXTable_release_data |
| 524 |
* |
| 525 |
* Purpose: release ifXTable data. |
| 526 |
*/ |
| 527 |
void |
| 528 |
ifXTable_release_data(ifXTable_data * data) |
| 529 |
{ |
| 530 |
DEBUGMSGTL(("verbose:ifXTable:ifXTable_release_data", "called\n")); |
| 531 |
|
| 532 |
free(data); |
| 533 |
} /* ifXTable_release_data */ |
| 534 |
|
| 535 |
/** |
| 536 |
* @internal |
| 537 |
* wrapper |
| 538 |
*/ |
| 539 |
static int |
| 540 |
_mfd_ifXTable_pre_request(netsnmp_mib_handler *handler, |
| 541 |
netsnmp_handler_registration *reginfo, |
| 542 |
netsnmp_agent_request_info *agtreq_info, |
| 543 |
netsnmp_request_info *requests) |
| 544 |
{ |
| 545 |
int rc; |
| 546 |
|
| 547 |
DEBUGMSGTL(("internal:ifXTable:_mfd_ifXTable_pre_request", |
| 548 |
"called\n")); |
| 549 |
|
| 550 |
if (1 != netsnmp_row_merge_status_first(reginfo, agtreq_info)) { |
| 551 |
DEBUGMSGTL(("internal:ifXTable", |
| 552 |
"skipping additional pre_request\n")); |
| 553 |
return SNMP_ERR_NOERROR; |
| 554 |
} |
| 555 |
|
| 556 |
rc = ifXTable_pre_request(ifXTable_if_ctx.user_ctx); |
| 557 |
if (MFD_SUCCESS != rc) { |
| 558 |
/* |
| 559 |
* nothing we can do about it but log it |
| 560 |
*/ |
| 561 |
DEBUGMSGTL(("ifXTable", "error %d from " |
| 562 |
"ifXTable_pre_request\n", rc)); |
| 563 |
netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); |
| 564 |
} |
| 565 |
|
| 566 |
return SNMP_ERR_NOERROR; |
| 567 |
} /* _mfd_ifXTable_pre_request */ |
| 568 |
|
| 569 |
/** |
| 570 |
* @internal |
| 571 |
* wrapper |
| 572 |
*/ |
| 573 |
static int |
| 574 |
_mfd_ifXTable_post_request(netsnmp_mib_handler *handler, |
| 575 |
netsnmp_handler_registration *reginfo, |
| 576 |
netsnmp_agent_request_info *agtreq_info, |
| 577 |
netsnmp_request_info *requests) |
| 578 |
{ |
| 579 |
ifXTable_rowreq_ctx *rowreq_ctx = (ifXTable_rowreq_ctx*) |
| 580 |
netsnmp_container_table_row_extract(requests); |
| 581 |
int rc, packet_rc; |
| 582 |
|
| 583 |
DEBUGMSGTL(("internal:ifXTable:_mfd_ifXTable_post_request", |
| 584 |
"called\n")); |
| 585 |
|
| 586 |
/* |
| 587 |
* release row context, if deleted |
| 588 |
*/ |
| 589 |
if (rowreq_ctx && (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED)) |
| 590 |
ifTable_release_rowreq_ctx(rowreq_ctx); |
| 591 |
|
| 592 |
/* |
| 593 |
* wait for last call before calling user |
| 594 |
*/ |
| 595 |
if (1 != netsnmp_row_merge_status_last(reginfo, agtreq_info)) { |
| 596 |
DEBUGMSGTL(("internal:ifXTable", |
| 597 |
"waiting for last post_request\n")); |
| 598 |
return SNMP_ERR_NOERROR; |
| 599 |
} |
| 600 |
|
| 601 |
packet_rc = netsnmp_check_all_requests_error(agtreq_info->asp, 0); |
| 602 |
if ((MFD_SUCCESS != packet_rc) && ifXTable_dirty_get()) { |
| 603 |
/* |
| 604 |
* we shouldn't get here. the undo steps should also clear |
| 605 |
* the dirty flags. |
| 606 |
*/ |
| 607 |
snmp_log(LOG_WARNING, "ifXTable dirty flag set in post_request " |
| 608 |
"but status != SUCCESS.\n"); |
| 609 |
} |
| 610 |
|
| 611 |
rc = ifXTable_post_request(ifXTable_if_ctx.user_ctx, packet_rc); |
| 612 |
if (MFD_SUCCESS != rc) { |
| 613 |
/* |
| 614 |
* nothing we can do about it but log it |
| 615 |
*/ |
| 616 |
DEBUGMSGTL(("ifXTable", "error %d from " |
| 617 |
"ifXTable_post_request\n", rc)); |
| 618 |
} |
| 619 |
|
| 620 |
return SNMP_ERR_NOERROR; |
| 621 |
} /* _mfd_ifXTable_post_request */ |
| 622 |
|
| 623 |
/** |
| 624 |
* @internal |
| 625 |
* wrapper |
| 626 |
*/ |
| 627 |
static int |
| 628 |
_mfd_ifXTable_object_lookup(netsnmp_mib_handler *handler, |
| 629 |
netsnmp_handler_registration *reginfo, |
| 630 |
netsnmp_agent_request_info *agtreq_info, |
| 631 |
netsnmp_request_info *requests) |
| 632 |
{ |
| 633 |
int rc = SNMP_ERR_NOERROR; |
| 634 |
ifXTable_rowreq_ctx *rowreq_ctx = (ifXTable_rowreq_ctx*) |
| 635 |
netsnmp_container_table_row_extract(requests); |
| 636 |
|
| 637 |
DEBUGMSGTL(("internal:ifXTable:_mfd_ifXTable_object_lookup", |
| 638 |
"called\n")); |
| 639 |
|
| 640 |
/* |
| 641 |
* get our context from mfd |
| 642 |
* ifXTable_interface_ctx *if_ctx = |
| 643 |
* (ifXTable_interface_ctx *)reginfo->my_reg_void; |
| 644 |
*/ |
| 645 |
|
| 646 |
if (NULL == rowreq_ctx) { |
| 647 |
rc = SNMP_ERR_NOCREATION; |
| 648 |
} |
| 649 |
|
| 650 |
if (MFD_SUCCESS != rc) |
| 651 |
netsnmp_request_set_error_all(requests, rc); |
| 652 |
else |
| 653 |
ifXTable_row_prep(rowreq_ctx); |
| 654 |
|
| 655 |
return SNMP_VALIDATE_ERR(rc); |
| 656 |
} /* _mfd_ifXTable_object_lookup */ |
| 657 |
|
| 658 |
/*********************************************************************** |
| 659 |
* |
| 660 |
* GET processing |
| 661 |
* |
| 662 |
***********************************************************************/ |
| 663 |
/* |
| 664 |
* @internal |
| 665 |
* Retrieve the value for a particular column |
| 666 |
*/ |
| 667 |
NETSNMP_STATIC_INLINE int |
| 668 |
_ifXTable_get_column(ifXTable_rowreq_ctx * rowreq_ctx, |
| 669 |
netsnmp_variable_list * var, int column) |
| 670 |
{ |
| 671 |
int rc = SNMPERR_SUCCESS; |
| 672 |
|
| 673 |
DEBUGMSGTL(("internal:ifXTable:_mfd_ifXTable_get_column", |
| 674 |
"called for %d\n", column)); |
| 675 |
|
| 676 |
|
| 677 |
netsnmp_assert(NULL != rowreq_ctx); |
| 678 |
|
| 679 |
switch (column) { |
| 680 |
|
| 681 |
/* |
| 682 |
* ifName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H |
| 683 |
*/ |
| 684 |
case COLUMN_IFNAME: |
| 685 |
var->type = ASN_OCTET_STR; |
| 686 |
rc = ifName_get(rowreq_ctx, (char **) &var->val.string, |
| 687 |
&var->val_len); |
| 688 |
break; |
| 689 |
|
| 690 |
/* |
| 691 |
* ifInMulticastPkts(2)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h |
| 692 |
*/ |
| 693 |
case COLUMN_IFINMULTICASTPKTS: |
| 694 |
var->val_len = sizeof(u_long); |
| 695 |
var->type = ASN_COUNTER; |
| 696 |
rc = ifInMulticastPkts_get(rowreq_ctx, (u_long *) var->val.string); |
| 697 |
break; |
| 698 |
|
| 699 |
/* |
| 700 |
* ifInBroadcastPkts(3)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h |
| 701 |
*/ |
| 702 |
case COLUMN_IFINBROADCASTPKTS: |
| 703 |
var->val_len = sizeof(u_long); |
| 704 |
var->type = ASN_COUNTER; |
| 705 |
rc = ifInBroadcastPkts_get(rowreq_ctx, (u_long *) var->val.string); |
| 706 |
break; |
| 707 |
|
| 708 |
/* |
| 709 |
* ifOutMulticastPkts(4)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h |
| 710 |
*/ |
| 711 |
case COLUMN_IFOUTMULTICASTPKTS: |
| 712 |
var->val_len = sizeof(u_long); |
| 713 |
var->type = ASN_COUNTER; |
| 714 |
rc = ifOutMulticastPkts_get(rowreq_ctx, |
| 715 |
(u_long *) var->val.string); |
| 716 |
break; |
| 717 |
|
| 718 |
/* |
| 719 |
* ifOutBroadcastPkts(5)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h |
| 720 |
*/ |
| 721 |
case COLUMN_IFOUTBROADCASTPKTS: |
| 722 |
var->val_len = sizeof(u_long); |
| 723 |
var->type = ASN_COUNTER; |
| 724 |
rc = ifOutBroadcastPkts_get(rowreq_ctx, |
| 725 |
(u_long *) var->val.string); |
| 726 |
break; |
| 727 |
|
| 728 |
/* |
| 729 |
* ifHCInOctets(6)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 730 |
*/ |
| 731 |
case COLUMN_IFHCINOCTETS: |
| 732 |
var->val_len = sizeof(struct counter64); |
| 733 |
var->type = ASN_COUNTER64; |
| 734 |
rc = ifHCInOctets_get(rowreq_ctx, (struct counter64 *) var->val.string); |
| 735 |
break; |
| 736 |
|
| 737 |
/* |
| 738 |
* ifHCInUcastPkts(7)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 739 |
*/ |
| 740 |
case COLUMN_IFHCINUCASTPKTS: |
| 741 |
var->val_len = sizeof(struct counter64); |
| 742 |
var->type = ASN_COUNTER64; |
| 743 |
rc = ifHCInUcastPkts_get(rowreq_ctx, (struct counter64 *) var->val.string); |
| 744 |
break; |
| 745 |
|
| 746 |
/* |
| 747 |
* ifHCInMulticastPkts(8)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 748 |
*/ |
| 749 |
case COLUMN_IFHCINMULTICASTPKTS: |
| 750 |
var->val_len = sizeof(struct counter64); |
| 751 |
var->type = ASN_COUNTER64; |
| 752 |
rc = ifHCInMulticastPkts_get(rowreq_ctx, (struct counter64 *) var->val.string); |
| 753 |
break; |
| 754 |
|
| 755 |
/* |
| 756 |
* ifHCInBroadcastPkts(9)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 757 |
*/ |
| 758 |
case COLUMN_IFHCINBROADCASTPKTS: |
| 759 |
var->val_len = sizeof(struct counter64); |
| 760 |
var->type = ASN_COUNTER64; |
| 761 |
rc = ifHCInBroadcastPkts_get(rowreq_ctx, (struct counter64 *) var->val.string); |
| 762 |
break; |
| 763 |
|
| 764 |
/* |
| 765 |
* ifHCOutOctets(10)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 766 |
*/ |
| 767 |
case COLUMN_IFHCOUTOCTETS: |
| 768 |
var->val_len = sizeof(struct counter64); |
| 769 |
var->type = ASN_COUNTER64; |
| 770 |
rc = ifHCOutOctets_get(rowreq_ctx, (struct counter64 *) var->val.string); |
| 771 |
break; |
| 772 |
|
| 773 |
/* |
| 774 |
* ifHCOutUcastPkts(11)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 775 |
*/ |
| 776 |
case COLUMN_IFHCOUTUCASTPKTS: |
| 777 |
var->val_len = sizeof(struct counter64); |
| 778 |
var->type = ASN_COUNTER64; |
| 779 |
rc = ifHCOutUcastPkts_get(rowreq_ctx, (struct counter64 *) var->val.string); |
| 780 |
break; |
| 781 |
|
| 782 |
/* |
| 783 |
* ifHCOutMulticastPkts(12)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 784 |
*/ |
| 785 |
case COLUMN_IFHCOUTMULTICASTPKTS: |
| 786 |
var->val_len = sizeof(struct counter64); |
| 787 |
var->type = ASN_COUNTER64; |
| 788 |
rc = ifHCOutMulticastPkts_get(rowreq_ctx, (struct counter64 *) var->val.string); |
| 789 |
break; |
| 790 |
|
| 791 |
/* |
| 792 |
* ifHCOutBroadcastPkts(13)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 793 |
*/ |
| 794 |
case COLUMN_IFHCOUTBROADCASTPKTS: |
| 795 |
var->val_len = sizeof(struct counter64); |
| 796 |
var->type = ASN_COUNTER64; |
| 797 |
rc = ifHCOutBroadcastPkts_get(rowreq_ctx, (struct counter64 *) var->val.string); |
| 798 |
break; |
| 799 |
|
| 800 |
/* |
| 801 |
* ifLinkUpDownTrapEnable(14)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h |
| 802 |
*/ |
| 803 |
case COLUMN_IFLINKUPDOWNTRAPENABLE: |
| 804 |
var->val_len = sizeof(u_long); |
| 805 |
var->type = ASN_INTEGER; |
| 806 |
rc = ifLinkUpDownTrapEnable_get(rowreq_ctx, |
| 807 |
(u_long *) var->val.string); |
| 808 |
break; |
| 809 |
|
| 810 |
/* |
| 811 |
* ifHighSpeed(15)/GAUGE/ASN_GAUGE/u_long(u_long)//l/A/w/e/r/d/h |
| 812 |
*/ |
| 813 |
case COLUMN_IFHIGHSPEED: |
| 814 |
var->val_len = sizeof(u_long); |
| 815 |
var->type = ASN_GAUGE; |
| 816 |
rc = ifHighSpeed_get(rowreq_ctx, (u_long *) var->val.string); |
| 817 |
break; |
| 818 |
|
| 819 |
/* |
| 820 |
* ifPromiscuousMode(16)/TruthValue/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h |
| 821 |
*/ |
| 822 |
case COLUMN_IFPROMISCUOUSMODE: |
| 823 |
var->val_len = sizeof(u_long); |
| 824 |
var->type = ASN_INTEGER; |
| 825 |
rc = ifPromiscuousMode_get(rowreq_ctx, (u_long *) var->val.string); |
| 826 |
break; |
| 827 |
|
| 828 |
/* |
| 829 |
* ifConnectorPresent(17)/TruthValue/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h |
| 830 |
*/ |
| 831 |
case COLUMN_IFCONNECTORPRESENT: |
| 832 |
var->val_len = sizeof(u_long); |
| 833 |
var->type = ASN_INTEGER; |
| 834 |
rc = ifConnectorPresent_get(rowreq_ctx, |
| 835 |
(u_long *) var->val.string); |
| 836 |
break; |
| 837 |
|
| 838 |
/* |
| 839 |
* ifAlias(18)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H |
| 840 |
*/ |
| 841 |
case COLUMN_IFALIAS: |
| 842 |
var->type = ASN_OCTET_STR; |
| 843 |
rc = ifAlias_get(rowreq_ctx, (char **) &var->val.string, |
| 844 |
&var->val_len); |
| 845 |
break; |
| 846 |
|
| 847 |
/* |
| 848 |
* ifCounterDiscontinuityTime(19)/TimeStamp/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h |
| 849 |
*/ |
| 850 |
case COLUMN_IFCOUNTERDISCONTINUITYTIME: |
| 851 |
var->val_len = sizeof(u_long); |
| 852 |
var->type = ASN_TIMETICKS; |
| 853 |
rc = ifCounterDiscontinuityTime_get(rowreq_ctx, |
| 854 |
(u_long *) var->val.string); |
| 855 |
break; |
| 856 |
|
| 857 |
default: |
| 858 |
snmp_log(LOG_ERR, "unknown column %d in _ifXTable_get_column\n", |
| 859 |
column); |
| 860 |
break; |
| 861 |
} |
| 862 |
|
| 863 |
return rc; |
| 864 |
} /* _ifXTable_get_column */ |
| 865 |
|
| 866 |
int |
| 867 |
_mfd_ifXTable_get_values(netsnmp_mib_handler *handler, |
| 868 |
netsnmp_handler_registration *reginfo, |
| 869 |
netsnmp_agent_request_info *agtreq_info, |
| 870 |
netsnmp_request_info *requests) |
| 871 |
{ |
| 872 |
ifXTable_rowreq_ctx *rowreq_ctx = (ifXTable_rowreq_ctx*) |
| 873 |
netsnmp_container_table_row_extract(requests); |
| 874 |
netsnmp_table_request_info *tri; |
| 875 |
u_char *old_string; |
| 876 |
void (*dataFreeHook) (void *); |
| 877 |
int rc; |
| 878 |
|
| 879 |
DEBUGMSGTL(("internal:ifXTable:_mfd_ifXTable_get_values", "called\n")); |
| 880 |
|
| 881 |
netsnmp_assert(NULL != rowreq_ctx); |
| 882 |
|
| 883 |
for (; requests; requests = requests->next) { |
| 884 |
/* |
| 885 |
* save old pointer, so we can free it if replaced |
| 886 |
*/ |
| 887 |
old_string = requests->requestvb->val.string; |
| 888 |
dataFreeHook = requests->requestvb->dataFreeHook; |
| 889 |
if (NULL == requests->requestvb->val.string) { |
| 890 |
requests->requestvb->val.string = requests->requestvb->buf; |
| 891 |
requests->requestvb->val_len = |
| 892 |
sizeof(requests->requestvb->buf); |
| 893 |
} else if (requests->requestvb->buf == |
| 894 |
requests->requestvb->val.string) { |
| 895 |
if (requests->requestvb->val_len != |
| 896 |
sizeof(requests->requestvb->buf)) |
| 897 |
requests->requestvb->val_len = |
| 898 |
sizeof(requests->requestvb->buf); |
| 899 |
} |
| 900 |
|
| 901 |
/* |
| 902 |
* get column data |
| 903 |
*/ |
| 904 |
tri = netsnmp_extract_table_info(requests); |
| 905 |
if (NULL == tri) |
| 906 |
continue; |
| 907 |
|
| 908 |
rc = _ifXTable_get_column(rowreq_ctx, requests->requestvb, |
| 909 |
tri->colnum); |
| 910 |
if (rc) { |
| 911 |
if (MFD_SKIP == rc) { |
| 912 |
requests->requestvb->type = SNMP_NOSUCHINSTANCE; |
| 913 |
rc = SNMP_ERR_NOERROR; |
| 914 |
} |
| 915 |
} else if (NULL == requests->requestvb->val.string) { |
| 916 |
snmp_log(LOG_ERR, "NULL varbind data pointer!\n"); |
| 917 |
rc = SNMP_ERR_GENERR; |
| 918 |
} |
| 919 |
if (rc) |
| 920 |
netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); |
| 921 |
|
| 922 |
/* |
| 923 |
* if the buffer wasn't used previously for the old data (i.e. it |
| 924 |
* was allocated memory) and the get routine replaced the pointer, |
| 925 |
* we need to free the previous pointer. |
| 926 |
*/ |
| 927 |
if (old_string && (old_string != requests->requestvb->buf) && |
| 928 |
(requests->requestvb->val.string != old_string)) { |
| 929 |
if (dataFreeHook) |
| 930 |
(*dataFreeHook) (old_string); |
| 931 |
else |
| 932 |
free(old_string); |
| 933 |
} |
| 934 |
} /* for results */ |
| 935 |
|
| 936 |
return SNMP_ERR_NOERROR; |
| 937 |
} /* _mfd_ifXTable_get_values */ |
| 938 |
|
| 939 |
#if !(defined(NETSNMP_NO_WRITE_SUPPORT) || defined(NETSNMP_DISABLE_SET_SUPPORT)) |
| 940 |
/*********************************************************************** |
| 941 |
* |
| 942 |
* SET processing |
| 943 |
* |
| 944 |
***********************************************************************/ |
| 945 |
|
| 946 |
/*---------------------------------------------------------------------- |
| 947 |
* |
| 948 |
* SET: Syntax checks |
| 949 |
* |
| 950 |
*---------------------------------------------------------------------*/ |
| 951 |
/* |
| 952 |
* @internal |
| 953 |
* Check the syntax for a particular column |
| 954 |
*/ |
| 955 |
NETSNMP_STATIC_INLINE int |
| 956 |
_ifXTable_check_column(ifXTable_rowreq_ctx * rowreq_ctx, |
| 957 |
netsnmp_variable_list * var, int column) |
| 958 |
{ |
| 959 |
int rc = SNMPERR_SUCCESS; |
| 960 |
|
| 961 |
DEBUGMSGTL(("internal:ifXTable:_ifXTable_check_column", |
| 962 |
"called for %d\n", column)); |
| 963 |
|
| 964 |
netsnmp_assert(NULL != rowreq_ctx); |
| 965 |
|
| 966 |
switch (column) { |
| 967 |
|
| 968 |
/* |
| 969 |
* ifName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H |
| 970 |
*/ |
| 971 |
case COLUMN_IFNAME: |
| 972 |
rc = SNMP_ERR_NOTWRITABLE; |
| 973 |
break; |
| 974 |
|
| 975 |
/* |
| 976 |
* ifInMulticastPkts(2)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h |
| 977 |
*/ |
| 978 |
case COLUMN_IFINMULTICASTPKTS: |
| 979 |
rc = SNMP_ERR_NOTWRITABLE; |
| 980 |
break; |
| 981 |
|
| 982 |
/* |
| 983 |
* ifInBroadcastPkts(3)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h |
| 984 |
*/ |
| 985 |
case COLUMN_IFINBROADCASTPKTS: |
| 986 |
rc = SNMP_ERR_NOTWRITABLE; |
| 987 |
break; |
| 988 |
|
| 989 |
/* |
| 990 |
* ifOutMulticastPkts(4)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h |
| 991 |
*/ |
| 992 |
case COLUMN_IFOUTMULTICASTPKTS: |
| 993 |
rc = SNMP_ERR_NOTWRITABLE; |
| 994 |
break; |
| 995 |
|
| 996 |
/* |
| 997 |
* ifOutBroadcastPkts(5)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h |
| 998 |
*/ |
| 999 |
case COLUMN_IFOUTBROADCASTPKTS: |
| 1000 |
rc = SNMP_ERR_NOTWRITABLE; |
| 1001 |
break; |
| 1002 |
|
| 1003 |
/* |
| 1004 |
* ifHCInOctets(6)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 1005 |
*/ |
| 1006 |
case COLUMN_IFHCINOCTETS: |
| 1007 |
rc = SNMP_ERR_NOTWRITABLE; |
| 1008 |
break; |
| 1009 |
|
| 1010 |
/* |
| 1011 |
* ifHCInUcastPkts(7)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 1012 |
*/ |
| 1013 |
case COLUMN_IFHCINUCASTPKTS: |
| 1014 |
rc = SNMP_ERR_NOTWRITABLE; |
| 1015 |
break; |
| 1016 |
|
| 1017 |
/* |
| 1018 |
* ifHCInMulticastPkts(8)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 1019 |
*/ |
| 1020 |
case COLUMN_IFHCINMULTICASTPKTS: |
| 1021 |
rc = SNMP_ERR_NOTWRITABLE; |
| 1022 |
break; |
| 1023 |
|
| 1024 |
/* |
| 1025 |
* ifHCInBroadcastPkts(9)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 1026 |
*/ |
| 1027 |
case COLUMN_IFHCINBROADCASTPKTS: |
| 1028 |
rc = SNMP_ERR_NOTWRITABLE; |
| 1029 |
break; |
| 1030 |
|
| 1031 |
/* |
| 1032 |
* ifHCOutOctets(10)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 1033 |
*/ |
| 1034 |
case COLUMN_IFHCOUTOCTETS: |
| 1035 |
rc = SNMP_ERR_NOTWRITABLE; |
| 1036 |
break; |
| 1037 |
|
| 1038 |
/* |
| 1039 |
* ifHCOutUcastPkts(11)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 1040 |
*/ |
| 1041 |
case COLUMN_IFHCOUTUCASTPKTS: |
| 1042 |
rc = SNMP_ERR_NOTWRITABLE; |
| 1043 |
break; |
| 1044 |
|
| 1045 |
/* |
| 1046 |
* ifHCOutMulticastPkts(12)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 1047 |
*/ |
| 1048 |
case COLUMN_IFHCOUTMULTICASTPKTS: |
| 1049 |
rc = SNMP_ERR_NOTWRITABLE; |
| 1050 |
break; |
| 1051 |
|
| 1052 |
/* |
| 1053 |
* ifHCOutBroadcastPkts(13)/COUNTER64/ASN_COUNTER64/U64(U64)//l/A/w/e/r/d/h |
| 1054 |
*/ |
| 1055 |
case COLUMN_IFHCOUTBROADCASTPKTS: |
| 1056 |
rc = SNMP_ERR_NOTWRITABLE; |
| 1057 |
break; |
| 1058 |
|
| 1059 |
/* |
| 1060 |
* ifLinkUpDownTrapEnable(14)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h |
| 1061 |
*/ |
| 1062 |
case COLUMN_IFLINKUPDOWNTRAPENABLE: |
| 1063 |
rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER, |
| 1064 |
sizeof(rowreq_ctx->data. |
| 1065 |
ifLinkUpDownTrapEnable)); |
| 1066 |
/* |
| 1067 |
* check that the value is one of defined enums |
| 1068 |
*/ |
| 1069 |
if ((SNMPERR_SUCCESS == rc) |
| 1070 |
&& (*var->val.integer != IFLINKUPDOWNTRAPENABLE_ENABLED) |
| 1071 |
&& (*var->val.integer != IFLINKUPDOWNTRAPENABLE_DISABLED) |
| 1072 |
) { |
| 1073 |
rc = SNMP_ERR_WRONGVALUE; |
| 1074 |
} |
| 1075 |
if (SNMPERR_SUCCESS != rc) { |
| 1076 |
DEBUGMSGTL(("ifXTable:_ifXTable_check_column:ifLinkUpDownTrapEnable", "varbind validation failed (eg bad type or size)\n")); |
| 1077 |
} else { |
| 1078 |
rc = ifLinkUpDownTrapEnable_check_value(rowreq_ctx, |
| 1079 |
*((u_long *) var->val. |
| 1080 |
string)); |
| 1081 |
if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc) |
| 1082 |
&& (MFD_NOT_VALID_NOW != rc)) { |
| 1083 |
snmp_log(LOG_ERR, |
| 1084 |
"bad rc %d from ifLinkUpDownTrapEnable_check_value\n", |
| 1085 |
rc); |
| 1086 |
rc = SNMP_ERR_GENERR; |
| 1087 |
} |
| 1088 |
} |
| 1089 |
break; |
| 1090 |
|
| 1091 |
/* |
| 1092 |
* ifHighSpeed(15)/GAUGE/ASN_GAUGE/u_long(u_long)//l/A/w/e/r/d/h |
| 1093 |
*/ |
| 1094 |
case COLUMN_IFHIGHSPEED: |
| 1095 |
rc = SNMP_ERR_NOTWRITABLE; |
| 1096 |
break; |
| 1097 |
|
| 1098 |
/* |
| 1099 |
* ifPromiscuousMode(16)/TruthValue/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h |
| 1100 |
*/ |
| 1101 |
case COLUMN_IFPROMISCUOUSMODE: |
| 1102 |
rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER, |
| 1103 |
sizeof(rowreq_ctx->data. |
| 1104 |
ifPromiscuousMode)); |
| 1105 |
/* |
| 1106 |
* check that the value is one of defined enums |
| 1107 |
*/ |
| 1108 |
if ((SNMPERR_SUCCESS == rc) |
| 1109 |
&& (*var->val.integer != TRUTHVALUE_TRUE) |
| 1110 |
&& (*var->val.integer != TRUTHVALUE_FALSE) |
| 1111 |
) { |
| 1112 |
rc = SNMP_ERR_WRONGVALUE; |
| 1113 |
} |
| 1114 |
if (SNMPERR_SUCCESS != rc) { |
| 1115 |
DEBUGMSGTL(("ifXTable:_ifXTable_check_column:ifPromiscuousMode", "varbind validation failed (eg bad type or size)\n")); |
| 1116 |
} else { |
| 1117 |
rc = ifPromiscuousMode_check_value(rowreq_ctx, |
| 1118 |
*((u_long *) var->val. |
| 1119 |
string)); |
| 1120 |
if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc) |
| 1121 |
&& (MFD_NOT_VALID_NOW != rc)) { |
| 1122 |
snmp_log(LOG_ERR, |
| 1123 |
"bad rc %d from ifPromiscuousMode_check_value\n", |
| 1124 |
rc); |
| 1125 |
rc = SNMP_ERR_GENERR; |
| 1126 |
} |
| 1127 |
} |
| 1128 |
break; |
| 1129 |
|
| 1130 |
/* |
| 1131 |
* ifConnectorPresent(17)/TruthValue/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h |
| 1132 |
*/ |
| 1133 |
case COLUMN_IFCONNECTORPRESENT: |
| 1134 |
rc = SNMP_ERR_NOTWRITABLE; |
| 1135 |
break; |
| 1136 |
|
| 1137 |
/* |
| 1138 |
* ifAlias(18)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H |
| 1139 |
*/ |
| 1140 |
case COLUMN_IFALIAS: |
| 1141 |
rc = netsnmp_check_vb_type_and_max_size(var, ASN_OCTET_STR, |
| 1142 |
sizeof(rowreq_ctx->data. |
| 1143 |
ifAlias)); |
| 1144 |
/* |
| 1145 |
* check defined range(s). |
| 1146 |
*/ |
| 1147 |
if (rc == SNMPERR_SUCCESS && var->val_len > 64) { |
| 1148 |
rc = SNMP_ERR_WRONGLENGTH; |
| 1149 |
} |
| 1150 |
if (SNMPERR_SUCCESS != rc) { |
| 1151 |
DEBUGMSGTL(("ifXTable:_ifXTable_check_column:ifAlias", |
| 1152 |
"varbind validation failed (eg bad type or size)\n")); |
| 1153 |
} else { |
| 1154 |
rc = ifAlias_check_value(rowreq_ctx, (char *) var->val.string, |
| 1155 |
var->val_len); |
| 1156 |
if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc) |
| 1157 |
&& (MFD_NOT_VALID_NOW != rc)) { |
| 1158 |
snmp_log(LOG_ERR, "bad rc %d from ifAlias_check_value\n", |
| 1159 |
rc); |
| 1160 |
rc = SNMP_ERR_GENERR; |
| 1161 |
} |
| 1162 |
} |
| 1163 |
break; |
| 1164 |
|
| 1165 |
/* |
| 1166 |
* ifCounterDiscontinuityTime(19)/TimeStamp/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h |
| 1167 |
*/ |
| 1168 |
case COLUMN_IFCOUNTERDISCONTINUITYTIME: |
| 1169 |
rc = SNMP_ERR_NOTWRITABLE; |
| 1170 |
break; |
| 1171 |
|
| 1172 |
default: /** We shouldn't get here */ |
| 1173 |
rc = SNMP_ERR_GENERR; |
| 1174 |
snmp_log(LOG_ERR, "unknown column %d in _ifXTable_check_column\n", |
| 1175 |
column); |
| 1176 |
} |
| 1177 |
|
| 1178 |
return rc; |
| 1179 |
} /* _ifXTable_check_column */ |
| 1180 |
|
| 1181 |
int |
| 1182 |
_mfd_ifXTable_check_objects(netsnmp_mib_handler *handler, |
| 1183 |
netsnmp_handler_registration *reginfo, |
| 1184 |
netsnmp_agent_request_info *agtreq_info, |
| 1185 |
netsnmp_request_info *requests) |
| 1186 |
{ |
| 1187 |
ifXTable_rowreq_ctx *rowreq_ctx = (ifXTable_rowreq_ctx*) |
| 1188 |
netsnmp_container_table_row_extract(requests); |
| 1189 |
netsnmp_table_request_info *tri; |
| 1190 |
int rc; |
| 1191 |
|
| 1192 |
DEBUGMSGTL(("internal:ifXTable:_mfd_ifXTable_check_objects", |
| 1193 |
"called\n")); |
| 1194 |
|
| 1195 |
netsnmp_assert(NULL != rowreq_ctx); |
| 1196 |
|
| 1197 |
for (; requests; requests = requests->next) { |
| 1198 |
|
| 1199 |
/* |
| 1200 |
* get column number from table request info, and check that column |
| 1201 |
*/ |
| 1202 |
tri = netsnmp_extract_table_info(requests); |
| 1203 |
if (NULL == tri) |
| 1204 |
continue; |
| 1205 |
|
| 1206 |
rc = _ifXTable_check_column(rowreq_ctx, requests->requestvb, |
| 1207 |
tri->colnum); |
| 1208 |
if (rc) { |
| 1209 |
netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); |
| 1210 |
break; |
| 1211 |
} |
| 1212 |
|
| 1213 |
} /* for results */ |
| 1214 |
|
| 1215 |
return SNMP_ERR_NOERROR; |
| 1216 |
} /* _mfd_ifXTable_check_objects */ |
| 1217 |
|
| 1218 |
/*---------------------------------------------------------------------- |
| 1219 |
* |
| 1220 |
* SET: check dependencies |
| 1221 |
* |
| 1222 |
*---------------------------------------------------------------------*/ |
| 1223 |
/* |
| 1224 |
* @internal |
| 1225 |
* Check dependencies wrapper |
| 1226 |
*/ |
| 1227 |
static int |
| 1228 |
_mfd_ifXTable_check_dependencies(netsnmp_mib_handler *handler, |
| 1229 |
netsnmp_handler_registration *reginfo, |
| 1230 |
netsnmp_agent_request_info *agtreq_info, |
| 1231 |
netsnmp_request_info *requests) |
| 1232 |
{ |
| 1233 |
int rc; |
| 1234 |
ifXTable_rowreq_ctx *rowreq_ctx = (ifXTable_rowreq_ctx*) |
| 1235 |
netsnmp_container_table_row_extract(requests); |
| 1236 |
DEBUGMSGTL(("internal:ifXTable:_mfd_ifXTable_check_dependencies", |
| 1237 |
"called\n")); |
| 1238 |
|
| 1239 |
netsnmp_assert(NULL != rowreq_ctx); |
| 1240 |
|
| 1241 |
rc = ifXTable_check_dependencies(rowreq_ctx); |
| 1242 |
if (rc) { |
| 1243 |
DEBUGMSGTL(("ifXTable:mfd", "error %d from " |
| 1244 |
"ifXTable_check_dependencies\n", rc)); |
| 1245 |
netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); |
| 1246 |
} |
| 1247 |
|
| 1248 |
return SNMP_ERR_NOERROR; |
| 1249 |
} /* _mfd_ifXTable_check_dependencies */ |
| 1250 |
|
| 1251 |
/*---------------------------------------------------------------------- |
| 1252 |
* |
| 1253 |
* SET: Undo setup |
| 1254 |
* |
| 1255 |
*---------------------------------------------------------------------*/ |
| 1256 |
/* |
| 1257 |
* @internal |
| 1258 |
* Set the value for a particular column |
| 1259 |
*/ |
| 1260 |
NETSNMP_STATIC_INLINE int |
| 1261 |
_ifXTable_undo_setup_column(ifXTable_rowreq_ctx * rowreq_ctx, int column) |
| 1262 |
{ |
| 1263 |
int rc = SNMPERR_SUCCESS; |
| 1264 |
|
| 1265 |
DEBUGMSGTL(("internal:ifXTable:_ifXTable_undo_setup_column", |
| 1266 |
"called for %d\n", column)); |
| 1267 |
|
| 1268 |
netsnmp_assert(NULL != rowreq_ctx); |
| 1269 |
|
| 1270 |
switch (column) { |
| 1271 |
|
| 1272 |
/* |
| 1273 |
* ifLinkUpDownTrapEnable(14)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h |
| 1274 |
*/ |
| 1275 |
case COLUMN_IFLINKUPDOWNTRAPENABLE: |
| 1276 |
rowreq_ctx->column_set_flags |= COLUMN_IFLINKUPDOWNTRAPENABLE_FLAG; |
| 1277 |
rc = ifLinkUpDownTrapEnable_undo_setup(rowreq_ctx); |
| 1278 |
break; |
| 1279 |
|
| 1280 |
/* |
| 1281 |
* ifPromiscuousMode(16)/TruthValue/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h |
| 1282 |
*/ |
| 1283 |
case COLUMN_IFPROMISCUOUSMODE: |
| 1284 |
rowreq_ctx->column_set_flags |= COLUMN_IFPROMISCUOUSMODE_FLAG; |
| 1285 |
rc = ifPromiscuousMode_undo_setup(rowreq_ctx); |
| 1286 |
break; |
| 1287 |
|
| 1288 |
/* |
| 1289 |
* ifAlias(18)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H |
| 1290 |
*/ |
| 1291 |
case COLUMN_IFALIAS: |
| 1292 |
rowreq_ctx->column_set_flags |= COLUMN_IFALIAS_FLAG; |
| 1293 |
rc = ifAlias_undo_setup(rowreq_ctx); |
| 1294 |
break; |
| 1295 |
|
| 1296 |
default: |
| 1297 |
snmp_log(LOG_ERR, |
| 1298 |
"unknown column %d in _ifXTable_undo_setup_column\n", |
| 1299 |
column); |
| 1300 |
break; |
| 1301 |
} |
| 1302 |
|
| 1303 |
return rc; |
| 1304 |
} /* _ifXTable_undo_setup_column */ |
| 1305 |
|
| 1306 |
|
| 1307 |
/** |
| 1308 |
* @internal |
| 1309 |
* undo setup |
| 1310 |
*/ |
| 1311 |
int |
| 1312 |
_mfd_ifXTable_undo_setup(netsnmp_mib_handler *handler, |
| 1313 |
netsnmp_handler_registration *reginfo, |
| 1314 |
netsnmp_agent_request_info *agtreq_info, |
| 1315 |
netsnmp_request_info *requests) |
| 1316 |
{ |
| 1317 |
int rc; |
| 1318 |
ifXTable_rowreq_ctx *rowreq_ctx = (ifXTable_rowreq_ctx*) |
| 1319 |
netsnmp_container_table_row_extract(requests); |
| 1320 |
|
| 1321 |
DEBUGMSGTL(("internal:ifXTable:_mfd_ifXTable_undo_setup", "called\n")); |
| 1322 |
|
| 1323 |
netsnmp_assert(NULL != rowreq_ctx); |
| 1324 |
|
| 1325 |
/* |
| 1326 |
* allocate undo context |
| 1327 |
*/ |
| 1328 |
rowreq_ctx->undo = ifXTable_allocate_data(); |
| 1329 |
if (NULL == rowreq_ctx->undo) { |
| 1330 |
/** msg already logged */ |
| 1331 |
netsnmp_request_set_error_all(requests, |
| 1332 |
SNMP_ERR_RESOURCEUNAVAILABLE); |
| 1333 |
return SNMP_ERR_NOERROR; |
| 1334 |
} |
| 1335 |
|
| 1336 |
/* |
| 1337 |
* row undo setup |
| 1338 |
*/ |
| 1339 |
rowreq_ctx->column_set_flags = 0; |
| 1340 |
rc = ifXTable_undo_setup(rowreq_ctx); |
| 1341 |
if (MFD_SUCCESS != rc) { |
| 1342 |
DEBUGMSGTL(("ifXTable:mfd", "error %d from " |
| 1343 |
"ifXTable_undo_setup\n", rc)); |
| 1344 |
netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); |
| 1345 |
} else { |
| 1346 |
/* |
| 1347 |
* column undo setup |
| 1348 |
*/ |
| 1349 |
netsnmp_table_request_info *tri; |
| 1350 |
for (; requests; requests = requests->next) { |
| 1351 |
/* |
| 1352 |
* set column data |
| 1353 |
*/ |
| 1354 |
tri = netsnmp_extract_table_info(requests); |
| 1355 |
if (NULL == tri) |
| 1356 |
continue; |
| 1357 |
|
| 1358 |
rc = _ifXTable_undo_setup_column(rowreq_ctx, tri->colnum); |
| 1359 |
if (MFD_SUCCESS != rc) { |
| 1360 |
DEBUGMSGTL(("ifXTable:mfd", "error %d from " |
| 1361 |
"ifXTable_undo_setup_column\n", rc)); |
| 1362 |
netsnmp_set_request_error(agtreq_info, requests, |
| 1363 |
SNMP_VALIDATE_ERR(rc)); |
| 1364 |
} |
| 1365 |
} /* for results */ |
| 1366 |
} |
| 1367 |
|
| 1368 |
return SNMP_ERR_NOERROR; |
| 1369 |
} /* _mfd_ifXTable_undo_setup */ |
| 1370 |
|
| 1371 |
/** |
| 1372 |
* @internal |
| 1373 |
* undo setup |
| 1374 |
*/ |
| 1375 |
int |
| 1376 |
_mfd_ifXTable_undo_cleanup(netsnmp_mib_handler *handler, |
| 1377 |
netsnmp_handler_registration *reginfo, |
| 1378 |
netsnmp_agent_request_info *agtreq_info, |
| 1379 |
netsnmp_request_info *requests) |
| 1380 |
{ |
| 1381 |
ifXTable_rowreq_ctx *rowreq_ctx = (ifXTable_rowreq_ctx*) |
| 1382 |
netsnmp_container_table_row_extract(requests); |
| 1383 |
int rc; |
| 1384 |
|
| 1385 |
DEBUGMSGTL(("internal:ifXTable:_mfd_ifXTable_undo_cleanup", |
| 1386 |
"called\n")); |
| 1387 |
|
| 1388 |
/* |
| 1389 |
* failed row create in early stages has no rowreq_ctx |
| 1390 |
*/ |
| 1391 |
if (NULL == rowreq_ctx) |
| 1392 |
return MFD_SUCCESS; |
| 1393 |
|
| 1394 |
/* |
| 1395 |
* call user cleanup |
| 1396 |
*/ |
| 1397 |
rc = ifXTable_undo_cleanup(rowreq_ctx); |
| 1398 |
if (MFD_SUCCESS != rc) { |
| 1399 |
/* |
| 1400 |
* nothing we can do about it but log it |
| 1401 |
*/ |
| 1402 |
DEBUGMSGTL(("ifXTable:mfd", "error %d from " |
| 1403 |
"ifXTable_undo_cleanup\n", rc)); |
| 1404 |
} |
| 1405 |
|
| 1406 |
/* |
| 1407 |
* release undo context, if needed |
| 1408 |
*/ |
| 1409 |
if (rowreq_ctx->undo) { |
| 1410 |
ifXTable_release_data(rowreq_ctx->undo); |
| 1411 |
rowreq_ctx->undo = NULL; |
| 1412 |
} |
| 1413 |
|
| 1414 |
|
| 1415 |
return SNMP_ERR_NOERROR; |
| 1416 |
} /* _mfd_ifXTable_undo_cleanup */ |
| 1417 |
|
| 1418 |
/*---------------------------------------------------------------------- |
| 1419 |
* |
| 1420 |
* SET: Set values |
| 1421 |
* |
| 1422 |
*---------------------------------------------------------------------*/ |
| 1423 |
/* |
| 1424 |
* @internal |
| 1425 |
* Set the value for a particular column |
| 1426 |
*/ |
| 1427 |
NETSNMP_STATIC_INLINE int |
| 1428 |
_ifXTable_set_column(ifXTable_rowreq_ctx * rowreq_ctx, |
| 1429 |
netsnmp_variable_list * var, int column) |
| 1430 |
{ |
| 1431 |
int rc = SNMPERR_SUCCESS; |
| 1432 |
|
| 1433 |
DEBUGMSGTL(("internal:ifXTable:_ifXTable_set_column", |
| 1434 |
"called for %d\n", column)); |
| 1435 |
|
| 1436 |
netsnmp_assert(NULL != rowreq_ctx); |
| 1437 |
|
| 1438 |
switch (column) { |
| 1439 |
|
| 1440 |
/* |
| 1441 |
* ifLinkUpDownTrapEnable(14)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h |
| 1442 |
*/ |
| 1443 |
case COLUMN_IFLINKUPDOWNTRAPENABLE: |
| 1444 |
rowreq_ctx->column_set_flags |= COLUMN_IFLINKUPDOWNTRAPENABLE_FLAG; |
| 1445 |
rc = ifLinkUpDownTrapEnable_set(rowreq_ctx, |
| 1446 |
*((u_long *) var->val.string)); |
| 1447 |
break; |
| 1448 |
|
| 1449 |
/* |
| 1450 |
* ifPromiscuousMode(16)/TruthValue/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h |
| 1451 |
*/ |
| 1452 |
case COLUMN_IFPROMISCUOUSMODE: |
| 1453 |
rowreq_ctx->column_set_flags |= COLUMN_IFPROMISCUOUSMODE_FLAG; |
| 1454 |
rc = ifPromiscuousMode_set(rowreq_ctx, |
| 1455 |
*((u_long *) var->val.string)); |
| 1456 |
break; |
| 1457 |
|
| 1458 |
/* |
| 1459 |
* ifAlias(18)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H |
| 1460 |
*/ |
| 1461 |
case COLUMN_IFALIAS: |
| 1462 |
rowreq_ctx->column_set_flags |= COLUMN_IFALIAS_FLAG; |
| 1463 |
rc = ifAlias_set(rowreq_ctx, (char *) var->val.string, |
| 1464 |
var->val_len); |
| 1465 |
break; |
| 1466 |
|
| 1467 |
default: |
| 1468 |
snmp_log(LOG_ERR, "unknown column %d in _ifXTable_set_column\n", |
| 1469 |
column); |
| 1470 |
rc = SNMP_ERR_GENERR; |
| 1471 |
break; |
| 1472 |
} |
| 1473 |
|
| 1474 |
return rc; |
| 1475 |
} /* _ifXTable_set_column */ |
| 1476 |
|
| 1477 |
int |
| 1478 |
_mfd_ifXTable_set_values(netsnmp_mib_handler *handler, |
| 1479 |
netsnmp_handler_registration *reginfo, |
| 1480 |
netsnmp_agent_request_info *agtreq_info, |
| 1481 |
netsnmp_request_info *requests) |
| 1482 |
{ |
| 1483 |
ifXTable_rowreq_ctx *rowreq_ctx = (ifXTable_rowreq_ctx*) |
| 1484 |
netsnmp_container_table_row_extract(requests); |
| 1485 |
netsnmp_table_request_info *tri; |
| 1486 |
int rc = SNMP_ERR_NOERROR; |
| 1487 |
|
| 1488 |
DEBUGMSGTL(("internal:ifXTable:_mfd_ifXTable_set_values", "called\n")); |
| 1489 |
|
| 1490 |
netsnmp_assert(NULL != rowreq_ctx); |
| 1491 |
|
| 1492 |
rowreq_ctx->column_set_flags = 0; |
| 1493 |
for (; requests; requests = requests->next) { |
| 1494 |
/* |
| 1495 |
* set column data |
| 1496 |
*/ |
| 1497 |
tri = netsnmp_extract_table_info(requests); |
| 1498 |
if (NULL == tri) |
| 1499 |
continue; |
| 1500 |
|
| 1501 |
rc = _ifXTable_set_column(rowreq_ctx, |
| 1502 |
requests->requestvb, tri->colnum); |
| 1503 |
if (MFD_SUCCESS != rc) { |
| 1504 |
DEBUGMSGTL(("ifXTable:mfd", "error %d from " |
| 1505 |
"ifXTable_set_column\n", rc)); |
| 1506 |
netsnmp_set_request_error(agtreq_info, requests, |
| 1507 |
SNMP_VALIDATE_ERR(rc)); |
| 1508 |
} |
| 1509 |
} /* for results */ |
| 1510 |
|
| 1511 |
return SNMP_ERR_NOERROR; |
| 1512 |
} /* _mfd_ifXTable_set_values */ |
| 1513 |
|
| 1514 |
/*---------------------------------------------------------------------- |
| 1515 |
* |
| 1516 |
* SET: commit |
| 1517 |
* |
| 1518 |
*---------------------------------------------------------------------*/ |
| 1519 |
/** |
| 1520 |
* @internal |
| 1521 |
* commit the values |
| 1522 |
*/ |
| 1523 |
int |
| 1524 |
_mfd_ifXTable_commit(netsnmp_mib_handler *handler, |
| 1525 |
netsnmp_handler_registration *reginfo, |
| 1526 |
netsnmp_agent_request_info *agtreq_info, |
| 1527 |
netsnmp_request_info *requests) |
| 1528 |
{ |
| 1529 |
int rc; |
| 1530 |
ifXTable_rowreq_ctx *rowreq_ctx = (ifXTable_rowreq_ctx*) |
| 1531 |
netsnmp_container_table_row_extract(requests); |
| 1532 |
|
| 1533 |
DEBUGMSGTL(("internal:ifXTable:_mfd_ifXTable_commit", "called\n")); |
| 1534 |
|
| 1535 |
netsnmp_assert(NULL != rowreq_ctx); |
| 1536 |
|
| 1537 |
rc = ifXTable_commit(rowreq_ctx); |
| 1538 |
if (MFD_SUCCESS != rc) { |
| 1539 |
DEBUGMSGTL(("ifXTable:mfd", "error %d from " |
| 1540 |
"ifXTable_commit\n", rc)); |
| 1541 |
netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); |
| 1542 |
} |
| 1543 |
|
| 1544 |
if (rowreq_ctx->rowreq_flags & MFD_ROW_DIRTY) { |
| 1545 |
/* |
| 1546 |
* if we successfully committed this row, set the dirty flag. Use the |
| 1547 |
* current value + 1 (i.e. dirty = # rows changed). |
| 1548 |
* this is checked in post_request... |
| 1549 |
*/ |
| 1550 |
ifXTable_dirty_set(ifXTable_dirty_get() + 1); /* set table dirty flag */ |
| 1551 |
} |
| 1552 |
|
| 1553 |
return SNMP_ERR_NOERROR; |
| 1554 |
} |
| 1555 |
|
| 1556 |
int |
| 1557 |
_mfd_ifXTable_undo_commit(netsnmp_mib_handler *handler, |
| 1558 |
netsnmp_handler_registration *reginfo, |
| 1559 |
netsnmp_agent_request_info *agtreq_info, |
| 1560 |
netsnmp_request_info *requests) |
| 1561 |
{ |
| 1562 |
int rc; |
| 1563 |
ifXTable_rowreq_ctx *rowreq_ctx = (ifXTable_rowreq_ctx*) |
| 1564 |
netsnmp_container_table_row_extract(requests); |
| 1565 |
|
| 1566 |
DEBUGMSGTL(("internal:ifXTable:_mfd_ifXTable_undo_commit", |
| 1567 |
"called\n")); |
| 1568 |
|
| 1569 |
netsnmp_assert(NULL != rowreq_ctx); |
| 1570 |
|
| 1571 |
if (rowreq_ctx->rowreq_flags & MFD_ROW_DIRTY) { |
| 1572 |
u_int d = ifXTable_dirty_get(); |
| 1573 |
|
| 1574 |
netsnmp_assert(d != 0); |
| 1575 |
if (d) |
| 1576 |
ifXTable_dirty_set(d - 1); |
| 1577 |
} |
| 1578 |
|
| 1579 |
rc = ifXTable_undo_commit(rowreq_ctx); |
| 1580 |
if (MFD_SUCCESS != rc) { |
| 1581 |
/* |
| 1582 |
* nothing we can do about it but log it |
| 1583 |
*/ |
| 1584 |
DEBUGMSGTL(("ifXTable:mfd", "error %d from " |
| 1585 |
"ifXTable_undo_commit\n", rc)); |
| 1586 |
} |
| 1587 |
|
| 1588 |
if (rowreq_ctx->rowreq_flags & MFD_ROW_DIRTY) { |
| 1589 |
snmp_log(LOG_WARNING, |
| 1590 |
"ifXTable row dirty flag still set after undo_commit\n"); |
| 1591 |
rowreq_ctx->rowreq_flags &= ~MFD_ROW_DIRTY; |
| 1592 |
} |
| 1593 |
|
| 1594 |
return SNMP_ERR_NOERROR; |
| 1595 |
} /* _mfd_ifXTable_commit */ |
| 1596 |
|
| 1597 |
/*---------------------------------------------------------------------- |
| 1598 |
* |
| 1599 |
* SET: Undo |
| 1600 |
* |
| 1601 |
*---------------------------------------------------------------------*/ |
| 1602 |
/** |
| 1603 |
* @internal |
| 1604 |
* undo the value for a particular column |
| 1605 |
*/ |
| 1606 |
NETSNMP_STATIC_INLINE int |
| 1607 |
_ifXTable_undo_column(ifXTable_rowreq_ctx * rowreq_ctx, |
| 1608 |
netsnmp_variable_list * var, int column) |
| 1609 |
{ |
| 1610 |
int rc = SNMPERR_SUCCESS; |
| 1611 |
|
| 1612 |
DEBUGMSGTL(("internal:ifXTable:_ifXTable_undo_column", |
| 1613 |
"called for %d\n", column)); |
| 1614 |
|
| 1615 |
netsnmp_assert(NULL != rowreq_ctx); |
| 1616 |
|
| 1617 |
switch (column) { |
| 1618 |
|
| 1619 |
/* |
| 1620 |
* ifLinkUpDownTrapEnable(14)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h |
| 1621 |
*/ |
| 1622 |
case COLUMN_IFLINKUPDOWNTRAPENABLE: |
| 1623 |
rc = ifLinkUpDownTrapEnable_undo(rowreq_ctx); |
| 1624 |
break; |
| 1625 |
|
| 1626 |
/* |
| 1627 |
* ifPromiscuousMode(16)/TruthValue/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h |
| 1628 |
*/ |
| 1629 |
case COLUMN_IFPROMISCUOUSMODE: |
| 1630 |
rc = ifPromiscuousMode_undo(rowreq_ctx); |
| 1631 |
break; |
| 1632 |
|
| 1633 |
/* |
| 1634 |
* ifAlias(18)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H |
| 1635 |
*/ |
| 1636 |
case COLUMN_IFALIAS: |
| 1637 |
rc = ifAlias_undo(rowreq_ctx); |
| 1638 |
break; |
| 1639 |
|
| 1640 |
default: |
| 1641 |
snmp_log(LOG_ERR, "unknown column %d in _ifXTable_undo_column\n", |
| 1642 |
column); |
| 1643 |
break; |
| 1644 |
} |
| 1645 |
|
| 1646 |
return rc; |
| 1647 |
} /* _ifXTable_undo_column */ |
| 1648 |
|
| 1649 |
int |
| 1650 |
_mfd_ifXTable_undo_values(netsnmp_mib_handler *handler, |
| 1651 |
netsnmp_handler_registration *reginfo, |
| 1652 |
netsnmp_agent_request_info *agtreq_info, |
| 1653 |
netsnmp_request_info *requests) |
| 1654 |
{ |
| 1655 |
int rc; |
| 1656 |
ifXTable_rowreq_ctx *rowreq_ctx = (ifXTable_rowreq_ctx*) |
| 1657 |
netsnmp_container_table_row_extract(requests); |
| 1658 |
netsnmp_table_request_info *tri; |
| 1659 |
|
| 1660 |
DEBUGMSGTL(("internal:ifXTable:_mfd_ifXTable_undo_values", |
| 1661 |
"called\n")); |
| 1662 |
|
| 1663 |
netsnmp_assert(NULL != rowreq_ctx); |
| 1664 |
|
| 1665 |
rc = ifXTable_undo(rowreq_ctx); |
| 1666 |
if (MFD_SUCCESS != rc) { |
| 1667 |
/* |
| 1668 |
* nothing we can do about it but log it |
| 1669 |
*/ |
| 1670 |
DEBUGMSGTL(("ifXTable:mfd", "error %d from " |
| 1671 |
"ifXTable_undo\n", rc)); |
| 1672 |
} |
| 1673 |
|
| 1674 |
for (; requests; requests = requests->next) { |
| 1675 |
/* |
| 1676 |
* set column data |
| 1677 |
*/ |
| 1678 |
tri = netsnmp_extract_table_info(requests); |
| 1679 |
if (NULL == tri) |
| 1680 |
continue; |
| 1681 |
|
| 1682 |
rc = _ifXTable_undo_column(rowreq_ctx, requests->requestvb, |
| 1683 |
tri->colnum); |
| 1684 |
if (MFD_SUCCESS != rc) { |
| 1685 |
/* |
| 1686 |
* nothing we can do about it but log it |
| 1687 |
*/ |
| 1688 |
DEBUGMSGTL(("ifXTable:mfd", "error %d from " |
| 1689 |
"ifXTable_undo_column\n", rc)); |
| 1690 |
} |
| 1691 |
} /* for results */ |
| 1692 |
|
| 1693 |
return SNMP_ERR_NOERROR; |
| 1694 |
} /* _mfd_ifXTable_undo_values */ |
| 1695 |
|
| 1696 |
/*---------------------------------------------------------------------- |
| 1697 |
* |
| 1698 |
* SET: irreversible commit |
| 1699 |
* |
| 1700 |
*---------------------------------------------------------------------*/ |
| 1701 |
/** |
| 1702 |
* @internal |
| 1703 |
* commit irreversible actions |
| 1704 |
*/ |
| 1705 |
int |
| 1706 |
_mfd_ifXTable_irreversible_commit(netsnmp_mib_handler *handler, |
| 1707 |
netsnmp_handler_registration *reginfo, |
| 1708 |
netsnmp_agent_request_info *agtreq_info, |
| 1709 |
netsnmp_request_info *requests) |
| 1710 |
{ |
| 1711 |
ifXTable_rowreq_ctx *rowreq_ctx = (ifXTable_rowreq_ctx*) |
| 1712 |
netsnmp_container_table_row_extract(requests); |
| 1713 |
|
| 1714 |
DEBUGMSGTL(("internal:ifXTable:_mfd_ifXTable_irreversible:commit", |
| 1715 |
"called\n")); |
| 1716 |
|
| 1717 |
netsnmp_assert(NULL != rowreq_ctx); |
| 1718 |
|
| 1719 |
/* |
| 1720 |
* check for and handle row creation/deletion |
| 1721 |
* and update column exist flags... |
| 1722 |
*/ |
| 1723 |
if (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED) { |
| 1724 |
CONTAINER_REMOVE(ifXTable_if_ctx.container, rowreq_ctx); |
| 1725 |
} else { |
| 1726 |
if (rowreq_ctx->column_set_flags) { |
| 1727 |
rowreq_ctx->column_set_flags = 0; |
| 1728 |
} |
| 1729 |
} |
| 1730 |
|
| 1731 |
return SNMP_ERR_NOERROR; |
| 1732 |
} /* _mfd_ifXTable_irreversible_commit */ |
| 1733 |
|
| 1734 |
#endif /* NETSNMP_NO_WRITE_SUPPORT || NETSNMP_DISABLE_SET_SUPPORT */ |
| 1735 |
|
| 1736 |
/*********************************************************************** |
| 1737 |
* |
| 1738 |
* DATA ACCESS |
| 1739 |
* |
| 1740 |
***********************************************************************/ |
| 1741 |
/** |
| 1742 |
* @internal |
| 1743 |
* initialize the container with functions or wrappers |
| 1744 |
*/ |
| 1745 |
void |
| 1746 |
_ifXTable_container_init(ifXTable_interface_ctx * if_ctx) |
| 1747 |
{ |
| 1748 |
DEBUGMSGTL(("internal:ifXTable:_ifXTable_container_init", "called\n")); |
| 1749 |
|
| 1750 |
/* |
| 1751 |
* cache init |
| 1752 |
* |
| 1753 |
* special case: sharing a cache |
| 1754 |
*/ |
| 1755 |
if_ctx->cache = |
| 1756 |
netsnmp_cache_find_by_oid(ifTable_oid, ifTable_oid_size); |
| 1757 |
if (NULL != if_ctx->cache) { |
| 1758 |
if_ctx->container = (netsnmp_container *) if_ctx->cache->magic; |
| 1759 |
return; |
| 1760 |
} else { |
| 1761 |
snmp_log(LOG_ERR, "error finding ifTable cache\n"); |
| 1762 |
} |
| 1763 |
} |
| 1764 |
|
| 1765 |
/* |
| 1766 |
* allow direct access to container. |
| 1767 |
*/ |
| 1768 |
netsnmp_container * |
| 1769 |
_ifXTable_container_get(void) |
| 1770 |
{ |
| 1771 |
return ifXTable_if_ctx.container; |
| 1772 |
} |
| 1773 |
|
| 1774 |
/** |
| 1775 |
* @internal |
| 1776 |
* shutdown the container with functions or wrappers |
| 1777 |
*/ |
| 1778 |
void |
| 1779 |
_ifXTable_container_shutdown(ifXTable_interface_ctx * if_ctx) |
| 1780 |
{ |
| 1781 |
DEBUGMSGTL(("internal:ifXTable:_ifXTable_container_shutdown", |
| 1782 |
"called\n")); |
| 1783 |
|
| 1784 |
/* |
| 1785 |
* ifTable does this for us |
| 1786 |
*/ |
| 1787 |
} /* _ifXTable_container_shutdown */ |
| 1788 |
|
| 1789 |
/*********************************************************************** |
| 1790 |
* |
| 1791 |
* PERSISTENCE |
| 1792 |
* |
| 1793 |
***********************************************************************/ |
| 1794 |
|
| 1795 |
static int _ifXTable_container_save_rows(int majorID, int minorID, |
| 1796 |
void *serverarg, |
| 1797 |
void *clientarg); |
| 1798 |
static void _ifXTable_container_row_restore(const char *token, |
| 1799 |
char *buf); |
| 1800 |
static void _ifXTable_container_row_save(void *data, void *type); |
| 1801 |
static char *_ifXTable_container_col_restore(ifXTable_rowreq_ctx * |
| 1802 |
rowreq_ctx, u_int col, |
| 1803 |
char *buf); |
| 1804 |
static char *_ifXTable_container_col_save(ifXTable_rowreq_ctx * |
| 1805 |
rowreq_ctx, u_int col, |
| 1806 |
char *buf); |
| 1807 |
|
| 1808 |
static const char row_token[] = "ifXTable"; |
| 1809 |
|
| 1810 |
/************************************************************ |
| 1811 |
* *_init_persistence should be called from the main table |
| 1812 |
* init routine. |
| 1813 |
* |
| 1814 |
* If your table depends on rows in another table, |
| 1815 |
* you should register your callback after the other table, |
| 1816 |
* which should ensure the rows on which you depend are saved |
| 1817 |
* (and re-created) before the dependent rows. |
| 1818 |
*/ |
| 1819 |
void |
| 1820 |
ifXTable_container_init_persistence(netsnmp_container *container) |
| 1821 |
{ |
| 1822 |
netsnmp_container **container_p; |
| 1823 |
int rc; |
| 1824 |
|
| 1825 |
register_config_handler(NULL, row_token, |
| 1826 |
_ifXTable_container_row_restore, NULL, NULL); |
| 1827 |
netsnmp_assert(container); |
| 1828 |
container_p = netsnmp_memdup(&container, sizeof(container)); |
| 1829 |
netsnmp_assert(container_p); |
| 1830 |
rc = snmp_register_callback(SNMP_CALLBACK_LIBRARY, |
| 1831 |
SNMP_CALLBACK_STORE_DATA, |
| 1832 |
_ifXTable_container_save_rows, container_p); |
| 1833 |
|
| 1834 |
if (rc != SNMP_ERR_NOERROR) |
| 1835 |
snmp_log(LOG_ERR, "error registering for STORE_DATA callback " |
| 1836 |
"in _ifXTable_container_init_persistence\n"); |
| 1837 |
} |
| 1838 |
|
| 1839 |
static int |
| 1840 |
_ifXTable_container_save_rows(int majorID, int minorID, void *serverarg, |
| 1841 |
void *clientarg) |
| 1842 |
{ |
| 1843 |
char sep[] = |
| 1844 |
"##############################################################"; |
| 1845 |
char buf[] = "#\n" "# ifXTable persistent data\n" "#"; |
| 1846 |
char *type = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, |
| 1847 |
NETSNMP_DS_LIB_APPTYPE); |
| 1848 |
|
| 1849 |
read_config_store((char *) type, sep); |
| 1850 |
read_config_store((char *) type, buf); |
| 1851 |
|
| 1852 |
/* |
| 1853 |
* save all rows |
| 1854 |
*/ |
| 1855 |
CONTAINER_FOR_EACH(*(netsnmp_container **)clientarg, |
| 1856 |
_ifXTable_container_row_save, type); |
| 1857 |
|
| 1858 |
read_config_store((char *) type, sep); |
| 1859 |
read_config_store((char *) type, "\n"); |
| 1860 |
|
| 1861 |
/* |
| 1862 |
* never fails |
| 1863 |
*/ |
| 1864 |
return SNMPERR_SUCCESS; |
| 1865 |
} |
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
/************************************************************ |
| 1870 |
* _ifXTable_container_row_save |
| 1871 |
*/ |
| 1872 |
static void _ifXTable_container_row_save(void *data, void *type) |
| 1873 |
{ |
| 1874 |
ifXTable_rowreq_ctx *rowreq_ctx = data; |
| 1875 |
|
| 1876 |
/* |
| 1877 |
* Allocate space for a line with all data for a row. An |
| 1878 |
* attempt is made to come up with a default maximum size, but |
| 1879 |
* there is no guarantee it will be enough. It probably will be, |
| 1880 |
* unless you are dealing with large values or you have external |
| 1881 |
* indexes. |
| 1882 |
* |
| 1883 |
* 1) allocate space for each column. Comment out columns you don't |
| 1884 |
* intend to save. You may also need to add room for any non- |
| 1885 |
* column data you want to store. Remeber, data will be stored in |
| 1886 |
* ASCII form, so you need to allow for that. Here are some |
| 1887 |
* general guidelines: |
| 1888 |
* |
| 1889 |
* Object ID : 12 * len [ASCII len of max int + 1 for .] |
| 1890 |
* Octet String: (2 * len) + 2 [2 ASCII chars per byte + "0x"] |
| 1891 |
* Integers : 12 [ASCII len for smallest negative number] |
| 1892 |
* |
| 1893 |
* 2) You also need to allocate space for the row index. This will |
| 1894 |
* be stored as an OID, which means that Octet Strings need to |
| 1895 |
* be treated a little differently. Specifically, you will need |
| 1896 |
* (4 * len) + 4 [3 ASCII chars per byte + 1 for ., + 4 for len]. |
| 1897 |
* |
| 1898 |
* 3) Also, remember to add space for the identifier and separator |
| 1899 |
* characters (for example, each column is prefixed by the |
| 1900 |
* column number and a semicolon. To allow for the maximum |
| 1901 |
* column values, 12 bytes [11 for oid + 1 for ':'] per |
| 1902 |
* column are added). |
| 1903 |
*/ |
| 1904 |
/** xxx: add storage for external index(s)! */ |
| 1905 |
#define MAX_ROW_SIZE (sizeof(row_token) + 1 + \ |
| 1906 |
( 12 ) + /* ASN_INTEGER ifLinkUpDownTrapEnable */ \ |
| 1907 |
( 12 ) + /* ASN_INTEGER ifPromiscuousMode */ \ |
| 1908 |
( ( 2 * sizeof(rowreq_ctx->data.ifAlias) ) + 3 ) + /* ASN_OCTET_STR */ \ |
| 1909 |
( IFXTABLE_MAX_COL * 12 ) + /* column num prefix + : */ \ |
| 1910 |
2 /* LINE_TERM_CHAR + \n */ ) |
| 1911 |
|
| 1912 |
char buf[MAX_ROW_SIZE], *pos = buf, *max = |
| 1913 |
&buf[MAX_ROW_SIZE - 1]; |
| 1914 |
char *tmp; |
| 1915 |
int i; |
| 1916 |
|
| 1917 |
if (ifXTable_container_should_save(rowreq_ctx) == 0) { |
| 1918 |
return; |
| 1919 |
} |
| 1920 |
|
| 1921 |
/* |
| 1922 |
* build the line |
| 1923 |
*/ |
| 1924 |
pos += sprintf(pos, "%s ", row_token); |
| 1925 |
pos = read_config_save_objid(pos, rowreq_ctx->oid_idx.oids, |
| 1926 |
rowreq_ctx->oid_idx.len); |
| 1927 |
if (NULL == pos) { |
| 1928 |
snmp_log(LOG_ERR, "error saving ifXTable row " |
| 1929 |
"to persistent file\n"); |
| 1930 |
return; |
| 1931 |
} |
| 1932 |
*pos++ = ' '; |
| 1933 |
if (pos > max) { |
| 1934 |
snmp_log(LOG_ERR, "error saving ifXTable row " |
| 1935 |
"to persistent file (too long)\n"); |
| 1936 |
return; |
| 1937 |
} |
| 1938 |
|
| 1939 |
/* |
| 1940 |
* add each column |
| 1941 |
*/ |
| 1942 |
for (i = IFXTABLE_MIN_COL; i <= IFXTABLE_MAX_COL; ++i) { |
| 1943 |
|
| 1944 |
if ((0x1 << (i - 1)) & ~IFXTABLE_SETTABLE_COLS) |
| 1945 |
continue; |
| 1946 |
|
| 1947 |
tmp = pos; |
| 1948 |
pos = _ifXTable_container_col_save(rowreq_ctx, i, pos); |
| 1949 |
if (NULL == pos) |
| 1950 |
pos = tmp; |
| 1951 |
else |
| 1952 |
*pos++ = ' '; |
| 1953 |
if (pos > max) { |
| 1954 |
snmp_log(LOG_ERR, "error saving ifXTable row " |
| 1955 |
"to persistent file (too long)\n"); |
| 1956 |
return; |
| 1957 |
} |
| 1958 |
} |
| 1959 |
|
| 1960 |
/* |
| 1961 |
* if you have non-column data, add it here |
| 1962 |
*/ |
| 1963 |
|
| 1964 |
|
| 1965 |
/* |
| 1966 |
* store the line |
| 1967 |
*/ |
| 1968 |
pos += sprintf(pos, "%c", LINE_TERM_CHAR); |
| 1969 |
if (pos > max) { |
| 1970 |
snmp_log(LOG_ERR, "error saving ifXTable row " |
| 1971 |
"to persistent file (too long)\n"); |
| 1972 |
return; |
| 1973 |
} |
| 1974 |
read_config_store((char *) type, buf); |
| 1975 |
|
| 1976 |
DEBUGMSGTL(("internal:ifXTable:_ifXTable_container_row_save", |
| 1977 |
"saving line '%s'\n", buf)); |
| 1978 |
} |
| 1979 |
|
| 1980 |
static void |
| 1981 |
_ifXTable_container_row_restore(const char *token, char *buf) |
| 1982 |
{ |
| 1983 |
ifXTable_rowreq_ctx *rowreq_ctx; |
| 1984 |
netsnmp_container *container; |
| 1985 |
netsnmp_index index; |
| 1986 |
oid tmp_oid[MAX_ifTable_IDX_LEN]; |
| 1987 |
u_int col = 0, found = 0; |
| 1988 |
|
| 1989 |
|
| 1990 |
if (strncmp(token, row_token, sizeof(row_token)) != 0) { |
| 1991 |
snmp_log(LOG_ERR, |
| 1992 |
"unknown token in _ifXTable_container_row_restore\n"); |
| 1993 |
return; |
| 1994 |
} |
| 1995 |
|
| 1996 |
container = _ifXTable_container_get(); |
| 1997 |
if (NULL == container) { |
| 1998 |
snmp_log(LOG_ERR, "null container in _ifXTable_restore\n"); |
| 1999 |
return; |
| 2000 |
} |
| 2001 |
|
| 2002 |
DEBUGMSGTL(("internal:ifXTable:_ifXTable_container_row_restore", |
| 2003 |
"parsing line '%s'\n", buf)); |
| 2004 |
|
| 2005 |
/* |
| 2006 |
* pull out index and find row. (Since we populate the cache |
| 2007 |
* during startup, all rows should exist.) |
| 2008 |
*/ |
| 2009 |
index.oids = tmp_oid; |
| 2010 |
index.len = OID_LENGTH(tmp_oid); |
| 2011 |
buf = read_config_read_objid(buf, &index.oids, &index.len); |
| 2012 |
if (NULL == buf) { |
| 2013 |
snmp_log(LOG_ERR, "error reading row index in " |
| 2014 |
"_ifXTable_container_row_restore\n"); |
| 2015 |
return; |
| 2016 |
} |
| 2017 |
rowreq_ctx = (ifXTable_rowreq_ctx*)CONTAINER_FIND(container, &index); |
| 2018 |
if (NULL == rowreq_ctx) { |
| 2019 |
snmp_log(LOG_DEBUG, "error finding row index in " |
| 2020 |
"_ifXTable_container_row_restore\n"); |
| 2021 |
return; |
| 2022 |
} |
| 2023 |
|
| 2024 |
/* |
| 2025 |
* loop through and get each column |
| 2026 |
*/ |
| 2027 |
buf = skip_white(buf); |
| 2028 |
while ((NULL != buf) && isdigit(*buf & 0xFF)) { |
| 2029 |
/* |
| 2030 |
* extract column, skip ':' |
| 2031 |
*/ |
| 2032 |
col = (u_int) strtol(buf, &buf, 10); |
| 2033 |
if (NULL == buf) |
| 2034 |
break; |
| 2035 |
if (*buf != ':') { |
| 2036 |
buf = NULL; |
| 2037 |
break; |
| 2038 |
} |
| 2039 |
++buf; /* skip : */ |
| 2040 |
|
| 2041 |
/* |
| 2042 |
* parse value |
| 2043 |
*/ |
| 2044 |
DEBUGMSGTL(("_ifXTable_container_row_restore", |
| 2045 |
"parsing column %d\n", col)); |
| 2046 |
buf = _ifXTable_container_col_restore(rowreq_ctx, col, buf); |
| 2047 |
++found; |
| 2048 |
} |
| 2049 |
if (0 == found) { |
| 2050 |
snmp_log(LOG_ERR, "error parsing ifXTable row; no columns found\n"); |
| 2051 |
return; |
| 2052 |
} |
| 2053 |
|
| 2054 |
/* |
| 2055 |
* if you added any non-column data, this is where |
| 2056 |
* you should handle it. |
| 2057 |
*/ |
| 2058 |
|
| 2059 |
/* |
| 2060 |
* if the pointer is NULL and we didn't reach the |
| 2061 |
* end of the line, something went wrong. Log message, |
| 2062 |
* and bail. |
| 2063 |
*/ |
| 2064 |
if ((buf == NULL) || (*buf != LINE_TERM_CHAR)) { |
| 2065 |
snmp_log(LOG_ERR, "error parsing ifXTable row around column %d\n", |
| 2066 |
col); |
| 2067 |
return; |
| 2068 |
} |
| 2069 |
|
| 2070 |
DEBUGMSGTL(("internal:ifXTable:_ifXTable_container_row_restore", |
| 2071 |
"inserting row\n")); |
| 2072 |
} |
| 2073 |
|
| 2074 |
/************************************************************ |
| 2075 |
* _ifXTable_container_col_save |
| 2076 |
*/ |
| 2077 |
static char * |
| 2078 |
_ifXTable_container_col_save(ifXTable_rowreq_ctx * rowreq_ctx, |
| 2079 |
u_int col, char *buf) |
| 2080 |
{ |
| 2081 |
if ((NULL == rowreq_ctx) || (NULL == buf)) { |
| 2082 |
snmp_log(LOG_ERR, "bad parameter in " |
| 2083 |
"_ifXTable_container_col_save\n"); |
| 2084 |
return NULL; |
| 2085 |
} |
| 2086 |
|
| 2087 |
DEBUGMSGTL(("internal:ifXTable:_ifXTable_container_col_save", |
| 2088 |
"processing column %d\n", col)); |
| 2089 |
|
| 2090 |
/* |
| 2091 |
* prefix with column number, so we don't ever depend on |
| 2092 |
* order saved. |
| 2093 |
*/ |
| 2094 |
buf += sprintf(buf, "%u:", col); |
| 2095 |
|
| 2096 |
/* |
| 2097 |
* save data for the column |
| 2098 |
*/ |
| 2099 |
switch (col) { |
| 2100 |
|
| 2101 |
case COLUMN_IFLINKUPDOWNTRAPENABLE: /** INTEGER = ASN_INTEGER */ |
| 2102 |
buf += |
| 2103 |
sprintf(buf, "%ld", rowreq_ctx->data.ifLinkUpDownTrapEnable); |
| 2104 |
break; |
| 2105 |
|
| 2106 |
case COLUMN_IFALIAS: /** DisplayString = ASN_OCTET_STR */ |
| 2107 |
buf = read_config_save_octet_string(buf, |
| 2108 |
(u_char *) rowreq_ctx->data.ifAlias, |
| 2109 |
rowreq_ctx->data.ifAlias_len); |
| 2110 |
break; |
| 2111 |
|
| 2112 |
default: |
| 2113 |
/** We shouldn't get here */ |
| 2114 |
snmp_log(LOG_ERR, "unknown column %d in " |
| 2115 |
"_ifXTable_container_col_save\n", col); |
| 2116 |
return NULL; |
| 2117 |
} |
| 2118 |
|
| 2119 |
return buf; |
| 2120 |
} |
| 2121 |
|
| 2122 |
/************************************************************ |
| 2123 |
* _ifXTable_container_col_restore |
| 2124 |
*/ |
| 2125 |
static char * |
| 2126 |
_ifXTable_container_col_restore(ifXTable_rowreq_ctx * rowreq_ctx, |
| 2127 |
u_int col, char *buf) |
| 2128 |
{ |
| 2129 |
size_t len; |
| 2130 |
if ((NULL == rowreq_ctx) || (NULL == buf)) { |
| 2131 |
snmp_log(LOG_ERR, "bad parameter in " |
| 2132 |
"_ifXTable_container_col_restore\n"); |
| 2133 |
return NULL; |
| 2134 |
} |
| 2135 |
|
| 2136 |
DEBUGMSGTL(("verbose:ifXTable:_ifXTable_container_col_restore", |
| 2137 |
"processing column %d\n", col)); |
| 2138 |
|
| 2139 |
/* |
| 2140 |
* restore data for the column |
| 2141 |
*/ |
| 2142 |
switch (col) { |
| 2143 |
|
| 2144 |
case COLUMN_IFLINKUPDOWNTRAPENABLE: /** INTEGER = ASN_INTEGER */ |
| 2145 |
len = sizeof(rowreq_ctx->data.ifLinkUpDownTrapEnable); |
| 2146 |
buf = read_config_read_memory(ASN_INTEGER, buf, |
| 2147 |
(char *) &rowreq_ctx->data. |
| 2148 |
ifLinkUpDownTrapEnable, &len); |
| 2149 |
break; |
| 2150 |
|
| 2151 |
case COLUMN_IFALIAS: /** DisplayString = ASN_OCTET_STR */ |
| 2152 |
rowreq_ctx->data.ifAlias_len = sizeof(rowreq_ctx->data.ifAlias); |
| 2153 |
buf = read_config_read_memory(ASN_OCTET_STR, buf, |
| 2154 |
(char *) &rowreq_ctx->data.ifAlias, |
| 2155 |
(size_t *) & rowreq_ctx->data. |
| 2156 |
ifAlias_len); |
| 2157 |
break; |
| 2158 |
|
| 2159 |
default: |
| 2160 |
/** We shouldn't get here */ |
| 2161 |
snmp_log(LOG_ERR, "unknown column %d in " |
| 2162 |
"_ifXTable_container_col_restore\n", col); |
| 2163 |
return NULL; |
| 2164 |
} |
| 2165 |
|
| 2166 |
return buf; |
| 2167 |
} |
| 2168 |
|
| 2169 |
|
| 2170 |
#ifndef NETSNMP_FEATURE_REMOVE_IFXTABLE_EXTERNAL_ACCESS |
| 2171 |
ifXTable_rowreq_ctx * |
| 2172 |
ifXTable_row_find_by_mib_index(ifXTable_mib_index * mib_idx) |
| 2173 |
{ |
| 2174 |
ifXTable_rowreq_ctx *rowreq_ctx; |
| 2175 |
oid oid_tmp[MAX_OID_LEN]; |
| 2176 |
netsnmp_index oid_idx; |
| 2177 |
int rc; |
| 2178 |
|
| 2179 |
/* |
| 2180 |
* set up storage for OID |
| 2181 |
*/ |
| 2182 |
oid_idx.oids = oid_tmp; |
| 2183 |
oid_idx.len = sizeof(oid_tmp) / sizeof(oid); |
| 2184 |
|
| 2185 |
/* |
| 2186 |
* convert |
| 2187 |
*/ |
| 2188 |
rc = ifXTable_index_to_oid(&oid_idx, mib_idx); |
| 2189 |
if (MFD_SUCCESS != rc) |
| 2190 |
return NULL; |
| 2191 |
|
| 2192 |
rowreq_ctx = (ifXTable_rowreq_ctx*)CONTAINER_FIND(ifXTable_if_ctx.container, &oid_idx); |
| 2193 |
|
| 2194 |
return rowreq_ctx; |
| 2195 |
} |
| 2196 |
#endif /* NETSNMP_FEATURE_REMOVE_IFXTABLE_EXTERNAL_ACCESS */ |