On Fri, Feb 10, 2012 at 7:16 PM, Bart Van Assche <[email protected]> wrote:

> However, I found this in RFC 3414 (http://tools.ietf.org/html/rfc3414):
>
>    When an SNMP engine is first installed, it sets its local values of
>    snmpEngineBoots and snmpEngineTime to zero.  If snmpEngineTime ever
>    reaches its maximum value (2147483647), then snmpEngineBoots is
>    incremented as if the SNMP engine has re-booted and snmpEngineTime is
>    reset to zero and starts incrementing again.
>
> I'll see what needs to be changed in the patch to make it compliant with
> RFC 3414.
>

Any comments about the follow-up patch below ?

---
 snmplib/snmpv3.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/snmplib/snmpv3.c b/snmplib/snmpv3.c
index e98a3e9..01941e1 100644
--- a/snmplib/snmpv3.c
+++ b/snmplib/snmpv3.c
@@ -1160,8 +1160,14 @@ snmpv3_generate_engineID(size_t * length)
 }                               /* end snmpv3_generate_engineID() */

 /**
- * Return the number of seconds since the SNMPv3 engine last incremented
- * engine_boots.
+ * Return the value of snmpEngineTime. According to RFC 3414 snmpEngineTime
+ * is a 31-bit counter. engineBoots must be incremented every time that
+ * counter wraps around.
+ *
+ * @see See also <a href="http://tools.ietf.org/html/rfc3414";>RFC 3414</a>.
+ *
+ * @note It is assumed that this function is called at least once every
+ *   2**31 seconds.
  */
 u_long
 snmpv3_local_snmpEngineTime(void)
@@ -1170,10 +1176,16 @@ snmpv3_local_snmpEngineTime(void)
     netsnmp_feature_require(calculate_sectime_diff)
 #endif /* NETSNMP_FEATURE_CHECKING */

+    static uint32_t last_engineTime;
     struct timeval  now;
+    uint32_t engineTime;

     netsnmp_get_monotonic_clock(&now);
-    return calculate_sectime_diff(&now, &snmpv3starttime);
+    engineTime = calculate_sectime_diff(&now, &snmpv3starttime) &
0x7fffffffL;
+    if (engineTime < last_engineTime)
+        engineBoots++;
+    last_engineTime = engineTime;
+    return engineTime;
 }
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to