]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_main.c
*: auto-convert to SPDX License IDs
[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 "thread.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
31 #include "isisd/isis_constants.h"
32 #include "isisd/isis_common.h"
33 #include "isisd/isis_flags.h"
34 #include "isisd/isis_circuit.h"
35 #include "isisd/isisd.h"
36 #include "isisd/isis_dynhn.h"
37 #include "isisd/isis_spf.h"
38 #include "isisd/isis_route.h"
39 #include "isisd/isis_routemap.h"
40 #include "isisd/isis_zebra.h"
41 #include "isisd/isis_te.h"
42 #include "isisd/isis_errors.h"
43 #include "isisd/isis_bfd.h"
44 #include "isisd/isis_lsp.h"
45 #include "isisd/isis_mt.h"
46 #include "isisd/fabricd.h"
47 #include "isisd/isis_nb.h"
48 #include "isisd/isis_ldp_sync.h"
49
50 /* Default configuration file name */
51 #define ISISD_DEFAULT_CONFIG "isisd.conf"
52 /* Default vty port */
53 #define ISISD_VTY_PORT 2608
54 #define FABRICD_VTY_PORT 2618
55
56 /* isisd privileges */
57 zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_SYS_ADMIN};
58
59 struct zebra_privs_t isisd_privs = {
60 #if defined(FRR_USER)
61 .user = FRR_USER,
62 #endif
63 #if defined FRR_GROUP
64 .group = FRR_GROUP,
65 #endif
66 #ifdef VTY_GROUP
67 .vty_group = VTY_GROUP,
68 #endif
69 .caps_p = _caps_p,
70 .cap_num_p = array_size(_caps_p),
71 .cap_num_i = 0};
72
73 /* isisd options */
74 static const struct option longopts[] = {
75 {"int_num", required_argument, NULL, 'I'},
76 {0}};
77
78 /* Master of threads. */
79 struct thread_master *master;
80
81 /*
82 * Prototypes.
83 */
84 void sighup(void);
85 void sigint(void);
86 void sigterm(void);
87 void sigusr1(void);
88
89
90 static __attribute__((__noreturn__)) void terminate(int i)
91 {
92 isis_terminate();
93 isis_sr_term();
94 isis_zebra_stop();
95 exit(i);
96 }
97
98 /*
99 * Signal handlers
100 */
101 #ifdef FABRICD
102 void sighup(void)
103 {
104 zlog_notice("SIGHUP/reload is not implemented for fabricd");
105 return;
106 }
107 #else
108 static struct frr_daemon_info isisd_di;
109 void sighup(void)
110 {
111 zlog_info("SIGHUP received");
112
113 /* Reload config file. */
114 vty_read_config(NULL, isisd_di.config_file, config_default);
115 }
116
117 #endif
118
119 __attribute__((__noreturn__)) void sigint(void)
120 {
121 zlog_notice("Terminating on signal SIGINT");
122 terminate(0);
123 }
124
125 __attribute__((__noreturn__)) void sigterm(void)
126 {
127 zlog_notice("Terminating on signal SIGTERM");
128 terminate(0);
129 }
130
131 void sigusr1(void)
132 {
133 zlog_debug("SIGUSR1 received");
134 zlog_rotate();
135 }
136
137 struct frr_signal_t isisd_signals[] = {
138 {
139 .signal = SIGHUP,
140 .handler = &sighup,
141 },
142 {
143 .signal = SIGUSR1,
144 .handler = &sigusr1,
145 },
146 {
147 .signal = SIGINT,
148 .handler = &sigint,
149 },
150 {
151 .signal = SIGTERM,
152 .handler = &sigterm,
153 },
154 };
155
156
157 static const struct frr_yang_module_info *const isisd_yang_modules[] = {
158 &frr_filter_info,
159 &frr_interface_info,
160 #ifndef FABRICD
161 &frr_isisd_info,
162 #endif /* ifndef FABRICD */
163 &frr_route_map_info,
164 &frr_vrf_info,
165 };
166
167 #ifdef FABRICD
168 FRR_DAEMON_INFO(fabricd, OPEN_FABRIC, .vty_port = FABRICD_VTY_PORT,
169
170 .proghelp = "Implementation of the OpenFabric routing protocol.",
171 #else
172 FRR_DAEMON_INFO(isisd, ISIS, .vty_port = ISISD_VTY_PORT,
173
174 .proghelp = "Implementation of the IS-IS routing protocol.",
175 #endif
176 .copyright =
177 "Copyright (c) 2001-2002 Sampo Saaristo, Ofer Wald and Hannes Gredler",
178
179 .signals = isisd_signals,
180 .n_signals = array_size(isisd_signals),
181
182 .privs = &isisd_privs, .yang_modules = isisd_yang_modules,
183 .n_yang_modules = array_size(isisd_yang_modules),
184 );
185
186 /*
187 * Main routine of isisd. Parse arguments and handle IS-IS state machine.
188 */
189 int main(int argc, char **argv, char **envp)
190 {
191 int opt;
192 int instance = 1;
193
194 #ifdef FABRICD
195 frr_preinit(&fabricd_di, argc, argv);
196 #else
197 frr_preinit(&isisd_di, argc, argv);
198 #endif
199 frr_opt_add(
200 "I:", longopts,
201 " -I, --int_num Set instance number (label-manager)\n");
202
203 /* Command line argument treatment. */
204 while (1) {
205 opt = frr_getopt(argc, argv, NULL);
206
207 if (opt == EOF)
208 break;
209
210 switch (opt) {
211 case 0:
212 break;
213 case 'I':
214 instance = atoi(optarg);
215 if (instance < 1 || instance > (unsigned short)-1)
216 zlog_err("Instance %i out of range (1..%u)",
217 instance, (unsigned short)-1);
218 break;
219 default:
220 frr_help_exit(1);
221 }
222 }
223
224 /* thread master */
225 isis_master_init(frr_init());
226 master = im->master;
227 /*
228 * initializations
229 */
230 isis_error_init();
231 access_list_init();
232 access_list_add_hook(isis_filter_update);
233 access_list_delete_hook(isis_filter_update);
234 isis_vrf_init();
235 prefix_list_init();
236 prefix_list_add_hook(isis_prefix_list_update);
237 prefix_list_delete_hook(isis_prefix_list_update);
238 isis_init();
239 isis_circuit_init();
240 #ifdef FABRICD
241 isis_vty_daemon_init();
242 #endif /* FABRICD */
243 #ifndef FABRICD
244 isis_cli_init();
245 #endif /* ifdef FABRICD */
246 isis_spf_init();
247 isis_redist_init();
248 isis_route_map_init();
249 isis_mpls_te_init();
250 isis_sr_init();
251 lsp_init();
252 mt_init();
253
254 isis_zebra_init(master, instance);
255 isis_bfd_init(master);
256 isis_ldp_sync_init();
257 fabricd_init();
258
259 frr_config_fork();
260 frr_run(master);
261
262 /* Not reached. */
263 exit(0);
264 }