summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2017-02-13 00:29:37 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2017-03-25 08:52:36 +0100
commit4f8ea50c0d97e8f339b40d95ce428f4ffd66ba76 (patch)
treed2b9bf793d33f1c14d17f8cf1db7750f0b645e8a
parent*: snmp: convert into modules (diff)
downloadfrr-4f8ea50c0d97e8f339b40d95ce428f4ffd66ba76.tar.xz
frr-4f8ea50c0d97e8f339b40d95ce428f4ffd66ba76.zip
zebra: fpm: convert into module
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
-rwxr-xr-xconfigure.ac4
-rw-r--r--zebra/Makefile.am42
-rw-r--r--zebra/main.c16
-rw-r--r--zebra/misc_null.c7
-rw-r--r--zebra/rib.h3
-rw-r--r--zebra/zebra_fpm.c71
-rw-r--r--zebra/zebra_fpm.h36
-rw-r--r--zebra/zebra_rib.c17
-rw-r--r--zebra/zserv.c23
9 files changed, 79 insertions, 140 deletions
diff --git a/configure.ac b/configure.ac
index 466acb25d..5f2e3ed51 100755
--- a/configure.ac
+++ b/configure.ac
@@ -365,9 +365,7 @@ if test "${enable_shell_access}" = "yes"; then
AC_DEFINE(HAVE_SHELL_ACCESS,,Allow user to use ssh/telnet/bash)
fi
-if test "${enable_fpm}" = "yes"; then
- AC_DEFINE(HAVE_FPM,,Forwarding Plane Manager support)
-fi
+AM_CONDITIONAL([FPM], [test "x$enable_fpm" = "xyes"])
if test "x${enable_dev_build}" = "xyes"; then
AC_DEFINE(DEV_BUILD,,Build for development)
diff --git a/zebra/Makefile.am b/zebra/Makefile.am
index 5958f63b5..af7a513d2 100644
--- a/zebra/Makefile.am
+++ b/zebra/Makefile.am
@@ -19,18 +19,6 @@ mpls_method = @MPLS_METHOD@
otherobj = $(ioctl_method) $(ipforward) $(if_method) \
$(rt_method) $(rtread_method) $(kernel_method) $(mpls_method)
-if HAVE_NETLINK
-othersrc = zebra_fpm_netlink.c
-endif
-
-if HAVE_PROTOBUF
-protobuf_srcs = zebra_fpm_protobuf.c
-endif
-
-if DEV_BUILD
-dev_srcs = zebra_fpm_dt.c
-endif
-
AM_CFLAGS = $(WERROR)
sbin_PROGRAMS = zebra
@@ -41,11 +29,12 @@ zebra_SOURCES = \
zebra_memory.c \
zserv.c main.c interface.c connected.c zebra_rib.c zebra_routemap.c \
redistribute.c debug.c rtadv.c zebra_vty.c \
- irdp_main.c irdp_interface.c irdp_packet.c router-id.c zebra_fpm.c \
- $(othersrc) zebra_ptm.c zebra_rnh.c zebra_ptm_redistribute.c \
+ irdp_main.c irdp_interface.c irdp_packet.c router-id.c \
+ zebra_ptm.c zebra_rnh.c zebra_ptm_redistribute.c \
zebra_ns.c zebra_vrf.c zebra_static.c zebra_mpls.c zebra_mpls_vty.c \
- $(protobuf_srcs) zebra_mroute.c \
- $(dev_srcs) label_manager.c
+ zebra_mroute.c \
+ label_manager.c \
+ # end
testzebra_SOURCES = test_main.c zebra_rib.c interface.c connected.c debug.c \
zebra_vty.c zebra_ptm.c zebra_routemap.c zebra_ns.c zebra_vrf.c \
@@ -57,12 +46,12 @@ noinst_HEADERS = \
zebra_memory.h \
connected.h ioctl.h rib.h rt.h zserv.h redistribute.h debug.h rtadv.h \
interface.h ipforward.h irdp.h router-id.h kernel_socket.h \
- rt_netlink.h zebra_fpm.h zebra_fpm_private.h zebra_rnh.h \
+ rt_netlink.h zebra_fpm_private.h zebra_rnh.h \
zebra_ptm_redistribute.h zebra_ptm.h zebra_routemap.h \
zebra_ns.h zebra_vrf.h ioctl_solaris.h zebra_static.h zebra_mpls.h \
kernel_netlink.h if_netlink.h zebra_mroute.h label_manager.h
-zebra_LDADD = $(otherobj) ../lib/libfrr.la $(LIBCAP) $(Q_FPM_PB_CLIENT_LDOPTS)
+zebra_LDADD = $(otherobj) ../lib/libfrr.la $(LIBCAP)
testzebra_LDADD = ../lib/libfrr.la $(LIBCAP)
@@ -75,6 +64,23 @@ zebra_snmp_la_SOURCES = zebra_snmp.c
zebra_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
zebra_snmp_la_LIBADD = ../lib/libfrrsnmp.la
+if FPM
+module_LTLIBRARIES += zebra_fpm.la
+endif
+zebra_fpm_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
+zebra_fpm_la_LIBADD = $(Q_FPM_PB_CLIENT_LDOPTS)
+zebra_fpm_la_SOURCES = zebra_fpm.c
+if HAVE_NETLINK
+zebra_fpm_la_SOURCES += zebra_fpm_netlink.c
+endif
+if HAVE_PROTOBUF
+zebra_fpm_la_SOURCES += zebra_fpm_protobuf.c
+endif
+if DEV_BUILD
+zebra_fpm_la_SOURCES += zebra_fpm_dt.c
+endif
+
+
EXTRA_DIST = if_ioctl.c if_ioctl_solaris.c if_netlink.c \
if_sysctl.c ipforward_proc.c \
ipforward_solaris.c ipforward_sysctl.c rt_netlink.c \
diff --git a/zebra/main.c b/zebra/main.c
index ac19c3410..459e6148d 100644
--- a/zebra/main.c
+++ b/zebra/main.c
@@ -43,7 +43,6 @@
#include "zebra/router-id.h"
#include "zebra/irdp.h"
#include "zebra/rtadv.h"
-#include "zebra/zebra_fpm.h"
#include "zebra/zebra_ptm.h"
#include "zebra/zebra_ns.h"
#include "zebra/redistribute.h"
@@ -84,7 +83,6 @@ struct option longopts[] =
{ "batch", no_argument, NULL, 'b'},
{ "allow_delete", no_argument, NULL, 'a'},
{ "keep_kernel", no_argument, NULL, 'k'},
- { "fpm_format", required_argument, NULL, 'F'},
{ "socket", required_argument, NULL, 'z'},
{ "ecmp", required_argument, NULL, 'e'},
{ "label_socket", no_argument, NULL, 'l'},
@@ -221,21 +219,18 @@ main (int argc, char **argv)
{
// int batch_mode = 0;
char *zserv_path = NULL;
- char *fpm_format = NULL;
/* Socket to external label manager */
char *lblmgr_path = NULL;
-
frr_preinit(&zebra_di, argc, argv);
- frr_opt_add("bakF:z:e:l:r"
+ frr_opt_add("bakz:e:l:r"
#ifdef HAVE_NETLINK
"s:"
#endif
, longopts,
" -b, --batch Runs in batch mode\n"
" -a, --allow_delete Allow other processes to delete zebra routes\n"
- " -F, --fpm_format Set fpm format to 'netlink' or 'protobuf'\n"
" -z, --socket Set path of zebra socket\n"
" -e, --ecmp Specify ECMP to use.\n"
" -l, --label_socket Socket to external label manager\n"\
@@ -266,9 +261,6 @@ main (int argc, char **argv)
case 'k':
keep_kernel_mode = 1;
break;
- case 'F':
- fpm_format = optarg;
- break;
case 'e':
multipath_num = atoi (optarg);
if (multipath_num > MULTIPATH_NUM || multipath_num <= 0)
@@ -329,12 +321,6 @@ main (int argc, char **argv)
/* Initialize NS( and implicitly the VRF module), and make kernel routing socket. */
zebra_ns_init ();
-#ifdef HAVE_FPM
- zfpm_init (zebrad.master, 1, 0, fpm_format);
-#else
- zfpm_init (zebrad.master, 0, 0, fpm_format);
-#endif
-
/* Process the configuration file. Among other configuration
* directives we can meet those installing static routes. Such
* requests will not be executed immediately, but queued in
diff --git a/zebra/misc_null.c b/zebra/misc_null.c
index a83c30741..49cb92bd7 100644
--- a/zebra/misc_null.c
+++ b/zebra/misc_null.c
@@ -25,7 +25,6 @@
#include "zebra/rtadv.h"
#include "zebra/irdp.h"
#include "zebra/interface.h"
-#include "zebra/zebra_fpm.h"
void rtadv_config_write (struct vty *vty, struct interface *ifp) { return; }
void irdp_config_write (struct vty *vty, struct interface *ifp) { return; }
@@ -35,9 +34,3 @@ void ifstat_update_proc (void) { return; }
#ifdef HAVE_NET_RT_IFLIST
void ifstat_update_sysctl (void) { return; }
#endif
-
-void
-zfpm_trigger_update (struct route_node *rn, const char *reason)
-{
- return;
-}
diff --git a/zebra/rib.h b/zebra/rib.h
index c0cde50ba..5381d76b9 100644
--- a/zebra/rib.h
+++ b/zebra/rib.h
@@ -24,6 +24,7 @@
#define _ZEBRA_RIB_H
#include "zebra.h"
+#include "hook.h"
#include "linklist.h"
#include "prefix.h"
#include "table.h"
@@ -490,4 +491,6 @@ rib_tables_iter_cleanup (rib_tables_iter_t *iter)
iter->state = RIB_TABLES_ITER_S_DONE;
}
+DECLARE_HOOK(rib_update, (struct route_node *rn, const char *reason), (rn, reason))
+
#endif /*_ZEBRA_RIB_H */
diff --git a/zebra/zebra_fpm.c b/zebra/zebra_fpm.c
index afa557096..405b2e9f7 100644
--- a/zebra/zebra_fpm.c
+++ b/zebra/zebra_fpm.c
@@ -25,10 +25,12 @@
#include <zebra.h>
#include "log.h"
+#include "libfrr.h"
#include "stream.h"
#include "thread.h"
#include "network.h"
#include "command.h"
+#include "version.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
@@ -36,7 +38,6 @@
#include "zebra/zebra_vrf.h"
#include "fpm/fpm.h"
-#include "zebra_fpm.h"
#include "zebra_fpm_private.h"
/*
@@ -254,6 +255,8 @@ typedef struct zfpm_glob_t_
static zfpm_glob_t zfpm_glob_space;
static zfpm_glob_t *zfpm_g = &zfpm_glob_space;
+static int zfpm_trigger_update (struct route_node *rn, const char *reason);
+
static int zfpm_read_cb (struct thread *thread);
static int zfpm_write_cb (struct thread *thread);
@@ -1296,7 +1299,6 @@ zfpm_start_connect_timer (const char *reason)
zfpm_set_state (ZFPM_STATE_ACTIVE, reason);
}
-#if defined (HAVE_FPM)
/*
* zfpm_is_enabled
*
@@ -1307,7 +1309,6 @@ zfpm_is_enabled (void)
{
return zfpm_g->enabled;
}
-#endif
/*
* zfpm_conn_is_up
@@ -1331,7 +1332,7 @@ zfpm_conn_is_up (void)
* The zebra code invokes this function to indicate that we should
* send an update to the FPM about the given route_node.
*/
-void
+static int
zfpm_trigger_update (struct route_node *rn, const char *reason)
{
rib_dest_t *dest;
@@ -1342,7 +1343,7 @@ zfpm_trigger_update (struct route_node *rn, const char *reason)
* all destinations once the connection comes up.
*/
if (!zfpm_conn_is_up ())
- return;
+ return 0;
dest = rib_dest_from_rnode (rn);
@@ -1353,12 +1354,12 @@ zfpm_trigger_update (struct route_node *rn, const char *reason)
if (!zfpm_is_table_for_fpm (rib_dest_table (dest)))
{
zfpm_g->stats.non_fpm_table_triggers++;
- return;
+ return 0;
}
if (CHECK_FLAG (dest->flags, RIB_DEST_UPDATE_FPM)) {
zfpm_g->stats.redundant_triggers++;
- return;
+ return 0;
}
if (reason)
@@ -1375,9 +1376,10 @@ zfpm_trigger_update (struct route_node *rn, const char *reason)
* Make sure that writes are enabled.
*/
if (zfpm_g->t_write)
- return;
+ return 0;
zfpm_write_on ();
+ return 0;
}
/*
@@ -1411,7 +1413,6 @@ zfpm_stats_timer_cb (struct thread *t)
return 0;
}
-#if defined (HAVE_FPM)
/*
* zfpm_stop_stats_timer
*/
@@ -1424,7 +1425,6 @@ zfpm_stop_stats_timer (void)
zfpm_debug ("Stopping existing stats timer");
THREAD_TIMER_OFF (zfpm_g->t_stats);
}
-#endif
/*
* zfpm_start_stats_timer
@@ -1447,7 +1447,6 @@ zfpm_start_stats_timer (void)
zfpm_g->last_ivl_stats.counter, VTY_NEWLINE); \
} while (0)
-#if defined (HAVE_FPM)
/*
* zfpm_show_stats
*/
@@ -1600,7 +1599,6 @@ DEFUN ( no_fpm_remote_ip,
return CMD_SUCCESS;
}
-#endif
/*
* zfpm_init_message_format
@@ -1670,7 +1668,7 @@ zfpm_init_message_format (const char *format)
* Returns ZERO on success.
*/
-int fpm_remote_srv_write (struct vty *vty )
+static int fpm_remote_srv_write (struct vty *vty)
{
struct in_addr in;
@@ -1684,6 +1682,15 @@ int fpm_remote_srv_write (struct vty *vty )
}
+/* Zebra node */
+static struct cmd_node zebra_node =
+{
+ ZEBRA_NODE,
+ "",
+ 1
+};
+
+
/**
* zfpm_init
*
@@ -1695,17 +1702,12 @@ int fpm_remote_srv_write (struct vty *vty )
*
* Returns TRUE on success.
*/
-int
-zfpm_init (struct thread_master *master, int enable, uint16_t port,
- const char *format)
+static int
+zfpm_init (struct thread_master *master)
{
- static int initialized = 0;
-
- if (initialized) {
- return 1;
- }
-
- initialized = 1;
+ int enable = 1;
+ uint16_t port = 0;
+ const char *format = THIS_MODULE->load_args;
memset (zfpm_g, 0, sizeof (*zfpm_g));
zfpm_g->master = master;
@@ -1717,12 +1719,11 @@ zfpm_init (struct thread_master *master, int enable, uint16_t port,
zfpm_stats_init (&zfpm_g->last_ivl_stats);
zfpm_stats_init (&zfpm_g->cumulative_stats);
-#if defined (HAVE_FPM)
+ install_node (&zebra_node, fpm_remote_srv_write);
install_element (ENABLE_NODE, &show_zebra_fpm_stats_cmd);
install_element (ENABLE_NODE, &clear_zebra_fpm_stats_cmd);
install_element (CONFIG_NODE, &fpm_remote_ip_cmd);
install_element (CONFIG_NODE, &no_fpm_remote_ip_cmd);
-#endif
zfpm_init_message_format(format);
@@ -1734,10 +1735,6 @@ zfpm_init (struct thread_master *master, int enable, uint16_t port,
zfpm_g->enabled = enable;
- if (!enable) {
- return 1;
- }
-
if (!zfpm_g->fpm_server)
zfpm_g->fpm_server = FPM_DEFAULT_IP;
@@ -1751,6 +1748,20 @@ zfpm_init (struct thread_master *master, int enable, uint16_t port,
zfpm_start_stats_timer ();
zfpm_start_connect_timer ("initialized");
+ return 0;
+}
- return 1;
+static int
+zebra_fpm_module_init (void)
+{
+ hook_register(rib_update, zfpm_trigger_update);
+ hook_register(frr_late_init, zfpm_init);
+ return 0;
}
+
+FRR_MODULE_SETUP(
+ .name = "zebra_fpm",
+ .version = FRR_VERSION,
+ .description = "zebra FPM (Forwarding Plane Manager) module",
+ .init = zebra_fpm_module_init,
+)
diff --git a/zebra/zebra_fpm.h b/zebra/zebra_fpm.h
deleted file mode 100644
index fdb069965..000000000
--- a/zebra/zebra_fpm.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Header file exported by the zebra FPM module to zebra.
- *
- * Copyright (C) 2012 by Open Source Routing.
- * Copyright (C) 2012 by Internet Systems Consortium, Inc. ("ISC")
- *
- * 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_FPM_H
-#define _ZEBRA_FPM_H
-
-/*
- * Externs.
- */
-extern int zfpm_init (struct thread_master *master, int enable, uint16_t port,
- const char *message_format);
-extern void zfpm_trigger_update (struct route_node *rn, const char *reason);
-extern int fpm_remote_srv_write (struct vty *vty);
-
-#endif /* _ZEBRA_FPM_H */
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index f5b54a2c0..b3e70e46f 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -48,11 +48,12 @@
#include "zebra/redistribute.h"
#include "zebra/zebra_routemap.h"
#include "zebra/debug.h"
-#include "zebra/zebra_fpm.h"
#include "zebra/zebra_rnh.h"
#include "zebra/interface.h"
#include "zebra/connected.h"
+DEFINE_HOOK(rib_update, (struct route_node *rn, const char *reason), (rn, reason))
+
/* Should we allow non Quagga processes to delete our routes */
extern int allow_delete;
@@ -1110,7 +1111,7 @@ rib_install_kernel (struct route_node *rn, struct rib *rib, struct rib *old)
* Make sure we update the FPM any time we send new information to
* the kernel.
*/
- zfpm_trigger_update (rn, "installing in kernel");
+ hook_call(rib_update, rn, "installing in kernel");
ret = kernel_route_rib (p, src_p, old, rib);
/* If install succeeds, update FIB flag for nexthops. */
@@ -1154,7 +1155,7 @@ rib_uninstall_kernel (struct route_node *rn, struct rib *rib)
* Make sure we update the FPM any time we send new information to
* the kernel.
*/
- zfpm_trigger_update (rn, "uninstalling from kernel");
+ hook_call(rib_update, rn, "uninstalling from kernel");
ret = kernel_route_rib (p, src_p, rib, NULL);
for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
@@ -1172,7 +1173,7 @@ rib_uninstall (struct route_node *rn, struct rib *rib)
if (CHECK_FLAG (rib->status, RIB_ENTRY_SELECTED_FIB))
{
if (info->safi == SAFI_UNICAST)
- zfpm_trigger_update (rn, "rib_uninstall");
+ hook_call(rib_update, rn, "rib_uninstall");
if (! RIB_SYSTEM_ROUTE (rib))
rib_uninstall_kernel (rn, rib);
@@ -1253,7 +1254,7 @@ static void
rib_process_add_fib(struct zebra_vrf *zvrf, struct route_node *rn,
struct rib *new)
{
- zfpm_trigger_update (rn, "new route selected");
+ hook_call(rib_update, rn, "new route selected");
/* Update real nexthop. This may actually determine if nexthop is active or not. */
if (!nexthop_active_update (rn, new, 1))
@@ -1289,7 +1290,7 @@ static void
rib_process_del_fib(struct zebra_vrf *zvrf, struct route_node *rn,
struct rib *old)
{
- zfpm_trigger_update (rn, "removing existing route");
+ hook_call(rib_update, rn, "removing existing route");
/* Uninstall from kernel. */
if (IS_ZEBRA_DEBUG_RIB)
@@ -1326,7 +1327,7 @@ rib_process_update_fib (struct zebra_vrf *zvrf, struct route_node *rn,
if (new != old ||
CHECK_FLAG (new->status, RIB_ENTRY_CHANGED))
{
- zfpm_trigger_update (rn, "updating existing route");
+ hook_call(rib_update, rn, "updating existing route");
/* Update the nexthop; we could determine here that nexthop is inactive. */
if (nexthop_active_update (rn, new, 1))
@@ -2874,7 +2875,7 @@ rib_close_table (struct route_table *table)
continue;
if (info->safi == SAFI_UNICAST)
- zfpm_trigger_update (rn, NULL);
+ hook_call(rib_update, rn, NULL);
if (! RIB_SYSTEM_ROUTE (rib))
rib_uninstall_kernel (rn, rib);
diff --git a/zebra/zserv.c b/zebra/zserv.c
index f9205a12c..c1978e55c 100644
--- a/zebra/zserv.c
+++ b/zebra/zserv.c
@@ -53,7 +53,6 @@
#include "zebra/zebra_ptm.h"
#include "zebra/rtadv.h"
#include "zebra/zebra_mpls.h"
-#include "zebra/zebra_fpm.h"
#include "zebra/zebra_mroute.h"
#include "zebra/label_manager.h"
@@ -2850,25 +2849,6 @@ static struct cmd_node forwarding_node =
1
};
-#ifdef HAVE_FPM
-/* function to write the fpm config info */
-static int
-config_write_fpm (struct vty *vty)
-{
- return
- fpm_remote_srv_write (vty);
-}
-
-/* Zebra node */
-static struct cmd_node zebra_node =
-{
- ZEBRA_NODE,
- "",
- 1
-};
-#endif
-
-
/* Initialisation of zebra and installation of commands. */
void
zebra_init (void)
@@ -2879,9 +2859,6 @@ zebra_init (void)
/* Install configuration write function. */
install_node (&table_node, config_write_table);
install_node (&forwarding_node, config_write_forwarding);
-#ifdef HAVE_FPM
- install_node (&zebra_node, config_write_fpm);
-#endif
install_element (VIEW_NODE, &show_ip_forwarding_cmd);
install_element (CONFIG_NODE, &ip_forwarding_cmd);