summaryrefslogtreecommitdiffstats
path: root/ospfd
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2016-06-12 17:32:23 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2017-03-25 08:52:36 +0100
commit3012671ffadbd839626b5c0b0b1fd36b3698f582 (patch)
tree847bacd0156e5e8dc2e64cbfbbf10c2f6e3ac9ac /ospfd
parentbuild: split off libfrrsnmp (diff)
downloadfrr-3012671ffadbd839626b5c0b0b1fd36b3698f582.tar.xz
frr-3012671ffadbd839626b5c0b0b1fd36b3698f582.zip
*: use hooks for sending SNMP traps
This means there are no ties into the SNMP code anymore other than the init call at startup. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'ospfd')
-rw-r--r--ospfd/Makefile.am2
-rw-r--r--ospfd/ospf_interface.c13
-rw-r--r--ospfd/ospf_interface.h4
-rw-r--r--ospfd/ospf_ism.c19
-rw-r--r--ospfd/ospf_ism.h10
-rw-r--r--ospfd/ospf_nsm.c34
-rw-r--r--ospfd/ospf_nsm.h6
-rw-r--r--ospfd/ospf_snmp.c78
-rw-r--r--ospfd/ospf_snmp.h38
-rw-r--r--ospfd/ospf_zebra.c22
-rw-r--r--ospfd/ospf_zebra.h4
11 files changed, 111 insertions, 119 deletions
diff --git a/ospfd/Makefile.am b/ospfd/Makefile.am
index 5555fb0da..52c7dade7 100644
--- a/ospfd/Makefile.am
+++ b/ospfd/Makefile.am
@@ -26,7 +26,7 @@ ospfdheader_HEADERS = \
noinst_HEADERS = \
ospf_interface.h ospf_neighbor.h ospf_network.h ospf_packet.h \
ospf_zebra.h ospf_spf.h ospf_route.h ospf_ase.h ospf_abr.h ospf_ia.h \
- ospf_flood.h ospf_snmp.h ospf_te.h ospf_ri.h ospf_vty.h ospf_apiserver.h \
+ ospf_flood.h ospf_te.h ospf_ri.h ospf_vty.h ospf_apiserver.h \
ospf_bfd.h ospf_memory.h
ospfd_SOURCES = ospf_main.c
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index 4fb206589..b4a282a52 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -47,11 +47,10 @@
#include "ospfd/ospf_abr.h"
#include "ospfd/ospf_network.h"
#include "ospfd/ospf_dump.h"
-#ifdef HAVE_SNMP
-#include "ospfd/ospf_snmp.h"
-#endif /* HAVE_SNMP */
DEFINE_QOBJ_TYPE(ospf_interface)
+DEFINE_HOOK(ospf_vl_add, (struct ospf_vl_data *vd), (vd))
+DEFINE_HOOK(ospf_vl_delete, (struct ospf_vl_data *vd), (vd))
int
ospf_if_get_output_cost (struct ospf_interface *oi)
@@ -993,9 +992,7 @@ void
ospf_vl_add (struct ospf *ospf, struct ospf_vl_data *vl_data)
{
listnode_add (ospf->vlinks, vl_data);
-#ifdef HAVE_SNMP
- ospf_snmp_vl_add (vl_data);
-#endif /* HAVE_SNMP */
+ hook_call(ospf_vl_add, vl_data);
}
void
@@ -1004,9 +1001,7 @@ ospf_vl_delete (struct ospf *ospf, struct ospf_vl_data *vl_data)
ospf_vl_shutdown (vl_data);
ospf_vl_if_delete (vl_data);
-#ifdef HAVE_SNMP
- ospf_snmp_vl_delete (vl_data);
-#endif /* HAVE_SNMP */
+ hook_call(ospf_vl_delete, vl_data);
listnode_delete (ospf->vlinks, vl_data);
ospf_vl_data_free (vl_data);
diff --git a/ospfd/ospf_interface.h b/ospfd/ospf_interface.h
index bd51bbf42..39202f777 100644
--- a/ospfd/ospf_interface.h
+++ b/ospfd/ospf_interface.h
@@ -24,6 +24,7 @@
#define _ZEBRA_OSPF_INTERFACE_H
#include "qobj.h"
+#include "hook.h"
#include "ospfd/ospf_packet.h"
#include "ospfd/ospf_spf.h"
@@ -309,4 +310,7 @@ extern u_char ospf_default_iftype (struct interface *ifp);
state of the interface. */
extern void ospf_if_set_multicast (struct ospf_interface *);
+DECLARE_HOOK(ospf_vl_add, (struct ospf_vl_data *vd), (vd))
+DECLARE_HOOK(ospf_vl_delete, (struct ospf_vl_data *vd), (vd))
+
#endif /* _ZEBRA_OSPF_INTERFACE_H */
diff --git a/ospfd/ospf_ism.c b/ospfd/ospf_ism.c
index 9630616ac..717c99c21 100644
--- a/ospfd/ospf_ism.c
+++ b/ospfd/ospf_ism.c
@@ -43,7 +43,10 @@
#include "ospfd/ospf_packet.h"
#include "ospfd/ospf_flood.h"
#include "ospfd/ospf_abr.h"
-#include "ospfd/ospf_snmp.h"
+
+DEFINE_HOOK(ospf_ism_change,
+ (struct ospf_interface *oi, int state, int oldstate),
+ (oi, state, oldstate))
/* elect DR and BDR. Refer to RFC2319 section 9.4 */
static struct ospf_neighbor *
@@ -545,19 +548,7 @@ 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
+ hook_call(ospf_ism_change, oi, state, old_state);
/* Set multicast memberships appropriately for new state. */
ospf_if_set_multicast(oi);
diff --git a/ospfd/ospf_ism.h b/ospfd/ospf_ism.h
index f0357a482..fa8e6d70f 100644
--- a/ospfd/ospf_ism.h
+++ b/ospfd/ospf_ism.h
@@ -24,6 +24,8 @@
#ifndef _ZEBRA_OSPF_ISM_H
#define _ZEBRA_OSPF_ISM_H
+#include "hook.h"
+
/* OSPF Interface State Machine Status. */
#define ISM_DependUpon 0
#define ISM_Down 1
@@ -35,10 +37,6 @@
#define ISM_DR 7
#define OSPF_ISM_STATE_MAX 8
-/* Because DR/DROther values are exhanged wrt RFC */
-#define ISM_SNMP(x) (((x) == ISM_DROther) ? ISM_DR : \
- ((x) == ISM_DR) ? ISM_DROther : (x))
-
/* OSPF Interface State Machine Event. */
#define ISM_NoEvent 0
#define ISM_InterfaceUp 1
@@ -111,4 +109,8 @@ extern int ospf_ism_event (struct thread *);
extern void ism_change_status (struct ospf_interface *, int);
extern int ospf_hello_timer (struct thread *thread);
+DECLARE_HOOK(ospf_ism_change,
+ (struct ospf_interface *oi, int state, int oldstate),
+ (oi, state, oldstate))
+
#endif /* _ZEBRA_OSPF_ISM_H */
diff --git a/ospfd/ospf_nsm.c b/ospfd/ospf_nsm.c
index 01617055c..97f3f6a38 100644
--- a/ospfd/ospf_nsm.c
+++ b/ospfd/ospf_nsm.c
@@ -48,9 +48,12 @@
#include "ospfd/ospf_dump.h"
#include "ospfd/ospf_flood.h"
#include "ospfd/ospf_abr.h"
-#include "ospfd/ospf_snmp.h"
#include "ospfd/ospf_bfd.h"
+DEFINE_HOOK(ospf_nsm_change,
+ (struct ospf_neighbor *on, int state, int oldstate),
+ (on, state, oldstate))
+
static void nsm_clear_adj (struct ospf_neighbor *);
/* OSPF NSM Timer functions. */
@@ -838,35 +841,12 @@ ospf_nsm_event (struct thread *thread)
/* If state is changed. */
if (next_state != nbr->state)
{
+ int old_state = nbr->state;
+
nsm_notice_state_change (nbr, next_state, event);
-#ifdef HAVE_SNMP
- int send_trap_virt = 0;
- int send_trap = 0;
- /* Terminal state or regression */
- if ((next_state == NSM_Full)
- || (next_state == NSM_TwoWay)
- || (next_state < nbr->state))
- {
- /* ospfVirtNbrStateChange */
- if (nbr->oi->type == OSPF_IFTYPE_VIRTUALLINK)
- send_trap_virt = 1;
- /* ospfNbrStateChange trap */
- else
- /* To/From FULL, only managed by DR */
- if (((next_state != NSM_Full) && (nbr->state != NSM_Full))
- || (nbr->oi->state == ISM_DR))
- send_trap = 1;
- }
-#endif
nsm_change_state (nbr, next_state);
-#ifdef HAVE_SNMP
- if (send_trap_virt) {
- ospfTrapVirtNbrStateChange(nbr);
- } else if (send_trap) {
- ospfTrapNbrStateChange(nbr);
- }
-#endif
+ hook_call(ospf_nsm_change, nbr, next_state, old_state);
}
/* Make sure timer is set. */
diff --git a/ospfd/ospf_nsm.h b/ospfd/ospf_nsm.h
index 9b7e14a4a..4531f6ec7 100644
--- a/ospfd/ospf_nsm.h
+++ b/ospfd/ospf_nsm.h
@@ -24,6 +24,8 @@
#ifndef _ZEBRA_OSPF_NSM_H
#define _ZEBRA_OSPF_NSM_H
+#include "hook.h"
+
/* OSPF Neighbor State Machine State. */
#define NSM_DependUpon 0
#define NSM_Deleted 1
@@ -86,5 +88,9 @@ extern int ospf_db_summary_isempty (struct ospf_neighbor *);
extern int ospf_db_summary_count (struct ospf_neighbor *);
extern void ospf_db_summary_clear (struct ospf_neighbor *);
+DECLARE_HOOK(ospf_nsm_change,
+ (struct ospf_neighbor *on, int state, int oldstate),
+ (on, state, oldstate))
+
#endif /* _ZEBRA_OSPF_NSM_H */
diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c
index 4afbda878..b5813d7d5 100644
--- a/ospfd/ospf_snmp.c
+++ b/ospfd/ospf_snmp.c
@@ -47,7 +47,7 @@
#include "ospfd/ospf_flood.h"
#include "ospfd/ospf_ism.h"
#include "ospfd/ospf_dump.h"
-#include "ospfd/ospf_snmp.h"
+#include "ospfd/ospf_zebra.h"
/* OSPF2-MIB. */
#define OSPF2MIB 1,3,6,1,2,1,14
@@ -205,6 +205,10 @@
#define IPADDRESS ASN_IPADDRESS
#define STRING ASN_OCTET_STR
+/* Because DR/DROther values are exhanged wrt RFC */
+#define ISM_SNMP(x) (((x) == ISM_DROther) ? ISM_DR : \
+ ((x) == ISM_DR) ? ISM_DROther : (x))
+
/* Declare static local variables for convenience. */
SNMP_LOCAL_VARIABLES
@@ -1429,7 +1433,7 @@ ospf_snmp_if_free (struct ospf_snmp_if *osif)
XFREE (MTYPE_TMP, osif);
}
-void
+static int
ospf_snmp_if_delete (struct interface *ifp)
{
struct listnode *node, *nnode;
@@ -1441,12 +1445,13 @@ ospf_snmp_if_delete (struct interface *ifp)
{
list_delete_node (ospf_snmp_iflist, node);
ospf_snmp_if_free (osif);
- return;
+ break;
}
}
+ return 0;
}
-void
+static int
ospf_snmp_if_update (struct interface *ifp)
{
struct listnode *node;
@@ -1511,6 +1516,7 @@ ospf_snmp_if_update (struct interface *ifp)
osif->ifp = ifp;
listnode_add_after (ospf_snmp_iflist, pn, osif);
+ return 0;
}
static int
@@ -1914,7 +1920,7 @@ ospfIfMetricEntry (struct variable *v, oid *name, size_t *length, int exact,
static struct route_table *ospf_snmp_vl_table;
-void
+static int
ospf_snmp_vl_add (struct ospf_vl_data *vl_data)
{
struct prefix_ls lp;
@@ -1931,9 +1937,10 @@ ospf_snmp_vl_add (struct ospf_vl_data *vl_data)
route_unlock_node (rn);
rn->info = vl_data;
+ return 0;
}
-void
+static int
ospf_snmp_vl_delete (struct ospf_vl_data *vl_data)
{
struct prefix_ls lp;
@@ -1947,10 +1954,11 @@ ospf_snmp_vl_delete (struct ospf_vl_data *vl_data)
rn = route_node_lookup (ospf_snmp_vl_table, (struct prefix *) &lp);
if (! rn)
- return;
+ return 0;
rn->info = NULL;
route_unlock_node (rn);
route_unlock_node (rn);
+ return 0;
}
static struct ospf_vl_data *
@@ -2651,7 +2659,7 @@ static struct trap_object ospfVirtIfTrapList[] =
{3, {9, 1, OSPFVIRTIFSTATE}}
};
-void
+static void
ospfTrapNbrStateChange (struct ospf_neighbor *on)
{
oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
@@ -2673,7 +2681,7 @@ ospfTrapNbrStateChange (struct ospf_neighbor *on)
NBRSTATECHANGE);
}
-void
+static void
ospfTrapVirtNbrStateChange (struct ospf_neighbor *on)
{
oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
@@ -2692,7 +2700,29 @@ ospfTrapVirtNbrStateChange (struct ospf_neighbor *on)
VIRTNBRSTATECHANGE);
}
-void
+static int
+ospf_snmp_nsm_change (struct ospf_neighbor *nbr,
+ int next_state, int old_state)
+{
+ /* Terminal state or regression */
+ if ((next_state == NSM_Full)
+ || (next_state == NSM_TwoWay)
+ || (next_state < old_state))
+ {
+ /* ospfVirtNbrStateChange */
+ if (nbr->oi->type == OSPF_IFTYPE_VIRTUALLINK)
+ ospfTrapVirtNbrStateChange(nbr);
+ /* ospfNbrStateChange trap */
+ else
+ /* To/From FULL, only managed by DR */
+ if (((next_state != NSM_Full) && (nbr->state != NSM_Full))
+ || (nbr->oi->state == ISM_DR))
+ ospfTrapNbrStateChange(nbr);
+ }
+ return 0;
+}
+
+static void
ospfTrapIfStateChange (struct ospf_interface *oi)
{
oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
@@ -2713,7 +2743,7 @@ ospfTrapIfStateChange (struct ospf_interface *oi)
IFSTATECHANGE);
}
-void
+static void
ospfTrapVirtIfStateChange (struct ospf_interface *oi)
{
oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
@@ -2731,10 +2761,36 @@ ospfTrapVirtIfStateChange (struct ospf_interface *oi)
sizeof ospfVirtIfTrapList / sizeof (struct trap_object),
VIRTIFSTATECHANGE);
}
+
+static int
+ospf_snmp_ism_change (struct ospf_interface *oi,
+ int state, int old_state)
+{
+ /* 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);
+ }
+ return 0;
+}
+
/* Register OSPF2-MIB. */
void
ospf_snmp_init ()
{
+ hook_register(ospf_if_update, ospf_snmp_if_update);
+ hook_register(ospf_if_delete, ospf_snmp_if_delete);
+ hook_register(ospf_vl_add, ospf_snmp_vl_add);
+ hook_register(ospf_vl_delete, ospf_snmp_vl_delete);
+ hook_register(ospf_ism_change, ospf_snmp_ism_change);
+ hook_register(ospf_nsm_change, ospf_snmp_nsm_change);
+
ospf_snmp_iflist = list_new ();
ospf_snmp_vl_table = route_table_init ();
smux_init (om->master);
diff --git a/ospfd/ospf_snmp.h b/ospfd/ospf_snmp.h
deleted file mode 100644
index 413d1d7f7..000000000
--- a/ospfd/ospf_snmp.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* OSPFv2 SNMP support
- * Copyright (C) 2000 IP Infusion Inc.
- *
- * Written by Kunihiro Ishiguro <kunihiro@zebra.org>
- *
- * This file is part of GNU Zebra.
- *
- * GNU Zebra is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * GNU Zebra is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Zebra; see the file COPYING. If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef _ZEBRA_OSPF_SNMP_H
-#define _ZEBRA_OSPF_SNMP_H
-
-extern void ospf_snmp_if_update (struct interface *);
-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 */
diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c
index cb14273ee..abb6db034 100644
--- a/ospfd/ospf_zebra.c
+++ b/ospfd/ospf_zebra.c
@@ -50,11 +50,11 @@
#include "ospfd/ospf_neighbor.h"
#include "ospfd/ospf_nsm.h"
#include "ospfd/ospf_zebra.h"
-#ifdef HAVE_SNMP
-#include "ospfd/ospf_snmp.h"
-#endif /* HAVE_SNMP */
#include "ospfd/ospf_te.h"
+DEFINE_HOOK(ospf_if_update, (struct interface *ifp), (ifp))
+DEFINE_HOOK(ospf_if_delete, (struct interface *ifp), (ifp))
+
/* Zebra structure to hold current status. */
struct zclient *zclient = NULL;
@@ -112,9 +112,7 @@ ospf_interface_add (int command, struct zclient *zclient, zebra_size_t length,
ospf_if_update (NULL, ifp);
-#ifdef HAVE_SNMP
- ospf_snmp_if_update (ifp);
-#endif /* HAVE_SNMP */
+ hook_call(ospf_if_update, ifp);
return 0;
}
@@ -143,9 +141,7 @@ ospf_interface_delete (int command, struct zclient *zclient,
("Zebra: interface delete %s[%u] index %d flags %llx metric %d mtu %d",
ifp->name, ifp->vrf_id, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
-#ifdef HAVE_SNMP
- ospf_snmp_if_delete (ifp);
-#endif /* HAVE_SNMP */
+ hook_call(ospf_if_delete, ifp);
for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
if (rn->info)
@@ -277,9 +273,7 @@ ospf_interface_address_add (int command, struct zclient *zclient,
ospf_if_update (NULL, c->ifp);
-#ifdef HAVE_SNMP
- ospf_snmp_if_update (c->ifp);
-#endif /* HAVE_SNMP */
+ hook_call(ospf_if_update, c->ifp);
return 0;
}
@@ -324,9 +318,7 @@ ospf_interface_address_delete (int command, struct zclient *zclient,
/* Call interface hook functions to clean up */
ospf_if_free (oi);
-#ifdef HAVE_SNMP
- ospf_snmp_if_update (c->ifp);
-#endif /* HAVE_SNMP */
+ hook_call(ospf_if_update, c->ifp);
connected_free (c);
diff --git a/ospfd/ospf_zebra.h b/ospfd/ospf_zebra.h
index 8e93ed269..22c71a49e 100644
--- a/ospfd/ospf_zebra.h
+++ b/ospfd/ospf_zebra.h
@@ -24,6 +24,7 @@
#define _ZEBRA_OSPF_ZEBRA_H
#include "vty.h"
+#include "hook.h"
#define EXTERNAL_METRIC_TYPE_1 0
#define EXTERNAL_METRIC_TYPE_2 1
@@ -79,5 +80,8 @@ extern int ospf_distance_unset (struct vty *, struct ospf *, const char *,
const char *, const char *);
extern void ospf_zebra_init(struct thread_master *, u_short);
+DECLARE_HOOK(ospf_if_update, (struct interface *ifp), (ifp))
+DECLARE_HOOK(ospf_if_delete, (struct interface *ifp), (ifp))
+
#endif /* _ZEBRA_OSPF_ZEBRA_H */