2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-05-08 13:58:32 +02:00
|
|
|
/*
|
|
|
|
* STATICd - main code
|
|
|
|
* Copyright (C) 2018 Cumulus Networks, Inc.
|
|
|
|
* Donald Sharp
|
|
|
|
*/
|
|
|
|
#include <zebra.h>
|
|
|
|
|
|
|
|
#include <lib/version.h>
|
|
|
|
#include "getopt.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "privs.h"
|
|
|
|
#include "sigevent.h"
|
|
|
|
#include "libfrr.h"
|
|
|
|
#include "vrf.h"
|
|
|
|
#include "nexthop.h"
|
2018-08-16 02:14:22 +02:00
|
|
|
#include "filter.h"
|
2020-04-24 14:38:43 +02:00
|
|
|
#include "routing_nb.h"
|
2018-05-08 13:58:32 +02:00
|
|
|
|
|
|
|
#include "static_vrf.h"
|
|
|
|
#include "static_vty.h"
|
|
|
|
#include "static_routes.h"
|
|
|
|
#include "static_zebra.h"
|
2020-01-08 20:13:42 +01:00
|
|
|
#include "static_debug.h"
|
2020-04-24 14:38:43 +02:00
|
|
|
#include "static_nb.h"
|
2018-05-08 13:58:32 +02:00
|
|
|
|
2018-05-08 14:12:41 +02:00
|
|
|
char backup_config_file[256];
|
|
|
|
|
2018-05-08 13:58:32 +02:00
|
|
|
bool mpls_enabled;
|
2020-06-11 17:16:02 +02:00
|
|
|
|
2018-05-08 13:58:32 +02:00
|
|
|
zebra_capabilities_t _caps_p[] = {
|
|
|
|
};
|
|
|
|
|
|
|
|
struct zebra_privs_t static_privs = {
|
|
|
|
#if defined(FRR_USER) && defined(FRR_GROUP)
|
|
|
|
.user = FRR_USER,
|
|
|
|
.group = FRR_GROUP,
|
|
|
|
#endif
|
|
|
|
#if defined(VTY_GROUP)
|
|
|
|
.vty_group = VTY_GROUP,
|
|
|
|
#endif
|
|
|
|
.caps_p = _caps_p,
|
|
|
|
.cap_num_p = array_size(_caps_p),
|
|
|
|
.cap_num_i = 0};
|
|
|
|
|
|
|
|
struct option longopts[] = { { 0 } };
|
|
|
|
|
|
|
|
/* Master of threads. */
|
|
|
|
struct thread_master *master;
|
|
|
|
|
2020-04-24 14:38:43 +02:00
|
|
|
static struct frr_daemon_info staticd_di;
|
2018-05-08 13:58:32 +02:00
|
|
|
/* SIGHUP handler. */
|
|
|
|
static void sighup(void)
|
|
|
|
{
|
|
|
|
zlog_info("SIGHUP received");
|
2020-04-24 14:38:43 +02:00
|
|
|
vty_read_config(NULL, staticd_di.config_file, config_default);
|
2018-05-08 13:58:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* SIGINT / SIGTERM handler. */
|
|
|
|
static void sigint(void)
|
|
|
|
{
|
|
|
|
zlog_notice("Terminating on signal");
|
|
|
|
|
2020-03-08 02:22:52 +01:00
|
|
|
static_vrf_terminate();
|
|
|
|
|
2022-10-11 18:57:57 +02:00
|
|
|
static_zebra_stop();
|
2020-06-11 17:16:02 +02:00
|
|
|
frr_fini();
|
|
|
|
|
2018-05-08 13:58:32 +02:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SIGUSR1 handler. */
|
|
|
|
static void sigusr1(void)
|
|
|
|
{
|
|
|
|
zlog_rotate();
|
|
|
|
}
|
|
|
|
|
2021-11-11 20:28:54 +01:00
|
|
|
struct frr_signal_t static_signals[] = {
|
2018-05-08 13:58:32 +02:00
|
|
|
{
|
|
|
|
.signal = SIGHUP,
|
|
|
|
.handler = &sighup,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.signal = SIGUSR1,
|
|
|
|
.handler = &sigusr1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.signal = SIGINT,
|
|
|
|
.handler = &sigint,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.signal = SIGTERM,
|
|
|
|
.handler = &sigint,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-11-20 17:23:04 +01:00
|
|
|
static const struct frr_yang_module_info *const staticd_yang_modules[] = {
|
2019-11-08 18:41:46 +01:00
|
|
|
&frr_filter_info,
|
2020-04-24 14:38:43 +02:00
|
|
|
&frr_interface_info,
|
2020-03-11 21:14:08 +01:00
|
|
|
&frr_vrf_info,
|
2020-04-24 14:38:43 +02:00
|
|
|
&frr_routing_info,
|
|
|
|
&frr_staticd_info,
|
2018-05-24 01:29:50 +02:00
|
|
|
};
|
|
|
|
|
2018-05-08 13:58:32 +02:00
|
|
|
#define STATIC_VTY_PORT 2616
|
|
|
|
|
|
|
|
FRR_DAEMON_INFO(staticd, STATIC, .vty_port = STATIC_VTY_PORT,
|
|
|
|
|
|
|
|
.proghelp = "Implementation of STATIC.",
|
|
|
|
|
|
|
|
.signals = static_signals,
|
|
|
|
.n_signals = array_size(static_signals),
|
|
|
|
|
2018-05-24 01:29:50 +02:00
|
|
|
.privs = &static_privs, .yang_modules = staticd_yang_modules,
|
|
|
|
.n_yang_modules = array_size(staticd_yang_modules),
|
2018-08-08 16:00:04 +02:00
|
|
|
);
|
2018-05-08 13:58:32 +02:00
|
|
|
|
|
|
|
int main(int argc, char **argv, char **envp)
|
|
|
|
{
|
|
|
|
frr_preinit(&staticd_di, argc, argv);
|
|
|
|
frr_opt_add("", longopts, "");
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
int opt;
|
|
|
|
|
|
|
|
opt = frr_getopt(argc, argv, NULL);
|
|
|
|
|
|
|
|
if (opt == EOF)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (opt) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
frr_help_exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
master = frr_init();
|
|
|
|
|
2020-01-08 20:13:42 +01:00
|
|
|
static_debug_init();
|
2018-05-08 13:58:32 +02:00
|
|
|
static_vrf_init();
|
|
|
|
|
|
|
|
static_zebra_init();
|
|
|
|
static_vty_init();
|
|
|
|
|
2020-04-24 14:38:43 +02:00
|
|
|
hook_register(routing_conf_event,
|
|
|
|
routing_control_plane_protocols_name_validate);
|
|
|
|
|
2021-02-16 10:57:01 +01:00
|
|
|
routing_control_plane_protocols_register_vrf_dependency();
|
|
|
|
|
2018-05-08 14:12:41 +02:00
|
|
|
snprintf(backup_config_file, sizeof(backup_config_file),
|
|
|
|
"%s/zebra.conf", frr_sysconfdir);
|
|
|
|
staticd_di.backup_config_file = backup_config_file;
|
|
|
|
|
2018-05-08 13:58:32 +02:00
|
|
|
frr_config_fork();
|
|
|
|
frr_run(master);
|
|
|
|
|
|
|
|
/* Not reached. */
|
|
|
|
return 0;
|
|
|
|
}
|