Browse Source

ospf6d: add SNMP notifications/traps support

Only implement ospfv3NbrStateChange and ospfv3IfStateChange.
Vincent Bernat 7 years ago
parent
commit
bf836661ef
4 changed files with 78 additions and 0 deletions
  1. 11 0
      ospf6d/ospf6_interface.c
  2. 9 0
      ospf6d/ospf6_neighbor.c
  3. 56 0
      ospf6d/ospf6_snmp.c
  4. 2 0
      ospf6d/ospf6_snmp.h

+ 11 - 0
ospf6d/ospf6_interface.c

@@ -421,6 +421,17 @@ ospf6_interface_state_change (u_char next_state, struct ospf6_interface *oi)
       OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
       OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
     }
+
+#ifdef HAVE_SNMP
+  /* Terminal state or regression */ 
+  if ((next_state == OSPF6_INTERFACE_POINTTOPOINT) ||
+      (next_state == OSPF6_INTERFACE_DROTHER) ||
+      (next_state == OSPF6_INTERFACE_BDR) ||
+      (next_state == OSPF6_INTERFACE_DR) ||
+      (next_state < prev_state))
+    ospf6TrapIfStateChange (oi);
+#endif
+
 }
 
 

+ 9 - 0
ospf6d/ospf6_neighbor.c

@@ -182,6 +182,15 @@ ospf6_neighbor_state_change (u_char next_state, struct ospf6_neighbor *on)
       (next_state != OSPF6_NEIGHBOR_EXCHANGE &&
        next_state != OSPF6_NEIGHBOR_LOADING))
     ospf6_maxage_remove (on->ospf6_if->area->ospf6);
+
+#ifdef HAVE_SNMP
+  /* Terminal state or regression */ 
+  if ((next_state == OSPF6_NEIGHBOR_FULL)  ||
+      (next_state == OSPF6_NEIGHBOR_TWOWAY) ||
+      (next_state < prev_state))
+    ospf6TrapNbrStateChange (on);
+#endif
+
 }
 
 /* RFC2328 section 10.4 */

+ 56 - 0
ospf6d/ospf6_snmp.c

@@ -204,6 +204,7 @@ SNMP_LOCAL_VARIABLES
 
 /* OSPFv3-MIB instances. */
 oid ospfv3_oid [] = { OSPFv3MIB };
+oid ospfv3_trap_oid [] = { OSPFv3MIB, 0 };
 
 /* Hook functions. */
 static u_char *ospfv3GeneralGroup (struct variable *, oid *, size_t *,
@@ -1110,6 +1111,61 @@ ospfv3NbrEntry (struct variable *v, oid *name, size_t *length,
   return NULL;
 }
 
+/* OSPF Traps. */
+#define NBRSTATECHANGE      2
+#define IFSTATECHANGE      10
+
+static struct trap_object ospf6NbrTrapList[] =
+{
+  {-3, {1, 1, OSPFv3ROUTERID}},
+  {4, {1, 9, 1, OSPFv3NBRADDRESSTYPE}},
+  {4, {1, 9, 1, OSPFv3NBRADDRESS}},
+  {4, {1, 9, 1, OSPFv3NBRSTATE}}
+};
+
+static struct trap_object ospf6IfTrapList[] =
+{
+  {-3, {1, 1, OSPFv3ROUTERID}},
+  {4, {1, 7, 1, OSPFv3IFSTATE}},
+  {4, {1, 7, 1, OSPFv3IFADMINSTATUS}},
+  {4, {1, 7, 1, OSPFv3IFAREAID}}
+};
+
+void
+ospf6TrapNbrStateChange (struct ospf6_neighbor *on)
+{
+  oid index[3];
+
+  index[0] = on->ospf6_if->interface->ifindex;
+  index[1] = on->ospf6_if->instance_id;
+  index[2] = ntohl (on->router_id);
+
+  smux_trap (ospfv3_variables, sizeof ospfv3_variables / sizeof (struct variable),
+	     ospfv3_trap_oid, sizeof ospfv3_trap_oid / sizeof (oid),
+	     ospfv3_oid, sizeof ospfv3_oid / sizeof (oid),
+             index,  3,
+             ospf6NbrTrapList, 
+             sizeof ospf6NbrTrapList / sizeof (struct trap_object),
+             NBRSTATECHANGE);
+}
+
+void
+ospf6TrapIfStateChange (struct ospf6_interface *oi)
+{
+  oid index[2];
+
+  index[0] = oi->interface->ifindex;
+  index[1] = oi->instance_id;
+
+  smux_trap (ospfv3_variables, sizeof ospfv3_variables / sizeof (struct variable),
+	     ospfv3_trap_oid, sizeof ospfv3_trap_oid / sizeof (oid),
+	     ospfv3_oid, sizeof ospfv3_oid / sizeof (oid),
+             index,  2,
+             ospf6IfTrapList, 
+             sizeof ospf6IfTrapList / sizeof (struct trap_object),
+             IFSTATECHANGE);
+}
+
 /* Register OSPFv3-MIB. */
 void
 ospf6_snmp_init (struct thread_master *master)

+ 2 - 0
ospf6d/ospf6_snmp.h

@@ -22,6 +22,8 @@
 #ifndef OSPF6_SNMP_H
 #define OSPF6_SNMP_H
 
+extern void ospf6TrapNbrStateChange (struct ospf6_neighbor *);
+extern void ospf6TrapIfStateChange (struct ospf6_interface *);
 extern void ospf6_snmp_init (struct thread_master *);
 
 #endif /*OSPF6_SNMP_H*/