Browse Source

2005-09-29 Alain Ritoux <alain.ritoux@6wind.com>

    * lib/smux.[ch]: allow to retreive global OID (identified by <0
      namelen).
    * ospf_ism.c: generate SNMP traps on Interface state change
    * ospf_nsm.c: generate SNMP traps on Neighbour state change
    * ospf_snmp.[ch]: support for SNMP traps for interface and neighbours.
vincent 14 years ago
parent
commit
5e4914c31e
8 changed files with 185 additions and 8 deletions
  1. 5 0
      lib/ChangeLog
  2. 27 6
      lib/smux.c
  3. 2 2
      lib/smux.h
  4. 6 0
      ospfd/ChangeLog
  5. 15 0
      ospfd/ospf_ism.c
  6. 17 0
      ospfd/ospf_nsm.c
  7. 108 0
      ospfd/ospf_snmp.c
  8. 5 0
      ospfd/ospf_snmp.h

+ 5 - 0
lib/ChangeLog

@@ -1,3 +1,8 @@
+2005-09-29 Alain Ritoux <alain.ritoux@6wind.com>
+
+	* smux.[ch]: allow to retreive global OID (identified by <0
+	  namelen).
+
 2005-09-29 Paul Jakma <paul.jakma@sun.com>
 
 	* zebra.h: Solaris capabilities requires priv.h to be included.

+ 27 - 6
lib/smux.c

@@ -1065,13 +1065,34 @@ smux_trap (oid *name, size_t namelen,
       u_char val_type;
 
       /* Make OID. */
-      oid_copy (oid, name, namelen);
-      oid_copy (oid + namelen, trapobj[i].name, trapobj[i].namelen);
-      oid_copy (oid + namelen + trapobj[i].namelen, iname, inamelen);
-      oid_len = namelen + trapobj[i].namelen + inamelen;
+      if (trapobj[i].namelen > 0) 
+        {
+          oid_copy (oid, name, namelen);
+          oid_copy (oid + namelen, trapobj[i].name, trapobj[i].namelen);
+          oid_copy (oid + namelen + trapobj[i].namelen, iname, inamelen);
+          oid_len = namelen + trapobj[i].namelen + inamelen;
+        }
+      else 
+        {
+          oid_copy (oid, name, namelen);
+          oid_copy (oid + namelen, trapobj[i].name, trapobj[i].namelen * (-1));
+          oid_len = namelen + trapobj[i].namelen * (-1) ;
+        }
 
-      if (debug_smux)
-	smux_oid_dump ("Trap", oid, oid_len);
+      if (debug_smux) 
+        {
+          smux_oid_dump ("Trap", name, namelen);
+          if (trapobj[i].namelen < 0)
+            smux_oid_dump ("Trap", 
+                           trapobj[i].name, (- 1) * (trapobj[i].namelen));
+          else 
+            {
+              smux_oid_dump ("Trap", trapobj[i].name, (trapobj[i].namelen));
+              smux_oid_dump ("Trap", iname, inamelen);
+            }
+          smux_oid_dump ("Trap", oid, oid_len);
+          zlog_info ("BUFSIZ: %d // oid_len: %d", BUFSIZ, oid_len);
+      }
 
       ret = smux_get (oid, &oid_len, 1, &val_type, &val, &val_len);
 

+ 2 - 2
lib/smux.h

@@ -94,7 +94,7 @@ struct variable
   FindVarMethod *findVar;
 
   /* Suffix of the MIB. */
-  u_char namelen;
+  int namelen;
   oid name[MAX_OID_LEN];
 };
 
@@ -121,7 +121,7 @@ struct subtree
 struct trap_object
 {
   FindVarMethod *findVar;
-  u_char namelen;
+  int namelen;
   oid name[MAX_OID_LEN];
 };
 

+ 6 - 0
ospfd/ChangeLog

@@ -1,5 +1,11 @@
 2005-09-29 Alain Ritoux <alain.ritoux@6wind.com>
 
+	* ospf_ism.c: generate SNMP traps on Interface state change
+	* ospf_nsm.c: generate SNMP traps on Neighbour state change
+	* ospf_snmp.[ch]: support for SNMP traps for interface and neighbours.
+
+2005-09-29 Alain Ritoux <alain.ritoux@6wind.com>
+
 	* ospf_vty.c: forece default route LSA to be re_issued whenever
 	  cost is changed ( [no] ip ospf area XXX default-cost YYY)
 	  Support ignore-mtu option

