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"
|
2023-03-07 20:22:48 +01:00
|
|
|
#include "frrevent.h"
|
2018-05-08 13:58:32 +02:00
|
|
|
#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
|
|
|
|
2023-02-28 10:08:41 +01:00
|
|
|
#include "mgmt_be_client.h"
|
|
|
|
|
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. */
|
2023-03-07 20:14:41 +01:00
|
|
|
struct event_loop *master;
|
2018-05-08 13:58:32 +02:00
|
|
|
|
2023-12-12 01:53:03 +01:00
|
|
|
static struct mgmt_be_client *mgmt_be_client;
|
2023-02-28 10:08:41 +01:00
|
|
|
|
2020-04-24 14:38:43 +02:00
|
|
|
static struct frr_daemon_info staticd_di;
|
2023-06-10 05:15:12 +02:00
|
|
|
|
2018-05-08 13:58:32 +02:00
|
|
|
/* SIGHUP handler. */
|
|
|
|
static void sighup(void)
|
|
|
|
{
|
2023-06-10 05:15:12 +02:00
|
|
|
zlog_info("SIGHUP received and ignored");
|
2018-05-08 13:58:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* SIGINT / SIGTERM handler. */
|
|
|
|
static void sigint(void)
|
|
|
|
{
|
|
|
|
zlog_notice("Terminating on signal");
|
|
|
|
|
2023-03-21 13:55:35 +01:00
|
|
|
/* Disable BFD events to avoid wasting processing. */
|
|
|
|
bfd_protocol_integration_set_shutdown(true);
|
|
|
|
|
2023-06-04 21:43:22 +02:00
|
|
|
mgmt_be_client_destroy(mgmt_be_client);
|
2023-02-28 10:08:41 +01:00
|
|
|
|
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[] = {
|
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
|
|
|
|
|
2023-03-31 18:34:49 +02:00
|
|
|
/*
|
|
|
|
* NOTE: .flags == FRR_NO_SPLIT_CONFIG to avoid reading split config, mgmtd will
|
|
|
|
* do this for us now
|
|
|
|
*/
|
2018-05-08 13:58:32 +02:00
|
|
|
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),
|
2023-03-31 18:34:49 +02:00
|
|
|
|
|
|
|
.flags = FRR_NO_SPLIT_CONFIG);
|
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();
|
|
|
|
|
2023-02-28 10:08:41 +01:00
|
|
|
/* Initialize MGMT backend functionalities */
|
2023-06-04 21:43:22 +02:00
|
|
|
mgmt_be_client = mgmt_be_client_create("staticd", NULL, 0, master);
|
2023-02-28 10:08:41 +01:00
|
|
|
|
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();
|
|
|
|
|
2023-03-31 18:34:49 +02:00
|
|
|
/*
|
|
|
|
* We set FRR_NO_SPLIT_CONFIG flag to avoid reading our config, but we
|
|
|
|
* still need to write one if vtysh tells us to. Setting the host
|
|
|
|
* config filename does this.
|
|
|
|
*/
|
|
|
|
host_config_set(config_default);
|
2018-05-08 14:12:41 +02:00
|
|
|
|
2018-05-08 13:58:32 +02:00
|
|
|
frr_config_fork();
|
|
|
|
frr_run(master);
|
|
|
|
|
|
|
|
/* Not reached. */
|
|
|
|
return 0;
|
|
|
|
}
|