📄 rpktasy.c
字号:
SGRPv1_INC_COUNTER(snmp_stats.snmpInGetResponses); else SGRPv1v2_INC_COUNTER(snmp_stats.snmpInASNParseErrs); break;#else SGRPv1_INC_COUNTER(snmp_stats.snmpInGetResponses); break;#endif /* INSTALL_COMMON_DYNAMIC_COMP_CONFIG */ case REPORT_PDU: break;#endif /* #if INSTALL_ENVOY_SNMP_V3_NOTIFY || INSTALL_ENVOY_USE_SNMP_PROXY */#if INSTALL_ENVOY_USE_SNMP_PROXY#if INSTALL_ENVOY_SNMP_VERSION_1 case TRAP_PDU:#if INSTALL_COMMON_DYNAMIC_COMP_CONFIG if (DYNCFG_VBL(envoy_snmp_proxy)) SGRPv1_INC_COUNTER(snmp_stats.snmpInTraps); else SGRPv1v2_INC_COUNTER(snmp_stats.snmpInASNParseErrs); break;#else SGRPv1_INC_COUNTER(snmp_stats.snmpInTraps); break;#endif /* INSTALL_COMMON_DYNAMIC_COMP_CONFIG */#endif /* #if INSTALL_ENVOY_SNMP_VERSION_1 */#if ENVOY_USE_V2_PROTOS case INFORM_REQUEST_PDU:#if INSTALL_COMMON_DYNAMIC_COMP_CONFIG if (DYNCFG_VBL(envoy_snmp_proxy) && DYNCFG_VBL(envoy_use_v2_protos)) ; else SGRPv1v2_INC_COUNTER(snmp_stats.snmpInASNParseErrs); break;#else break;#endif /* INSTALL_COMMON_DYNAMIC_COMP_CONFIG */ case TRAP2_PDU:#if INSTALL_COMMON_DYNAMIC_COMP_CONFIG if (DYNCFG_VBL(envoy_snmp_proxy) && DYNCFG_VBL(envoy_use_v2_protos)) SGRPv1_INC_COUNTER(snmp_stats.snmpInTraps); else SGRPv1v2_INC_COUNTER(snmp_stats.snmpInASNParseErrs); break; #else SGRPv1_INC_COUNTER(snmp_stats.snmpInTraps); break;#endif /* INSTALL_COMMON_DYNAMIC_COMP_CONFIG */#endif /* #if ENVOY_USE_V2_PROTOS */#endif /* #if INSTALL_ENVOY_USE_SNMP_PROXY */ default: SGRPv1v2_INC_COUNTER(snmp_stats.snmpInASNParseErrs); }/* Check SNMPv3 notifies. */#if INSTALL_ENVOY_SNMP_V3_NOTIFYDYNCFG_IFCFGVBL_BEGIN(envoy_snmp_notify)if ((rp->pdu_type == GET_RESPONSE_PDU) || (rp->pdu_type == REPORT_PDU)) {#if INSTALL_ENVOY_SNMP_LOCK ENVOY_SNMP_RELEASE_READ_LOCK(SNMP_CoarseLock);#endif DYNCFG_FUNCALL(SNMP_Check_Retrans_List)(rp);#if INSTALL_ENVOY_SNMP_LOCK ENVOY_SNMP_GET_READ_LOCK(SNMP_CoarseLock);#endif }DYNCFG_IFCFGVBL_END(envoy_snmp_notify)#endif /* #if INSTALL_ENVOY_SNMP_V3_NOTIFY */#if INSTALL_ENVOY_SNMP_V3_PROXY/* Then check SNMPv3 proxies. */DYNCFG_IFCFGVBL_BEGIN(envoy_snmp_proxy)if (rp->proxy_routine != 0) { if ((rp->proxy_routine)(rp) != ENVOY_ERR_NOERR) { SGRPv1v2_INC_COUNTER(snmp_stats.snmpProxyDrops); new_rp = DYNCFG_FUNCALL(Send_Report_PDU)(rp, 0, 2, V3_SNMPPROXYDROPS, sizeof(V3_SNMPPROXYDROPS)/sizeof(OIDC_T), snmp_stats.snmpProxyDrops, &error_code, &rp->pkt_src, &rp->pkt_dst); if (new_rp) ENVOY_Send_SNMP_Packet(new_rp); else rp->error_complete(&rp->pkt_src, &rp->pkt_dst, 1, rp->async_cookie); SNMP_Free(rp); return; } if ((rp->pdu_type != GET_REQUEST_PDU) && (rp->pdu_type != GET_NEXT_REQUEST_PDU) && (rp->pdu_type != SET_REQUEST_PDU) && (rp->pdu_type != GET_BULK_REQUEST_PDU) && (rp->pdu_type != INFORM_REQUEST_PDU)) { rp->error_complete(&rp->pkt_src, &rp->pkt_dst, 1, rp->async_cookie); SNMP_Free(rp); } return; }DYNCFG_IFCFGVBL_END(envoy_snmp_proxy)#elif INSTALL_ENVOY_SNMP_PROXY/* ...or check old-style proxies */switch(rp->pdu_type) { case GET_RESPONSE_PDU: if (SNMP_Proxy_Response(rp) == 0) { SNMP_Free(rp); return; } break;#if INSTALL_ENVOY_SNMP_VERSION_1 case TRAP_PDU: SNMP_Proxy_Traps_And_Reports(rp); break;#endif /* #if INSTALL_ENVOY_SNMP_VERSION_1 */#if ENVOY_USE_V2_PROTOS case TRAP2_PDU: case REPORT_PDU: SNMP_Proxy_Traps_And_Reports(rp); break; case INFORM_REQUEST_PDU: if (rp->proxy_routine) { SNMP_Proxy_Request(rp); SNMP_Free(rp); break; } SGRPv1v2_INC_COUNTER(snmp_stats.snmpInASNParseErrs); break;#endif /* #if ENVOY_USE_V2_PROTOS */ default: if (rp->proxy_routine) { SNMP_Proxy_Request(rp); SNMP_Free(rp); return; } }#endif /* #elif INSTALL_ENVOY_SNMP_PROXY *//* Decide whether to continue */switch (rp->pdu_type) { case GET_RESPONSE_PDU: case TRAP_PDU: case TRAP2_PDU: case REPORT_PDU: case INFORM_REQUEST_PDU: rp->error_complete(&rp->pkt_src, &rp->pkt_dst, 1, rp->async_cookie); SNMP_Free(rp); return; default: break; }#if (INSTALL_ENVOY_SNMP_SERIALIZE)switch (GateKeeper_Add(GATE_SNMP, (PTR_T)rp, process_packet_two)) { case 0: break; case 1: return; default: ENVOY_Send_SNMP_Error_Packet(rp, GEN_ERR, 0); SNMP_Free(rp); return; }#endif /* (INSTALL_ENVOY_SNMP_SERIALIZE) */process_packet_two((PTR_T)rp);}/********************************************************************************* Process_Rcvd_SNMP_Packet_Async - start to process a received PDU* SYNOPSIS** \cs* void Process_Rcvd_SNMP_Packet_Async* ( * size_t pktl, * bits8_t * pktp, * SNMPADDR_T * for_addr, * SNMPADDR_T * loc_addr, * ALENGTH_T pktsize, * IO_COMPLETE_T * io_complete, * ERR_COMPLETE_T * error_complete, * PTR_T cookie * )* \ce** DESCRIPTION** This routine initiates the processing of a received PDU for an SNMP agent. * This depends on the type of agent as follows:* \ml* \m -* SNMPv1 agents can handle 'GET', 'GET NEXT', and' SET' PDUs.* \m -* SNMPv2 and SNMPv3 agents can handle 'GET BULK' PDUs, in addition to 'GET', * 'GET NEXT', and' SET' PDUs.* \m -* Only agents that are acting in a proxy capability can process PDUs of types * of 'RESPONSE', 'TRAP', 'TRAP2', and 'INFORM'.* \me* Process_Rcvd_SNMP_Packet_Async() passes the <for_addr> and <loc_addr> * parameters to the user-exits for community string, SNMP_validate_community() * and address verification, SNMP_validate_address(). If other user-provided * routines (for example, completion routines) plan to use this information, the * validation routine must attach the address information to the packet * structure.* When Envoy finishes processing the packet, it calls a completion routine as * follows:* \ml* \m -* If Envoy produced a response packet to be sent to the requester, it calls * 'io_complete'.* \m -* Otherwise, it calls 'ERR_COMPLETE_T(),' giving you a chance to release any * resources associated with this packet (for example, the <for_addr>, * <loc_addr> and <cookie>.)* \me** \&NOTE: The call to the completion routine can occur before or after * Process_Rcvd_SNMP_Packet_Async() returns.** PARAMETERS* \is* \i <pktl>* Specify the packet buffer\抯 length.* \i <*pktp>* Contain the address of the received packet buffer.* \i <*for_addr>* Specify the destination of the packet.* \i <*loc_addr>* Specify the source of the packet.* \i <pktsize>* Specify the maximum length for the response. This value is compared against * the value of 'SNMP_MAX_PACKET_SIZE' and the smaller of the two is used as the * maximum for this packet. If you do not need the finer control possible with * this parameter, set it to 'SNMP_MAX_PACKET_SIZE'.* \i <*io_complete>* Specify the user-provided I/O completion routine.* \i <*error_complete>* Specify the user-provided error completion routine.* \i <cookie>* Can be used to pass information, for example, the packet\抯 source address, * to a completion or cleanup routine.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: 'ERR_COMPLETE_T(),' SNMP_Continue(), SNMP_Process_Finish(), * SNMP_validate_address(), SNMP_validate_community()*/void Process_Rcvd_SNMP_Packet_Async(size_t pktl, bits8_t *pktp, SNMPADDR_T *for_addr, SNMPADDR_T *loc_addr, ALENGTH_T pktsize, IO_COMPLETE_T *io_complete, ERR_COMPLETE_T *error_complete, PTR_T complete_cookie){SNMP_PKT_T *rp;int error_code;SGRPv1v2_INC_COUNTER(snmp_stats.snmpInPkts);rp = SNMP_Decode_Packet_WER((unsigned char *)pktp, (int)pktl, for_addr, loc_addr, &error_code);if (rp == 0) { error_complete(for_addr, loc_addr, 1, complete_cookie); return; } SNMP_TRACE_INPUT(rp);/* See if the given maximum size is smaller than the default */if (pktsize < rp->maxpkt) rp->maxpkt = pktsize;/* Attach the completion routines to the packet structure */rp->io_complete = io_complete;rp->error_complete = error_complete;rp->async_cookie = complete_cookie;rp->cont = SNMP_Continue_function;/* Check the error code returned from decode_pkt, if it isn't zero then the decode routine is requesting that we send an error packet to the requester. We need to encode the packet and call the completion routine, if we can't do the encode we call the error routine. */if (error_code != 0) { ENVOY_Send_SNMP_Packet(rp); SNMP_Free(rp); return; }process_packet_one(rp);}/****************************************************************************\NOMANUALNAME: Process_Internal_SNMP_PacketWARNING: This is an intentionally undocumented, internal API. It is not intended for customer use. PURPOSE: The entry point to allow a user to process an internally constructed snmp packet, mostly this is a way to get the counters (in pkts) correct.PARAMETERS: SNMP_PKT_T * The packet, in its c-structure format, to processRETURNS: void****************************************************************************/void Process_Internal_SNMP_Packet(SNMP_PKT_T *rp){SGRPv1v2_INC_COUNTER(snmp_stats.snmpInPkts);rp->cont = SNMP_Continue_function;process_packet_one(rp);}/********************************************************************************* SNMP_Process_Finish - encode <pktp> into an octet string* SYNOPSIS** \cs* int SNMP_Process_Finish * ( * SNMP_PKT_T * pktp * EBUFFER_T * ebuf * ALENGTH_T len * )* \ce** DESCRIPTION** The IO_COMPLETE_T() routine must call this routine to encode <pktp> into an * octet string in <ebuf>.* You can either allocate the required buffer space in the completion routine * and attach it to <ebuf>, or pass an initialized but empty <ebuf> and let<> * Wind Manage SNMP call SNMP_memory_alloc(), SNMP_memory_free() to attempt to * allocate space.** PARAMETERS* \is* \i <*pktp>* Point to the packet being processed.* \i <*ebuf>* Point the extended buffer structure used to store the resulting octet string.* \i <len>* Specify the length of the encoded packet and should be passed unchanged from * the call to the completion routine.* \ie** RETURNS: If successful, this routine returns 0. If the specified buffer was * too short or if there was a failure to allocate space, it returns -1.** ERRNO: N/A** SEE ALSO: IO_COMPLETE_T(), Process_Rcvd_SNMP_Packet_Async(), SNMP_Continue(), * SNMP_memory_alloc(), SNMP_memory_free()*/int SNMP_Process_Finish(SNMP_PKT_T *pktp, EBUFFER_T *ebufp, ALENGTH_T need){if (SNMP_Encode_Pkt_With_Siz(pktp, ebufp, need)) return(-1);return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -