# Picked up from upstream. The fix should be available in the next release of Net-snmp.
index a04b18a..82c1fbf 100644
@@ -161,6 +161,7 @@ close_agentx_session(netsnmp_session * session, int sessid)
for (sp = session->subsession; sp != NULL; sp = sp->next) {
if (sp->sessid == sessid) {
+ netsnmp_remove_delegated_requests_for_session(sp);
unregister_mibs_by_session(sp);
unregister_index_by_session(sp);
snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
diff --git a/agent/snmp_agent.c b/agent/snmp_agent.c
index c655900..466ec4c 100644
--- net-snmp-5.7.2.1/agent/snmp_agent.c Wed Feb 19 16:36:42 2014
+++ net-snmp-5.7.2.1/agent/snmp_agent.c Thu Oct 30 02:36:23 2014
@@ -1409,6 +1409,7 @@
asp->treecache_num = -1;
asp->treecache_len = 0;
asp->reqinfo = SNMP_MALLOC_TYPEDEF(netsnmp_agent_request_info);
+ asp->flags = SNMP_AGENT_FLAGS_NONE;
DEBUGMSGTL(("verbose:asp", "asp %p reqinfo %p created\n",
asp, asp->reqinfo));
@@ -1457,6 +1458,9 @@
if (NULL == asp->treecache)
return 0;
+
+ if (asp->flags & SNMP_AGENT_FLAGS_CANCEL_IN_PROGRESS)
+ return 0;
for (i = 0; i <= asp->treecache_num; i++) {
for (request = asp->treecache[i].requests_begin; request;
@@ -1535,39 +1539,48 @@
netsnmp_remove_delegated_requests_for_session(netsnmp_session *sess)
{
netsnmp_agent_session *asp;
- int count = 0;
+ int total_count = 0;
for (asp = agent_delegated_list; asp; asp = asp->next) {
/*
* check each request
*/
+ int i;
+ int count = 0;
netsnmp_request_info *request;
- for(request = asp->requests; request; request = request->next) {
- /*
- * check session
- */
- netsnmp_assert(NULL!=request->subtree);
- if(request->subtree->session != sess)
- continue;
+ for (i = 0; i <= asp->treecache_num; i++) {
+ for (request = asp->treecache[i].requests_begin; request;
+ request = request->next) {
+ /*
+ * check session
+ */
+ netsnmp_assert(NULL!=request->subtree);
+ if(request->subtree->session != sess)
+ continue;
- /*
- * matched! mark request as done
- */
- netsnmp_request_set_error(request, SNMP_ERR_GENERR);
- ++count;
+ /*
+ * matched! mark request as done
+ */
+ netsnmp_request_set_error(request, SNMP_ERR_GENERR);
+ ++count;
+ }
}
+ if (count) {
+ asp->flags |= SNMP_AGENT_FLAGS_CANCEL_IN_PROGRESS;
+ total_count += count;
+ }
}
/*
* if we found any, that request may be finished now
*/
- if(count) {
+ if(total_count) {
DEBUGMSGTL(("snmp_agent", "removed %d delegated request(s) for session "
- "%8p\n", count, sess));
- netsnmp_check_outstanding_agent_requests();
+ "%08p\n", total_count, sess));
+ netsnmp_check_delegated_requests();
}
- return count;
+ return total_count;
}
int
@@ -2739,19 +2752,11 @@
return final_status;
}
-/*
- * loop through our sessions known delegated sessions and check to see
- * if they've completed yet. If there are no more delegated sessions,
- * check for and process any queued requests
- */
void
-netsnmp_check_outstanding_agent_requests(void)
+netsnmp_check_delegated_requests(void)
{
netsnmp_agent_session *asp, *prev_asp = NULL, *next_asp = NULL;
- /*
- * deal with delegated requests
- */
for (asp = agent_delegated_list; asp; asp = next_asp) {
next_asp = asp->next; /* save in case we clean up asp */
if (!netsnmp_check_for_delegated(asp)) {
@@ -2790,8 +2795,24 @@
prev_asp = asp;
}
}
+}
+/*
+ * loop through our sessions known delegated sessions and check to see
+ * if they've completed yet. If there are no more delegated sessions,
+ * check for and process any queued requests
+ */
+void
+netsnmp_check_outstanding_agent_requests(void)
+{
+ netsnmp_agent_session *asp;
+
/*
+ * deal with delegated requests
+ */
+ netsnmp_check_delegated_requests();
+
+ /*
* if we are processing a set and there are more delegated
* requests, keep waiting before getting to queued requests.
*/
@@ -2819,7 +2840,8 @@
netsnmp_processing_set = netsnmp_agent_queued_list;
DEBUGMSGTL(("snmp_agent", "SET request remains queued while "
- "delegated requests finish, asp = %8p\n", asp));
+ "delegated requests finish, asp = %08p\n",
+ agent_delegated_list));
break;
}
#endif /* NETSNMP_NO_WRITE_SUPPORT */
@@ -2880,6 +2902,10 @@
case SNMP_MSG_GETBULK:
case SNMP_MSG_GETNEXT:
netsnmp_check_all_requests_status(asp, 0);
+ if (asp->flags & SNMP_AGENT_FLAGS_CANCEL_IN_PROGRESS) {
+ DEBUGMSGTL(("snmp_agent","canceling next walk for asp %p\n", asp));
+ break;
+ }
handle_getnext_loop(asp);
if (netsnmp_check_for_delegated(asp) &&
netsnmp_check_transaction_id(asp->pdu->transid) !=
index fd84f0f..efbeb5b 100644
@@ -32,6 +32,9 @@ extern "C" {
#define SNMP_MAX_PDU_SIZE 64000 /* local constraint on PDU size sent by agent
* (see also SNMP_MAX_MSG_SIZE in snmp_api.h) */
+#define SNMP_AGENT_FLAGS_NONE 0x0
+#define SNMP_AGENT_FLAGS_CANCEL_IN_PROGRESS 0x1
+
/*
* If non-zero, causes the addresses of peers to be logged when receptions
* occur.
@@ -197,6 +200,7 @@ extern "C" {
int treecache_num; /* number of current cache entries */
netsnmp_cachemap *cache_store;
int vbcount;
+ int flags;
} netsnmp_agent_session;
/*
@@ -231,6 +235,7 @@ extern "C" {
int init_master_agent(void);
void shutdown_master_agent(void);
int agent_check_and_process(int block);
+ void netsnmp_check_delegated_requests(void);
void netsnmp_check_outstanding_agent_requests(void);
int netsnmp_request_set_error(netsnmp_request_info *request,