[PATCH] Fix engine id discovery on the trap listen port.

Dominik Vogt dominik.vogt at external.thalesgroup.com
Fri Sep 17 10:24:59 CEST 2010


Before the fix, the reply to an engine id discovery attempt would be sent from
the regular snm port, but it must be sent from the port that received the
discovery request, i.e. from the trap listen port.
---
 include/snmp_pp/mp_v3.h   |    8 ++++++--
 include/snmp_pp/snmpmsg.h |   12 ++++++++----
 src/mp_v3.cpp             |   17 +++++++++++++----
 src/snmpmsg.cpp           |   12 ++++++++----
 src/uxsnmp.cpp            |    9 +++++----
 5 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/include/snmp_pp/mp_v3.h b/include/snmp_pp/mp_v3.h
index b133db5..b763235 100644
--- a/include/snmp_pp/mp_v3.h
+++ b/include/snmp_pp/mp_v3.h
@@ -304,6 +304,7 @@ class DLLOPT v3MP
    * @param spp_version      - OUT: SNMP version (SNMPv3)
    * @param from_address     - Where the message came from (used to send
    *                           a report if neccessary)
+   * @param isRequestFromTrapPort - True if request arrived on the trap port
    *
    * @return - SNMPv3_MP_OK or any error listed in snmperr.h
    */
@@ -318,7 +319,8 @@ class DLLOPT v3MP
 		 long     &securityLevel,
 		 long     &msgSecurityModel,
 		 snmp_version &spp_version,
-		 UdpAddress from_address);
+		 UdpAddress from_address,
+		 bool isRequestFromTrapPort);
 
   /**
    * Tests if the given buffer contains a SNMPv3-Message. The buffer is
@@ -404,13 +406,15 @@ class DLLOPT v3MP
    * @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
+   * @param isRequestFromTrapPort - True if request arrived on the trap port
    *
    * @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);
+		  UdpAddress &destination, Snmp *snmp_session,
+		  bool isRequestFromTrapPort);
 
 
 
diff --git a/include/snmp_pp/snmpmsg.h b/include/snmp_pp/snmpmsg.h
index 897f253..bb32b62 100644
--- a/include/snmp_pp/snmpmsg.h
+++ b/include/snmp_pp/snmpmsg.h
@@ -116,12 +116,15 @@ class DLLOPT SnmpMessage
                     OctetStr *security_name, // optional v3
                     long int *security_model,
 		    UdpAddress *from_addr,
-                    Snmp *snmp_session);
+                    Snmp *snmp_session,
+		    bool isRequestFromTrapPort = false);
  public:
 	int unload( Pdu &pdu,                    // Pdu returned
                     OctetStr &community,         // community name
-                    snmp_version &version)       // version
-	  { return unload(pdu, community, version, 0, 0, 0, 0, 0); };
+                    snmp_version &version,       // version
+		    bool isRequestFromTrapPort = false)
+	{ return unload(pdu, community, version, 0, 0, 0, 0, 0,
+			isRequestFromTrapPort); };
 
 
 #ifdef _SNMPv3
@@ -138,7 +141,8 @@ class DLLOPT SnmpMessage
                       OctetStr &security_name,   // optional v3
                       long int &security_model,
 		      UdpAddress &from_addr,
-                      Snmp &snmp_session);
+                      Snmp &snmp_session,
+		      bool isRequestFromTrapPort = false);
 
         // returns TRUE if the message in the buffer is a v3 message
         bool is_v3_message() {return v3MP::is_v3_msg(databuff, (int)bufflen);};
diff --git a/src/mp_v3.cpp b/src/mp_v3.cpp
index 0ca4d98..e2003cd 100644
--- a/src/mp_v3.cpp
+++ b/src/mp_v3.cpp
@@ -710,7 +710,8 @@ int v3MP::remove_engine_id(const OctetStr &engine_id)
 int v3MP::send_report(unsigned char* scopedPDU, int scopedPDULength,
 		      struct snmp_pdu *pdu, int errorCode, int sLevel,
 		      int sModel, OctetStr &sName,
-		      UdpAddress &destination, Snmp *snmp_session)
+		      UdpAddress &destination, Snmp *snmp_session,
+		      bool isRequestFromTrapPort)
 {
   debugprintf(2, "v3MP::send_report: Sending report message.");
 
@@ -862,6 +863,11 @@ int v3MP::send_report(unsigned char* scopedPDU, int scopedPDULength,
     if (snmp_session->get_eventListHolder()->notifyEventList())
       send_fd = snmp_session->get_eventListHolder()->notifyEventList()->get_notify_fd();
   }
+  else if (isRequestFromTrapPort == true)
+  {
+    if (snmp_session->get_eventListHolder()->notifyEventList())
+      send_fd = snmp_session->get_eventListHolder()->notifyEventList()->get_notify_fd();
+  }
 
   status = snmp_session->send_raw_data(sendbuffer.get_ptr(),
                                        (size_t)sendbufferlen,// pdu to send
@@ -888,7 +894,8 @@ int v3MP::snmp_parse(Snmp *snmp_session,
                      long     &securityLevel,
                      long     &msgSecurityModel,
                      snmp_version &spp_version,
-                     UdpAddress from_address)
+                     UdpAddress from_address,
+		     bool isRequestFromTrapPort)
 {
   debugprintf(3, "mp is parsing incoming message:");
   debughexprintf(25, inBuf, inBufLength);
@@ -1107,7 +1114,8 @@ int v3MP::snmp_parse(Snmp *snmp_session,
 
       send_report(scopedPDUPtr, scopedPDULength, pdu, errorCode,
 		  securityLevel, msgSecurityModel, securityName,
-		  from_address, snmp_session);
+		  from_address, snmp_session, isRequestFromTrapPort);
+
       clear_pdu(pdu, true);   // Clear pdu and free all content AND IDs!
     }
     else {
@@ -1211,7 +1219,8 @@ int v3MP::snmp_parse(Snmp *snmp_session,
 
 	    send_report(0, MAX_SNMP_PACKET, pdu, SNMPv3_MP_INVALID_ENGINEID,
 			SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV, msgSecurityModel,
-			securityName, from_address, snmp_session);
+			securityName, from_address, snmp_session,
+			isRequestFromTrapPort);
 	    clear_pdu(pdu, true);  // Clear pdu and free all content AND IDs!
 	  }
 	  else
diff --git a/src/snmpmsg.cpp b/src/snmpmsg.cpp
index a1036fc..0e857f9 100644
--- a/src/snmpmsg.cpp
+++ b/src/snmpmsg.cpp
@@ -202,11 +202,13 @@ int SnmpMessage::unloadv3( Pdu &pdu,                // Pdu returned
                            OctetStr &security_name, // optional v3
                            long int &security_model,
                            UdpAddress &from_addr,
-			   Snmp &snmp_session)
+			   Snmp &snmp_session,
+			   bool isRequestFromTrapPort)
 {
   OctetStr tmp;
   return unload(pdu, tmp, version, &engine_id,
-                &security_name, &security_model, &from_addr, &snmp_session);
+                &security_name, &security_model, &from_addr, &snmp_session,
+		isRequestFromTrapPort);
 }
 
 #endif
@@ -544,7 +546,8 @@ int SnmpMessage::unload(Pdu &pdu,                 // Pdu object
                         OctetStr *security_name,  // optional v3
                         long int *security_model,
                         UdpAddress *from_addr,
-                        Snmp *snmp_session)
+                        Snmp *snmp_session,
+			bool isRequestFromTrapPort)
 {
   pdu.clear();
 
@@ -565,7 +568,8 @@ int SnmpMessage::unload(Pdu &pdu,                 // Pdu object
     status = v3MP::I->snmp_parse(snmp_session, raw_pdu,
                          databuff, (int)bufflen, *engine_id,
                          *security_name, context_engine_id, context_name,
-                         security_level, *security_model, version, *from_addr);
+			 security_level, *security_model, version, *from_addr,
+			 isRequestFromTrapPort);
     if (status != SNMPv3_MP_OK) {
       pdu.set_request_id( raw_pdu->reqid);
       pdu.set_type( raw_pdu->command);
diff --git a/src/uxsnmp.cpp b/src/uxsnmp.cpp
index 6c5c792..19cb767 100644
--- a/src/uxsnmp.cpp
+++ b/src/uxsnmp.cpp
@@ -400,14 +400,15 @@ int receive_snmp_response(SnmpSocket sock, Snmp &snmp_session,
   {
     int returncode = snmpmsg.unloadv3(pdu, version, engine_id,
                                       security_name, security_model,
-                                      fromaddress, snmp_session);
+                                      fromaddress, snmp_session, false);
     if (returncode != SNMP_CLASS_SUCCESS)
       return returncode;
   }
   else
   {
 #endif
-    int returncode = snmpmsg.unload( pdu, community_name, version);
+	  int returncode = snmpmsg.unload( pdu, community_name, version,
+					   false);
     if (returncode != SNMP_CLASS_SUCCESS)
       return SNMP_CLASS_ERROR;
 #ifdef _SNMPv3
@@ -528,14 +529,14 @@ int receive_snmp_notification(SnmpSocket sock, Snmp &snmp_session,
   {
     int returncode = snmpmsg.unloadv3(pdu, version, engine_id,
                                       security_name, security_model,
-                                      fromaddress, snmp_session);
+                                      fromaddress, snmp_session, true);
     if (returncode != SNMP_CLASS_SUCCESS)
       return returncode;
   }
   else
   {
 #endif
-    int returncode = snmpmsg.unload( pdu, community_name, version);
+	  int returncode = snmpmsg.unload( pdu, community_name, version, true);
     if (returncode != SNMP_CLASS_SUCCESS)
       return SNMP_CLASS_ERROR;
 #ifdef _SNMPv3
-- 
1.5.5.6


--Dxnq1zWXvFF0Q93v--



More information about the AGENTPP mailing list