]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_main.c
Merge pull request #8666 from idryzhov/bgp-replace-as
[mirror_frr.git] / isisd / isis_main.c
1 /*
2 * IS-IS Rout(e)ing protocol - isis_main.c
3 *
4 * Copyright (C) 2001,2002 Sampo Saaristo
5 * Tampere University of Technology
6 * Institute of Communications Engineering
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public Licenseas published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <zebra.h>
24
25 #include "getopt.h"
26 #include "thread.h"
27 #include "log.h"
28 #include <lib/version.h>
29 #include "command.h"
30 #include "vty.h"
31 #include "memory.h"
32 #include "stream.h"
33 #include "if.h"
34 #include "privs.h"
35 #include "sigevent.h"
36 #include "filter.h"
37 #include "plist.h"
38 #include "zclient.h"
39 #include "vrf.h"
40 #include "qobj.h"
41 #include "libfrr.h"
42 #include "routemap.h"
43
44 #include "isisd/isis_constants.h"
45 #include "isisd/isis_common.h"
46 #include "isisd/isis_flags.h"
47 #include "isisd/isis_circuit.h"
48 #include "isisd/isisd.h"
49 #include "isisd/isis_dynhn.h"
50 #include "isisd/isis_spf.h"
51 #include "isisd/isis_route.h"
52 #include "isisd/isis_routemap.h"
53 #include "isisd/isis_zebra.h"
54 #include "isisd/isis_te.h"
55 #include "isisd/isis_errors.h"
56 #include "isisd/isis_bfd.h"
57 #include "isisd/isis_lsp.h"
58 #include "isisd/isis_mt.h"
59 #include "isisd/fabricd.h"
60 #include "isisd/isis_nb.h"
61 #include "isisd/isis_ldp_sync.h"
62
63 /* Default configuration file name */
64 #define ISISD_DEFAULT_CONFIG "isisd.conf"
65 /* Default vty port */
66 #define ISISD_VTY_PORT 2608
67 #define FABRICD_VTY_PORT 2618
68
69 /* isisd privileges */
70 zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_SYS_ADMIN};
71
72 struct zebra_privs_t isisd_privs = {
73 #if defined(FRR_USER)
74 .user = FRR_USER,
75 #endif
76 #if defined FRR_GROUP
77 .group = FRR_GROUP,
78 #endif
79 #ifdef VTY_GROUP
80 .vty_group = VTY_GROUP,
81 #endif
82 .caps_p = _caps_p,
83 .cap_num_p = array_size(_caps_p),
84 .cap_num_i = 0};
85
86 /* isisd options */
87 static const struct option longopts[] = {
88 {"int_num", required_argument, NULL, 'I'},
89 {0}};
90
91 /* Master of threads. */
92 struct thread_master *master;
93
94 /*
95 * Prototypes.
96 */
97 void sighup(void);
98 void sigint(void);
99 void sigterm(void);
100 void sigusr1(void);
101
102
103 static __attribute__((__noreturn__)) void terminate(int i)
104 {
105 isis_terminate();
106 isis_sr_term();
107 isis_zebra_stop();
108 exit(i);
109 }
110
111 /*
112 * Signal handlers
113 */
114 #ifdef FABRICD
115 void sighup(void)
116 {
117 zlog_notice("SIGHUP/reload is not implemented for fabricd");
118 return;
119 }
120 #else
121 static struct frr_daemon_info isisd_di;
122 void sighup(void)
123 {
124 zlog_info("SIGHUP received");
125
126 /* Reload config file. */
127 vty_read_config(NULL, isisd_di.config_file, config_default);
128 }
129
130 #endif
131
132 __attribute__((__noreturn__)) void sigint(void)
133 {
134 zlog_notice("Terminating on signal SIGINT");
135 terminate(0);
136 }
137
138 __attribute__((__noreturn__)) void sigterm(void)
139 {
140 zlog_notice("Terminating on signal SIGTERM");
141 terminate(0);
142 }
143
144 void sigusr1(void)
145 {
146 zlog_debug("SIGUSR1 received");
147 zlog_rotate();
148 }
149
150 struct quagga_signal_t isisd_signals[] = {
151 {
152 .signal = SIGHUP,
153 .handler = &sighup,
154 },
155 {
156 .signal = SIGUSR1,
157 .handler = &sigusr1,
158 },
159 {
160 .signal = SIGINT,
161 .handler = &sigint,
162 },
163 {
164 .signal = SIGTERM,
165 .handler = &sigterm,
166 },
167 };
168
169
170 static const struct frr_yang_module_info *const isisd_yang_modules[] = {
171 &frr_filter_info,
172 &frr_interface_info,
173 #ifndef FABRICD
174 &frr_isisd_info,
175 #endif /* ifndef FABRICD */
176 &frr_route_map_info,
177 &frr_vrf_info,
178 };
179
180 #ifdef FABRICD
181 FRR_DAEMON_INFO(fabricd, OPEN_FABRIC, .vty_port = FABRICD_VTY_PORT,
182
183 .proghelp = "Implementation of the OpenFabric routing protocol.",
184 #else
185 FRR_DAEMON_INFO(isisd, ISIS, .vty_port = ISISD_VTY_PORT,
186
187 .proghelp = "Implementation of the IS-IS routing protocol.",
188 #endif
189 .copyright =
190 "Copyright (c) 2001-2002 Sampo Saaristo, Ofer Wald and Hannes Gredler",
191
192 .signals = isisd_signals,
193 .n_signals = array_size(isisd_signals),
194
195 .privs = &isisd_privs, .yang_modules = isisd_yang_modules,
196 .n_yang_modules = array_size(isisd_yang_modules),
197 );
198
199 /*
200 * Main routine of isisd. Parse arguments and handle IS-IS state machine.
201 */
202 int main(int argc, char **argv, char **envp)
203 {
204 int opt;
205 int instance = 1;
206
207 #ifdef FABRICD
208 frr_preinit(&fabricd_di, argc, argv);
209 #else
210 frr_preinit(&isisd_di, argc, argv);
211 #endif
212 frr_opt_add(
213 "I:", longopts,
214 " -I, --int_num Set instance number (label-manager)\n");
215
216 /* Command line argument treatment. */
217 while (1) {
218 opt = frr_getopt(argc, argv, NULL);
219
220 if (opt == EOF)
221 break;
222
223 switch (opt) {
224 case 0:
225 break;
226 case 'I':
227 instance = atoi(optarg);
228 if (instance < 1 || instance > (unsigned short)-1)
229 zlog_err("Instance %i out of range (1..%u)",
230 instance, (unsigned short)-1);
231 break;
232 default:
233 frr_help_exit(1);
234 break;
235 }
236 }
237
238 /* thread master */
239 isis_master_init(frr_init());
240 master = im->master;
241 /*
242 * initializations
243 */
244 isis_error_init();
245 access_list_init();
246 access_list_add_hook(isis_filter_update);
247 access_list_delete_hook(isis_filter_update);
248 isis_vrf_init();
249 prefix_list_init();
250 prefix_list_add_hook(isis_prefix_list_update);
251 prefix_list_delete_hook(isis_prefix_list_update);
252 isis_init();
253 isis_circuit_init();
254 #ifdef FABRICD
255 isis_vty_daemon_init();
256 #endif /* FABRICD */
257 #ifndef FABRICD
258 isis_cli_init();
259 #endif /* ifdef FABRICD */
260 isis_spf_init();
261 isis_redist_init();
262 isis_route_map_init();
263 isis_mpls_te_init();
264 isis_sr_init();
265 lsp_init();
266 mt_init();
267
268 isis_zebra_init(master, instance);
269 isis_bfd_init(master);
270 isis_ldp_sync_init();
271 fabricd_init();
272
273 frr_config_fork();
274 frr_run(master);
275
276 /* Not reached. */
277 exit(0);
278 }