⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subagent.c

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 C
📖 第 1 页 / 共 3 页
字号:
        break;    case AGENTX_MSG_RESPONSE:        DEBUGMSGTL(("agentx/subagent", "  -> response\n"));        return 1;    case AGENTX_MSG_TESTSET:        /*         * XXXWWW we have to map this twice to both RESERVE1 and RESERVE2          */        DEBUGMSGTL(("agentx/subagent", "  -> testset\n"));        asi = save_set_vars(session, pdu);        if (asi == NULL) {            snmp_log(LOG_WARNING, "save_set_vars() failed\n");            return 1;        }        asi->mode = pdu->command = SNMP_MSG_INTERNAL_SET_RESERVE1;        mycallback = handle_subagent_set_response;        retmagic = asi;        break;    case AGENTX_MSG_COMMITSET:        DEBUGMSGTL(("agentx/subagent", "  -> commitset\n"));        asi = restore_set_vars(session, pdu);        if (asi == NULL) {            snmp_log(LOG_WARNING, "restore_set_vars() failed\n");            return 1;        }        if (asi->mode != SNMP_MSG_INTERNAL_SET_RESERVE2) {            snmp_log(LOG_WARNING,                     "dropping bad AgentX request (wrong mode %d)\n",                     asi->mode);            return 1;        }        asi->mode = pdu->command = SNMP_MSG_INTERNAL_SET_ACTION;        mycallback = handle_subagent_set_response;        retmagic = asi;        break;    case AGENTX_MSG_CLEANUPSET:        DEBUGMSGTL(("agentx/subagent", "  -> cleanupset\n"));        asi = restore_set_vars(session, pdu);        if (asi == NULL) {            snmp_log(LOG_WARNING, "restore_set_vars() failed\n");            return 1;        }        if (asi->mode == SNMP_MSG_INTERNAL_SET_RESERVE1 ||            asi->mode == SNMP_MSG_INTERNAL_SET_RESERVE2) {            asi->mode = pdu->command = SNMP_MSG_INTERNAL_SET_FREE;        } else if (asi->mode == SNMP_MSG_INTERNAL_SET_ACTION) {            asi->mode = pdu->command = SNMP_MSG_INTERNAL_SET_COMMIT;        } else {            snmp_log(LOG_WARNING,                     "dropping bad AgentX request (wrong mode %d)\n",                     asi->mode);            return 1;        }        mycallback = handle_subagent_set_response;        retmagic = asi;        break;    case AGENTX_MSG_UNDOSET:        DEBUGMSGTL(("agentx/subagent", "  -> undoset\n"));        asi = restore_set_vars(session, pdu);        if (asi == NULL) {            snmp_log(LOG_WARNING, "restore_set_vars() failed\n");            return 1;        }        asi->mode = pdu->command = SNMP_MSG_INTERNAL_SET_UNDO;        mycallback = handle_subagent_set_response;        retmagic = asi;        break;    default:        DEBUGMSGTL(("agentx/subagent", "  -> unknown command %d (%02x)\n",                    pdu->command, pdu->command));        return 0;    }    /*     * submit the pdu to the internal handler      */    /*     * We have to clone the PDU here, because when we return from this     * callback, sess_process_packet will free(pdu), but this call also     * free()s its argument PDU.       */    internal_pdu = snmp_clone_pdu(pdu);    internal_pdu->contextName = internal_pdu->community;    internal_pdu->contextNameLen = internal_pdu->community_len;    internal_pdu->community = NULL;    internal_pdu->community_len = 0;    snmp_async_send(agentx_callback_sess, internal_pdu, mycallback,                    retmagic);    return 1;}inthandle_subagent_response(int op, netsnmp_session * session, int reqid,                         netsnmp_pdu *pdu, void *magic){    ns_subagent_magic *smagic = (ns_subagent_magic *) magic;    netsnmp_variable_list *u = NULL, *v = NULL;    int             rc = 0;    if (op != NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE || magic == NULL) {        return 1;    }    pdu = snmp_clone_pdu(pdu);    DEBUGMSGTL(("agentx/subagent",                "handling AgentX response (cmd 0x%02x orig_cmd 0x%02x)\n",                pdu->command, smagic->original_command));    if (pdu->command == SNMP_MSG_INTERNAL_SET_FREE ||        pdu->command == SNMP_MSG_INTERNAL_SET_UNDO ||        pdu->command == SNMP_MSG_INTERNAL_SET_COMMIT) {        free_set_vars(smagic->session, pdu);    }    if (smagic->original_command == AGENTX_MSG_GETNEXT) {        DEBUGMSGTL(("agentx/subgaent",                    "do getNext scope processing %p %p\n", smagic->ovars,                    pdu->variables));        for (u = smagic->ovars, v = pdu->variables; u != NULL && v != NULL;             u = u->next_variable, v = v->next_variable) {            if (snmp_oid_compare                (u->val.objid, u->val_len / sizeof(oid), nullOid,                 nullOidLen) != 0) {                /*                 * The master agent requested scoping for this variable.                   */                rc = snmp_oid_compare(v->name, v->name_length,                                      u->val.objid,                                      u->val_len / sizeof(oid));                DEBUGMSGTL(("agentx/subagent", "result "));                DEBUGMSGOID(("agentx/subagent", v->name, v->name_length));                DEBUGMSG(("agentx/subagent", " scope to "));                DEBUGMSGOID(("agentx/subagent",                             u->val.objid, u->val_len / sizeof(oid)));                DEBUGMSG(("agentx/subagent", " result %d\n", rc));                if (rc >= 0) {                    /*                     * The varbind is out of scope.  From RFC2741, p. 66: "If                     * the subagent cannot locate an appropriate variable,                     * v.name is set to the starting OID, and the VarBind is                     * set to `endOfMibView'".                       */                    snmp_set_var_objid(v, u->name, u->name_length);                    snmp_set_var_typed_value(v, SNMP_ENDOFMIBVIEW, 0, 0);                    DEBUGMSGTL(("agentx/subagent",                                "scope violation -- return endOfMibView\n"));                }            } else {                DEBUGMSGTL(("agentx/subagent", "unscoped var\n"));            }        }    }    /*     * XXXJBPN: similar for GETBULK but the varbinds can get re-ordered I     * think which makes it er more difficult.       */    if (smagic->ovars != NULL) {        snmp_free_varbind(smagic->ovars);    }    pdu->command = AGENTX_MSG_RESPONSE;    pdu->version = smagic->session->version;    if (!snmp_send(smagic->session, pdu)) {        snmp_free_pdu(pdu);    }    DEBUGMSGTL(("agentx/subagent", "  FINISHED\n"));    free(smagic);    return 1;}inthandle_subagent_set_response(int op, netsnmp_session * session, int reqid,                             netsnmp_pdu *pdu, void *magic){    netsnmp_session *retsess;    struct agent_netsnmp_set_info *asi;    if (op != NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE || magic == NULL) {        return 1;    }    DEBUGMSGTL(("agentx/subagent",                "handling agentx subagent set response (mode=%d,req=0x%x,"                "trans=0x%x,sess=0x%x)\n",                pdu->command, pdu->reqid,pdu->transid, pdu->sessid));    pdu = snmp_clone_pdu(pdu);    asi = (struct agent_netsnmp_set_info *) magic;    retsess = asi->sess;    asi->errstat = pdu->errstat;    if (asi->mode == SNMP_MSG_INTERNAL_SET_RESERVE1) {        /*         * reloop for RESERVE2 mode, an internal only agent mode          */        /*         * XXX: check exception statuses of reserve1 first          */        if (!pdu->errstat) {            asi->mode = pdu->command = SNMP_MSG_INTERNAL_SET_RESERVE2;            snmp_async_send(agentx_callback_sess, pdu,                            handle_subagent_set_response, asi);            DEBUGMSGTL(("agentx/subagent",                        "  going from RESERVE1 -> RESERVE2\n"));            return 1;        }    } else {        if (asi->mode == SNMP_MSG_INTERNAL_SET_FREE ||            asi->mode == SNMP_MSG_INTERNAL_SET_UNDO ||            asi->mode == SNMP_MSG_INTERNAL_SET_COMMIT) {            free_set_vars(retsess, pdu);        }        snmp_free_varbind(pdu->variables);        pdu->variables = NULL;  /* the variables were added by us */    }    netsnmp_assert(retsess != NULL);    pdu->command = AGENTX_MSG_RESPONSE;    pdu->version = retsess->version;    if (!snmp_send(retsess, pdu)) {        snmp_free_pdu(pdu);    }    DEBUGMSGTL(("agentx/subagent", "  FINISHED\n"));    return 1;}intagentx_registration_callback(int majorID, int minorID, void *serverarg,                             void *clientarg){    struct register_parameters *reg_parms =        (struct register_parameters *) serverarg;    netsnmp_session *agentx_ss = (netsnmp_session *) clientarg;    if (minorID == SNMPD_CALLBACK_REGISTER_OID)        return agentx_register(agentx_ss,                               reg_parms->name, reg_parms->namelen,                               reg_parms->priority,                               reg_parms->range_subid,                               reg_parms->range_ubound, reg_parms->timeout,                               reg_parms->flags,                               reg_parms->contextName);    else        return agentx_unregister(agentx_ss,                                 reg_parms->name, reg_parms->namelen,                                 reg_parms->priority,                                 reg_parms->range_subid,                                 reg_parms->range_ubound,                                 reg_parms->contextName);}#ifdef USING_MIBII_SYSORTABLE_MODULEintagentx_sysOR_callback(int majorID, int minorID, void *serverarg,                      void *clientarg){    struct register_sysOR_parameters *reg_parms =        (struct register_sysOR_parameters *) serverarg;    netsnmp_session *agentx_ss = (netsnmp_session *) clientarg;    if (minorID == SNMPD_CALLBACK_REG_SYSOR)        return agentx_add_agentcaps(agentx_ss,                                    reg_parms->name, reg_parms->namelen,                                    reg_parms->descr);    else        return agentx_remove_agentcaps(agentx_ss,                                       reg_parms->name,                                       reg_parms->namelen);}#endifstatic intsubagent_shutdown(int majorID, int minorID, void *serverarg, void *clientarg){    netsnmp_session *thesession = (netsnmp_session *)clientarg;    DEBUGMSGTL(("agentx/subagent", "shutting down session....\n"));    if (thesession == NULL) {	DEBUGMSGTL(("agentx/subagent", "Empty session to shutdown\n"));	main_session = NULL;	return 0;    }    agentx_close_session(thesession, AGENTX_CLOSE_SHUTDOWN);    snmp_close(thesession);    main_session = NULL;    DEBUGMSGTL(("agentx/subagent", "shut down finished.\n"));    return 1;}/* * Register all the "standard" AgentX callbacks for the given session.   */voidagentx_register_callbacks(netsnmp_session * s){    DEBUGMSGTL(("agentx/subagent",                "registering callbacks for session %p\n", s));    snmp_register_callback(SNMP_CALLBACK_LIBRARY,                           SNMP_CALLBACK_POST_READ_CONFIG,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -