Wes Hardaker wrote:
On Wed, 28 Sep 2005 13:00:10 +0300, Pantelis Antoniou <[EMAIL PROTECTED]> said:
Pantelis> The following small patch allows a wildcard context "*" be used.
Pantelis> That way an agent/proxy that responds to a large number of contexts
Pantelis> can be used in a more lightweight manner.
I don't mind the idea at all, and in fact it's been discussed before
but no one has ever implemented it! However, doesn't the code
submitted match against the * if it's earlier in the list even if
there may be something more specific later on? IE, if there was a
true registration of the context "foo" and "*" and the incoming
request was of context "bar" then it would only match "*", but if it
was incoming of "foo" it could get either depending on the ordering of
the list. I'd argue that we should look for an exact match before
returning the "*" match.
Hi Wes
Here's an updated version of the patch, that does just that.
Due to the context possibly being empty, there is another pass
since I'd like the wildcard "*" context matching that too.
Arguably the final solution would be matching using a regural
expression, but the closeness of the match is a very tough
subject for the standard unix regural expression library.
Haven't got the time anyway :)
Regards
Pantelis
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-29 10:13:06.000000000 +0300
@@ -150,13 +150,43 @@
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) {
- DEBUGMSGTL(("subtree", "found one for: \"%s\"\n", context_name));
- return ptr->first_subtree;
- }
+
+ /* first find specific match (with a context present) */
+ if (context_name[0] != '\0') {
+ for (ptr = context_subtrees; ptr != NULL; ptr = ptr->next) {
+ 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;
+ }
+ }
+ }
+
+ /* search for wildcard match, if context is not wildcard */
+ if (strcmp(context_name, "*") != 0) {
+ for (ptr = context_subtrees; ptr != NULL; ptr = ptr->next) {
+ if (ptr->context_name == NULL)
+ continue;
+ if (strcmp(ptr->context_name, "*") == 0) {
+ DEBUGMSGTL(("subtree", "found one for: \"%s\" (*)\n", context_name));
+ return ptr->first_subtree;
+ }
+ }
+ }
+
+ /* last ditch attempt if context is empty */
+ if (context_name[0] == '\0') {
+ for (ptr = context_subtrees; ptr != NULL; ptr = ptr->next) {
+ if (ptr->context_name == NULL)
+ continue;
+ if (ptr->context_name[0] == '\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));
return NULL;
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)