| 1 |
/* |
| 2 |
* AgentX Administrative request handling |
| 3 |
*/ |
| 4 |
#include <net-snmp/net-snmp-config.h> |
| 5 |
#include <net-snmp/net-snmp-features.h> |
| 6 |
|
| 7 |
#include <sys/types.h> |
| 8 |
#ifdef HAVE_STRING_H |
| 9 |
#include <string.h> |
| 10 |
#else |
| 11 |
#include <strings.h> |
| 12 |
#endif |
| 13 |
#ifdef HAVE_STDLIB_H |
| 14 |
#include <stdlib.h> |
| 15 |
#endif |
| 16 |
#ifdef TIME_WITH_SYS_TIME |
| 17 |
# include <sys/time.h> |
| 18 |
# include <time.h> |
| 19 |
#else |
| 20 |
# ifdef HAVE_SYS_TIME_H |
| 21 |
# include <sys/time.h> |
| 22 |
# else |
| 23 |
# include <time.h> |
| 24 |
# endif |
| 25 |
#endif |
| 26 |
#ifdef HAVE_NETINET_IN_H |
| 27 |
#include <netinet/in.h> |
| 28 |
#endif |
| 29 |
#ifdef HAVE_SYS_SOCKET_H |
| 30 |
#include <sys/socket.h> |
| 31 |
#endif |
| 32 |
|
| 33 |
#include <net-snmp/net-snmp-includes.h> |
| 34 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 35 |
#include "agent_global_vars.h" |
| 36 |
|
| 37 |
#include "agentx/protocol.h" |
| 38 |
#include "agentx/client.h" |
| 39 |
#include "agentx/subagent.h" |
| 40 |
#include "agentx/master_admin.h" |
| 41 |
|
| 42 |
#include <net-snmp/agent/agent_index.h> |
| 43 |
#include <net-snmp/agent/agent_trap.h> |
| 44 |
#include <net-snmp/agent/agent_callbacks.h> |
| 45 |
#include <net-snmp/agent/agent_sysORTable.h> |
| 46 |
#include "master.h" |
| 47 |
|
| 48 |
netsnmp_feature_require(unregister_mib_table_row); |
| 49 |
netsnmp_feature_require(trap_vars_with_context); |
| 50 |
netsnmp_feature_require(calculate_sectime_diff); |
| 51 |
netsnmp_feature_require(allocate_globalcacheid); |
| 52 |
netsnmp_feature_require(remove_index); |
| 53 |
|
| 54 |
netsnmp_session * |
| 55 |
find_agentx_session(netsnmp_session * session, int sessid) |
| 56 |
{ |
| 57 |
netsnmp_session *sp; |
| 58 |
for (sp = session->subsession; sp != NULL; sp = sp->next) { |
| 59 |
if (sp->sessid == sessid) |
| 60 |
return sp; |
| 61 |
} |
| 62 |
return NULL; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
int |
| 67 |
open_agentx_session(netsnmp_session * session, netsnmp_pdu *pdu) |
| 68 |
{ |
| 69 |
netsnmp_session *sp; |
| 70 |
|
| 71 |
DEBUGMSGTL(("agentx/master", "open %8p\n", session)); |
| 72 |
sp = (netsnmp_session *) malloc(sizeof(netsnmp_session)); |
| 73 |
if (sp == NULL) { |
| 74 |
session->s_snmp_errno = AGENTX_ERR_OPEN_FAILED; |
| 75 |
return -1; |
| 76 |
} |
| 77 |
|
| 78 |
memcpy(sp, session, sizeof(netsnmp_session)); |
| 79 |
sp->sessid = snmp_get_next_sessid(); |
| 80 |
sp->version = pdu->version; |
| 81 |
sp->timeout = pdu->time; |
| 82 |
|
| 83 |
/* |
| 84 |
* Be careful with fields: if these aren't zeroed, they will get free()d |
| 85 |
* more than once when the session is closed -- once in the main session, |
| 86 |
* and once in each subsession. Basically, if it's not being used for |
| 87 |
* some AgentX-specific purpose, it ought to be zeroed here. |
| 88 |
*/ |
| 89 |
|
| 90 |
sp->community = NULL; |
| 91 |
sp->peername = NULL; |
| 92 |
sp->contextEngineID = NULL; |
| 93 |
sp->contextName = NULL; |
| 94 |
sp->securityEngineID = NULL; |
| 95 |
sp->securityPrivProto = NULL; |
| 96 |
sp->sessUser = NULL; |
| 97 |
|
| 98 |
/* |
| 99 |
* This next bit utilises unused SNMPv3 fields |
| 100 |
* to store the subagent OID and description. |
| 101 |
* This really ought to use AgentX-specific fields, |
| 102 |
* but it hardly seems worth it for a one-off use. |
| 103 |
* |
| 104 |
* But I'm willing to be persuaded otherwise.... */ |
| 105 |
sp->securityAuthProto = snmp_duplicate_objid(pdu->variables->name, |
| 106 |
pdu->variables-> |
| 107 |
name_length); |
| 108 |
sp->securityAuthProtoLen = pdu->variables->name_length; |
| 109 |
sp->securityName = strdup((char *) pdu->variables->val.string); |
| 110 |
sp->engineTime = (uint32_t)((netsnmp_get_agent_runtime() + 50) / 100) & 0x7fffffffL; |
| 111 |
|
| 112 |
sp->subsession = session; /* link back to head */ |
| 113 |
sp->flags |= SNMP_FLAGS_SUBSESSION; |
| 114 |
sp->flags &= ~AGENTX_MSG_FLAG_NETWORK_BYTE_ORDER; |
| 115 |
sp->flags |= (pdu->flags & AGENTX_MSG_FLAG_NETWORK_BYTE_ORDER); |
| 116 |
sp->next = session->subsession; |
| 117 |
session->subsession = sp; |
| 118 |
DEBUGMSGTL(("agentx/master", "opened %8p = %ld with flags = %02lx\n", |
| 119 |
sp, sp->sessid, sp->flags & AGENTX_MSG_FLAGS_MASK)); |
| 120 |
|
| 121 |
return sp->sessid; |
| 122 |
} |
| 123 |
|
| 124 |
int |
| 125 |
close_agentx_session(netsnmp_session * session, int sessid) |
| 126 |
{ |
| 127 |
netsnmp_session *sp, **prevNext; |
| 128 |
|
| 129 |
if (!session) |
| 130 |
return AGENTX_ERR_NOT_OPEN; |
| 131 |
|
| 132 |
DEBUGMSGTL(("agentx/master", "close %8p, %d\n", session, sessid)); |
| 133 |
if (sessid == -1) { |
| 134 |
/* |
| 135 |
* The following is necessary to avoid locking up the agent when |
| 136 |
* a sugagent dies during a set request. We must clean up the |
| 137 |
* requests, so that the delegated request will be completed and |
| 138 |
* further requests can be processed |
| 139 |
*/ |
| 140 |
while (netsnmp_remove_delegated_requests_for_session(session)) { |
| 141 |
DEBUGMSGTL(("agentx/master", "Continue removing delegated reqests\n")); |
| 142 |
} |
| 143 |
|
| 144 |
if (session->subsession != NULL) { |
| 145 |
netsnmp_session *subsession = session->subsession; |
| 146 |
for(; subsession; subsession = subsession->next) { |
| 147 |
while (netsnmp_remove_delegated_requests_for_session(subsession)) { |
| 148 |
DEBUGMSGTL(("agentx/master", "Continue removing delegated subsession reqests\n")); |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
unregister_mibs_by_session(session); |
| 154 |
unregister_index_by_session(session); |
| 155 |
unregister_sysORTable_by_session(session); |
| 156 |
SNMP_FREE(session->myvoid); |
| 157 |
return AGENTX_ERR_NOERROR; |
| 158 |
} |
| 159 |
|
| 160 |
prevNext = &(session->subsession); |
| 161 |
|
| 162 |
for (sp = session->subsession; sp != NULL; sp = sp->next) { |
| 163 |
|
| 164 |
if (sp->sessid == sessid) { |
| 165 |
netsnmp_remove_delegated_requests_for_session(sp); |
| 166 |
unregister_mibs_by_session(sp); |
| 167 |
unregister_index_by_session(sp); |
| 168 |
unregister_sysORTable_by_session(sp); |
| 169 |
|
| 170 |
*prevNext = sp->next; |
| 171 |
|
| 172 |
if (sp->securityAuthProto != NULL) { |
| 173 |
free(sp->securityAuthProto); |
| 174 |
} |
| 175 |
if (sp->securityName != NULL) { |
| 176 |
free(sp->securityName); |
| 177 |
} |
| 178 |
free(sp); |
| 179 |
sp = NULL; |
| 180 |
|
| 181 |
DEBUGMSGTL(("agentx/master", "closed %8p, %d okay\n", |
| 182 |
session, sessid)); |
| 183 |
return AGENTX_ERR_NOERROR; |
| 184 |
} |
| 185 |
|
| 186 |
prevNext = &(sp->next); |
| 187 |
} |
| 188 |
|
| 189 |
DEBUGMSGTL(("agentx/master", "sessid %d not found\n", sessid)); |
| 190 |
return AGENTX_ERR_NOT_OPEN; |
| 191 |
} |
| 192 |
|
| 193 |
int |
| 194 |
register_agentx_list(netsnmp_session * session, netsnmp_pdu *pdu) |
| 195 |
{ |
| 196 |
netsnmp_session *sp; |
| 197 |
char buf[128]; |
| 198 |
oid ubound = 0; |
| 199 |
u_long flags = 0; |
| 200 |
netsnmp_handler_registration *reg; |
| 201 |
int rc = 0; |
| 202 |
int cacheid; |
| 203 |
|
| 204 |
DEBUGMSGTL(("agentx/master", "in register_agentx_list\n")); |
| 205 |
|
| 206 |
sp = find_agentx_session(session, pdu->sessid); |
| 207 |
if (sp == NULL) |
| 208 |
return AGENTX_ERR_NOT_OPEN; |
| 209 |
|
| 210 |
sprintf(buf, "AgentX subagent %ld, session %8p, subsession %8p", |
| 211 |
sp->sessid, session, sp); |
| 212 |
/* |
| 213 |
* * TODO: registration timeout |
| 214 |
* * registration context |
| 215 |
*/ |
| 216 |
if (pdu->range_subid) { |
| 217 |
ubound = pdu->variables->val.objid[pdu->range_subid - 1]; |
| 218 |
} |
| 219 |
|
| 220 |
if (pdu->flags & AGENTX_MSG_FLAG_INSTANCE_REGISTER) { |
| 221 |
flags = FULLY_QUALIFIED_INSTANCE; |
| 222 |
} |
| 223 |
|
| 224 |
reg = netsnmp_create_handler_registration(buf, agentx_master_handler, pdu->variables->name, pdu->variables->name_length, HANDLER_CAN_RWRITE | HANDLER_CAN_GETBULK); /* fake it */ |
| 225 |
if (!session->myvoid) { |
| 226 |
session->myvoid = malloc(sizeof(cacheid)); |
| 227 |
cacheid = netsnmp_allocate_globalcacheid(); |
| 228 |
*((int *) session->myvoid) = cacheid; |
| 229 |
} else { |
| 230 |
cacheid = *((int *) session->myvoid); |
| 231 |
} |
| 232 |
|
| 233 |
reg->handler->myvoid = session; |
| 234 |
reg->global_cacheid = cacheid; |
| 235 |
if (NULL != pdu->community) |
| 236 |
reg->contextName = strdup((char *)pdu->community); |
| 237 |
|
| 238 |
/* |
| 239 |
* register mib. Note that for failure cases, the registration info |
| 240 |
* (reg) will be freed, and thus is no longer a valid pointer. |
| 241 |
*/ |
| 242 |
switch (netsnmp_register_mib(buf, NULL, 0, 0, |
| 243 |
pdu->variables->name, |
| 244 |
pdu->variables->name_length, |
| 245 |
pdu->priority, pdu->range_subid, ubound, |
| 246 |
sp, (char *) pdu->community, pdu->time, |
| 247 |
flags, reg, 1)) { |
| 248 |
|
| 249 |
case MIB_REGISTERED_OK: |
| 250 |
DEBUGMSGTL(("agentx/master", "registered ok\n")); |
| 251 |
return AGENTX_ERR_NOERROR; |
| 252 |
|
| 253 |
case MIB_DUPLICATE_REGISTRATION: |
| 254 |
DEBUGMSGTL(("agentx/master", "duplicate registration\n")); |
| 255 |
rc = AGENTX_ERR_DUPLICATE_REGISTRATION; |
| 256 |
break; |
| 257 |
|
| 258 |
case MIB_REGISTRATION_FAILED: |
| 259 |
default: |
| 260 |
rc = AGENTX_ERR_REQUEST_DENIED; |
| 261 |
DEBUGMSGTL(("agentx/master", "failed registration\n")); |
| 262 |
} |
| 263 |
return rc; |
| 264 |
} |
| 265 |
|
| 266 |
int |
| 267 |
unregister_agentx_list(netsnmp_session * session, netsnmp_pdu *pdu) |
| 268 |
{ |
| 269 |
netsnmp_session *sp; |
| 270 |
int rc = 0; |
| 271 |
|
| 272 |
sp = find_agentx_session(session, pdu->sessid); |
| 273 |
if (sp == NULL) { |
| 274 |
return AGENTX_ERR_NOT_OPEN; |
| 275 |
} |
| 276 |
|
| 277 |
if (pdu->range_subid != 0) { |
| 278 |
oid ubound = |
| 279 |
pdu->variables->val.objid[pdu->range_subid - 1]; |
| 280 |
rc = netsnmp_unregister_mib_table_row(pdu->variables->name, |
| 281 |
pdu->variables->name_length, |
| 282 |
pdu->priority, |
| 283 |
pdu->range_subid, ubound, |
| 284 |
(char *) pdu->community); |
| 285 |
} else { |
| 286 |
rc = unregister_mib_context(pdu->variables->name, |
| 287 |
pdu->variables->name_length, |
| 288 |
pdu->priority, 0, 0, |
| 289 |
(char *) pdu->community); |
| 290 |
} |
| 291 |
|
| 292 |
switch (rc) { |
| 293 |
case MIB_UNREGISTERED_OK: |
| 294 |
return AGENTX_ERR_NOERROR; |
| 295 |
case MIB_NO_SUCH_REGISTRATION: |
| 296 |
return AGENTX_ERR_UNKNOWN_REGISTRATION; |
| 297 |
case MIB_UNREGISTRATION_FAILED: |
| 298 |
default: |
| 299 |
return AGENTX_ERR_REQUEST_DENIED; |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
int |
| 304 |
allocate_idx_list(netsnmp_session * session, netsnmp_pdu *pdu) |
| 305 |
{ |
| 306 |
netsnmp_session *sp; |
| 307 |
netsnmp_variable_list *vp, *vp2, *next, *res; |
| 308 |
int flags = 0; |
| 309 |
|
| 310 |
sp = find_agentx_session(session, pdu->sessid); |
| 311 |
if (sp == NULL) |
| 312 |
return AGENTX_ERR_NOT_OPEN; |
| 313 |
|
| 314 |
if (pdu->flags & AGENTX_MSG_FLAG_ANY_INSTANCE) |
| 315 |
flags |= ALLOCATE_ANY_INDEX; |
| 316 |
if (pdu->flags & AGENTX_MSG_FLAG_NEW_INSTANCE) |
| 317 |
flags |= ALLOCATE_NEW_INDEX; |
| 318 |
|
| 319 |
/* |
| 320 |
* XXX - what about errors? |
| 321 |
* |
| 322 |
* If any allocations fail, then we need to |
| 323 |
* *fully* release the earlier ones. |
| 324 |
* (i.e. remove them completely from the index registry, |
| 325 |
* not simply mark them as available for re-use) |
| 326 |
* |
| 327 |
* For now - assume they all succeed. |
| 328 |
*/ |
| 329 |
for (vp = pdu->variables; vp != NULL; vp = next) { |
| 330 |
next = vp->next_variable; |
| 331 |
res = register_index(vp, flags, session); |
| 332 |
if (res == NULL) { |
| 333 |
/* |
| 334 |
* If any allocations fail, we need to *fully* release |
| 335 |
* all previous ones (i.e. remove them completely |
| 336 |
* from the index registry) |
| 337 |
*/ |
| 338 |
for (vp2 = pdu->variables; vp2 != vp; vp2 = vp2->next_variable) { |
| 339 |
remove_index(vp2, session); |
| 340 |
} |
| 341 |
return AGENTX_ERR_INDEX_NONE_AVAILABLE; /* XXX */ |
| 342 |
} else { |
| 343 |
(void) snmp_clone_var(res, vp); |
| 344 |
free(res); |
| 345 |
} |
| 346 |
vp->next_variable = next; |
| 347 |
} |
| 348 |
return AGENTX_ERR_NOERROR; |
| 349 |
} |
| 350 |
|
| 351 |
int |
| 352 |
release_idx_list(netsnmp_session * session, netsnmp_pdu *pdu) |
| 353 |
{ |
| 354 |
netsnmp_session *sp; |
| 355 |
netsnmp_variable_list *vp, *vp2, *rv = NULL; |
| 356 |
int res; |
| 357 |
|
| 358 |
sp = find_agentx_session(session, pdu->sessid); |
| 359 |
if (sp == NULL) |
| 360 |
return AGENTX_ERR_NOT_OPEN; |
| 361 |
|
| 362 |
for (vp = pdu->variables; vp != NULL; vp = vp->next_variable) { |
| 363 |
res = unregister_index(vp, TRUE, session); |
| 364 |
/* |
| 365 |
* If any releases fail, |
| 366 |
* we need to reinstate all previous ones. |
| 367 |
*/ |
| 368 |
if (res != SNMP_ERR_NOERROR) { |
| 369 |
for (vp2 = pdu->variables; vp2 != vp; vp2 = vp2->next_variable) { |
| 370 |
rv = register_index(vp2, ALLOCATE_THIS_INDEX, session); |
| 371 |
free(rv); |
| 372 |
} |
| 373 |
return AGENTX_ERR_INDEX_NOT_ALLOCATED; /* Probably */ |
| 374 |
} |
| 375 |
} |
| 376 |
return AGENTX_ERR_NOERROR; |
| 377 |
} |
| 378 |
|
| 379 |
int |
| 380 |
add_agent_caps_list(netsnmp_session * session, netsnmp_pdu *pdu) |
| 381 |
{ |
| 382 |
netsnmp_session *sp; |
| 383 |
char* description; |
| 384 |
|
| 385 |
sp = find_agentx_session(session, pdu->sessid); |
| 386 |
if (sp == NULL) |
| 387 |
return AGENTX_ERR_NOT_OPEN; |
| 388 |
|
| 389 |
description = netsnmp_strdup_and_null(pdu->variables->val.string, |
| 390 |
pdu->variables->val_len); |
| 391 |
register_sysORTable_sess(pdu->variables->name, pdu->variables->name_length, |
| 392 |
description, sp); |
| 393 |
free(description); |
| 394 |
return AGENTX_ERR_NOERROR; |
| 395 |
} |
| 396 |
|
| 397 |
int |
| 398 |
remove_agent_caps_list(netsnmp_session * session, netsnmp_pdu *pdu) |
| 399 |
{ |
| 400 |
netsnmp_session *sp; |
| 401 |
int rc; |
| 402 |
|
| 403 |
sp = find_agentx_session(session, pdu->sessid); |
| 404 |
if (sp == NULL) |
| 405 |
return AGENTX_ERR_NOT_OPEN; |
| 406 |
|
| 407 |
rc = unregister_sysORTable_sess(pdu->variables->name, |
| 408 |
pdu->variables->name_length, sp); |
| 409 |
|
| 410 |
if (rc < 0) |
| 411 |
return AGENTX_ERR_UNKNOWN_AGENTCAPS; |
| 412 |
|
| 413 |
return AGENTX_ERR_NOERROR; |
| 414 |
} |
| 415 |
|
| 416 |
int |
| 417 |
agentx_notify(netsnmp_session * session, netsnmp_pdu *pdu) |
| 418 |
{ |
| 419 |
netsnmp_session *sp; |
| 420 |
netsnmp_variable_list *var; |
| 421 |
|
| 422 |
sp = find_agentx_session(session, pdu->sessid); |
| 423 |
if (sp == NULL) |
| 424 |
return AGENTX_ERR_NOT_OPEN; |
| 425 |
|
| 426 |
var = pdu->variables; |
| 427 |
if (!var) |
| 428 |
return AGENTX_ERR_PROCESSING_ERROR; |
| 429 |
|
| 430 |
if (snmp_oid_compare(var->name, var->name_length, |
| 431 |
sysuptime_oid, sysuptime_oid_len) == 0) { |
| 432 |
var = var->next_variable; |
| 433 |
} |
| 434 |
|
| 435 |
if (!var || snmp_oid_compare(var->name, var->name_length, |
| 436 |
snmptrap_oid, snmptrap_oid_len) != 0) |
| 437 |
return AGENTX_ERR_PROCESSING_ERROR; |
| 438 |
|
| 439 |
/* |
| 440 |
* If sysUptime isn't the first varbind, don't worry. |
| 441 |
* send_trap_vars() will add it if necessary. |
| 442 |
* |
| 443 |
* Note that if this behaviour is altered, it will |
| 444 |
* be necessary to add sysUptime here, |
| 445 |
* as this is valid AgentX syntax. |
| 446 |
*/ |
| 447 |
|
| 448 |
/* If a context name was specified, send the trap using that context. |
| 449 |
* Otherwise, send the trap without the context using the old method */ |
| 450 |
if (pdu->contextName != NULL) |
| 451 |
send_trap_vars_with_context(-1, -1, pdu->variables, pdu->contextName); |
| 452 |
else |
| 453 |
send_trap_vars(-1, -1, pdu->variables); |
| 454 |
|
| 455 |
return AGENTX_ERR_NOERROR; |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
int |
| 460 |
agentx_ping_response(netsnmp_session * session, netsnmp_pdu *pdu) |
| 461 |
{ |
| 462 |
netsnmp_session *sp; |
| 463 |
|
| 464 |
sp = find_agentx_session(session, pdu->sessid); |
| 465 |
if (sp == NULL) |
| 466 |
return AGENTX_ERR_NOT_OPEN; |
| 467 |
else |
| 468 |
return AGENTX_ERR_NOERROR; |
| 469 |
} |
| 470 |
|
| 471 |
int |
| 472 |
handle_master_agentx_packet(int operation, |
| 473 |
netsnmp_session * session, |
| 474 |
int reqid, netsnmp_pdu *pdu, void *magic) |
| 475 |
{ |
| 476 |
netsnmp_agent_session *asp; |
| 477 |
|
| 478 |
if (operation == NETSNMP_CALLBACK_OP_DISCONNECT) { |
| 479 |
DEBUGMSGTL(("agentx/master", |
| 480 |
"transport disconnect on session %8p\n", session)); |
| 481 |
/* |
| 482 |
* Shut this session down gracefully. |
| 483 |
*/ |
| 484 |
close_agentx_session(session, -1); |
| 485 |
return 1; |
| 486 |
} else if (operation == NETSNMP_CALLBACK_OP_CONNECT) { |
| 487 |
DEBUGMSGTL(("agentx/master", |
| 488 |
"transport connect on session %8p\n", session)); |
| 489 |
return 1; |
| 490 |
} else if (operation != NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE) { |
| 491 |
DEBUGMSGTL(("agentx/master", "unexpected callback op %d\n", |
| 492 |
operation)); |
| 493 |
return 1; |
| 494 |
} |
| 495 |
|
| 496 |
/* |
| 497 |
* Okay, it's a NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE op. |
| 498 |
*/ |
| 499 |
|
| 500 |
if (magic) { |
| 501 |
asp = (netsnmp_agent_session *) magic; |
| 502 |
} else { |
| 503 |
asp = init_agent_snmp_session(session, pdu); |
| 504 |
if (asp == NULL) { |
| 505 |
return 1; |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
DEBUGMSGTL(("agentx/master", "handle pdu (req=0x%lx,trans=0x%lx,sess=0x%lx)\n", |
| 510 |
(unsigned long)pdu->reqid, (unsigned long)pdu->transid, |
| 511 |
(unsigned long)pdu->sessid)); |
| 512 |
|
| 513 |
switch (pdu->command) { |
| 514 |
case AGENTX_MSG_OPEN: |
| 515 |
asp->pdu->sessid = open_agentx_session(session, pdu); |
| 516 |
if (asp->pdu->sessid == -1) |
| 517 |
asp->status = session->s_snmp_errno; |
| 518 |
break; |
| 519 |
|
| 520 |
case AGENTX_MSG_CLOSE: |
| 521 |
asp->status = close_agentx_session(session, pdu->sessid); |
| 522 |
break; |
| 523 |
|
| 524 |
case AGENTX_MSG_REGISTER: |
| 525 |
asp->status = register_agentx_list(session, pdu); |
| 526 |
break; |
| 527 |
|
| 528 |
case AGENTX_MSG_UNREGISTER: |
| 529 |
asp->status = unregister_agentx_list(session, pdu); |
| 530 |
break; |
| 531 |
|
| 532 |
case AGENTX_MSG_INDEX_ALLOCATE: |
| 533 |
asp->status = allocate_idx_list(session, asp->pdu); |
| 534 |
if (asp->status != AGENTX_ERR_NOERROR) { |
| 535 |
snmp_free_pdu(asp->pdu); |
| 536 |
asp->pdu = snmp_clone_pdu(pdu); |
| 537 |
} |
| 538 |
break; |
| 539 |
|
| 540 |
case AGENTX_MSG_INDEX_DEALLOCATE: |
| 541 |
asp->status = release_idx_list(session, pdu); |
| 542 |
break; |
| 543 |
|
| 544 |
case AGENTX_MSG_ADD_AGENT_CAPS: |
| 545 |
asp->status = add_agent_caps_list(session, pdu); |
| 546 |
break; |
| 547 |
|
| 548 |
case AGENTX_MSG_REMOVE_AGENT_CAPS: |
| 549 |
asp->status = remove_agent_caps_list(session, pdu); |
| 550 |
break; |
| 551 |
|
| 552 |
case AGENTX_MSG_NOTIFY: |
| 553 |
asp->status = agentx_notify(session, pdu); |
| 554 |
break; |
| 555 |
|
| 556 |
case AGENTX_MSG_PING: |
| 557 |
asp->status = agentx_ping_response(session, pdu); |
| 558 |
break; |
| 559 |
|
| 560 |
/* |
| 561 |
* TODO: Other admin packets |
| 562 |
*/ |
| 563 |
|
| 564 |
case AGENTX_MSG_GET: |
| 565 |
case AGENTX_MSG_GETNEXT: |
| 566 |
case AGENTX_MSG_GETBULK: |
| 567 |
case AGENTX_MSG_TESTSET: |
| 568 |
case AGENTX_MSG_COMMITSET: |
| 569 |
case AGENTX_MSG_UNDOSET: |
| 570 |
case AGENTX_MSG_CLEANUPSET: |
| 571 |
case AGENTX_MSG_RESPONSE: |
| 572 |
/* |
| 573 |
* Shouldn't be handled here |
| 574 |
*/ |
| 575 |
break; |
| 576 |
|
| 577 |
default: |
| 578 |
asp->status = AGENTX_ERR_PARSE_FAILED; |
| 579 |
break; |
| 580 |
} |
| 581 |
|
| 582 |
asp->pdu->time = netsnmp_get_agent_uptime(); |
| 583 |
asp->pdu->command = AGENTX_MSG_RESPONSE; |
| 584 |
asp->pdu->errstat = asp->status; |
| 585 |
DEBUGMSGTL(("agentx/master", "send response, stat %d (req=0x%lx,trans=" |
| 586 |
"0x%lx,sess=0x%lx)\n", |
| 587 |
asp->status, (unsigned long)pdu->reqid, |
| 588 |
(unsigned long)pdu->transid, (unsigned long)pdu->sessid)); |
| 589 |
if (!snmp_send(asp->session, asp->pdu)) { |
| 590 |
char *eb = NULL; |
| 591 |
int pe, pse; |
| 592 |
snmp_error(asp->session, &pe, &pse, &eb); |
| 593 |
snmp_free_pdu(asp->pdu); |
| 594 |
DEBUGMSGTL(("agentx/master", "FAILED %d %d %s\n", pe, pse, eb)); |
| 595 |
free(eb); |
| 596 |
} |
| 597 |
asp->pdu = NULL; |
| 598 |
free_agent_snmp_session(asp); |
| 599 |
|
| 600 |
return 1; |
| 601 |
} |