📄 asy_util.c
字号:
/****************************************************************************NAME: testproc_goodPURPOSE: Indicates that the testproc has completed successfully for this varbind. PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processedRETURNS: Nothing****************************************************************************/void testproc_good(SNMP_PKT_T *pktp, VB_T *vbp){vbp->vb_flags |= VFLAG_TEST_DONE;}#endif /* INSTALL_ENVOY_SNMP_UTIL_MACROS */ /****************************************************************************NAME: testproc_errorPURPOSE: Install a test type error into the packet structure. As there is a different ordering of some errors in version 1 vs version 2 we try to handle that here. The customer may try to overwrite the error status. We allow for the overwrite if: packet type current status new status version 1 any value no_such_name no_creation version 2 no_such_name bad_value no_creation wrong_length wrong_value rfc1905 section 4.2.5 step 6 is the check for WRONG_VALUE which maps to BAD_VALUE step 7 is the check for NO_CREATION which maps to NO_SUCH_NAME rfc1157 section 4.1.5 step 1 is the view check which results in NO_SUCH_NAME step 2 is the check for BAD_VALUE PARAMETERS: SNMP_PKT_T * The decoded PDU VB_T * A var bind sbits32_t the error codeRETURNS: void****************************************************************************/void testproc_error(SNMP_PKT_T *pktp, VB_T *vbp, sbits32_t err_code){/* mark the varbind as done */vbp->vb_flags |= VFLAG_TEST_DONE;if (pktp->pdu.std_pdu.error_status) { if (pktp->snmp_version == SNMP_VERSION_1) { if ((err_code != NO_CREATION) && (err_code != NO_SUCH_NAME)) return; } else { if (((pktp->pdu.std_pdu.error_status != NO_SUCH_NAME) && (pktp->pdu.std_pdu.error_status != NO_CREATION)) || ((err_code != BAD_VALUE) && (err_code != WRONG_LENGTH) && (err_code != WRONG_VALUE))) return; } }pktp->pdu.std_pdu.error_status = err_code;pktp->pdu.std_pdu.error_index = vbp_to_index(pktp, vbp) + 1;}/****************************************************************************NAME: testproc_tproc_errorPURPOSE: Routine to translate a tproc style error to a standard error and attach the result to the packet structure. If error is > 0, then we have a bad value error and we use error as the vbp index. Otherwise we work out what the correct error is and use the given vb_t for the index (if necessary). PARAMETERS: SNMP_PKT_T * The decoded NEXT/BULK PDU VB_T * A var bind int the tproc style errorRETURNS: void****************************************************************************/void testproc_tproc_error(SNMP_PKT_T *pktp, VB_T *vbp, int err_code){INT_32_T ecode;if (err_code > 0) { pktp->pdu.std_pdu.error_status = BAD_VALUE; pktp->pdu.std_pdu.error_index = (INT_32_T)err_code; vbp->vb_flags |= VFLAG_TEST_DONE; return; }switch(err_code) { case TPROC_READ_ONLY: case TPROC_NOSUCH: ecode = NO_SUCH_NAME; break; default: case TPROC_GENERR: ecode = GEN_ERR; break; case TPROC_BADVALUE: ecode = BAD_VALUE; break; case TPROC_TOO_BIG: ecode = TOO_BIG; break; case TPROC_LAST_ERROR: /* don't need to do anything, they are already in the packet */ vbp->vb_flags |= VFLAG_TEST_DONE; return;/* For the following cases the return code is the negative of the *//* true (snmp) error code so we set the status to be the *//* negative of the err_code. */ case TPROC_NO_ACCESS: case TPROC_NO_CREATION: case TPROC_WRONG_TYPE: case TPROC_WRONG_LENGTH: case TPROC_WRONG_ENCODING: case TPROC_WRONG_VALUE: case TPROC_INCONSISTENT_VALUE: case TPROC_RESOURCE_UNAVAILABLE: case TPROC_COMMIT_FAILED: case TPROC_UNDO_FAILED: case TPROC_AUTHORIZATION_ERROR: case TPROC_NOT_WRITABLE: case TPROC_INCONSISTENT_NAME: ecode = (INT_32_T)(-err_code); break; }pktp->pdu.std_pdu.error_status = ecode;pktp->pdu.std_pdu.error_index = vbp_to_index(pktp, vbp) + 1;vbp->vb_flags |= VFLAG_TEST_DONE;}#if !(INSTALL_ENVOY_SNMP_UTIL_MACROS) /****************************************************************************NAME: setproc_startedPURPOSE: Indicates that the setproc has been started for this varbind. PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processedRETURNS: Nothing****************************************************************************/void setproc_started(SNMP_PKT_T *pktp, VB_T *vbp){vbp->vb_flags |= VFLAG_SET_STARTED;} /****************************************************************************NAME: setproc_goodPURPOSE: Indicates that the setproc has complete successfully for this varbind. PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processedRETURNS: Nothing****************************************************************************/void setproc_good(SNMP_PKT_T *pktp, VB_T *vbp){vbp->vb_flags |= VFLAG_SET_DONE;}/****************************************************************************NAME: setproc_errorPURPOSE: Indicates that the setproc has encountered an error.PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processed INT_32_T error codeRETURNS: Nothing****************************************************************************/void setproc_error(SNMP_PKT_T *pktp, VB_T *vbp, INT_32_T error){pktp->pdu.std_pdu.error_status = error;pktp->pdu.std_pdu.error_index = vbp_to_index_error(pktp, vbp, 1);vbp->vb_flags |= VFLAG_SET_DONE;}/****************************************************************************NAME: undoproc_startedPURPOSE: Indicates that an undoproc operation has begun.PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processedRETURNS: Nothing****************************************************************************/void undoproc_started(SNMP_PKT_T *pktp, VB_T *vbp){vbp->vb_flags |= VFLAG_UNDO_STARTED;}/****************************************************************************NAME: undoproc_goodPURPOSE: Indicates successful completion of an undoproc operation.PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processedRETURNS: Nothing****************************************************************************/void undoproc_good(SNMP_PKT_T *pktp, VB_T *vbp){ vbp->vb_flags |= VFLAG_UNDO_DONE;}/****************************************************************************NAME: undoproc_errorPURPOSE: Indicates that an undoproc operation encountered an error.PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processed INT_32_T error codeRETURNS: Nothing****************************************************************************/void undoproc_error(SNMP_PKT_T *pktp, VB_T *vbp, INT_32_T error){pktp->pdu.std_pdu.error_status = error;pktp->pdu.std_pdu.error_index = vbp_to_index_error(pktp, vbp, 1);vbp->vb_flags |= VFLAG_UNDO_DONE;}/****************************************************************************NAME: getproc_got_int32PURPOSE: Called from a getproc or nextproc when a 32-bit integer value is retrieved for a varbind.PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processed INT_32_T 32-bit integer value for varbindRETURNS: Nothing****************************************************************************/void getproc_got_int32(SNMP_PKT_T *pktp, VB_T *vbp, INT_32_T data){vbp->vb_data_flags_n_type = VT_NUMBER;vbp->value_u.v_number = data;vbp->vb_flags |= VFLAG_GET_DONE;}/****************************************************************************NAME: getproc_got_uint32PURPOSE: Called from a getproc or nextproc when a 32-bit unsigned integer value is retrieved for a varbind.PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processed INT_32_T unsigned 32-bit integer value for varbind OCTET_T SNMP type of valueRETURNS: Nothing****************************************************************************/void getproc_got_uint32(SNMP_PKT_T *pktp, VB_T *vbp, UINT_32_T data, OCTET_T type){vbp->vb_data_flags_n_type = type;vbp->value_u.v_counter = data;vbp->vb_flags |= VFLAG_GET_DONE;}/****************************************************************************NAME: getproc_got_ip_addressPURPOSE: Called from a getproc or nextproc when an IP address is retrieved for a varbind.PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processed UINT_32_T IP address valueRETURNS: Nothing****************************************************************************/void getproc_got_ip_address(SNMP_PKT_T *pktp, VB_T *vbp, UINT_32_T data){vbp->vb_data_flags_n_type = VT_IPADDRESS;MEMCPY(&(vbp->value_u.v_network_address), &data, 4);vbp->vb_flags |= VFLAG_GET_DONE;}/****************************************************************************NAME: getproc_got_emptyPURPOSE: Called from a getproc or nextproc to indicate retrieval of a null value for a varbind.PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processedRETURNS: Nothing****************************************************************************/void getproc_got_empty(SNMP_PKT_T *pktp, VB_T *vbp){vbp->vb_data_flags_n_type = VT_EMPTY;vbp->vb_flags |= VFLAG_GET_DONE;}/****************************************************************************NAME: getproc_got_stringPURPOSE: Called from a getproc or nextproc when an octet string is retrieved for a varbind. The string data is stored in an EBuffer in the varbind. The parameter <dynamic> indicates the storage type. If non-zero, the buffer is assumed to have been allocated dynamically and will be freed later. Otherwise, the buffer is assumed to be static.PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processed ALENGTH_T size of string in octets OCTET_T * string data int storage type - dynamic or static OCTET_T SNMP type of string dataRETURNS: Nothing****************************************************************************/void getproc_got_string(SNMP_PKT_T *pktp, VB_T *vbp, ALENGTH_T stringlen, OCTET_T *string, int dynamic, OCTET_T type){vbp->vb_data_flags_n_type = type;vbp->vb_flags |= VFLAG_GET_DONE;EBufferPreLoad(dynamic ? BFL_IS_DYNAMIC : BFL_IS_STATIC, &(vbp->value_u.v_string), string, stringlen);}/****************************************************************************NAME: getproc_got_octet_stringPURPOSE: Called from a getproc or nextproc when an octet string is retrieved for a varbind. The string data is stored in an EBuffer in the varbind. NOTE: This function is intended as an alternative to getproc_got_string(). It will always allocate a buffer to store the data, which prevents problems such as static buffer reuse for getbulks.PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processed ALENGTH_T size of string in octets OCTET_T * string data OCTET_T SNMP type of string dataRETURNS: Nothing****************************************************************************/void getproc_got_octet_string(SNMP_PKT_T *pktp, VB_T *vbp, ALENGTH_T stringlen, OCTET_T *string, OCTET_T type){vbp->vb_data_flags_n_type = type;vbp->vb_flags |= VFLAG_GET_DONE;EBufferPreLoad(BFL_IS_ALLOC, &(vbp->value_u.v_string), string, stringlen);}/****************************************************************************NAME: getproc_got_uint64PURPOSE: Called from a getproc or nextproc when an 64-bit unsigned integer is retrieved for a varbind.PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processed UINT_64_T * 64-bit unsigned valueRETURNS: Nothing****************************************************************************/void getproc_got_uint64(SNMP_PKT_T *pktp, VB_T *vbp, UINT_64_T *data){vbp->vb_data_flags_n_type = VT_COUNTER64;vbp->value_u.v_counter64.high = data->high;vbp->value_u.v_counter64.low = data->low;vbp->vb_flags |= VFLAG_GET_DONE;}/****************************************************************************NAME: getproc_got_uint64_high_lowPURPOSE: Called from a getproc or nextproc when an 64-bit unsigned integer with high and low halves is retrieved for a varbind.PARAMETERS: SNMP_PKT_T * the SNMP packet VB_T * the varbind being processed UINT_32_T high half of data UINT_32_T low half of dataRETURNS: Nothing****************************************************************************/void getproc_got_uint64_high_low(SNMP_PKT_T *pktp, VB_T *vbp, UINT_32_T high, UINT_32_T low){vbp->vb_data_flags_n_type = VT_COUNTER64;vbp->value_u.v_counter64.high = high;vbp->value_u.v_counter64.low = low;vbp->vb_flags |= VFLAG_GET_DONE;}#endif /* INSTALL_ENVOY_SNMP_UTIL_MACROS */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -