Patch 3042765 breaks synchronous handling of a remote client disconnect
for a tcp session, causing the client to be stuck inside a select() call
waiting for data that will never come.

CHANGES: snmplib: PATCH 3042765: from mehaf: make snmp_synch_response_cb() 
re-entrant

Here are debug traces for behavior before and after this patch:

BEFORE
------
registered debug token sess, 1
2010-08-24 14:33:49 sess_process_packet: sending message id#931770471 
reqid#1091566763 len 69
2010-08-24 14:33:49 Sending 69 bytes to TLSTCP: unknown
2010-08-24 14:33:53 sess_select: for single session: 8 
2010-08-24 14:34:25 sess_read: perform callback with op=DISCONNECT
2010-08-24 14:35:00 sess_read: fd 8 closed
2010-08-24 14:35:07 failed rfc5343 contextEngineID probing
2010-08-24 14:35:07 snmpset: Session abort failure
** app exits

AFTER
-----
registered debug token sess, 1
2010-08-24 14:36:17 sess_process_packet: sending message id#774987689 
reqid#1622709773 len 69
2010-08-24 14:36:17 Sending 69 bytes to TLSTCP: unknown
2010-08-24 14:36:17 sess_select: for single session: 8 
2010-08-24 14:36:59 sess_read: fd 8 closed
2010-08-24 14:37:02 sess_select: for single session: delete
2010-08-24 14:37:02 sess_select: for single session: 
2010-08-24 14:37:02 sess_select: blocking:no session requests or alarms.
** app hangs

Basically the change in session handling results in the session callback
pointer being NULL, so the disconnect callback is never sent to the client.

The original patch is attached, and I think it should be reversed ASAP.

#registered debug token sess, 1
#2010-08-24 14:33:49 sess_process_packet: sending message id#931770471 reqid#1091566763 len 69
#2010-08-24 14:33:49 
#Sending 69 bytes to TLSTCP: unknown
#2010-08-24 14:33:49 0000: 30 43 02 01  03 30 11 02  04 37 89 B0  67 02 03 00    0C...0...7..g...
#2010-08-24 14:33:49 0016: FF E3 04 01  04 02 01 04  04 00 30 29  04 05 80 00    ..........0)....
#2010-08-24 14:33:49 0032: 00 00 06 04  00 A0 1E 02  04 41 0F FC  AB 02 01 00    .........A......
#2010-08-24 14:33:49 0048: 02 01 00 30  10 30 0E 06  0A 2B 06 01  06 03 0A 02    ...0.0...+......
#2010-08-24 14:33:49 0064: 01 01 00 05  00                                       .....
#2010-08-24 14:33:49 
#2010-08-24 14:33:53 sess_select: for single session: 8 
#2010-08-24 14:34:25 sess_read: perform callback with op=DISCONNECT
#2010-08-24 14:35:00 sess_read: fd 8 closed
#2010-08-24 14:35:07 failed rfc5343 contextEngineID probing
#2010-08-24 14:35:07 snmpset: Session abort failure
#
#registered debug token sess, 1
#2010-08-24 14:36:17 sess_process_packet: sending message id#774987689 reqid#1622709773 len 69
#2010-08-24 14:36:17 
#Sending 69 bytes to TLSTCP: unknown
#2010-08-24 14:36:17 0000: 30 43 02 01  03 30 11 02  04 2E 31 5F  A9 02 03 00    0C...0....1_....
#2010-08-24 14:36:17 0016: FF E3 04 01  04 02 01 04  04 00 30 29  04 05 80 00    ..........0)....
#2010-08-24 14:36:17 0032: 00 00 06 04  00 A0 1E 02  04 60 B8 96  0D 02 01 00    .........`......
#2010-08-24 14:36:17 0048: 02 01 00 30  10 30 0E 06  0A 2B 06 01  06 03 0A 02    ...0.0...+......
#2010-08-24 14:36:17 0064: 01 01 00 05  00                                       .....
#2010-08-24 14:36:17 
#2010-08-24 14:36:17 sess_select: for single session: 8 
#2010-08-24 14:36:59 sess_read: fd 8 closed
#2010-08-24 14:37:02 sess_select: for single session: delete
#2010-08-24 14:37:02 sess_select: for single session: 
#2010-08-24 14:37:02 sess_select: blocking:no session requests or alarms.
#
commit efdb1a0e955540b5f1b1e67ca7f25f50d94c1e9e
Author: hardaker <harda...@06827809-a52a-0410-b366-d66718629ded>
Date:   Thu Aug 19 20:14:53 2010 +0000

    CHANGES: snmplib: PATCH 3042765: from mehaf: make snmp_synch_response_cb() re-entrant
    
    git-svn-id: https://net-snmp.svn.sourceforge.net/svnroot/net-snmp/tr...@19341 06827809-a52a-0410-b366-d66718629ded

diff --git a/net-snmp/snmplib/snmp_client.c b/net-snmp/snmplib/snmp_client.c
index 0173a39..6103937 100644
--- a/net-snmp/snmplib/snmp_client.c
+++ b/net-snmp/snmplib/snmp_client.c
@@ -989,8 +989,6 @@ snmp_synch_response_cb(netsnmp_session * ss,
                        netsnmp_pdu **response, snmp_callback pcb)
 {
     struct synch_state lstate, *state;
-    snmp_callback   cbsav;
-    void           *cbmagsav;
     int             numfds, count;
     fd_set          fdset;
     struct timeval  timeout, *tvp;
@@ -998,12 +996,8 @@ snmp_synch_response_cb(netsnmp_session * ss,
 
     memset((void *) &lstate, 0, sizeof(lstate));
     state = &lstate;
-    cbsav = ss->callback;
-    cbmagsav = ss->callback_magic;
-    ss->callback = pcb;
-    ss->callback_magic = (void *) state;
 
-    if ((state->reqid = snmp_send(ss, pdu)) == 0) {
+    if ((state->reqid = snmp_async_send(ss, pdu, pcb, (void *) state)) == 0) {
         snmp_free_pdu(pdu);
         state->status = STAT_ERROR;
     } else
@@ -1058,8 +1052,6 @@ snmp_synch_response_cb(netsnmp_session * ss,
         }
     }
     *response = state->pdu;
-    ss->callback = cbsav;
-    ss->callback_magic = cbmagsav;
     return state->status;
 }
 
@@ -1076,8 +1068,6 @@ snmp_sess_synch_response(void *sessp,
 {
     netsnmp_session *ss;
     struct synch_state lstate, *state;
-    snmp_callback   cbsav;
-    void           *cbmagsav;
     int             numfds, count;
     fd_set          fdset;
     struct timeval  timeout, *tvp;
@@ -1090,12 +1080,9 @@ snmp_sess_synch_response(void *sessp,
 
     memset((void *) &lstate, 0, sizeof(lstate));
     state = &lstate;
-    cbsav = ss->callback;
-    cbmagsav = ss->callback_magic;
-    ss->callback = snmp_synch_input;
-    ss->callback_magic = (void *) state;
 
-    if ((state->reqid = snmp_sess_send(sessp, pdu)) == 0) {
+    if ((state->reqid = snmp_sess_async_send(sessp, pdu,
+                                             snmp_synch_input, state)) == 0) {
         snmp_free_pdu(pdu);
         state->status = STAT_ERROR;
     } else
@@ -1142,8 +1129,6 @@ snmp_sess_synch_response(void *sessp,
             }
     }
     *response = state->pdu;
-    ss->callback = cbsav;
-    ss->callback_magic = cbmagsav;
     return state->status;
 }
 
------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to