On tis, 2008-05-27 at 16:00 +0100, Dave Shield wrote:
> 2008/5/19 Dave Shield <[EMAIL PROTECTED]>:
> > 2008/5/18 Magnus Fromreide <[EMAIL PROTECTED]>:
> >> The interesting thing from my point of view is that scalar registers
> >> <oid> and answers with the value for <oid>.0 and with NO_SUCH_OBJECT
> >> otherwise
> >
> > Does it?  I must check and fix that.
> > It ought to return noSuchInstance for <oid>.<non-0> requests.
> >
> >>      whereas scalar_group registers <oid> and answers with the
> >> value for <oid>.<index>.0 and with NO_SUCH_OBJECT otherwise.
> >
> > That ought to return noSuchInstance for <oid>.<valid>.<non-0>
> > and noSuchObject for <oid>.<non-valid>.*
> 
> Hmmm...
> I've just checked the behaviour of these two helpers,
> and they both seem to behave as expected.
> 
>     snmpget  ...   icmpOutMsgs.1
> and
>     snmpget  ...   nsDebugEnabled.1
> 
> both return noSuchInstance.
> Running "snmpd -Dhelper:scalar ..."  confirms that these requests
> are being processed through the scalar/scalare_group helpers.

Yes - it seems that in the GET/SET case

      * scalar_group_helper_handler sets noSuchObject on anything not in
        the <oid>.<valid-range> and passes everything else to
        scalar_helper_handler after rootoid massage.
      * scalar_helper_handler sets noSuchObject on anything not in
        <oid>.<specific> and passes everything else to
        instance_helper_handler after more rootoid massage.
      * instance_helper_handler sets noSuch instance on anything
        different from <oid>.<current>.0 and passes everything else to
        the user handler.

and in the GET_NEXT case

      * scalar_group_helper_handler iterates through the group massaging
        rootoid and calling scalar_helper_handler for each loop.
      * scalar_helper_handler massages rootoid further and calls
        instance_handler.
      * instance_handler changes the GET_NEXT to a GET and calls the
        user handler.

In this stack I think that the call to scalar_helper_handler is
unnecessary as it is used only to add a trailing 0 to the rootoid that
is sent from the scalar_group_helper.
The scalar_group massage gurantees that scalar check always pass and
thus the massage in scalar_group could be adopted to fit instance as in
the attached patch.

/MF

Index: clean/agent/helpers/scalar_group.c
===================================================================
--- clean.orig/agent/helpers/scalar_group.c	2008-05-27 19:48:12.000000000 +0200
+++ clean/agent/helpers/scalar_group.c	2008-05-27 20:32:43.000000000 +0200
@@ -12,9 +12,8 @@
 #include <strings.h>
 #endif
 
-#include <net-snmp/agent/scalar.h>
+#include <net-snmp/agent/instance.h>
 #include <net-snmp/agent/serialize.h>
-#include <net-snmp/agent/read_only.h>
 
 /** @defgroup scalar_group_group scalar_group
  *  Process groups of scalars.
@@ -49,7 +48,6 @@
                               oid first, oid last)
 {
     netsnmp_inject_handler(reginfo, netsnmp_get_instance_handler());
-    netsnmp_inject_handler(reginfo, netsnmp_get_scalar_handler());
     netsnmp_inject_handler(reginfo, netsnmp_get_scalar_group_handler(first, last));
     return netsnmp_register_serialize(reginfo);
 }
@@ -129,12 +127,13 @@
                 netsnmp_set_request_error(reqinfo, requests, ret);
                 return SNMP_ERR_NOERROR;
 	    }
-            root_tmp[reginfo->rootoid_len++] = subid;
+            root_tmp[reginfo->rootoid_len] = subid;
+            reginfo->rootoid_len += 2;
             reginfo->rootoid = root_tmp;
             ret = netsnmp_call_next_handler(handler, reginfo, reqinfo,
                                             requests);
             reginfo->rootoid = root_save;
-            reginfo->rootoid_len--;
+            reginfo->rootoid_len -= 2;
             return ret;
         }
         break;
@@ -161,7 +160,8 @@
 	if (subid > sgroup->ubound)
             return SNMP_ERR_NOERROR;
         
-        root_tmp[reginfo->rootoid_len++] = subid;
+        root_tmp[reginfo->rootoid_len] = subid;
+        reginfo->rootoid_len += 2;
         reginfo->rootoid = root_tmp;
         ret = netsnmp_call_next_handler(handler, reginfo, reqinfo,
                                             requests);
@@ -174,12 +174,12 @@
              requests->requestvb->type == SNMP_NOSUCHOBJECT ||
              requests->requestvb->type == SNMP_NOSUCHINSTANCE)) {
             snmp_set_var_objid(requests->requestvb,
-                               reginfo->rootoid, reginfo->rootoid_len);
-            requests->requestvb->name[reginfo->rootoid_len-1] = ++subid;
+                               reginfo->rootoid, reginfo->rootoid_len - 1);
+            requests->requestvb->name[reginfo->rootoid_len - 2] = ++subid;
             requests->requestvb->type = ASN_PRIV_RETRY;
         }
         reginfo->rootoid = root_save;
-        reginfo->rootoid_len--;
+        reginfo->rootoid_len -= 2;
         return ret;
     }
     /*
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to