]> git.proxmox.com Git - mirror_frr.git/blame - staticd/static_main.c
Merge pull request #12074 from donaldsharp/lib_debugs
[mirror_frr.git] / staticd / static_main.c
CommitLineData
7e24fdf3
DS
1/*
2 * STATICd - main code
3 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * Donald Sharp
5 *
8d5cbee9
DS
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
7e24fdf3 10 *
8d5cbee9
DS
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
7e24fdf3
DS
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20#include <zebra.h>
21
22#include <lib/version.h>
23#include "getopt.h"
24#include "thread.h"
25#include "command.h"
26#include "log.h"
27#include "memory.h"
28#include "privs.h"
29#include "sigevent.h"
30#include "libfrr.h"
31#include "vrf.h"
32#include "nexthop.h"
29348bd7 33#include "filter.h"
88fa5104 34#include "routing_nb.h"
7e24fdf3
DS
35
36#include "static_vrf.h"
37#include "static_vty.h"
38#include "static_routes.h"
39#include "static_zebra.h"
31ddf3b7 40#include "static_debug.h"
88fa5104 41#include "static_nb.h"
7e24fdf3 42
ad3489a0
DS
43char backup_config_file[256];
44
7e24fdf3 45bool mpls_enabled;
41b21bfa 46
7e24fdf3
DS
47zebra_capabilities_t _caps_p[] = {
48};
49
50struct zebra_privs_t static_privs = {
51#if defined(FRR_USER) && defined(FRR_GROUP)
52 .user = FRR_USER,
53 .group = FRR_GROUP,
54#endif
55#if defined(VTY_GROUP)
56 .vty_group = VTY_GROUP,
57#endif
58 .caps_p = _caps_p,
59 .cap_num_p = array_size(_caps_p),
60 .cap_num_i = 0};
61
62struct option longopts[] = { { 0 } };
63
64/* Master of threads. */
65struct thread_master *master;
66
88fa5104 67static struct frr_daemon_info staticd_di;
7e24fdf3
DS
68/* SIGHUP handler. */
69static void sighup(void)
70{
71 zlog_info("SIGHUP received");
88fa5104 72 vty_read_config(NULL, staticd_di.config_file, config_default);
7e24fdf3
DS
73}
74
75/* SIGINT / SIGTERM handler. */
76static void sigint(void)
77{
78 zlog_notice("Terminating on signal");
79
a4155a1b 80 static_vrf_terminate();
81
41b21bfa
MS
82 frr_fini();
83
7e24fdf3
DS
84 exit(0);
85}
86
87/* SIGUSR1 handler. */
88static void sigusr1(void)
89{
90 zlog_rotate();
91}
92
7cc91e67 93struct frr_signal_t static_signals[] = {
7e24fdf3
DS
94 {
95 .signal = SIGHUP,
96 .handler = &sighup,
97 },
98 {
99 .signal = SIGUSR1,
100 .handler = &sigusr1,
101 },
102 {
103 .signal = SIGINT,
104 .handler = &sigint,
105 },
106 {
107 .signal = SIGTERM,
108 .handler = &sigint,
109 },
110};
111
0d8c7a26 112static const struct frr_yang_module_info *const staticd_yang_modules[] = {
c2aab693 113 &frr_filter_info,
88fa5104 114 &frr_interface_info,
6fd8972a 115 &frr_vrf_info,
88fa5104 116 &frr_routing_info,
117 &frr_staticd_info,
8fcdd0d6
RW
118};
119
7e24fdf3
DS
120#define STATIC_VTY_PORT 2616
121
122FRR_DAEMON_INFO(staticd, STATIC, .vty_port = STATIC_VTY_PORT,
123
124 .proghelp = "Implementation of STATIC.",
125
126 .signals = static_signals,
127 .n_signals = array_size(static_signals),
128
8fcdd0d6
RW
129 .privs = &static_privs, .yang_modules = staticd_yang_modules,
130 .n_yang_modules = array_size(staticd_yang_modules),
80413c20 131);
7e24fdf3
DS
132
133int main(int argc, char **argv, char **envp)
134{
135 frr_preinit(&staticd_di, argc, argv);
136 frr_opt_add("", longopts, "");
137
138 while (1) {
139 int opt;
140
141 opt = frr_getopt(argc, argv, NULL);
142
143 if (opt == EOF)
144 break;
145
146 switch (opt) {
147 case 0:
148 break;
149 default:
150 frr_help_exit(1);
7e24fdf3
DS
151 }
152 }
153
154 master = frr_init();
155
31ddf3b7 156 static_debug_init();
7e24fdf3
DS
157 static_vrf_init();
158
159 static_zebra_init();
160 static_vty_init();
161
88fa5104 162 hook_register(routing_conf_event,
163 routing_control_plane_protocols_name_validate);
164
2ada6269
IR
165 routing_control_plane_protocols_register_vrf_dependency();
166
ad3489a0
DS
167 snprintf(backup_config_file, sizeof(backup_config_file),
168 "%s/zebra.conf", frr_sysconfdir);
169 staticd_di.backup_config_file = backup_config_file;
170
7e24fdf3
DS
171 frr_config_fork();
172 frr_run(master);
173
174 /* Not reached. */
175 return 0;
176}