]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_main.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / isisd / isis_main.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * IS-IS Rout(e)ing protocol - isis_main.c
4 *
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
8 */
9
10 #include <zebra.h>
11
12 #include "getopt.h"
13 #include "frrevent.h"
14 #include "log.h"
15 #include <lib/version.h>
16 #include "command.h"
17 #include "vty.h"
18 #include "memory.h"
19 #include "stream.h"
20 #include "if.h"
21 #include "privs.h"
22 #include "sigevent.h"
23 #include "filter.h"
24 #include "plist.h"
25 #include "zclient.h"
26 #include "vrf.h"
27 #include "qobj.h"
28 #include "libfrr.h"
29 #include "routemap.h"
30 #include "affinitymap.h"
31
32 #include "isisd/isis_affinitymap.h"
33 #include "isisd/isis_constants.h"
34 #include "isisd/isis_common.h"
35 #include "isisd/isis_flags.h"
36 #include "isisd/isis_circuit.h"
37 #include "isisd/isisd.h"
38 #include "isisd/isis_dynhn.h"
39 #include "isisd/isis_spf.h"
40 #include "isisd/isis_route.h"
41 #include "isisd/isis_routemap.h"
42 #include "isisd/isis_zebra.h"
43 #include "isisd/isis_te.h"
44 #include "isisd/isis_errors.h"
45 #include "isisd/isis_bfd.h"
46 #include "isisd/isis_lsp.h"
47 #include "isisd/isis_mt.h"
48 #include "isisd/fabricd.h"
49 #include "isisd/isis_nb.h"
50 #include "isisd/isis_ldp_sync.h"
51
52 /* Default configuration file name */
53 #define ISISD_DEFAULT_CONFIG "isisd.conf"
54 /* Default vty port */
55 #define ISISD_VTY_PORT 2608
56 #define FABRICD_VTY_PORT 2618
57
58 /* isisd privileges */
59 zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_SYS_ADMIN};
60
61 struct zebra_privs_t isisd_privs = {
62 #if defined(FRR_USER)
63 .user = FRR_USER,
64 #endif
65 #if defined FRR_GROUP
66 .group = FRR_GROUP,
67 #endif
68 #ifdef VTY_GROUP
69 .vty_group = VTY_GROUP,
70 #endif
71 .caps_p = _caps_p,
72 .cap_num_p = array_size(_caps_p),
73 .cap_num_i = 0};
74
75 /* isisd options */
76 static const struct option longopts[] = {
77 {"int_num", required_argument, NULL, 'I'},
78 {0}};
79
80 /* Master of threads. */
81 struct event_loop *master;
82
83 /*
84 * Prototypes.
85 */
86 void sighup(void);
87 void sigint(void);
88 void sigterm(void);
89 void sigusr1(void);
90
91
92 static __attribute__((__noreturn__)) void terminate(int i)
93 {
94 isis_terminate();
95 isis_sr_term();
96 isis_zebra_stop();
97 exit(i);
98 }
99
100 /*
101 * Signal handlers
102 */
103 #ifdef FABRICD
104 void sighup(void)
105 {
106 zlog_notice("SIGHUP/reload is not implemented for fabricd");
107 return;
108 }
109 #else
110 static struct frr_daemon_info isisd_di;
111 void sighup(void)
112 {
113 zlog_info("SIGHUP received");
114
115 /* Reload config file. */
116 vty_read_config(NULL, isisd_di.config_file, config_default);
117 }
118
119 #endif
120
121 __attribute__((__noreturn__)) void sigint(void)
122 {
123 zlog_notice("Terminating on signal SIGINT");
124 terminate(0);
125 }
126
127 __attribute__((__noreturn__)) void sigterm(void)
128 {
129 zlog_notice("Terminating on signal SIGTERM");
130 terminate(0);
131 }
132
133 void sigusr1(void)
134 {
135 zlog_debug("SIGUSR1 received");
136 zlog_rotate();
137 }
138
139 struct frr_signal_t isisd_signals[] = {
140 {
141 .signal = SIGHUP,
142 .handler = &sighup,
143 },
144 {
145 .signal = SIGUSR1,
146 .handler = &sigusr1,
147 },
148 {
149 .signal = SIGINT,
150 .handler = &sigint,
151 },
152 {
153 .signal = SIGTERM,
154 .handler = &sigterm,
155 },
156 };
157
158
159 /* clang-format off */
160 static const struct frr_yang_module_info *const isisd_yang_modules[] = {
161 &frr_filter_info,
162 &frr_interface_info,
163 #ifndef FABRICD
164 &frr_isisd_info,
165 #endif /* ifndef FABRICD */
166 &frr_route_map_info,
167 &frr_affinity_map_info,
168 &frr_vrf_info,
169 };
170 /* clang-format on */
171
172
173 static void isis_config_finish(struct event *t)
174 {
175 struct listnode *node, *inode;
176 struct isis *isis;
177 struct isis_area *area;
178
179 for (ALL_LIST_ELEMENTS_RO(im->isis, inode, isis)) {
180 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area))
181 config_end_lsp_generate(area);
182 }
183 }
184
185 static void isis_config_start(void)
186 {
187 /* Max wait time for config to load before generating lsp */
188 #define ISIS_PRE_CONFIG_MAX_WAIT_SECONDS 600
189 EVENT_OFF(t_isis_cfg);
190 event_add_timer(im->master, isis_config_finish, NULL,
191 ISIS_PRE_CONFIG_MAX_WAIT_SECONDS, &t_isis_cfg);
192 }
193
194 static void isis_config_end(void)
195 {
196 /* If ISIS config processing thread isn't running, then
197 * we can return and rely it's properly handled.
198 */
199 if (!event_is_scheduled(t_isis_cfg))
200 return;
201
202 EVENT_OFF(t_isis_cfg);
203 isis_config_finish(t_isis_cfg);
204 }
205
206 #ifdef FABRICD
207 FRR_DAEMON_INFO(fabricd, OPEN_FABRIC, .vty_port = FABRICD_VTY_PORT,
208
209 .proghelp = "Implementation of the OpenFabric routing protocol.",
210 #else
211 FRR_DAEMON_INFO(isisd, ISIS, .vty_port = ISISD_VTY_PORT,
212
213 .proghelp = "Implementation of the IS-IS routing protocol.",
214 #endif
215 .copyright =
216 "Copyright (c) 2001-2002 Sampo Saaristo, Ofer Wald and Hannes Gredler",
217
218 .signals = isisd_signals,
219 .n_signals = array_size(isisd_signals),
220
221 .privs = &isisd_privs, .yang_modules = isisd_yang_modules,
222 .n_yang_modules = array_size(isisd_yang_modules),
223 );
224
225 /*
226 * Main routine of isisd. Parse arguments and handle IS-IS state machine.
227 */
228 int main(int argc, char **argv, char **envp)
229 {
230 int opt;
231 int instance = 1;
232
233 #ifdef FABRICD
234 frr_preinit(&fabricd_di, argc, argv);
235 #else
236 frr_preinit(&isisd_di, argc, argv);
237 #endif
238 frr_opt_add(
239 "I:", longopts,
240 " -I, --int_num Set instance number (label-manager)\n");
241
242 /* Command line argument treatment. */
243 while (1) {
244 opt = frr_getopt(argc, argv, NULL);
245
246 if (opt == EOF)
247 break;
248
249 switch (opt) {
250 case 0:
251 break;
252 case 'I':
253 instance = atoi(optarg);
254 if (instance < 1 || instance > (unsigned short)-1)
255 zlog_err("Instance %i out of range (1..%u)",
256 instance, (unsigned short)-1);
257 break;
258 default:
259 frr_help_exit(1);
260 }
261 }
262
263 /* thread master */
264 isis_master_init(frr_init());
265 master = im->master;
266 /*
267 * initializations
268 */
269 cmd_init_config_callbacks(isis_config_start, isis_config_end);
270 isis_error_init();
271 access_list_init();
272 access_list_add_hook(isis_filter_update);
273 access_list_delete_hook(isis_filter_update);
274 isis_vrf_init();
275 prefix_list_init();
276 prefix_list_add_hook(isis_prefix_list_update);
277 prefix_list_delete_hook(isis_prefix_list_update);
278 isis_init();
279 isis_circuit_init();
280 #ifdef FABRICD
281 isis_vty_daemon_init();
282 #endif /* FABRICD */
283 #ifndef FABRICD
284 isis_cli_init();
285 #endif /* ifndef FABRICD */
286 isis_spf_init();
287 isis_redist_init();
288 isis_route_map_init();
289 isis_mpls_te_init();
290 isis_sr_init();
291 lsp_init();
292 mt_init();
293
294 #ifndef FABRICD
295 isis_affinity_map_init();
296 #endif /* ifndef FABRICD */
297
298 isis_zebra_init(master, instance);
299 isis_bfd_init(master);
300 isis_ldp_sync_init();
301 fabricd_init();
302
303 frr_config_fork();
304 frr_run(master);
305
306 /* Not reached. */
307 exit(0);
308 }