Hi Dave, I could forward the trap after converting to V2.
The issue with previous try: It seems that convert_v1pdu_to_v2() function doesn't update pdu->version parameter as needed (not sure whether this is intentional or not). So in order to forward SNMPV1 trap as SNMPv2 notification, after PDU conversion I have to do two things inside forward_handler() 1. Set session.version = SNMP_VERSION_2c; 2. Set v2_pdu->version = SNMP_VERSION_2c; (if it is not done, the error 'Forward failed: Bad version specified' will be logged in syslog file) Here again I have one doubt. Even though the trap is forwarded and the forwarded trap could be received properly using a trap receiver at the destination end, the syslog file shows an error without proper error code. The error log is "snmptrapd[22813]: Forward failed:" Is there any issue still persisting? Let me clarify one more thing which is already commented by you. I understood that there is nothing like "SNMPv3 trap". SNMPV3 uses SNMPv2 PDU. So I hope in order to forward SNMPV1 trap to a v3 destination, 1. Modify session parameter with v3 configuration 2. Use SNMPv2 PDU (convert v1pdu to v2 and update pdu version as SNMP_VERSION_3) Am I correct? If so, can you please tell me how the session should be modified to send as SNMPV3? thank you, renjith -----Original Message----- From: Renjith R. V. Sent: Tuesday, October 19, 2010 7:44 PM To: 'Dave Shield' Cc: [email protected] Subject: RE: how to identify variable 'type' and 'value' from pdu structure Okay. I am not sure what went wrong here. Can you please go through the below code snippet and try to find out what could be the issue? int forward_handler( netsnmp_pdu *pdu, netsnmp_transport *transport, netsnmp_trapd_handler *handler) { netsnmp_session session, *ss; netsnmp_pdu *clone_v2_pdu; int oldquick; char buf[BUFSIZ], *cp; DEBUGMSGTL(( "snmptrapd", "forward_handler (%s)\n", handler->token)); #if 1 // MODIFICATION.. Converted SNMP v1 trap to V2 trap netsnmp_pdu *v2_pdu = NULL; if (pdu->command == SNMP_MSG_TRAP) v2_pdu = convert_v1pdu_to_v2(pdu); else v2_pdu = pdu; oldquick = snmp_get_quick_print(); snmp_set_quick_print(1); #endif snmp_sess_init( &session ); if (strchr( handler->token, ':') == NULL) { snprintf( buf, BUFSIZ, "%s:%d", handler->token, SNMP_TRAP_PORT); cp = buf; } else { cp = handler->token; } session.peername = cp; //session.version = pdu->version; //ORIG.. commented for testing session.version = v2_pdu->version; //Try 1 //session.version = SNMP_VERSION_2c; // Try 2 ss = snmp_open( &session ); if (!ss) return NETSNMPTRAPD_HANDLER_FAIL; /* XXX: wjh we should be caching sessions here and not always reopening a session. It's very ineffecient, especially with v3 INFORMS which may require engineID probing */ clone_v2_pdu = snmp_clone_pdu(v2_pdu); if (clone_v2_pdu->transport_data) { free(clone_v2_pdu->transport_data); clone_v2_pdu->transport_data = NULL; clone_v2_pdu->transport_data_length = 0; } if (!snmp_send( ss, clone_v2_pdu )) { snmp_sess_perror("Forward failed", ss); snmp_free_pdu(clone_v2_pdu); snmp_free_pdu(v2_pdu); } snmp_close( ss ); return NETSNMPTRAPD_HANDLER_OK; } thank you renjith -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Dave Shield Sent: Tuesday, October 19, 2010 6:58 PM To: Renjith R. V. Cc: [email protected] Subject: Re: how to identify variable 'type' and 'value' from pdu structure On 19 October 2010 14:20, Renjith R. V. <[email protected]> wrote: > I haven't created any new session. > The session related code in forward_handler() is attached below. > I have updated session.version with the version available in v2_pdu > which is created using convert_v1pdu_to_v2(). Yes - that should work. The error you were getting before probably came from the earlier code session.version = pdu->version; (since the original pdu was v1) Dave ***** Confidentiality Statement/Disclaimer ***** This message and any attachments is intended for the sole use of the intended recipient. It may contain confidential information. Any unauthorized use, dissemination or modification is strictly prohibited. If you are not the intended recipient, please notify the sender immediately then delete it from all your systems, and do not copy, use or print. Internet communications are not secure and it is the responsibility of the recipient to make sure that it is virus/malicious code exempt. The company/sender cannot be responsible for any unauthorized alterations or modifications made to the contents. If you require any form of confirmation of the contents, please contact the company/sender. The company/sender is not liable for any errors or omissions in the content of this message. ------------------------------------------------------------------------------ Download new Adobe(R) Flash(R) Builder(TM) 4 The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly Flex(R) Builder(TM)) enable the development of rich applications that run across multiple browsers and platforms. Download your free trials today! http://p.sf.net/sfu/adobe-dev2dev _______________________________________________ Net-snmp-coders mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/net-snmp-coders
