From 3012671ffadbd839626b5c0b0b1fd36b3698f582 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sun, 12 Jun 2016 17:32:23 +0200 Subject: [PATCH] *: 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 --- bgpd/Makefile.am | 2 +- bgpd/bgp_fsm.c | 14 +++----- bgpd/bgp_fsm.h | 4 +++ bgpd/bgp_snmp.c | 16 ++++++--- bgpd/bgp_snmp.h | 28 --------------- bgpd/bgpd.c | 5 ++- ospf6d/Makefile.am | 2 +- ospf6d/ospf6_interface.c | 15 +++----- ospf6d/ospf6_interface.h | 5 +++ ospf6d/ospf6_neighbor.c | 13 +++---- ospf6d/ospf6_neighbor.h | 6 ++++ ospf6d/ospf6_snmp.c | 32 ++++++++++++++--- ospf6d/ospf6_snmp.h | 31 ---------------- ospf6d/ospf6d.c | 2 +- ospfd/Makefile.am | 2 +- ospfd/ospf_interface.c | 13 +++---- ospfd/ospf_interface.h | 4 +++ ospfd/ospf_ism.c | 19 +++------- ospfd/ospf_ism.h | 10 +++--- ospfd/ospf_nsm.c | 34 ++++-------------- ospfd/ospf_nsm.h | 6 ++++ ospfd/ospf_snmp.c | 78 ++++++++++++++++++++++++++++++++++------ ospfd/ospf_snmp.h | 38 -------------------- ospfd/ospf_zebra.c | 22 ++++-------- ospfd/ospf_zebra.h | 4 +++ ripd/rip_interface.c | 11 +++--- ripd/rip_snmp.c | 20 +++++++---- ripd/ripd.h | 7 ++-- 28 files changed, 206 insertions(+), 237 deletions(-) delete mode 100644 bgpd/bgp_snmp.h delete mode 100644 ospf6d/ospf6_snmp.h delete mode 100644 ospfd/ospf_snmp.h diff --git a/bgpd/Makefile.am b/bgpd/Makefile.am index 50cd2d28ec..4050e01620 100644 --- a/bgpd/Makefile.am +++ b/bgpd/Makefile.am @@ -89,7 +89,7 @@ noinst_HEADERS = \ bgpd.h bgp_filter.h bgp_clist.h bgp_dump.h bgp_zebra.h \ bgp_ecommunity.h bgp_lcommunity.h \ bgp_mplsvpn.h bgp_nexthop.h bgp_damp.h bgp_table.h \ - bgp_advertise.h bgp_snmp.h bgp_vty.h bgp_mpath.h bgp_nht.h \ + bgp_advertise.h bgp_vty.h bgp_mpath.h bgp_nht.h \ bgp_updgrp.h bgp_bfd.h bgp_encap.h bgp_encap_tlv.h bgp_encap_types.h \ $(BGP_VNC_RFAPI_HD) bgp_attr_evpn.h bgp_evpn.h bgp_evpn_vty.h bgp_vpn.h diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index 7dc7f053d6..2bbdca595c 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -45,14 +45,14 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "bgpd/bgp_dump.h" #include "bgpd/bgp_open.h" #include "bgpd/bgp_advertise.h" -#ifdef HAVE_SNMP -#include "bgpd/bgp_snmp.h" -#endif /* HAVE_SNMP */ #include "bgpd/bgp_updgrp.h" #include "bgpd/bgp_nht.h" #include "bgpd/bgp_bfd.h" #include "bgpd/bgp_memory.h" +DEFINE_HOOK(peer_backward_transition, (struct peer *peer), (peer)) +DEFINE_HOOK(peer_established, (struct peer *peer), (peer)) + /* Definition of display strings corresponding to FSM events. This should be * kept consistent with the events defined in bgpd.h */ @@ -1061,9 +1061,7 @@ bgp_stop (struct peer *peer) zlog_debug ("%s remove from all update group", peer->host); update_group_remove_peer_afs(peer); -#ifdef HAVE_SNMP - bgpTrapBackwardTransition (peer); -#endif /* HAVE_SNMP */ + hook_call(peer_backward_transition, peer); /* Reset peer synctime */ peer->synctime = 0; @@ -1508,9 +1506,7 @@ bgp_establish (struct peer *peer) zlog_debug ("%s graceful restart timer stopped", peer->host); } -#ifdef HAVE_SNMP - bgpTrapEstablished (peer); -#endif /* HAVE_SNMP */ + hook_call(peer_established, peer); /* Reset uptime, send keepalive, send current table. */ peer->uptime = bgp_clock (); diff --git a/bgpd/bgp_fsm.h b/bgpd/bgp_fsm.h index e47d07702b..4d0b48f529 100644 --- a/bgpd/bgp_fsm.h +++ b/bgpd/bgp_fsm.h @@ -109,4 +109,8 @@ extern void bgp_start_routeadv (struct bgp *); */ extern void bgp_adjust_routeadv (struct peer *); +#include "hook.h" +DECLARE_HOOK(peer_backward_transition, (struct peer *peer), (peer)) +DECLARE_HOOK(peer_established, (struct peer *peer), (peer)) + #endif /* _QUAGGA_BGP_FSM_H */ diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c index 5e6218e8a3..6896c86e40 100644 --- a/bgpd/bgp_snmp.c +++ b/bgpd/bgp_snmp.c @@ -38,7 +38,6 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "bgpd/bgp_attr.h" #include "bgpd/bgp_route.h" #include "bgpd/bgp_fsm.h" -#include "bgpd/bgp_snmp.h" /* BGP4-MIB described in RFC1657. */ #define BGP4MIB 1,3,6,1,2,1,15 @@ -838,7 +837,7 @@ static struct trap_object bgpTrapList[] = {3, {3, 1, BGPPEERSTATE}} }; -void +static int bgpTrapEstablished (struct peer *peer) { int ret; @@ -847,7 +846,7 @@ bgpTrapEstablished (struct peer *peer) ret = inet_aton (peer->host, &addr); if (ret == 0) - return; + return 0; oid_copy_addr (index, &addr, IN_ADDR_SIZE); @@ -857,9 +856,10 @@ bgpTrapEstablished (struct peer *peer) index, IN_ADDR_SIZE, bgpTrapList, sizeof bgpTrapList / sizeof (struct trap_object), BGPESTABLISHED); + return 0; } -void +static int bgpTrapBackwardTransition (struct peer *peer) { int ret; @@ -868,7 +868,7 @@ bgpTrapBackwardTransition (struct peer *peer) ret = inet_aton (peer->host, &addr); if (ret == 0) - return; + return 0; oid_copy_addr (index, &addr, IN_ADDR_SIZE); @@ -878,11 +878,17 @@ bgpTrapBackwardTransition (struct peer *peer) index, IN_ADDR_SIZE, bgpTrapList, sizeof bgpTrapList / sizeof (struct trap_object), BGPBACKWARDTRANSITION); + return 0; } +void bgp_snmp_init (void); + void bgp_snmp_init (void) { + hook_register(peer_established, bgpTrapEstablished); + hook_register(peer_backward_transition, bgpTrapBackwardTransition); + smux_init (bm->master); REGISTER_MIB("mibII/bgp", bgp_variables, variable, bgp_oid); } diff --git a/bgpd/bgp_snmp.h b/bgpd/bgp_snmp.h deleted file mode 100644 index 7a0d9dd007..0000000000 --- a/bgpd/bgp_snmp.h +++ /dev/null @@ -1,28 +0,0 @@ -/* BGP4 SNMP support - Copyright (C) 1999, 2000 Kunihiro Ishiguro - -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 _QUAGGA_BGP_SNMP_H -#define _QUAGGA_BGP_SNMP_H - -extern void bgp_snmp_init (void); -extern void bgpTrapEstablished (struct peer *); -extern void bgpTrapBackwardTransition (struct peer *); - -#endif /* _QUAGGA_BGP_SNMP_H */ diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 30243e80b2..031cab902a 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -72,9 +72,6 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "bgpd/bgp_vty.h" #include "bgpd/bgp_mpath.h" #include "bgpd/bgp_nht.h" -#ifdef HAVE_SNMP -#include "bgpd/bgp_snmp.h" -#endif /* HAVE_SNMP */ #include "bgpd/bgp_updgrp.h" #include "bgpd/bgp_bfd.h" #include "bgpd/bgp_memory.h" @@ -7647,6 +7644,8 @@ bgp_if_finish (struct bgp *bgp) } } +extern void bgp_snmp_init (void); + void bgp_init (void) { diff --git a/ospf6d/Makefile.am b/ospf6d/Makefile.am index 8e62b1d5b4..30268c6882 100644 --- a/ospf6d/Makefile.am +++ b/ospf6d/Makefile.am @@ -22,7 +22,7 @@ noinst_HEADERS = \ ospf6_network.h ospf6_message.h ospf6_lsa.h ospf6_lsdb.h \ ospf6_top.h ospf6_area.h ospf6_interface.h ospf6_neighbor.h \ ospf6_flood.h ospf6_route.h ospf6_intra.h ospf6_zebra.h \ - ospf6_spf.h ospf6_proto.h ospf6_asbr.h ospf6_abr.h ospf6_snmp.h \ + ospf6_spf.h ospf6_proto.h ospf6_asbr.h ospf6_abr.h \ ospf6d.h ospf6_bfd.h ospf6d_SOURCES = \ diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index 8e0779df92..8cf7f4afaa 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -41,12 +41,14 @@ #include "ospf6_neighbor.h" #include "ospf6_intra.h" #include "ospf6_spf.h" -#include "ospf6_snmp.h" #include "ospf6d.h" #include "ospf6_bfd.h" DEFINE_MTYPE_STATIC(OSPF6D, CFG_PLIST_NAME, "configured prefix list names") DEFINE_QOBJ_TYPE(ospf6_interface) +DEFINE_HOOK(ospf6_interface_change, + (struct ospf6_interface *oi, int state, int old_state), + (oi, state, old_state)) unsigned char conf_debug_ospf6_interface = 0; @@ -518,16 +520,7 @@ ospf6_interface_state_change (u_char next_state, struct ospf6_interface *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 - + hook_call(ospf6_interface_change, oi, next_state, prev_state); } diff --git a/ospf6d/ospf6_interface.h b/ospf6d/ospf6_interface.h index 179477a634..846cde4191 100644 --- a/ospf6d/ospf6_interface.h +++ b/ospf6d/ospf6_interface.h @@ -23,6 +23,7 @@ #define OSPF6_INTERFACE_H #include "qobj.h" +#include "hook.h" #include "if.h" /* Debug option */ @@ -182,4 +183,8 @@ extern void install_element_ospf6_clear_interface (void); extern int config_write_ospf6_debug_interface (struct vty *vty); extern void install_element_ospf6_debug_interface (void); +DECLARE_HOOK(ospf6_interface_change, + (struct ospf6_interface *oi, int state, int old_state), + (oi, state, old_state)) + #endif /* OSPF6_INTERFACE_H */ diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c index ec79a1552b..118210dfc7 100644 --- a/ospf6d/ospf6_neighbor.c +++ b/ospf6d/ospf6_neighbor.c @@ -38,7 +38,6 @@ #include "ospf6_neighbor.h" #include "ospf6_intra.h" #include "ospf6_flood.h" -#include "ospf6_snmp.h" #include "ospf6d.h" #include "ospf6_bfd.h" #include "ospf6_abr.h" @@ -47,6 +46,10 @@ #include "ospf6_spf.h" #include "ospf6_zebra.h" +DEFINE_HOOK(ospf6_neighbor_change, + (struct ospf6_neighbor *on, int state, int next_state), + (on, state, next_state)) + unsigned char conf_debug_ospf6_neighbor = 0; const char *ospf6_neighbor_state_str[] = @@ -202,13 +205,7 @@ ospf6_neighbor_state_change (u_char next_state, struct ospf6_neighbor *on, int e 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 + hook_call(ospf6_neighbor_change, on, next_state, prev_state); ospf6_bfd_trigger_event(on, prev_state, next_state); } diff --git a/ospf6d/ospf6_neighbor.h b/ospf6d/ospf6_neighbor.h index f9e197e99b..c275ff830e 100644 --- a/ospf6d/ospf6_neighbor.h +++ b/ospf6d/ospf6_neighbor.h @@ -22,6 +22,8 @@ #ifndef OSPF6_NEIGHBOR_H #define OSPF6_NEIGHBOR_H +#include "hook.h" + /* Debug option */ extern unsigned char conf_debug_ospf6_neighbor; #define OSPF6_DEBUG_NEIGHBOR_STATE 0x01 @@ -179,4 +181,8 @@ extern void ospf6_neighbor_init (void); extern int config_write_ospf6_debug_neighbor (struct vty *vty); extern void install_element_ospf6_debug_neighbor (void); +DECLARE_HOOK(ospf6_neighbor_change, + (struct ospf6_neighbor *on, int state, int next_state), + (on, state, next_state)) + #endif /* OSPF6_NEIGHBOR_H */ diff --git a/ospf6d/ospf6_snmp.c b/ospf6d/ospf6_snmp.c index 86cfd17c83..57fc94fd52 100644 --- a/ospf6d/ospf6_snmp.c +++ b/ospf6d/ospf6_snmp.c @@ -45,7 +45,8 @@ #include "ospf6_abr.h" #include "ospf6_asbr.h" #include "ospf6d.h" -#include "ospf6_snmp.h" + +void ospf6_snmp_init (struct thread_master *master); /* OSPFv3-MIB */ #define OSPFv3MIB 1,3,6,1,2,1,191 @@ -1139,11 +1140,18 @@ static struct trap_object ospf6IfTrapList[] = {4, {1, 7, 1, OSPFv3IFAREAID}} }; -void -ospf6TrapNbrStateChange (struct ospf6_neighbor *on) +static int +ospf6TrapNbrStateChange (struct ospf6_neighbor *on, + int next_state, int prev_state) { oid index[3]; + /* Terminal state or regression */ + if ((next_state != OSPF6_NEIGHBOR_FULL) && + (next_state != OSPF6_NEIGHBOR_TWOWAY) && + (next_state >= prev_state)) + return 0; + index[0] = on->ospf6_if->interface->ifindex; index[1] = on->ospf6_if->instance_id; index[2] = ntohl (on->router_id); @@ -1155,13 +1163,23 @@ ospf6TrapNbrStateChange (struct ospf6_neighbor *on) ospf6NbrTrapList, sizeof ospf6NbrTrapList / sizeof (struct trap_object), NBRSTATECHANGE); + return 0; } -void -ospf6TrapIfStateChange (struct ospf6_interface *oi) +static int +ospf6TrapIfStateChange (struct ospf6_interface *oi, + int next_state, int prev_state) { oid index[2]; + /* 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)) + return 0; + index[0] = oi->interface->ifindex; index[1] = oi->instance_id; @@ -1172,12 +1190,16 @@ ospf6TrapIfStateChange (struct ospf6_interface *oi) ospf6IfTrapList, sizeof ospf6IfTrapList / sizeof (struct trap_object), IFSTATECHANGE); + return 0; } /* Register OSPFv3-MIB. */ void ospf6_snmp_init (struct thread_master *master) { + hook_register(ospf6_interface_change, ospf6TrapIfStateChange); + hook_register(ospf6_neighbor_change, ospf6TrapNbrStateChange); + smux_init (master); REGISTER_MIB ("OSPFv3MIB", ospfv3_variables, variable, ospfv3_oid); } diff --git a/ospf6d/ospf6_snmp.h b/ospf6d/ospf6_snmp.h deleted file mode 100644 index fa1b0c37a8..0000000000 --- a/ospf6d/ospf6_snmp.h +++ /dev/null @@ -1,31 +0,0 @@ -/* OSPFv3 SNMP support - * Copyright (C) 2004 Yasuhiro Ohara - * - * 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 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*/ - - diff --git a/ospf6d/ospf6d.c b/ospf6d/ospf6d.c index 2aaed5fcbf..9a5868f57e 100644 --- a/ospf6d/ospf6d.c +++ b/ospf6d/ospf6d.c @@ -46,7 +46,7 @@ #include "ospf6_bfd.h" #ifdef HAVE_SNMP -#include "ospf6_snmp.h" +extern void ospf6_snmp_init (struct thread_master *); #endif /*HAVE_SNMP*/ char ospf6_daemon_version[] = OSPF6_DAEMON_VERSION; diff --git a/ospfd/Makefile.am b/ospfd/Makefile.am index 5555fb0da4..52c7dade7c 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 4fb206589a..b4a282a52a 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 bd51bbf422..39202f777a 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 9630616acc..717c99c21f 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 f0357a4824..fa8e6d70f6 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 01617055ce..97f3f6a382 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 9b7e14a4ae..4531f6ec7d 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 4afbda8788..b5813d7d53 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 413d1d7f79..0000000000 --- a/ospfd/ospf_snmp.h +++ /dev/null @@ -1,38 +0,0 @@ -/* OSPFv2 SNMP support - * Copyright (C) 2000 IP Infusion Inc. - * - * Written by Kunihiro Ishiguro - * - * 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 cb14273eed..abb6db0347 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 8e93ed2691..22c71a49e1 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 */ diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index 4c750faf4c..a4ee2ba570 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -42,6 +42,9 @@ #include "ripd/rip_debug.h" #include "ripd/rip_interface.h" +DEFINE_HOOK(rip_ifaddr_add, (struct connected *ifc), (ifc)) +DEFINE_HOOK(rip_ifaddr_del, (struct connected *ifc), (ifc)) + /* static prototypes */ static void rip_enable_apply (struct interface *); static void rip_passive_interface_apply (struct interface *); @@ -673,9 +676,7 @@ rip_interface_address_add (int command, struct zclient *zclient, /* Check if this prefix needs to be redistributed */ rip_apply_address_add(ifc); -#ifdef HAVE_SNMP - rip_ifaddr_add (ifc->ifp, ifc); -#endif /* HAVE_SNMP */ + hook_call(rip_ifaddr_add, ifc); } return 0; @@ -723,9 +724,7 @@ rip_interface_address_delete (int command, struct zclient *zclient, zlog_debug ("connected address %s/%d is deleted", inet_ntoa (p->u.prefix4), p->prefixlen); -#ifdef HAVE_SNMP - rip_ifaddr_delete (ifc->ifp, ifc); -#endif /* HAVE_SNMP */ + hook_call(rip_ifaddr_del, ifc); /* Chech wether this prefix needs to be removed */ rip_apply_address_del(ifc); diff --git a/ripd/rip_snmp.c b/ripd/rip_snmp.c index 36fd9c26ec..bdae0409d2 100644 --- a/ripd/rip_snmp.c +++ b/ripd/rip_snmp.c @@ -175,24 +175,27 @@ rip2Globals (struct variable *v, oid name[], size_t *length, return NULL; } -void -rip_ifaddr_add (struct interface *ifp, struct connected *ifc) +static int +rip_snmp_ifaddr_add (struct connected *ifc) { + struct interface *ifp = ifc->ifp; struct prefix *p; struct route_node *rn; p = ifc->address; if (p->family != AF_INET) - return; + return 0; rn = route_node_get (rip_ifaddr_table, p); rn->info = ifp; + return 0; } -void -rip_ifaddr_delete (struct interface *ifp, struct connected *ifc) +static int +rip_snmp_ifaddr_del (struct connected *ifc) { + struct interface *ifp = ifc->ifp; struct prefix *p; struct route_node *rn; struct interface *i; @@ -200,11 +203,11 @@ rip_ifaddr_delete (struct interface *ifp, struct connected *ifc) p = ifc->address; if (p->family != AF_INET) - return; + return 0; rn = route_node_lookup (rip_ifaddr_table, p); if (! rn) - return; + return 0; i = rn->info; if (rn && !strncmp(i->name,ifp->name,INTERFACE_NAMSIZ)) { @@ -212,6 +215,7 @@ rip_ifaddr_delete (struct interface *ifp, struct connected *ifc) route_unlock_node (rn); route_unlock_node (rn); } + return 0; } static struct interface * @@ -587,6 +591,8 @@ void rip_snmp_init () { rip_ifaddr_table = route_table_init (); + hook_register(rip_ifaddr_add, rip_snmp_ifaddr_add); + hook_register(rip_ifaddr_del, rip_snmp_ifaddr_del); smux_init (master); REGISTER_MIB("mibII/rip", rip_variables, variable, rip_oid); diff --git a/ripd/ripd.h b/ripd/ripd.h index 68b3d1fc6e..66113cdc95 100644 --- a/ripd/ripd.h +++ b/ripd/ripd.h @@ -23,6 +23,7 @@ #define _ZEBRA_RIP_H #include "qobj.h" +#include "hook.h" #include "rip_memory.h" /* RIP version number. */ @@ -432,8 +433,6 @@ extern void rip_offset_clean (void); extern void rip_info_free (struct rip_info *); extern u_char rip_distance_apply (struct rip_info *); extern void rip_redistribute_clean (void); -extern void rip_ifaddr_add (struct interface *, struct connected *); -extern void rip_ifaddr_delete (struct interface *, struct connected *); extern struct rip_info *rip_ecmp_add (struct rip_info *); extern struct rip_info *rip_ecmp_replace (struct rip_info *); @@ -448,4 +447,8 @@ extern struct thread_master *master; /* RIP statistics for SNMP. */ extern long rip_global_route_changes; extern long rip_global_queries; + +DECLARE_HOOK(rip_ifaddr_add, (struct connected *ifc), (ifc)) +DECLARE_HOOK(rip_ifaddr_del, (struct connected *ifc), (ifc)) + #endif /* _ZEBRA_RIP_H */ -- 2.39.5