2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2003-06-04 15:59:38 +02:00
|
|
|
/* zebra daemon main routine.
|
2002-12-13 21:15:29 +01:00
|
|
|
* Copyright (C) 1997, 98 Kunihiro Ishiguro
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zebra.h>
|
|
|
|
|
2023-11-04 09:15:54 +01:00
|
|
|
#ifdef GNU_LINUX
|
|
|
|
#include <linux/rtnetlink.h>
|
|
|
|
#endif
|
|
|
|
|
2004-03-16 15:38:36 +01:00
|
|
|
#include <lib/version.h>
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "getopt.h"
|
|
|
|
#include "command.h"
|
2023-03-07 20:22:48 +01:00
|
|
|
#include "frrevent.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "filter.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "prefix.h"
|
|
|
|
#include "log.h"
|
2007-05-02 18:05:35 +02:00
|
|
|
#include "plist.h"
|
2003-06-04 15:59:38 +02:00
|
|
|
#include "privs.h"
|
2004-01-19 22:31:15 +01:00
|
|
|
#include "sigevent.h"
|
2015-05-22 11:39:56 +02:00
|
|
|
#include "vrf.h"
|
2016-11-13 08:02:23 +01:00
|
|
|
#include "libfrr.h"
|
2022-11-03 14:30:23 +01:00
|
|
|
#include "affinitymap.h"
|
2018-04-22 22:01:20 +02:00
|
|
|
#include "routemap.h"
|
2020-07-02 07:36:51 +02:00
|
|
|
#include "routing_nb.h"
|
2023-10-03 23:53:11 +02:00
|
|
|
#include "mgmt_be_client.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2018-08-27 16:43:37 +02:00
|
|
|
#include "zebra/zebra_router.h"
|
2018-06-19 20:29:05 +02:00
|
|
|
#include "zebra/zebra_errors.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "zebra/rib.h"
|
|
|
|
#include "zebra/zserv.h"
|
|
|
|
#include "zebra/debug.h"
|
2004-10-03 20:18:34 +02:00
|
|
|
#include "zebra/router-id.h"
|
2004-06-12 16:33:05 +02:00
|
|
|
#include "zebra/irdp.h"
|
2005-06-28 19:17:12 +02:00
|
|
|
#include "zebra/rtadv.h"
|
2015-05-20 02:40:44 +02:00
|
|
|
#include "zebra/zebra_ptm.h"
|
2016-04-14 04:40:18 +02:00
|
|
|
#include "zebra/zebra_ns.h"
|
2016-04-13 16:06:36 +02:00
|
|
|
#include "zebra/redistribute.h"
|
2016-04-15 19:51:56 +02:00
|
|
|
#include "zebra/zebra_mpls.h"
|
2017-03-20 15:34:49 +01:00
|
|
|
#include "zebra/label_manager.h"
|
2017-12-13 11:04:31 +01:00
|
|
|
#include "zebra/zebra_netns_notify.h"
|
2018-04-22 23:03:52 +02:00
|
|
|
#include "zebra/zebra_rnh.h"
|
2018-05-22 12:22:08 +02:00
|
|
|
#include "zebra/zebra_pbr.h"
|
2019-06-19 23:45:21 +02:00
|
|
|
#include "zebra/zebra_vxlan.h"
|
2020-03-16 03:23:38 +01:00
|
|
|
#include "zebra/zebra_routemap.h"
|
2020-01-29 18:38:03 +01:00
|
|
|
#include "zebra/zebra_nb.h"
|
2020-04-19 19:23:09 +02:00
|
|
|
#include "zebra/zebra_opaque.h"
|
2020-07-20 13:43:54 +02:00
|
|
|
#include "zebra/zebra_srte.h"
|
2020-12-09 10:52:17 +01:00
|
|
|
#include "zebra/zebra_srv6.h"
|
2020-09-30 05:59:19 +02:00
|
|
|
#include "zebra/zebra_srv6_vty.h"
|
2015-05-20 02:40:44 +02:00
|
|
|
|
|
|
|
#define ZEBRA_PTM_SUPPORT
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* process id. */
|
|
|
|
pid_t pid;
|
|
|
|
|
2017-02-03 13:59:04 +01:00
|
|
|
/* Pacify zclient.o in libfrr, which expects this variable. */
|
2023-03-07 20:14:41 +01:00
|
|
|
struct event_loop *master;
|
2004-06-30 19:36:11 +02:00
|
|
|
|
2023-10-03 23:53:11 +02:00
|
|
|
struct mgmt_be_client *mgmt_be_client;
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Route retain mode flag. */
|
|
|
|
int retain_mode = 0;
|
|
|
|
|
2019-05-10 02:06:13 +02:00
|
|
|
int graceful_restart;
|
|
|
|
|
2022-02-26 21:40:15 +01:00
|
|
|
/* Receive buffer size for kernel control sockets */
|
2022-05-12 16:04:17 +02:00
|
|
|
#define RCVBUFSIZE_MIN 4194304
|
2004-08-31 15:41:49 +02:00
|
|
|
#ifdef HAVE_NETLINK
|
2022-05-12 16:04:17 +02:00
|
|
|
uint32_t rcvbufsize = RCVBUFSIZE_MIN;
|
2022-02-26 21:40:15 +01:00
|
|
|
#else
|
|
|
|
uint32_t rcvbufsize = 128 * 1024;
|
|
|
|
#endif
|
2004-08-31 15:41:49 +02:00
|
|
|
|
2023-08-22 13:27:59 +02:00
|
|
|
uint32_t rt_table_main_id = RT_TABLE_MAIN;
|
|
|
|
|
2018-05-18 21:41:46 +02:00
|
|
|
#define OPTION_V6_RR_SEMANTICS 2000
|
2020-09-28 21:22:52 +02:00
|
|
|
#define OPTION_ASIC_OFFLOAD 2001
|
2023-07-24 17:16:53 +02:00
|
|
|
#define OPTION_V6_WITH_V4_NEXTHOP 2002
|
2020-09-28 21:22:52 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Command line options. */
|
2019-11-20 17:26:59 +01:00
|
|
|
const struct option longopts[] = {
|
2023-07-24 17:16:53 +02:00
|
|
|
{ "batch", no_argument, NULL, 'b' },
|
|
|
|
{ "allow_delete", no_argument, NULL, 'a' },
|
|
|
|
{ "socket", required_argument, NULL, 'z' },
|
|
|
|
{ "ecmp", required_argument, NULL, 'e' },
|
|
|
|
{ "retain", no_argument, NULL, 'r' },
|
|
|
|
{ "graceful_restart", required_argument, NULL, 'K' },
|
|
|
|
{ "asic-offload", optional_argument, NULL, OPTION_ASIC_OFFLOAD },
|
|
|
|
{ "v6-with-v4-nexthops", no_argument, NULL, OPTION_V6_WITH_V4_NEXTHOP },
|
2004-08-31 15:41:49 +02:00
|
|
|
#ifdef HAVE_NETLINK
|
2023-07-24 17:16:53 +02:00
|
|
|
{ "vrfwnetns", no_argument, NULL, 'n' },
|
|
|
|
{ "nl-bufsize", required_argument, NULL, 's' },
|
|
|
|
{ "v6-rr-semantics", no_argument, NULL, OPTION_V6_RR_SEMANTICS },
|
2004-08-31 15:41:49 +02:00
|
|
|
#endif /* HAVE_NETLINK */
|
2023-08-22 13:27:59 +02:00
|
|
|
{"routing-table", optional_argument, NULL, 'R'},
|
2023-07-24 17:16:53 +02:00
|
|
|
{ 0 }
|
|
|
|
};
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2021-12-30 23:41:42 +01:00
|
|
|
zebra_capabilities_t _caps_p[] = {ZCAP_NET_ADMIN, ZCAP_SYS_ADMIN,
|
|
|
|
ZCAP_NET_RAW,
|
|
|
|
#ifdef HAVE_DPDK
|
|
|
|
ZCAP_IPC_LOCK, ZCAP_READ_SEARCH,
|
|
|
|
ZCAP_SYS_RAWIO
|
|
|
|
#endif
|
|
|
|
};
|
2003-06-04 15:59:38 +02:00
|
|
|
|
|
|
|
/* zebra privileges to run with */
|
|
|
|
struct zebra_privs_t zserv_privs = {
|
2016-12-14 19:30:44 +01:00
|
|
|
#if defined(FRR_USER) && defined(FRR_GROUP)
|
|
|
|
.user = FRR_USER,
|
|
|
|
.group = FRR_GROUP,
|
2003-06-04 15:59:38 +02:00
|
|
|
#endif
|
|
|
|
#ifdef VTY_GROUP
|
|
|
|
.vty_group = VTY_GROUP,
|
|
|
|
#endif
|
|
|
|
.caps_p = _caps_p,
|
2012-09-26 10:39:10 +02: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
|
|
|
/* 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 of config file. */
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SIGINT handler. */
|
2004-01-19 22:31:15 +01:00
|
|
|
static void sigint(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2016-10-31 18:15:16 +01:00
|
|
|
struct vrf *vrf;
|
|
|
|
struct zebra_vrf *zvrf;
|
2018-07-26 02:27:40 +02:00
|
|
|
struct listnode *ln, *nn;
|
|
|
|
struct zserv *client;
|
2018-10-15 17:14:07 +02:00
|
|
|
static bool sigint_done;
|
|
|
|
|
|
|
|
if (sigint_done)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sigint_done = true;
|
2016-04-14 04:40:18 +02:00
|
|
|
|
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
|
|
|
|
2023-11-01 14:08:24 +01:00
|
|
|
nb_oper_cancel_all_walks();
|
2023-10-03 23:53:11 +02:00
|
|
|
mgmt_be_client_destroy(mgmt_be_client);
|
2023-11-01 14:08:24 +01:00
|
|
|
mgmt_be_client = NULL;
|
2023-10-03 23:53:11 +02:00
|
|
|
|
2019-09-27 18:15:34 +02:00
|
|
|
atomic_store_explicit(&zrouter.in_shutdown, true,
|
|
|
|
memory_order_relaxed);
|
|
|
|
|
2019-12-03 15:02:20 +01:00
|
|
|
/* send RA lifetime of 0 before stopping. rfc4861/6.2.5 */
|
|
|
|
rtadv_stop_ra_all();
|
|
|
|
|
2017-08-06 08:28:16 +02:00
|
|
|
frr_early_fini();
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2020-04-19 19:23:09 +02:00
|
|
|
/* Stop the opaque module pthread */
|
|
|
|
zebra_opaque_stop();
|
|
|
|
|
2018-08-27 22:03:37 +02:00
|
|
|
zebra_dplane_pre_finish();
|
|
|
|
|
2020-01-09 18:53:27 +01:00
|
|
|
/* Clean up GR related info. */
|
|
|
|
zebra_gr_stale_client_cleanup(zrouter.stale_client_list);
|
|
|
|
list_delete_all_node(zrouter.stale_client_list);
|
|
|
|
|
2020-04-19 19:23:09 +02:00
|
|
|
/* Clean up zapi clients and server module */
|
2019-01-11 19:38:19 +01:00
|
|
|
for (ALL_LIST_ELEMENTS(zrouter.client_list, ln, nn, client))
|
2018-07-26 02:27:40 +02:00
|
|
|
zserv_close_client(client);
|
|
|
|
|
2019-02-09 22:38:34 +01:00
|
|
|
zserv_close();
|
2019-01-11 19:38:19 +01:00
|
|
|
list_delete_all_node(zrouter.client_list);
|
2019-02-09 22:38:34 +01:00
|
|
|
|
2020-04-19 19:23:09 +02:00
|
|
|
/* Once all the zclients are cleaned up, clean up the opaque module */
|
|
|
|
zebra_opaque_finish();
|
|
|
|
|
2017-10-02 16:47:25 +02:00
|
|
|
zebra_ptm_finish();
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-10-22 14:02:33 +02:00
|
|
|
if (retain_mode) {
|
|
|
|
zebra_nhg_mark_keep();
|
2017-09-15 17:47:35 +02:00
|
|
|
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
|
2016-10-31 18:15:16 +01:00
|
|
|
zvrf = vrf->info;
|
|
|
|
if (zvrf)
|
|
|
|
SET_FLAG(zvrf->flags, ZEBRA_VRF_RETAIN);
|
|
|
|
}
|
2020-10-22 14:02:33 +02:00
|
|
|
}
|
2019-03-08 16:35:38 +01:00
|
|
|
|
2021-11-18 13:32:01 +01:00
|
|
|
if (zrouter.lsp_process_q)
|
|
|
|
work_queue_free_and_null(&zrouter.lsp_process_q);
|
|
|
|
|
2016-11-01 21:57:53 +01:00
|
|
|
access_list_reset();
|
|
|
|
prefix_list_reset();
|
2020-03-16 03:23:38 +01:00
|
|
|
/*
|
|
|
|
* zebra_routemap_finish will
|
|
|
|
* 1 set rmap upd timer to 0 so that rmap update wont be scheduled again
|
|
|
|
* 2 Put off the rmap update thread
|
|
|
|
* 3 route_map_finish
|
|
|
|
*/
|
|
|
|
zebra_routemap_finish();
|
2017-08-06 08:28:16 +02:00
|
|
|
|
2023-03-31 15:08:23 +02:00
|
|
|
rib_update_finish();
|
|
|
|
|
2019-01-11 19:38:19 +01:00
|
|
|
list_delete(&zrouter.client_list);
|
2018-08-27 22:03:37 +02:00
|
|
|
|
2018-10-15 17:14:07 +02:00
|
|
|
/* Indicate that all new dplane work has been enqueued. When that
|
|
|
|
* work is complete, the dataplane will enqueue an event
|
|
|
|
* with the 'finalize' function.
|
|
|
|
*/
|
2018-08-17 21:50:09 +02:00
|
|
|
zebra_dplane_finish();
|
2018-08-27 22:03:37 +02:00
|
|
|
}
|
|
|
|
|
2018-10-15 17:14:07 +02:00
|
|
|
/*
|
|
|
|
* Final shutdown step for the zebra main thread. This is run after all
|
|
|
|
* async update processing has completed.
|
|
|
|
*/
|
2022-03-01 22:18:12 +01:00
|
|
|
void zebra_finalize(struct event *dummy)
|
2018-08-27 22:03:37 +02:00
|
|
|
{
|
|
|
|
zlog_info("Zebra final shutdown");
|
|
|
|
|
2023-03-22 09:51:07 +01:00
|
|
|
vrf_terminate();
|
|
|
|
|
2023-06-08 18:03:49 +02:00
|
|
|
/*
|
|
|
|
* Stop dplane thread and finish any cleanup
|
|
|
|
* This is before the zebra_ns_early_shutdown call
|
|
|
|
* because sockets that the dplane depends on are closed
|
|
|
|
* in those functions
|
|
|
|
*/
|
|
|
|
zebra_dplane_shutdown();
|
|
|
|
|
2023-03-22 09:51:07 +01:00
|
|
|
ns_walk_func(zebra_ns_early_shutdown, NULL, NULL);
|
|
|
|
zebra_ns_notify_close();
|
|
|
|
|
2022-12-17 20:09:29 +01:00
|
|
|
/* Final shutdown of ns resources */
|
|
|
|
ns_walk_func(zebra_ns_final_shutdown, NULL, NULL);
|
|
|
|
|
2023-11-16 18:55:34 +01:00
|
|
|
zebra_rib_terminate();
|
2018-08-27 16:43:37 +02:00
|
|
|
zebra_router_terminate();
|
|
|
|
|
2023-11-20 19:52:01 +01:00
|
|
|
zebra_mpls_terminate();
|
|
|
|
|
2023-12-11 21:22:07 +01:00
|
|
|
zebra_pw_terminate();
|
|
|
|
|
2023-12-12 18:03:10 +01:00
|
|
|
zebra_srv6_terminate();
|
|
|
|
|
2023-12-11 21:26:20 +01:00
|
|
|
label_manager_terminate();
|
|
|
|
|
2022-10-11 22:26:42 +02:00
|
|
|
ns_terminate();
|
2017-08-06 08:28:16 +02:00
|
|
|
frr_fini();
|
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
|
|
|
struct frr_signal_t zebra_signals[] = {
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-03-20 15:34:49 +01:00
|
|
|
.signal = SIGHUP,
|
2004-01-19 22:31:15 +01:00
|
|
|
.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,
|
|
|
|
},
|
2004-01-19 22:31:15 +01:00
|
|
|
};
|
2015-05-22 11:39:56 +02:00
|
|
|
|
2022-11-03 14:30:23 +01:00
|
|
|
/* clang-format off */
|
2019-11-20 17:23:04 +01:00
|
|
|
static const struct frr_yang_module_info *const zebra_yang_modules[] = {
|
2019-11-08 18:41:46 +01:00
|
|
|
&frr_filter_info,
|
2018-07-08 03:04:33 +02:00
|
|
|
&frr_interface_info,
|
2019-10-01 22:56:41 +02:00
|
|
|
&frr_route_map_info,
|
2019-10-07 23:30:27 +02:00
|
|
|
&frr_zebra_info,
|
2020-03-11 21:14:08 +01:00
|
|
|
&frr_vrf_info,
|
2020-07-02 07:36:51 +02:00
|
|
|
&frr_routing_info,
|
2022-11-03 14:30:23 +01:00
|
|
|
&frr_affinity_map_info,
|
2020-10-30 08:41:19 +01:00
|
|
|
&frr_zebra_route_map_info,
|
2018-05-24 01:29:50 +02:00
|
|
|
};
|
2022-11-03 14:30:23 +01:00
|
|
|
/* clang-format on */
|
2018-05-24 01:29:50 +02:00
|
|
|
|
2024-01-25 18:30:10 +01:00
|
|
|
/* clang-format off */
|
|
|
|
FRR_DAEMON_INFO(zebra, ZEBRA,
|
|
|
|
.vty_port = ZEBRA_VTY_PORT,
|
2016-11-13 08:02:23 +01:00
|
|
|
.proghelp =
|
2020-03-27 12:35:23 +01:00
|
|
|
"Daemon which manages kernel routing table management and\nredistribution between different routing protocols.",
|
2016-11-13 08:02:23 +01:00
|
|
|
|
2024-01-25 18:30:10 +01:00
|
|
|
.flags = FRR_NO_ZCLIENT,
|
|
|
|
|
|
|
|
.signals = zebra_signals,
|
|
|
|
.n_signals = array_size(zebra_signals),
|
2016-11-13 08:02:23 +01:00
|
|
|
|
2018-05-24 01:29:50 +02:00
|
|
|
.privs = &zserv_privs,
|
|
|
|
|
|
|
|
.yang_modules = zebra_yang_modules,
|
|
|
|
.n_yang_modules = array_size(zebra_yang_modules),
|
|
|
|
);
|
2024-01-25 18:30:10 +01:00
|
|
|
/* clang-format on */
|
2016-11-13 08:02:23 +01:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Main startup routine. */
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2016-11-13 09:48:56 +01:00
|
|
|
// int batch_mode = 0;
|
2011-11-25 15:51:48 +01:00
|
|
|
char *zserv_path = NULL;
|
2017-08-06 07:35:50 +02:00
|
|
|
struct sockaddr_storage dummy;
|
|
|
|
socklen_t dummylen;
|
2020-09-28 21:22:52 +02:00
|
|
|
bool asic_offload = false;
|
2023-07-24 17:16:53 +02:00
|
|
|
bool v6_with_v4_nexthop = false;
|
2020-09-28 21:22:52 +02:00
|
|
|
bool notify_on_ack = true;
|
2017-03-20 15:34:49 +01:00
|
|
|
|
2019-05-10 02:06:13 +02:00
|
|
|
graceful_restart = 0;
|
2018-01-22 09:42:53 +01:00
|
|
|
vrf_configure_backend(VRF_BACKEND_VRF_LITE);
|
|
|
|
|
2016-11-13 08:02:23 +01:00
|
|
|
frr_preinit(&zebra_di, argc, argv);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2023-08-22 13:27:59 +02:00
|
|
|
frr_opt_add("baz:e:rK:s:R:"
|
2016-11-13 08:02:23 +01:00
|
|
|
#ifdef HAVE_NETLINK
|
2023-07-24 17:16:53 +02:00
|
|
|
"n"
|
2017-11-02 15:56:03 +01:00
|
|
|
#endif
|
2023-07-24 17:16:53 +02:00
|
|
|
,
|
|
|
|
longopts,
|
|
|
|
" -b, --batch Runs in batch mode\n"
|
|
|
|
" -a, --allow_delete Allow other processes to delete zebra routes\n"
|
|
|
|
" -z, --socket Set path of zebra socket\n"
|
|
|
|
" -e, --ecmp Specify ECMP to use.\n"
|
|
|
|
" -r, --retain When program terminates, retain added route by zebra.\n"
|
|
|
|
" -K, --graceful_restart Graceful restart at the kernel level, timer in seconds for expiration\n"
|
|
|
|
" -A, --asic-offload FRR is interacting with an asic underneath the linux kernel\n"
|
|
|
|
" --v6-with-v4-nexthops Underlying dataplane supports v6 routes with v4 nexthops"
|
2016-11-13 08:02:23 +01:00
|
|
|
#ifdef HAVE_NETLINK
|
2023-07-24 17:16:53 +02:00
|
|
|
" -s, --nl-bufsize Set netlink receive buffer size\n"
|
|
|
|
" -n, --vrfwnetns Use NetNS as VRF backend\n"
|
|
|
|
" --v6-rr-semantics Use v6 RR semantics\n"
|
2022-02-26 21:40:15 +01:00
|
|
|
#else
|
2023-07-24 17:16:53 +02:00
|
|
|
" -s, Set kernel socket receive buffer size\n"
|
2016-11-13 08:02:23 +01:00
|
|
|
#endif /* HAVE_NETLINK */
|
2023-08-22 13:27:59 +02:00
|
|
|
" -R, --routing-table Set kernel routing table\n"
|
2018-05-18 21:41:46 +02:00
|
|
|
);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-11-13 08:02:23 +01:00
|
|
|
while (1) {
|
|
|
|
int opt = frr_getopt(argc, argv, NULL);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (opt == EOF)
|
|
|
|
break;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-03-20 15:34:49 +01:00
|
|
|
switch (opt) {
|
2002-12-13 21:15:29 +01:00
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 'b':
|
2016-11-13 09:48:56 +01:00
|
|
|
// batch_mode = 1;
|
2002-12-13 21:15:29 +01:00
|
|
|
break;
|
2015-08-26 14:21:40 +02:00
|
|
|
case 'a':
|
2022-06-30 17:59:39 +02:00
|
|
|
zrouter.allow_delete = true;
|
2015-08-26 14:21:40 +02:00
|
|
|
break;
|
2020-04-05 05:26:19 +02:00
|
|
|
case 'e': {
|
|
|
|
unsigned long int parsed_multipath =
|
|
|
|
strtoul(optarg, NULL, 10);
|
|
|
|
if (parsed_multipath == 0
|
|
|
|
|| parsed_multipath > MULTIPATH_NUM
|
|
|
|
|| parsed_multipath > UINT32_MAX) {
|
2018-08-03 20:03:29 +02:00
|
|
|
flog_err(
|
2018-09-13 21:21:05 +02:00
|
|
|
EC_ZEBRA_BAD_MULTIPATH_NUM,
|
2020-04-05 05:26:19 +02:00
|
|
|
"Multipath Number specified must be less than %u and greater than 0",
|
2016-11-04 00:59:19 +01:00
|
|
|
MULTIPATH_NUM);
|
|
|
|
return 1;
|
|
|
|
}
|
2020-04-05 05:26:19 +02:00
|
|
|
zrouter.multipath_num = parsed_multipath;
|
2016-11-04 00:59:19 +01:00
|
|
|
break;
|
2020-04-05 05:26:19 +02:00
|
|
|
}
|
2011-11-25 15:51:48 +01:00
|
|
|
case 'z':
|
|
|
|
zserv_path = optarg;
|
2017-08-06 07:35:50 +02:00
|
|
|
if (!frr_zclient_addr(&dummy, &dummylen, optarg)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Invalid zserv socket path: %s\n",
|
|
|
|
optarg);
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-11-25 15:51:48 +01:00
|
|
|
break;
|
2002-12-13 21:15:29 +01:00
|
|
|
case 'r':
|
|
|
|
retain_mode = 1;
|
|
|
|
break;
|
2019-05-10 02:06:13 +02:00
|
|
|
case 'K':
|
|
|
|
graceful_restart = atoi(optarg);
|
|
|
|
break;
|
2004-08-31 15:41:49 +02:00
|
|
|
case 's':
|
2022-02-26 21:40:15 +01:00
|
|
|
rcvbufsize = atoi(optarg);
|
2022-05-12 16:04:17 +02:00
|
|
|
if (rcvbufsize < RCVBUFSIZE_MIN)
|
|
|
|
fprintf(stderr,
|
|
|
|
"Rcvbufsize is smaller than recommended value: %d\n",
|
|
|
|
RCVBUFSIZE_MIN);
|
2004-08-31 15:41:49 +02:00
|
|
|
break;
|
2023-08-22 13:27:59 +02:00
|
|
|
case 'R':
|
|
|
|
rt_table_main_id = atoi(optarg);
|
|
|
|
break;
|
2022-02-26 21:40:15 +01:00
|
|
|
#ifdef HAVE_NETLINK
|
2018-01-22 09:42:53 +01:00
|
|
|
case 'n':
|
|
|
|
vrf_configure_backend(VRF_BACKEND_NETNS);
|
|
|
|
break;
|
2018-05-18 21:41:46 +02:00
|
|
|
case OPTION_V6_RR_SEMANTICS:
|
2023-11-03 17:58:42 +01:00
|
|
|
zrouter.v6_rr_semantics = true;
|
2018-05-18 21:41:46 +02:00
|
|
|
break;
|
2020-09-28 21:22:52 +02:00
|
|
|
case OPTION_ASIC_OFFLOAD:
|
|
|
|
if (!strcmp(optarg, "notify_on_offload"))
|
|
|
|
notify_on_ack = false;
|
|
|
|
if (!strcmp(optarg, "notify_on_ack"))
|
|
|
|
notify_on_ack = true;
|
|
|
|
asic_offload = true;
|
|
|
|
break;
|
2023-07-24 17:16:53 +02:00
|
|
|
case OPTION_V6_WITH_V4_NEXTHOP:
|
|
|
|
v6_with_v4_nexthop = true;
|
|
|
|
break;
|
2004-08-31 15:41:49 +02:00
|
|
|
#endif /* HAVE_NETLINK */
|
2002-12-13 21:15:29 +01:00
|
|
|
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
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-11 19:31:46 +01:00
|
|
|
zrouter.master = frr_init();
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Zebra related initialize. */
|
2023-07-24 17:16:53 +02:00
|
|
|
zebra_router_init(asic_offload, notify_on_ack, v6_with_v4_nexthop);
|
2017-12-06 02:21:37 +01:00
|
|
|
zserv_init();
|
2023-11-16 18:55:34 +01:00
|
|
|
zebra_rib_init();
|
2002-12-13 21:15:29 +01:00
|
|
|
zebra_if_init();
|
|
|
|
zebra_debug_init();
|
2018-01-09 20:47:11 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize NS( and implicitly the VRF module), and make kernel
|
|
|
|
* routing socket. */
|
*: rework renaming the default VRF
Currently, it is possible to rename the default VRF either by passing
`-o` option to zebra or by creating a file in `/var/run/netns` and
binding it to `/proc/self/ns/net`.
In both cases, only zebra knows about the rename and other daemons learn
about it only after they connect to zebra. This is a problem, because
daemons may read their config before they connect to zebra. To handle
this rename after the config is read, we have some special code in every
single daemon, which is not very bad but not desirable in my opinion.
But things are getting worse when we need to handle this in northbound
layer as we have to manually rewrite the config nodes. This approach is
already hacky, but still works as every daemon handles its own NB
structures. But it is completely incompatible with the central
management daemon architecture we are aiming for, as mgmtd doesn't even
have a connection with zebra to learn from it. And it shouldn't have it,
because operational state changes should never affect configuration.
To solve the problem and simplify the code, I propose to expand the `-o`
option to all daemons. By using the startup option, we let daemons know
about the rename before they read their configs so we don't need any
special code to deal with it. There's an easy way to pass the option to
all daemons by using `frr_global_options` variable.
Unfortunately, the second way of renaming by creating a file in
`/var/run/netns` is incompatible with the new mgmtd architecture.
Theoretically, we could force daemons to read their configs only after
they connect to zebra, but it means adding even more code to handle a
very specific use-case. And anyway this won't work for mgmtd as it
doesn't have a connection with zebra. So I had to remove this option.
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-12-03 23:22:55 +01:00
|
|
|
zebra_ns_init();
|
2020-07-09 17:57:22 +02:00
|
|
|
router_id_cmd_init();
|
2018-01-09 20:47:11 +01:00
|
|
|
zebra_vty_init();
|
2023-10-03 23:53:11 +02:00
|
|
|
mgmt_be_client = mgmt_be_client_create("zebra", NULL, 0,
|
|
|
|
zrouter.master);
|
2024-01-24 22:04:23 +01:00
|
|
|
access_list_init_new(true);
|
2007-05-02 18:05:35 +02:00
|
|
|
prefix_list_init();
|
2023-12-12 19:29:47 +01:00
|
|
|
|
|
|
|
rtadv_init();
|
2015-05-22 11:40:10 +02:00
|
|
|
rtadv_cmd_init();
|
2015-05-20 02:40:44 +02:00
|
|
|
/* PTM socket */
|
|
|
|
#ifdef ZEBRA_PTM_SUPPORT
|
|
|
|
zebra_ptm_init();
|
|
|
|
#endif
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2016-04-15 19:51:56 +02:00
|
|
|
zebra_mpls_init();
|
2016-09-22 04:59:57 +02:00
|
|
|
zebra_mpls_vty_init();
|
2017-08-02 01:16:28 +02:00
|
|
|
zebra_pw_vty_init();
|
2018-05-22 12:22:08 +02:00
|
|
|
zebra_pbr_init();
|
2020-04-19 19:23:09 +02:00
|
|
|
zebra_opaque_init();
|
2020-07-20 13:43:54 +02:00
|
|
|
zebra_srte_init();
|
2020-12-09 10:52:17 +01:00
|
|
|
zebra_srv6_init();
|
2020-09-30 05:59:19 +02:00
|
|
|
zebra_srv6_vty_init();
|
2016-04-15 19:51:56 +02:00
|
|
|
|
2020-07-20 13:43:54 +02:00
|
|
|
/* For debug purpose. */
|
|
|
|
/* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2007-09-14 15:31:52 +02:00
|
|
|
/* Process the configuration file. Among other configuration
|
2017-07-22 14:52:33 +02:00
|
|
|
* directives we can meet those installing static routes. Such
|
|
|
|
* requests will not be executed immediately, but queued in
|
|
|
|
* zebra->ribq structure until we enter the main execution loop.
|
|
|
|
* The notifications from kernel will show originating PID equal
|
|
|
|
* to that after daemon() completes (if ever called).
|
|
|
|
*/
|
2016-11-13 09:48:56 +01:00
|
|
|
frr_config_fork();
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2007-09-14 15:31:52 +02:00
|
|
|
/* After we have successfully acquired the pidfile, we can be sure
|
2017-07-22 14:52:33 +02:00
|
|
|
* about being the only copy of zebra process, which is submitting
|
|
|
|
* changes to the FIB.
|
|
|
|
* Clean up zebra-originated routes. The requests will be sent to OS
|
|
|
|
* immediately, so originating PID in notifications from kernel
|
|
|
|
* will be equal to the current getpid(). To know about such routes,
|
|
|
|
* we have to have route_read() called before.
|
|
|
|
*/
|
2019-05-10 02:06:13 +02:00
|
|
|
zrouter.startup_time = monotime(NULL);
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_timer(zrouter.master, rib_sweep_route, NULL, graceful_restart,
|
|
|
|
&zrouter.sweeper);
|
2007-09-14 15:31:52 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Needed for BSD routing socket. */
|
|
|
|
pid = getpid();
|
|
|
|
|
2018-09-07 21:46:13 +02:00
|
|
|
/* Start dataplane system */
|
|
|
|
zebra_dplane_start();
|
|
|
|
|
2020-04-19 19:23:09 +02:00
|
|
|
/* Start the ted module, before zserv */
|
|
|
|
zebra_opaque_start();
|
|
|
|
|
2018-04-24 00:35:35 +02:00
|
|
|
/* Start Zebra API server */
|
|
|
|
zserv_start(zserv_path);
|
2009-07-24 18:45:31 +02:00
|
|
|
|
2017-03-20 15:34:49 +01:00
|
|
|
/* Init label manager */
|
2019-06-27 10:11:35 +02:00
|
|
|
label_manager_init();
|
2017-03-20 15:34:49 +01:00
|
|
|
|
2018-04-22 23:03:52 +02:00
|
|
|
/* RNH init */
|
|
|
|
zebra_rnh_init();
|
2018-08-27 16:43:37 +02:00
|
|
|
|
2019-06-19 23:45:21 +02:00
|
|
|
/* Config handler Init */
|
|
|
|
zebra_evpn_init();
|
|
|
|
|
2018-06-20 20:48:35 +02:00
|
|
|
/* Error init */
|
|
|
|
zebra_error_init();
|
2018-04-22 23:03:52 +02:00
|
|
|
|
2019-01-11 19:31:46 +01:00
|
|
|
frr_run(zrouter.master);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Not reached... */
|
2006-01-19 21:16:55 +01:00
|
|
|
return 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|