]> git.proxmox.com Git - mirror_frr.git/blob - staticd/static_main.c
Merge pull request #12603 from opensourcerouting/fix/deprecate_bgp_stuff_some
[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 static_zebra_stop();
83 frr_fini();
84
85 exit(0);
86 }
87
88 /* SIGUSR1 handler. */
89 static void sigusr1(void)
90 {
91 zlog_rotate();
92 }
93
94 struct frr_signal_t static_signals[] = {
95 {
96 .signal = SIGHUP,
97 .handler = &sighup,
98 },
99 {
100 .signal = SIGUSR1,
101 .handler = &sigusr1,
102 },
103 {
104 .signal = SIGINT,
105 .handler = &sigint,
106 },
107 {
108 .signal = SIGTERM,
109 .handler = &sigint,
110 },
111 };
112
113 static const struct frr_yang_module_info *const staticd_yang_modules[] = {
114 &frr_filter_info,
115 &frr_interface_info,
116 &frr_vrf_info,
117 &frr_routing_info,
118 &frr_staticd_info,
119 };
120
121 #define STATIC_VTY_PORT 2616
122
123 FRR_DAEMON_INFO(staticd, STATIC, .vty_port = STATIC_VTY_PORT,
124
125 .proghelp = "Implementation of STATIC.",
126
127 .signals = static_signals,
128 .n_signals = array_size(static_signals),
129
130 .privs = &static_privs, .yang_modules = staticd_yang_modules,
131 .n_yang_modules = array_size(staticd_yang_modules),
132 );
133
134 int main(int argc, char **argv, char **envp)
135 {
136 frr_preinit(&staticd_di, argc, argv);
137 frr_opt_add("", longopts, "");
138
139 while (1) {
140 int opt;
141
142 opt = frr_getopt(argc, argv, NULL);
143
144 if (opt == EOF)
145 break;
146
147 switch (opt) {
148 case 0:
149 break;
150 default:
151 frr_help_exit(1);
152 }
153 }
154
155 master = frr_init();
156
157 static_debug_init();
158 static_vrf_init();
159
160 static_zebra_init();
161 static_vty_init();
162
163 hook_register(routing_conf_event,
164 routing_control_plane_protocols_name_validate);
165
166 routing_control_plane_protocols_register_vrf_dependency();
167
168 snprintf(backup_config_file, sizeof(backup_config_file),
169 "%s/zebra.conf", frr_sysconfdir);
170 staticd_di.backup_config_file = backup_config_file;
171
172 frr_config_fork();
173 frr_run(master);
174
175 /* Not reached. */
176 return 0;
177 }