+ 15 - 0
ospfd/ospf_ism.c

@@ -43,6 +43,7 @@
 #include "ospfd/ospf_packet.h"
 #include "ospfd/ospf_flood.h"
 #include "ospfd/ospf_abr.h"
+#include "ospfd/ospf_snmp.h"
 
 /* elect DR and BDR. Refer to RFC2319 section 9.4 */
 static struct ospf_neighbor *
@@ -552,6 +553,20 @@ ism_change_state (struct ospf_interface *oi, int state)
   oi->state = state;
   oi->state_change++;
 
+#ifdef HAVE_SNMP
+  /* Terminal state or regression */ 
+  if ((state == ISM_DR) || (state == ISM_Backup) || (state == ISM_DROther) ||
+      (state == ISM_PointToPoint) || (state < old_state))
+    {
+      /* ospfVirtIfStateChange */
+      if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
+        ospfTrapVirtIfStateChange (oi);
+      /* ospfIfStateChange */
+      else
+        ospfTrapIfStateChange (oi);
+    }
+#endif
+
   /* Set multicast memberships appropriately for new state. */
   ospf_if_set_multicast(oi);
 

+ 17 - 0
ospfd/ospf_nsm.c

@@ -47,6 +47,7 @@
 #include "ospfd/ospf_dump.h"
 #include "ospfd/ospf_flood.h"
 #include "ospfd/ospf_abr.h"
+#include "ospfd/ospf_snmp.h"
 
 void nsm_reset_nbr (struct ospf_neighbor *);
 
@@ -692,6 +693,22 @@ nsm_change_state (struct ospf_neighbor *nbr, int state)
   if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
     vl_area = ospf_area_lookup_by_area_id (oi->ospf, oi->vl_data->vl_area_id);
   
+#ifdef HAVE_SNMP
+  /* Terminal state or regression */ 
+  if ((state == NSM_Full) || (state == NSM_TwoWay) || (state < old_state))
+    {
+      /* ospfVirtNbrStateChange */
+      if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
+        ospfTrapVirtNbrStateChange(nbr);
+      /* ospfNbrStateChange trap  */
+      else
+        /* To/From FULL, only managed by DR */
+        if (((state != NSM_Full) && (old_state != NSM_Full)) ||
+            (oi->state == ISM_DR))
+          ospfTrapNbrStateChange(nbr);
+    }
+#endif
+
   /* One of the neighboring routers changes to/from the FULL state. */
   if ((old_state != NSM_Full && state == NSM_Full) ||
       (old_state == NSM_Full && state != NSM_Full))

+ 108 - 0
ospfd/ospf_snmp.c

