📄 mp_v3.h
字号:
unsigned char *inBuf, int inBufLength, OctetStr &securityEngineID, OctetStr &securityName, OctetStr &contextEngineID, OctetStr &contextName, long &securityLevel, long &msgSecurityModel, snmp_version &spp_version, UdpAddress from_address); /** * Tests if the given buffer contains a SNMPv3-Message. The buffer is * only parsed to extract the version of the message, no other checks * are made. * * @param buffer - The message * @param length - The length of the message * * @return - TRUE if the version could be extracted and it * is a SNMPv3 message. On any error: FALSE. * */ static bool is_v3_msg( unsigned char *buffer, int length); /** * Do the complete process of encoding the given values into the buffer * ready to send to the target. * * @param pdu - The pdu structure * @param packet - The buffer to store the serialized message * @param out_length - IN: Length of the buffer, * OUT: Length of the message * @param securityEngineID - The securityEngineID * @param securityNameIn - The securityName * @param securityModel - Use this security model * @param securityLevel - Use this security level * @param contextEngineID - The contextEngineID * @param contextName - The contextName * * @return - SNMPv3_MP_OK or any error listed in snmperr.h */ int snmp_build(struct snmp_pdu *pdu, unsigned char *packet, int *out_length, // maximum Bytes in packet const OctetStr &securityEngineID, const OctetStr &securityNameIn, int securityModel, int securityLevel, const OctetStr &contextEngineID, const OctetStr &contextName); /** * Delete the entry with the given request id from the cache. * This function is used in eventlist.cpp when a request * has timed out. * * @param requestID - The request id. */ void delete_from_cache(unsigned long requestID) { cache.delete_entry(requestID, true); }; private: /** * Send a report message. * * @param scopedPDU - The scopedPDU as received. If the pdu is not * encrypted, the request id is extracted * @param scopedPDULength - The lkength of the scopedPDU * @param pdu - The pdu structure. * @param errorCode - The code of the error that occured. * @param sLevel - Send the report with this security level. * @param sModel - Use this security model. * @param sName - Use this security name * @param destination - Send the report to this address. * @param snmp_session - Snmp session to use for sending a report * * @return - SNMPv3_MP_ERROR, SNMPv3_MP_OK */ int send_report(unsigned char* scopedPDU, int scopedPDULength, struct snmp_pdu *pdu, int errorCode, int sLevel, int sModel, OctetStr &sName, UdpAddress &destination, Snmp *snmp_session); // =====================[ member classes ]============================== /** * The engine id table is used to store known engine ids with * corresponding hostadress and port. */ class DLLOPT EngineIdTable { public: EngineIdTable(int initial_size = 10); ~EngineIdTable(); /** * Add an entry to the table. * * @param engine_id - The engineID * @param host - The numerical IP address * @param port - The port * * @return - SNMPv3_MP_ERROR, SNMPv3_MP_OK */ int add_entry(const OctetStr &engine_id, const OctetStr &host, int port); /** * Get the engine_id of the SNMP entity at the given host/port. * * @param engine_id - OUT: The engineID * @param hostport - The numerical IP address and port * (syntax: a.b.c.d/port) * * @return - SNMPv3_MP_NOT_INITIALIZED, SNMPv3_MP_ERROR, * SNMPv3_MP_OK */ int get_entry(OctetStr &engine_id, const OctetStr &hostport) const; /** * Get the engineID of the SNMP entity at the given host/port. * * @param engine_id - OUT: The engineID * @param host - The numerical IP address * @param port - The port * * @return - SNMPv3_MP_NOT_INITIALIZED, SNMPv3_MP_ERROR, * SNMPv3_MP_OK */ int get_entry(OctetStr &engine_id, const OctetStr &host, int port) const; /** * Remove all entries from the engine id table. * * @return - SNMPv3_MP_NOT_INITIALIZED, SNMPv3_MP_ERROR, * SNMPv3_MP_OK */ int reset(); /** * Remove the given engine id from the table. * * @param engine_id - The engine id to remove * * @return - SNMPv3_MP_NOT_INITIALIZED, SNMPv3_MP_ERROR, * SNMPv3_MP_OK */ int delete_entry(const OctetStr &engine_id); /** * Remove the entry for the given address/port from the table. * * @param host - Numeric IP address * @param port - listen port of the snmp entity * * @return - SNMPv3_MP_NOT_INITIALIZED, SNMPv3_MP_ERROR, * SNMPv3_MP_OK */ int delete_entry(const OctetStr &host, int port); private: int initialize_table(const int size); struct Entry_T { OctetStr engine_id; OctetStr host; int port; }; struct Entry_T *table; int max_entries; ///< the maximum number of entries int entries; ///< the current amount of entries SNMP_PP_MUTABLE SnmpSynchronized lock; }; /** * Holds cache entries for currently processed requests. */ class DLLOPT Cache { public: Cache(); ~Cache(); struct Entry_T { int msg_id; unsigned long req_id; OctetStr sec_engine_id; int sec_model; OctetStr sec_name; int sec_level; OctetStr context_engine_id; OctetStr context_name; struct SecurityStateReference *sec_state_ref; int error_code; bool local_request; }; /** * Add an entry to the cache. * * @param msg_id - The message id of the message * @param req_id - The request id of the message * @param sec_engine_id - The authoritative engineID * @param sec_model - The security model used for this message * @param sec_name - The name of the user * @param sec_level - The security level used for this message * @param context_engine_id - The context_engine_id * @param context_name - The context_name * @param sec_state_ref - The reference of the USM * @param error_code - The code of the error that occured while * parsing the received message * * @return - SNMPv3_MP_OK, SNMPv3_MP_ERROR or SNMPv3_DOUBLED_MESSAGE * (an entry with the given values is already in the cache) */ int add_entry(int msg_id, unsigned long req_id, const OctetStr &sec_engine_id, int sec_model, const OctetStr &sec_name, int sec_level, const OctetStr &context_engine_id, const OctetStr &context_name, struct SecurityStateReference *sec_state_ref, int error_code, bool local_request); /** * Search the cache for a message id, return the error code and * the sec_state_ref and delete the entry from the cache. * * @param msg_id - Search for this message id * @param error_code - OUT: The error code of the received message * @param sec_state_ref - IN: Pointer to a pointer of the structure * OUT: The structure as received by the USM when * the message was parsed. * * @return - SNMPv3_MP_ERROR, SNMPv3_MP_OK */ int get_entry(int msg_id, bool local_request, int *error_code, struct SecurityStateReference **sec_state_ref); /** * Delete the entry with the given request id from the cache. * This function is used in eventlist.cpp when a request * has timed out. * * @param req_id - The request id. */ void delete_entry(unsigned long req_id, bool local_request); /** * Search the cache for a message id, return the whole entry and * delete the entry from the cache. * * @param searchedID - Search for this message id * @param res - IN: Pointer to an empy structure * OUT: The filled structure * * @return - SNMPv3_MP_ERROR, SNMPv3_MP_OK */ int get_entry(int searchedID, bool local_request, struct Cache::Entry_T *res); void delete_content(struct Cache::Entry_T &ce); void set_usm(USM *usm_to_use) { usm = usm_to_use; }; private:#ifdef _THREADS SNMP_PP_MUTABLE SnmpSynchronized lock;#endif struct Entry_T *table; ///< whole table int max_entries; ///< the maximum number of entries int entries; ///< the current amount of entries USM *usm; }; // =====================[ member variables ]============================== EngineIdTable engine_id_table; Cache cache; // the engineID of this SNMP entity unsigned char *own_engine_id; int own_engine_id_len; OctetStr own_engine_id_oct; unsigned int cur_msg_id; ///< msgID to use for next message USM *usm; ///< the USM object used // MIB Counters unsigned int snmpUnknownSecurityModels; unsigned int snmpInvalidMsgs; unsigned int snmpUnknownPDUHandlers;};#ifdef SNMP_PP_NAMESPACE}; // end of namespace Snmp_pp#endif #endif // _SNMPv3#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -