]> git.proxmox.com Git - mirror_frr.git/blob - staticd/static_main.c
Merge pull request #10447 from ton31337/fix/json_with_whitespaces
[mirror_frr.git] / staticd / static_main.c
1 /*
2 * STATICd - main code
3 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * Donald Sharp
5 *
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.
10 *
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.
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"
33 #include "filter.h"
34 #include "routing_nb.h"
35
36 #include "static_vrf.h"
37 #include "static_vty.h"
38 #include "static_routes.h"
39 #include "static_zebra.h"
40 #include "static_debug.h"
41 #include "static_nb.h"
42
43 char backup_config_file[256];
44
45 bool mpls_enabled;
46
47 zebra_capabilities_t _caps_p[] = {
48 };
49
50 struct 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
62 struct option longopts[] = { { 0 } };
63
64 /* Master of threads. */
65 struct thread_master *master;
66
67 static struct frr_daemon_info staticd_di;
68 /* SIGHUP handler. */
69 static void sighup(void)
70 {
71 zlog_info("SIGHUP received");
72 vty_read_config(NULL, staticd_di.config_file, config_default);
73 }
74
75 /* SIGINT / SIGTERM handler. */
76 static void sigint(void)
77 {
78 zlog_notice("Terminating on signal");
79
80 static_vrf_terminate();
81
82 frr_fini();
83
84 exit(0);
85 }
86
87 /* SIGUSR1 handler. */
88 static void sigusr1(void)
89 {
90 zlog_rotate();
91 }
92
93 struct frr_signal_t static_signals[] = {
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
112 static const struct frr_yang_module_info *const staticd_yang_modules[] = {
113 &frr_filter_info,
114 &frr_interface_info,
115 &frr_vrf_info,
116 &frr_routing_info,
117 &frr_staticd_info,
118 };
119
120 #define STATIC_VTY_PORT 2616
121
122 FRR_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
129 .privs = &static_privs, .yang_modules = staticd_yang_modules,
130 .n_yang_modules = array_size(staticd_yang_modules),
131 );
132
133 int 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);
151 }
152 }
153
154 master = frr_init();
155
156 static_debug_init();
157 static_vrf_init();
158
159 static_zebra_init();
160 static_vty_init();
161
162 hook_register(routing_conf_event,
163 routing_control_plane_protocols_name_validate);
164
165 routing_control_plane_protocols_register_vrf_dependency();
166
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
171 frr_config_fork();
172 frr_run(master);
173
174 /* Not reached. */
175 return 0;
176 }