2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2002-12-13 21:15:29 +01:00
|
|
|
/* RIPd main routine.
|
|
|
|
* Copyright (C) 1997, 98 Kunihiro Ishiguro <kunihiro@zebra.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zebra.h>
|
|
|
|
|
2004-03-16 15:38:36 +01:00
|
|
|
#include <lib/version.h>
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "getopt.h"
|
2023-03-07 20:22:48 +01:00
|
|
|
#include "frrevent.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "command.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "prefix.h"
|
|
|
|
#include "filter.h"
|
|
|
|
#include "keychain.h"
|
|
|
|
#include "log.h"
|
2003-06-04 15:59:38 +02:00
|
|
|
#include "privs.h"
|
2004-01-19 22:31:15 +01:00
|
|
|
#include "sigevent.h"
|
2011-11-25 15:51:48 +01:00
|
|
|
#include "zclient.h"
|
2015-05-22 11:39:58 +02:00
|
|
|
#include "vrf.h"
|
2019-03-02 19:00:46 +01:00
|
|
|
#include "if_rmap.h"
|
2016-11-13 08:02:23 +01:00
|
|
|
#include "libfrr.h"
|
2019-10-01 22:56:41 +02:00
|
|
|
#include "routemap.h"
|
2021-10-14 17:12:37 +02:00
|
|
|
#include "bfd.h"
|
2024-01-19 17:40:12 +01:00
|
|
|
#include "mgmt_be_client.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
#include "ripd/ripd.h"
|
2021-10-14 17:12:37 +02:00
|
|
|
#include "ripd/rip_bfd.h"
|
2019-10-17 20:46:54 +02:00
|
|
|
#include "ripd/rip_nb.h"
|
2018-06-19 22:13:45 +02:00
|
|
|
#include "ripd/rip_errors.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* ripd options. */
|
2019-05-22 17:42:40 +02:00
|
|
|
static struct option longopts[] = {{0}};
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2003-06-04 15:59:38 +02:00
|
|
|
/* ripd privileges */
|
2019-01-04 22:08:10 +01:00
|
|
|
zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_SYS_ADMIN};
|
2003-06-04 15:59:38 +02:00
|
|
|
|
2023-05-17 21:47:56 +02:00
|
|
|
uint32_t zebra_ecmp_count = MULTIPATH_NUM;
|
|
|
|
|
2003-06-04 15:59:38 +02:00
|
|
|
struct zebra_privs_t ripd_privs = {
|
2016-12-14 19:30:44 +01:00
|
|
|
#if defined(FRR_USER)
|
|
|
|
.user = FRR_USER,
|
2003-06-04 15:59:38 +02:00
|
|
|
#endif
|
2016-12-14 19:30:44 +01:00
|
|
|
#if defined FRR_GROUP
|
|
|
|
.group = FRR_GROUP,
|
2003-08-14 07:32:12 +02:00
|
|
|
#endif
|
|
|
|
#ifdef VTY_GROUP
|
|
|
|
.vty_group = VTY_GROUP,
|
2003-06-04 15:59:38 +02:00
|
|
|
#endif
|
|
|
|
.caps_p = _caps_p,
|
2019-01-04 22:08:10 +01:00
|
|
|
.cap_num_p = array_size(_caps_p),
|
2003-06-04 15:59:38 +02:00
|
|
|
.cap_num_i = 0};
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Master of threads. */
|
2023-03-07 20:14:41 +01:00
|
|
|
struct event_loop *master;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2024-01-19 17:40:12 +01:00
|
|
|
struct mgmt_be_client *mgmt_be_client;
|
|
|
|
|
2016-11-13 09:48:56 +01:00
|
|
|
static struct frr_daemon_info ripd_di;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* SIGHUP handler. */
|
2004-01-19 22:31:15 +01:00
|
|
|
static void sighup(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
zlog_info("SIGHUP received");
|
|
|
|
|
|
|
|
/* Reload config file. */
|
2017-12-07 20:31:48 +01:00
|
|
|
vty_read_config(NULL, ripd_di.config_file, config_default);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* SIGINT handler. */
|
2004-01-19 22:31:15 +01:00
|
|
|
static void sigint(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2023-11-12 04:55:00 +01:00
|
|
|
struct vrf *vrf;
|
|
|
|
|
2004-12-03 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* bgp_main.c: (sigint) Use zlog_notice for termination message.
(main) Use zlog_notice for startup announcement.
* isis_main.c: (sigint,sigterm) Use zlog_notice for termination message.
(terminate) This function should be static, not global.
(main) Use zlog_notice for startup announcement, and remove
ifdef ZEBRA_VERSION.
* version.h.in: Remove declaration for pid_output_lock, this function
is now static, not global.
* pid_output.c: (pid_output_lock) This function should be static, not
global. And remove "old umask" error message, since it was really
an unimportant debug message, not an error.
(pid_output) Need to declare static function pid_output_lock.
* ospf6_main.c: (sigint,sigterm) Use zlog_notice for termination
message.
(main) Remove commented-out call to pid_output_lock (which should
never be called other than from inside pid_output). And use
zlog_notice to print the startup message, which now includes
the vty port.
* ospf_main.c: (sigint) Use zlog_notice for termination message.
(main) Issue a startup announcement using zlog_notice.
* rip_main.c: (sigint) Use zlog_notice for termination message.
(main) Add a startup announcement using zlog_notice.
* ripng_main.c: (sighup) Remove spurious terminating message.
(sigint) Use zlog_notice for termination message.
(main) Issue a startup announcement using zlog_notice.
* main.c: (sigint) Use zlog_notice for termination message.
(main) Add a startup announcement using zlog_notice.
2004-12-03 17:36:46 +01:00
|
|
|
zlog_notice("Terminating on signal");
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2021-10-14 17:12:37 +02:00
|
|
|
bfd_protocol_integration_set_shutdown(true);
|
2023-11-12 04:55:00 +01:00
|
|
|
|
2024-01-19 17:40:12 +01:00
|
|
|
|
|
|
|
nb_oper_cancel_all_walks();
|
|
|
|
mgmt_be_client_destroy(mgmt_be_client);
|
|
|
|
mgmt_be_client = NULL;
|
|
|
|
|
2023-11-12 04:55:00 +01:00
|
|
|
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
|
|
|
|
if (!vrf->info)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rip_clean(vrf->info);
|
|
|
|
}
|
|
|
|
|
2019-01-04 22:08:10 +01:00
|
|
|
rip_vrf_terminate();
|
2019-03-02 19:00:46 +01:00
|
|
|
if_rmap_terminate();
|
2017-06-30 16:32:26 +02:00
|
|
|
rip_zclient_stop();
|
2023-11-12 04:55:00 +01:00
|
|
|
|
|
|
|
route_map_finish();
|
2023-11-15 20:36:24 +01:00
|
|
|
|
|
|
|
keychain_terminate();
|
2017-09-12 04:05:16 +02:00
|
|
|
frr_fini();
|
2017-06-30 16:32:26 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SIGUSR1 handler. */
|
2004-01-19 22:31:15 +01:00
|
|
|
static void sigusr1(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2016-02-23 12:49:45 +01:00
|
|
|
zlog_rotate();
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2021-11-11 20:28:54 +01:00
|
|
|
static struct frr_signal_t ripd_signals[] = {
|
2004-01-19 22:31:15 +01:00
|
|
|
{
|
|
|
|
.signal = SIGHUP,
|
|
|
|
.handler = &sighup,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.signal = SIGUSR1,
|
|
|
|
.handler = &sigusr1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.signal = SIGINT,
|
2004-03-17 21:39:18 +01:00
|
|
|
.handler = &sigint,
|
2004-01-19 22:31:15 +01:00
|
|
|
},
|
2004-03-22 09:55:25 +01:00
|
|
|
{
|
|
|
|
.signal = SIGTERM,
|
|
|
|
.handler = &sigint,
|
|
|
|
},
|
2017-07-17 14:03:14 +02:00
|
|
|
};
|
2016-11-13 08:02:23 +01:00
|
|
|
|
2019-11-20 17:23:04 +01:00
|
|
|
static const struct frr_yang_module_info *const ripd_yang_modules[] = {
|
2019-11-08 18:41:46 +01:00
|
|
|
&frr_filter_info,
|
2018-07-08 03:04:33 +02:00
|
|
|
&frr_interface_info,
|
2018-05-09 06:34:57 +02:00
|
|
|
&frr_ripd_info,
|
2019-10-01 22:56:41 +02:00
|
|
|
&frr_route_map_info,
|
2020-03-11 21:14:08 +01:00
|
|
|
&frr_vrf_info,
|
2024-02-24 11:48:40 +01:00
|
|
|
&ietf_key_chain_info,
|
|
|
|
&ietf_key_chain_deviation_info,
|
2018-05-24 01:29:50 +02:00
|
|
|
};
|
|
|
|
|
2024-01-25 18:30:10 +01:00
|
|
|
/* clang-format off */
|
|
|
|
FRR_DAEMON_INFO(ripd, RIP,
|
|
|
|
.vty_port = RIP_VTY_PORT,
|
|
|
|
.proghelp = "Implementation of the RIP routing protocol.",
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2024-01-25 18:30:10 +01:00
|
|
|
.signals = ripd_signals,
|
|
|
|
.n_signals = array_size(ripd_signals),
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2024-01-25 18:30:10 +01:00
|
|
|
.privs = &ripd_privs,
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2024-01-25 18:30:10 +01:00
|
|
|
.yang_modules = ripd_yang_modules,
|
|
|
|
.n_yang_modules = array_size(ripd_yang_modules),
|
2024-01-19 17:40:12 +01:00
|
|
|
|
2024-01-25 18:30:10 +01:00
|
|
|
/* mgmtd will load the per-daemon config file now */
|
|
|
|
.flags = FRR_NO_SPLIT_CONFIG,
|
2018-05-24 01:29:50 +02:00
|
|
|
);
|
2024-01-25 18:30:10 +01:00
|
|
|
/* clang-format on */
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-05-22 17:42:40 +02:00
|
|
|
#define DEPRECATED_OPTIONS ""
|
2018-05-16 23:07:54 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Main routine of ripd. */
|
|
|
|
int main(int argc, char **argv)
|
2017-07-17 14:03:14 +02:00
|
|
|
{
|
2016-11-13 08:02:23 +01:00
|
|
|
frr_preinit(&ripd_di, argc, argv);
|
2018-05-16 23:07:54 +02:00
|
|
|
|
|
|
|
frr_opt_add("" DEPRECATED_OPTIONS, longopts, "");
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Command line option parse. */
|
|
|
|
while (1) {
|
2017-07-17 14:03:14 +02:00
|
|
|
int opt;
|
|
|
|
|
2016-11-13 08:02:23 +01:00
|
|
|
opt = frr_getopt(argc, argv, NULL);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-05-16 23:07:54 +02:00
|
|
|
if (opt && opt < 128 && strchr(DEPRECATED_OPTIONS, opt)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"The -%c option no longer exists.\nPlease refer to the manual.\n",
|
|
|
|
opt);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (opt == EOF)
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
switch (opt) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
2016-11-13 08:02:23 +01:00
|
|
|
frr_help_exit(1);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepare master thread. */
|
2016-11-13 08:02:23 +01:00
|
|
|
master = frr_init();
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Library initialization. */
|
2018-06-19 22:13:45 +02:00
|
|
|
rip_error_init();
|
2024-02-24 11:48:40 +01:00
|
|
|
keychain_init_new(true);
|
2019-01-04 22:08:10 +01:00
|
|
|
rip_vrf_init();
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* RIP related initialization. */
|
|
|
|
rip_init();
|
|
|
|
rip_if_init();
|
2024-01-19 17:40:12 +01:00
|
|
|
|
|
|
|
mgmt_be_client = mgmt_be_client_create("ripd", NULL, 0, master);
|
|
|
|
|
2015-09-23 22:26:56 +02:00
|
|
|
rip_zclient_init(master);
|
2021-10-14 17:12:37 +02:00
|
|
|
rip_bfd_init(master);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2016-11-13 09:48:56 +01:00
|
|
|
frr_config_fork();
|
2016-11-14 01:56:02 +01:00
|
|
|
frr_run(master);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Not reached. */
|
2020-02-09 13:21:56 +01:00
|
|
|
return 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|