[quagga-dev 4624] Re: snmp neighbor states off by 1

Andrew J. Schorr aschorr at telemetry-investments.com
Mon Mar 12 16:45:36 GMT 2007


On Thu, Mar 08, 2007 at 04:41:40PM -0500, Andrew J. Schorr wrote:
> And ospf_snmp.c:ospfNbrEntry simply returns
> the nbr->state field.  So the values being reported
> by SNMP are now off by 1.  
> 
> Thoughts on the best way to fix?  We could either change
> the values in ospf_nsm.h to match the MIB, or we could
> translate our values inside ospf_snmp.c.  What seems
> best?  I'm guessing translation?

Does the attached patch make sense?  It's not terribly elegant,
but I think should do the trick.  Is there some header file we
could pull in where the official MIB values are defined?

Regards,
Andy
-------------- next part --------------
Index: ospfd/ospf_snmp.c
===================================================================
RCS file: /var/cvsroot/quagga/ospfd/ospf_snmp.c,v
retrieving revision 1.19
diff -b -u -p -r1.19 ospf_snmp.c
--- ospfd/ospf_snmp.c	12 Dec 2006 19:18:21 -0000	1.19
+++ ospfd/ospf_snmp.c	12 Mar 2007 16:41:47 -0000
@@ -2216,6 +2216,44 @@ ospfNbrLookup (struct variable *v, oid *
   return NULL;
 }
 
+/* map internal quagga neighbor states to official MIB values:
+
+ospfNbrState OBJECT-TYPE
+        SYNTAX   INTEGER    {
+                    down (1),
+                    attempt (2),
+                    init (3),
+                    twoWay (4),
+                    exchangeStart (5),
+                    exchange (6),
+                    loading (7),
+                    full (8)
+                  }
+*/
+static int32_t
+ospf_snmp_neighbor_state(u_char nst)
+{
+  switch (nst)
+    {
+    case NSM_Attempt:
+      return 2;
+    case NSM_Init:
+      return 3;
+    case NSM_TwoWay:
+      return 4;
+    case NSM_ExStart:
+      return 5;
+    case NSM_Exchange:
+      return 6;
+    case NSM_Loading:
+      return 7;
+    case NSM_Full:
+      return 8;
+    default:
+      return 1; /* down */
+    }
+}
+
 static u_char *
 ospfNbrEntry (struct variable *v, oid *name, size_t *length, int exact,
 	      size_t  *var_len, WriteMethod **write_method)
@@ -2254,7 +2292,7 @@ ospfNbrEntry (struct variable *v, oid *n
       return SNMP_INTEGER (nbr->priority);
       break;
     case OSPFNBRSTATE:
-      return SNMP_INTEGER (nbr->state);
+      return SNMP_INTEGER (ospf_snmp_neighbor_state(nbr->state));
       break;
     case OSPFNBREVENTS:
       return SNMP_INTEGER (nbr->state_change);


More information about the Quagga-dev mailing list