/** * Process the get request. This is called in the mode end callback. */ int clSnmpProcessRequest(netsnmp_request_info *requests) { ClRcT rc = CL_SNMP_ERR_NOERROR; ClUint32T i = 0; ClMedErrorListT medErrList = {0}; _ClSnmpGetReqInfoT *pReqInfo = NULL; clLogDebug("SNP", NULL, "Calling the snmpCommit now."); rc = clSnmpCommit (&medErrList); if (CL_OK != rc) { clSnmpDataReset(); clLogError("SNP", NULL, "Failed while committing the get request. rc[0x%x]", rc); if (CL_ERR_NO_MEMORY == rc) rc = CL_SNMP_ERR_NOCREATION; else rc = CL_SNMP_ERR_GENERR; netsnmp_request_set_error(requests, rc); return rc; } for (i = 0 ; i < gOper.opInfo.varCount ; i++) { pReqInfo = ((_ClSnmpGetReqInfoT *)(gOper.pOpAddData) + i); clLogDebug("SNP", NULL, "Processing the agentId [%s]", gOper.opInfo.varInfo[i].attrId.id); if (gOper.opInfo.varInfo[i].errId == CL_OK) { snmp_set_var_typed_value(pReqInfo->pRequest->requestvb, pReqInfo->columnType, gOper.opInfo.varInfo[i].pVal, gOper.opInfo.varInfo[i].len); } else { clLogDebug("SNP", NULL, "Job failed with error [0x%x]", gOper.opInfo.varInfo[i].errId); netsnmp_request_set_error(pReqInfo->pRequest, gOper.opInfo.varInfo[i].errId); } } clSnmpDataReset(); return rc; }
int clSnmpsaAmfClusterAdminStateTriggerHandler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { ClSNMPRequestInfoT requestInfo; netsnmp_variable_list *reqVar = NULL; if(!requests || !reqinfo) return SNMP_ERR_GENERR; reqVar = requests->requestvb; /* We are never called for a GETNEXT if it's registered as a "instance", as it's "magically" handled for us. */ /* An instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ memset(&requestInfo, 0, sizeof(ClSNMPRequestInfoT)); /* Extract the scalar OID, convert it to string form and assign it to requestInfo.oid */ requestInfo.oidLen = OID_LENGTH(saAmfClusterAdminStateTriggerOid); clSnmpOidCpy(&requestInfo, reqVar->name); requestInfo.tableType = CL_SAFAMF_SCALARS; switch(reqinfo->mode) { case MODE_GET: { ClInt32T retVal = 0, errorCode = 0; _ClSnmpGetReqInfoT reqAddInfo = {0}; void * pVal = NULL; ClInt32T saAmfClusterAdminStateTriggerVal = 0; requestInfo.dataLen = sizeof(ClInt32T); pVal = &saAmfClusterAdminStateTriggerVal; requestInfo.index.scalarType = 0; requestInfo.opCode = CL_SNMP_GET; reqAddInfo.pRequest = requests; reqAddInfo.columnType = ASN_INTEGER; clLogDebug("SUB", "SCL", "Received GET request"); retVal = clRequestAdd(&requestInfo, pVal, NULL, &errorCode, &reqAddInfo); if(retVal != 0 || errorCode < 0) { netsnmp_request_set_error (requests, errorCode); return errorCode; } break; } /* * SET REQUEST * * multiple states in the transaction. See: * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg */ case MODE_SET_RESERVE1: { ClInt32T retVal = 0; clLogDebug("SUB", "SCL", "Received RESERVE1 request"); retVal = netsnmp_check_vb_type(reqVar, ASN_INTEGER); if(retVal != SNMP_ERR_NOERROR ) { netsnmp_request_set_error(requests, retVal ); return retVal; } switch(*(reqVar->val.integer)) { case SAAMFCLUSTERADMINSTATETRIGGER_STABLE: break; case SAAMFCLUSTERADMINSTATETRIGGER_UNLOCK: break; case SAAMFCLUSTERADMINSTATETRIGGER_LOCK: break; case SAAMFCLUSTERADMINSTATETRIGGER_LOCKINSTANTIATION: break; case SAAMFCLUSTERADMINSTATETRIGGER_UNLOCKINSTANTIATION: break; case SAAMFCLUSTERADMINSTATETRIGGER_SHUTDOWN: break; /** not a legal enum value. return an error */ default: CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Inconsistent value.")); netsnmp_request_set_error(requests, SNMP_ERR_WRONGVALUE); return SNMP_ERR_WRONGVALUE; } break; } case MODE_SET_RESERVE2: { ClInt32T retVal = 0, errorCode = 0, noOfOp = 1; ClPtrT pVal = NULL; ClInt32T Val = 0; pVal = &Val; requestInfo.dataLen = sizeof(ClInt32T); requestInfo.opCode = CL_SNMP_SET; requestInfo.index.scalarType = 0; memcpy(pVal, (void *)reqVar->val.integer, requestInfo.dataLen); clLogDebug("SUB", "SCL", "Calling request add"); retVal = clRequestAdd( &requestInfo, pVal, &noOfOp, &errorCode, NULL); if(CL_OK != retVal) { clLogError("SUB", "SCL", "Failed to add request to store, rc=[0x%x], errorCode=[0x%x]", retVal, errorCode); netsnmp_request_set_error(requests, errorCode); return retVal; } clLogDebug("SUB", "SCL", "Successfully added request in store"); break; } case MODE_SET_FREE: { clLogDebug("SUB", "SCL", "Received FREE request"); clSnmpUndo(); break; } case MODE_SET_ACTION: { ClInt32T retVal = 0; ClMedErrorListT medErrList; clLogDebug("SUB", "SCL", "Received ACTION request for oid[%s] ",requestInfo.oid); retVal = clSnmpCommit(&medErrList); if (retVal != 0) { clLogDebug("SUB", "SCL", "Error in commit errCount[%d]", medErrList.count); if(retVal == CL_ERR_NO_MEMORY) { retVal = CL_SNMP_ERR_NOCREATION; /* Set SNMP equivalent error from oidErrMapTable in clSnmpInit.c */ clLogError("SUB", "SCL", "ACTION phase failed, setting errorCode[0x%x] for oid[%s]", retVal, requestInfo.oid); netsnmp_request_set_error(requests, retVal); return retVal; } else { ClUint32T i; for(i = 0; i < medErrList.count; i++) { /* the oid matches the request, set error and return*/ if(!memcmp((ClUint8T*)requestInfo.oid, medErrList.pErrorList[i].oidInfo.id, medErrList.pErrorList[i].oidInfo.len)) { clLogError("SUB", "SCL", "ACTION phase failed, setting errorCode[0x%x] for oid[%s]", medErrList.pErrorList[i].errId, requestInfo.oid); netsnmp_request_set_error(requests, medErrList.pErrorList[i].errId); return retVal; } } } } break; } case MODE_SET_COMMIT: { clLogDebug("SUB", "SCL", "Received COMMIT request"); clSnmpUndo(); break; } case MODE_SET_UNDO: { clLogDebug("SUB", "SCL", "Received UNDO request"); clSnmpUndo(); break; } default: /* we should never get here, so this is a really bad error */ CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("unknown mode (%d) in clSnmpsaAmfClusterAdminStateTriggerHandler\n", reqinfo->mode) ); return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; }