]> git.proxmox.com Git - mirror_frr.git/blame - staticd/static_main.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / staticd / static_main.c
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
7e24fdf3
DS
2/*
3 * STATICd - main code
4 * Copyright (C) 2018 Cumulus Networks, Inc.
5 * Donald Sharp
7e24fdf3
DS
6 */
7#include <zebra.h>
8
9#include <lib/version.h>
10#include "getopt.h"
11#include "thread.h"
12#include "command.h"
13#include "log.h"
14#include "memory.h"
15#include "privs.h"
16#include "sigevent.h"
17#include "libfrr.h"
18#include "vrf.h"
19#include "nexthop.h"
29348bd7 20#include "filter.h"
88fa5104 21#include "routing_nb.h"
7e24fdf3
DS
22
23#include "static_vrf.h"
24#include "static_vty.h"
25#include "static_routes.h"
26#include "static_zebra.h"
31ddf3b7 27#include "static_debug.h"
88fa5104 28#include "static_nb.h"
7e24fdf3 29
ad3489a0
DS
30char backup_config_file[256];
31
7e24fdf3 32bool mpls_enabled;
41b21bfa 33
7e24fdf3
DS
34zebra_capabilities_t _caps_p[] = {
35};
36
37struct zebra_privs_t static_privs = {
38#if defined(FRR_USER) && defined(FRR_GROUP)
39 .user = FRR_USER,
40 .group = FRR_GROUP,
41#endif
42#if defined(VTY_GROUP)
43 .vty_group = VTY_GROUP,
44#endif
45 .caps_p = _caps_p,
46 .cap_num_p = array_size(_caps_p),
47 .cap_num_i = 0};
48
49struct option longopts[] = { { 0 } };
50
51/* Master of threads. */
52struct thread_master *master;
53
88fa5104 54static struct frr_daemon_info staticd_di;
7e24fdf3
DS
55/* SIGHUP handler. */
56static void sighup(void)
57{
58 zlog_info("SIGHUP received");
88fa5104 59 vty_read_config(NULL, staticd_di.config_file, config_default);
7e24fdf3
DS
60}
61
62/* SIGINT / SIGTERM handler. */
63static void sigint(void)
64{
65 zlog_notice("Terminating on signal");
66
a4155a1b 67 static_vrf_terminate();
68
08040409 69 static_zebra_stop();
41b21bfa
MS
70 frr_fini();
71
7e24fdf3
DS
72 exit(0);
73}
74
75/* SIGUSR1 handler. */
76static void sigusr1(void)
77{
78 zlog_rotate();
79}
80
7cc91e67 81struct frr_signal_t static_signals[] = {
7e24fdf3
DS
82 {
83 .signal = SIGHUP,
84 .handler = &sighup,
85 },
86 {
87 .signal = SIGUSR1,
88 .handler = &sigusr1,
89 },
90 {
91 .signal = SIGINT,
92 .handler = &sigint,
93 },
94 {
95 .signal = SIGTERM,
96 .handler = &sigint,
97 },
98};
99
0d8c7a26 100static const struct frr_yang_module_info *const staticd_yang_modules[] = {
c2aab693 101 &frr_filter_info,
88fa5104 102 &frr_interface_info,
6fd8972a 103 &frr_vrf_info,
88fa5104 104 &frr_routing_info,
105 &frr_staticd_info,
8fcdd0d6
RW
106};
107
7e24fdf3
DS
108#define STATIC_VTY_PORT 2616
109
110FRR_DAEMON_INFO(staticd, STATIC, .vty_port = STATIC_VTY_PORT,
111
112 .proghelp = "Implementation of STATIC.",
113
114 .signals = static_signals,
115 .n_signals = array_size(static_signals),
116
8fcdd0d6
RW
117 .privs = &static_privs, .yang_modules = staticd_yang_modules,
118 .n_yang_modules = array_size(staticd_yang_modules),
80413c20 119);
7e24fdf3
DS
120
121int main(int argc, char **argv, char **envp)
122{
123 frr_preinit(&staticd_di, argc, argv);
124 frr_opt_add("", longopts, "");
125
126 while (1) {
127 int opt;
128
129 opt = frr_getopt(argc, argv, NULL);
130
131 if (opt == EOF)
132 break;
133
134 switch (opt) {
135 case 0:
136 break;
137 default:
138 frr_help_exit(1);
7e24fdf3
DS
139 }
140 }
141
142 master = frr_init();
143
31ddf3b7 144 static_debug_init();
7e24fdf3
DS
145 static_vrf_init();
146
147 static_zebra_init();
148 static_vty_init();
149
88fa5104 150 hook_register(routing_conf_event,
151 routing_control_plane_protocols_name_validate);
152
2ada6269
IR
153 routing_control_plane_protocols_register_vrf_dependency();
154
ad3489a0
DS
155 snprintf(backup_config_file, sizeof(backup_config_file),
156 "%s/zebra.conf", frr_sysconfdir);
157 staticd_di.backup_config_file = backup_config_file;
158
7e24fdf3
DS
159 frr_config_fork();
160 frr_run(master);
161
162 /* Not reached. */
163 return 0;
164}