program coredump because "callback_magic" behavior was changed since 5.6.x

Hao Chen <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <CY1PR16MB0395D731A28F1A54CED28E58B2140@CY1PR16MB0395.namprd16.prod.outlook.com>
Hi All:



1.

My program need to use "callback" function and pass something back.

So, I use "callback_magic" to store an C++ object address.

So, I can get my C++ object and use it my callback function.



My code looks like:

================================

bool CERSnmpSession::open()

{

.....

   m_sessionData.callback = callBack;

   m_sessionData.callback_magic = this;

.....

}



int SNMPSession::callBack(

    int operation,

    struct snmp_session *ses,

    int reqid,

    struct snmp_pdu *pdu,

    void* magic)

{

    SNMPSession* ss = static_cast<SNMPSession*>(magic);

.....

}





2.

The above code works well with net-snmp 5.4.4.

But it coredump with net-snmp 5.7.3 while I set correct username & wrong password to do negative test.



(1).

The reason is that "_sess_process_packet()" (in snmp_api.c in 5.7.3) does:

      if (callback == NULL

                 || callback(NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE, sp,

                                    pdu->reqid, pdu, magic) == 1) {

               if (pdu->command == SNMP_MSG_REPORT) {

                 if (sp->s_snmp_errno == SNMPERR_NOT_IN_TIME_WINDOW ||

                     snmpv3_get_report_type(pdu) ==

                     SNMPERR_NOT_IN_TIME_WINDOW) {

                   /*

                    * trigger immediate retry on recoverable Reports

                    * * (notInTimeWindow), incr_retries == TRUE to prevent

                    * * inifinite resend

                    */

                   if (rp->retries <= sp->retries) {

                     snmp_resend_request(slp, rp, TRUE);

                     break;

                   } else {

                     /* We're done with retries, so no longer waiting for a response */

                     if (magic) {

                              ((struct synch_state*)magic)->waiting = 0;

                     }

                   }

                 } else {

                   if (SNMPV3_IGNORE_UNAUTH_REPORTS) {

                     break;

                   } else { /* Set the state to no longer be waiting, since we're done with retries */

                     if (magic) {

                              ((struct synch_state*)magic)->waiting = 0;  ====> culprit

                     }





(2).

I compared the same code in 5.4.4, it is:

      if (callback == NULL

                 || callback(NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE, sp,

                                    pdu->reqid, pdu, magic) == 1) {

               if (pdu->command == SNMP_MSG_REPORT) {

                 if (sp->s_snmp_errno == SNMPERR_NOT_IN_TIME_WINDOW ||

                     snmpv3_get_report_type(pdu) ==

                     SNMPERR_NOT_IN_TIME_WINDOW) {

                   /*

                    * trigger immediate retry on recoverable Reports

                    * * (notInTimeWindow), incr_retries == TRUE to prevent

                    * * inifinite resend

                    */

                   if (rp->retries <= sp->retries) {

                     snmp_resend_request(slp, rp, TRUE);

                     break;

                   }

                 } else {

                   if (SNMPV3_IGNORE_UNAUTH_REPORTS) {

                     break;

                   }

                 }





(3).

We can see 5.7.3 has extra "((struct synch_state*)magic)->waiting = 0;" than 5.4.4



3.

Can you please help me:

1). If I want to pass private stuff, shall I use "callback_magic" or "myvoid in struct snmp_session" to contain it?

    I tested by using "myvoid" instead of "callback_magic" to contain my private call back data. It works fine.



2). Since "callback_magic" was changed since net-snmp 5.6.x, will net-snmp change "myvoid" in future release?







Thanks and regards

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.