Hi all

The following small patch allows a wildcard context "*" be used.
That way an agent/proxy that responds to a large number of contexts
can be used in a more lightweight manner.

Regards

Pantelis

PS. This is my first net-snmp patch, so if it's a stupid idea, I don't
mind being told :)

-----------------------------------------------------

 agent_registry.c         |   12 ++++++++++--
 mibgroup/agentx/master.c |    9 +++++++--
 2 files changed, 17 insertions(+), 4 deletions(-)

-----------------------------------------------------

diff -ruN net-snmp-cvs-MAIN_20050927_0437-original/agent/agent_registry.c net-snmp-cvs-MAIN_20050927_0437/agent/agent_registry.c
--- net-snmp-cvs-MAIN_20050927_0437-original/agent/agent_registry.c	2005-08-18 11:37:07.000000000 +0300
+++ net-snmp-cvs-MAIN_20050927_0437/agent/agent_registry.c	2005-09-28 12:40:19.000000000 +0300
@@ -143,19 +143,27 @@
 netsnmp_subtree_find_first(const char *context_name)
 {
     subtree_context_cache *ptr;
+    int is_wildcard;
 
     if (!context_name) {
         context_name = "";
     }
 
+    is_wildcard = strcmp(context_name, "*") == 0;
+
     DEBUGMSGTL(("subtree", "looking for subtree for context: \"%s\"\n", 
 		context_name));
     for (ptr = context_subtrees; ptr != NULL; ptr = ptr->next) {
-        if (ptr->context_name != NULL && 
-	    strcmp(ptr->context_name, context_name) == 0) {
+	if (ptr->context_name == NULL)
+		continue;
+        if (strcmp(ptr->context_name, context_name) == 0) {
             DEBUGMSGTL(("subtree", "found one for: \"%s\"\n", context_name));
             return ptr->first_subtree;
         }
+	if (!is_wildcard && strcmp(ptr->context_name, "*") == 0) {
+            DEBUGMSGTL(("subtree", "found one for: \"%s\" (*)\n", context_name));
+            return ptr->first_subtree;
+	}
     }
     DEBUGMSGTL(("subtree", "didn't find a subtree for context: \"%s\"\n", 
 		context_name));
diff -ruN net-snmp-cvs-MAIN_20050927_0437-original/agent/mibgroup/agentx/master.c net-snmp-cvs-MAIN_20050927_0437/agent/mibgroup/agentx/master.c
--- net-snmp-cvs-MAIN_20050927_0437-original/agent/mibgroup/agentx/master.c	2005-08-18 11:37:07.000000000 +0300
+++ net-snmp-cvs-MAIN_20050927_0437/agent/mibgroup/agentx/master.c	2005-09-28 12:45:59.000000000 +0300
@@ -440,6 +440,7 @@
     netsnmp_request_info *request = requests;
     netsnmp_pdu    *pdu;
     void           *cb_data;
+    const char     *cxtname;
 
     DEBUGMSGTL(("agentx/master",
                 "agentx master handler starting, mode = 0x%02x\n",
@@ -501,8 +502,12 @@
     pdu->transid = reqinfo->asp->pdu->transid;
     pdu->sessid = ax_session->subsession->sessid;
     if (reginfo->contextName) {
-        pdu->community = strdup(reginfo->contextName);
-        pdu->community_len = strlen(reginfo->contextName);
+
+        cxtname = reqinfo->asp->pdu->contextName && strlen(reqinfo->asp->pdu->contextName) > 0 ?
+			reqinfo->asp->pdu->contextName : reginfo->contextName;
+
+        pdu->community = strdup(cxtname);
+        pdu->community_len = strlen(cxtname);
         pdu->flags |= AGENTX_MSG_FLAG_NON_DEFAULT_CONTEXT;
     }
     if (ax_session->subsession->flags & AGENTX_MSG_FLAG_NETWORK_BYTE_ORDER)

Reply via email to