@@ -2064,7 +2064,9 @@ ospf_snmp_nbr_lookup (struct ospf *ospf, struct in_addr *nbr_addr,
       for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
 	if ((nbr = rn->info) != NULL
 	    && nbr != oi->nbr_self
+/* If EXACT match is needed, provide ALL entry found
 	    && nbr->state != NSM_Down
+ */
 	    && nbr->src.s_addr != 0)
 	  {
 	    if (IPV4_ADDR_SAME (&nbr->src, nbr_addr))
@@ -2475,6 +2477,112 @@ ospfAreaAggregateEntry (struct variable *v, oid *name, size_t *length,
   return NULL;
 }
 
+/* OSPF Traps. */
+#define IFSTATECHANGE      16
+#define VIRTIFSTATECHANGE   1
+#define NBRSTATECHANGE      2
+#define VIRTNBRSTATECHANGE  3
+
+struct trap_object ospfNbrTrapList[] =
+{
+  {ospfGeneralGroup, -2, {1, OSPFROUTERID}},
+  {ospfNbrEntry, 3, {10, 1, OSPFNBRIPADDR}},
+  {ospfNbrEntry, 3, {10, 1, OSPFNBRRTRID}},
+  {ospfNbrEntry, 3, {10, 1, OSPFNBRSTATE}}
+};
+
+
+struct trap_object ospfVirtNbrTrapList[] =
+{
+  {ospfGeneralGroup, -2, {1, 1}},
+  {ospfVirtNbrEntry, 3, {11, 1, OSPFVIRTNBRAREA}},
+  {ospfVirtNbrEntry, 3, {11, 1, OSPFVIRTNBRRTRID}},
+  {ospfVirtNbrEntry, 3, {11, 1, OSPFVIRTNBRSTATE}}
+};
+
+struct trap_object ospfIfTrapList[] =
+{
+  {ospfGeneralGroup, -2, {1, OSPFROUTERID}},
+  {ospfIfEntry, 3, {7, 1, OSPFIFIPADDRESS}},
+  {ospfIfEntry, 3, {7, 1, OSPFADDRESSLESSIF}},
+  {ospfIfEntry, 3, {7, 1, OSPFIFSTATE}}
+};
+
+struct trap_object ospfVirtIfTrapList[] =
+{
+  {ospfGeneralGroup, -2, {1, OSPFROUTERID}},
+  {ospfVirtIfEntry, 3, {9, 1, OSPFVIRTIFAREAID}},
+  {ospfVirtIfEntry, 3, {9, 1, OSPFVIRTIFNEIGHBOR}},
+  {ospfVirtIfEntry, 3, {9, 1, OSPFVIRTIFSTATE}}
+};
+
+void
+ospfTrapNbrStateChange (struct ospf_neighbor *on)
+{
+  oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
+  
+  zlog (NULL, LOG_INFO, "ospfTrapNbrStateChange trap sent");
+
+  oid_copy_addr (index, &(on->address.u.prefix4), IN_ADDR_SIZE);
+  index[IN_ADDR_SIZE] = 0;
+
+  smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid),
+             index,  IN_ADDR_SIZE + 1,
+             ospfNbrTrapList, 
+             sizeof ospfNbrTrapList / sizeof (struct trap_object),
+             time (NULL), NBRSTATECHANGE);
+}
+
+void
+ospfTrapVirtNbrStateChange (struct ospf_neighbor *on)
+{
+  oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
+  
+  zlog (NULL, LOG_INFO, "ospfTrapVirtNbrStateChange trap sent");
+
+  oid_copy_addr (index, &(on->address.u.prefix4), IN_ADDR_SIZE);
+  index[IN_ADDR_SIZE] = 0;
+
+  smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid),
+             index,  IN_ADDR_SIZE + 1,
+             ospfVirtNbrTrapList, 
+             sizeof ospfVirtNbrTrapList / sizeof (struct trap_object),
+             time (NULL), VIRTNBRSTATECHANGE);
+}
+
+void
+ospfTrapIfStateChange (struct ospf_interface *oi)
+{
+  oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
+
+  zlog (NULL, LOG_INFO, "ospfTrapIfStateChange trap sent");
+  
+  oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE);
+  index[IN_ADDR_SIZE] = 0;
+
+  smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid),
+             index, IN_ADDR_SIZE + 1,
+             ospfIfTrapList, 
+             sizeof ospfIfTrapList / sizeof (struct trap_object),
+             time (NULL), IFSTATECHANGE);
+}
+
+void
+ospfTrapVirtIfStateChange (struct ospf_interface *oi)
+{
+  oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
+
+  zlog (NULL, LOG_INFO, "ospfTrapVirtIfStateChange trap sent");
+  
+  oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE);
+  index[IN_ADDR_SIZE] = 0;
+
+  smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid),
+             index, IN_ADDR_SIZE + 1,
+             ospfVirtIfTrapList,
+             sizeof ospfVirtIfTrapList / sizeof (struct trap_object),
+             time (NULL), VIRTIFSTATECHANGE);
+}
 /* Register OSPF2-MIB. */
 void
 ospf_snmp_init ()

+ 5 - 0
ospfd/ospf_snmp.h

@@ -30,4 +30,9 @@ extern void ospf_snmp_if_delete (struct interface *);
 extern void ospf_snmp_vl_add (struct ospf_vl_data *);
 extern void ospf_snmp_vl_delete (struct ospf_vl_data *);
 
+extern void ospfTrapIfStateChange (struct ospf_interface *);
+extern void ospfTrapVirtIfStateChange (struct ospf_interface *);
+extern void ospfTrapNbrStateChange (struct ospf_neighbor *);
+extern void ospfTrapVirtNbrStateChange (struct ospf_neighbor *);
+
 #endif /* _ZEBRA_OSPF_SNMP_H */