blob: 1dda43bccb7ea72d683dab581c2901a6b3bffc23 [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
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; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
jardineb5d44e2003-12-23 08:09:43 +000023#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000024
25#include "getopt.h"
26#include "thread.h"
27#include "log.h"
gdt5e4fa162004-03-16 14:38:36 +000028#include <lib/version.h>
jardineb5d44e2003-12-23 08:09:43 +000029#include "command.h"
30#include "vty.h"
31#include "memory.h"
32#include "stream.h"
33#include "if.h"
jardin9e867fe2003-12-23 08:56:18 +000034#include "privs.h"
paul2d75d052004-01-19 21:31:15 +000035#include "sigevent.h"
hassoc729c652004-10-13 08:36:47 +000036#include "filter.h"
Christian Frankeacf98652015-11-12 14:24:22 +010037#include "plist.h"
Vyacheslav Trushkin48d8bea2011-11-25 18:51:48 +040038#include "zclient.h"
Feng Lu126215c2015-05-22 11:39:58 +020039#include "vrf.h"
jardineb5d44e2003-12-23 08:09:43 +000040
41#include "isisd/dict.h"
42#include "include-netbsd/iso.h"
43#include "isisd/isis_constants.h"
44#include "isisd/isis_common.h"
45#include "isisd/isis_flags.h"
46#include "isisd/isis_circuit.h"
47#include "isisd/isisd.h"
48#include "isisd/isis_dynhn.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070049#include "isisd/isis_spf.h"
50#include "isisd/isis_route.h"
Christian Frankeacf98652015-11-12 14:24:22 +010051#include "isisd/isis_routemap.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070052#include "isisd/isis_zebra.h"
Olivier Dugeon4f593572016-04-19 19:03:05 +020053#include "isisd/isis_tlv.h"
54#include "isisd/isis_te.h"
jardineb5d44e2003-12-23 08:09:43 +000055
56/* Default configuration file name */
57#define ISISD_DEFAULT_CONFIG "isisd.conf"
58/* Default vty port */
jardinfc58e872003-12-23 10:42:45 +000059#define ISISD_VTY_PORT 2608
jardineb5d44e2003-12-23 08:09:43 +000060
jardin9e867fe2003-12-23 08:56:18 +000061/* isisd privileges */
hassof390d2c2004-09-10 20:48:21 +000062zebra_capabilities_t _caps_p[] = {
paulceacedb2005-09-29 14:39:32 +000063 ZCAP_NET_RAW,
jardin9e867fe2003-12-23 08:56:18 +000064 ZCAP_BIND
65};
66
hassof390d2c2004-09-10 20:48:21 +000067struct zebra_privs_t isisd_privs = {
jardin9e867fe2003-12-23 08:56:18 +000068#if defined(QUAGGA_USER)
69 .user = QUAGGA_USER,
70#endif
71#if defined QUAGGA_GROUP
72 .group = QUAGGA_GROUP,
73#endif
74#ifdef VTY_GROUP
75 .vty_group = VTY_GROUP,
76#endif
77 .caps_p = _caps_p,
Josh Bailey3f045a02012-03-24 08:35:20 -070078 .cap_num_p = sizeof (_caps_p) / sizeof (*_caps_p),
jardin9e867fe2003-12-23 08:56:18 +000079 .cap_num_i = 0
80};
81
jardineb5d44e2003-12-23 08:09:43 +000082/* isisd options */
hassof390d2c2004-09-10 20:48:21 +000083struct option longopts[] = {
Vyacheslav Trushkin1627b202011-11-25 17:56:21 +040084 {"daemon", no_argument, NULL, 'd'},
hassof390d2c2004-09-10 20:48:21 +000085 {"config_file", required_argument, NULL, 'f'},
Vyacheslav Trushkin1627b202011-11-25 17:56:21 +040086 {"pid_file", required_argument, NULL, 'i'},
Vyacheslav Trushkin48d8bea2011-11-25 18:51:48 +040087 {"socket", required_argument, NULL, 'z'},
Vyacheslav Trushkin1627b202011-11-25 17:56:21 +040088 {"vty_addr", required_argument, NULL, 'A'},
89 {"vty_port", required_argument, NULL, 'P'},
90 {"user", required_argument, NULL, 'u'},
91 {"group", required_argument, NULL, 'g'},
92 {"version", no_argument, NULL, 'v'},
93 {"dryrun", no_argument, NULL, 'C'},
94 {"help", no_argument, NULL, 'h'},
hassof390d2c2004-09-10 20:48:21 +000095 {0}
jardineb5d44e2003-12-23 08:09:43 +000096};
97
98/* Configuration file and directory. */
jardineb5d44e2003-12-23 08:09:43 +000099char config_default[] = SYSCONFDIR ISISD_DEFAULT_CONFIG;
100char *config_file = NULL;
101
102/* isisd program name. */
103char *progname;
104
105int daemon_mode = 0;
106
107/* Master of threads. */
108struct thread_master *master;
109
hassoc3aac6f2004-02-20 18:44:21 +0000110/* Process ID saved for use by init system */
hasso1cd80842004-10-07 20:07:40 +0000111const char *pid_file = PATH_ISISD_PID;
jardineb5d44e2003-12-23 08:09:43 +0000112
113/* for reload */
hasso37da8c02004-05-19 11:38:40 +0000114char _cwd[MAXPATHLEN];
115char _progpath[MAXPATHLEN];
jardineb5d44e2003-12-23 08:09:43 +0000116int _argc;
117char **_argv;
118char **_envp;
119
Paul Jakma41b36e92006-12-08 01:09:50 +0000120/*
121 * Prototypes.
122 */
123void reload(void);
124void sighup(void);
125void sigint(void);
126void sigterm(void);
127void sigusr1(void);
128
129
jardineb5d44e2003-12-23 08:09:43 +0000130/* Help information display. */
131static void
132usage (int status)
133{
134 if (status != 0)
135 fprintf (stderr, "Try `%s --help' for more information.\n", progname);
136 else
hassof390d2c2004-09-10 20:48:21 +0000137 {
jardineb5d44e2003-12-23 08:09:43 +0000138 printf ("Usage : %s [OPTION...]\n\n\
139Daemon which manages IS-IS routing\n\n\
140-d, --daemon Runs in daemon mode\n\
141-f, --config_file Set configuration file name\n\
hassoc3aac6f2004-02-20 18:44:21 +0000142-i, --pid_file Set process identifier file name\n\
Vyacheslav Trushkin48d8bea2011-11-25 18:51:48 +0400143-z, --socket Set path of zebra socket\n\
hassoc3aac6f2004-02-20 18:44:21 +0000144-A, --vty_addr Set vty's bind address\n\
jardineb5d44e2003-12-23 08:09:43 +0000145-P, --vty_port Set vty's port number\n\
hassoc0652302004-11-25 19:33:48 +0000146-u, --user User to run as\n\
147-g, --group Group to run as\n\
jardineb5d44e2003-12-23 08:09:43 +0000148-v, --version Print program version\n\
Paul Jakma876b8be2006-10-15 23:35:57 +0000149-C, --dryrun Check configuration for validity and exit\n\
jardineb5d44e2003-12-23 08:09:43 +0000150-h, --help Display this help and exit\n\
151\n\
Christian Franke4ff3bca2013-03-20 10:50:07 +0000152Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
jardineb5d44e2003-12-23 08:09:43 +0000153 }
154
155 exit (status);
156}
157
158
159void
160reload ()
161{
hasso529d65b2004-12-24 00:14:50 +0000162 zlog_debug ("Reload");
jardineb5d44e2003-12-23 08:09:43 +0000163 /* FIXME: Clean up func call here */
ajscdb6ee92005-02-23 15:48:32 +0000164 vty_reset ();
Josh Bailey3f045a02012-03-24 08:35:20 -0700165 (void) isisd_privs.change (ZPRIVS_RAISE);
jardineb5d44e2003-12-23 08:09:43 +0000166 execve (_progpath, _argv, _envp);
Josh Bailey3f045a02012-03-24 08:35:20 -0700167 zlog_err ("Reload failed: cannot exec %s: %s", _progpath,
168 safe_strerror (errno));
jardineb5d44e2003-12-23 08:09:43 +0000169}
170
ajs887c44a2004-12-03 16:36:46 +0000171static void
jardineb5d44e2003-12-23 08:09:43 +0000172terminate (int i)
173{
174 exit (i);
175}
176
177/*
178 * Signal handlers
179 */
paul2d75d052004-01-19 21:31:15 +0000180
hassof390d2c2004-09-10 20:48:21 +0000181void
paul2d75d052004-01-19 21:31:15 +0000182sighup (void)
jardineb5d44e2003-12-23 08:09:43 +0000183{
hasso529d65b2004-12-24 00:14:50 +0000184 zlog_debug ("SIGHUP received");
jardineb5d44e2003-12-23 08:09:43 +0000185 reload ();
186
187 return;
188}
189
190void
paul2d75d052004-01-19 21:31:15 +0000191sigint (void)
jardineb5d44e2003-12-23 08:09:43 +0000192{
ajs887c44a2004-12-03 16:36:46 +0000193 zlog_notice ("Terminating on signal SIGINT");
jardineb5d44e2003-12-23 08:09:43 +0000194 terminate (0);
jardineb5d44e2003-12-23 08:09:43 +0000195}
196
197void
paul2d75d052004-01-19 21:31:15 +0000198sigterm (void)
jardineb5d44e2003-12-23 08:09:43 +0000199{
ajs887c44a2004-12-03 16:36:46 +0000200 zlog_notice ("Terminating on signal SIGTERM");
jardineb5d44e2003-12-23 08:09:43 +0000201 terminate (0);
202}
203
204void
paul2d75d052004-01-19 21:31:15 +0000205sigusr1 (void)
jardineb5d44e2003-12-23 08:09:43 +0000206{
hasso529d65b2004-12-24 00:14:50 +0000207 zlog_debug ("SIGUSR1 received");
jardineb5d44e2003-12-23 08:09:43 +0000208 zlog_rotate (NULL);
209}
210
paul2d75d052004-01-19 21:31:15 +0000211struct quagga_signal_t isisd_signals[] =
hassof390d2c2004-09-10 20:48:21 +0000212{
paul2d75d052004-01-19 21:31:15 +0000213 {
hassof390d2c2004-09-10 20:48:21 +0000214 .signal = SIGHUP,
215 .handler = &sighup,
216 },
paul2d75d052004-01-19 21:31:15 +0000217 {
hassof390d2c2004-09-10 20:48:21 +0000218 .signal = SIGUSR1,
219 .handler = &sigusr1,
220 },
paul2d75d052004-01-19 21:31:15 +0000221 {
hassof390d2c2004-09-10 20:48:21 +0000222 .signal = SIGINT,
223 .handler = &sigint,
224 },
225 {
226 .signal = SIGTERM,
227 .handler = &sigterm,
228 },
paul2d75d052004-01-19 21:31:15 +0000229};
jardineb5d44e2003-12-23 08:09:43 +0000230
231/*
232 * Main routine of isisd. Parse arguments and handle IS-IS state machine.
233 */
hassof390d2c2004-09-10 20:48:21 +0000234int
jardineb5d44e2003-12-23 08:09:43 +0000235main (int argc, char **argv, char **envp)
236{
237 char *p;
238 int opt, vty_port = ISISD_VTY_PORT;
239 struct thread thread;
240 char *config_file = NULL;
241 char *vty_addr = NULL;
Paul Jakma876b8be2006-10-15 23:35:57 +0000242 int dryrun = 0;
jardineb5d44e2003-12-23 08:09:43 +0000243
244 /* Get the programname without the preceding path. */
245 progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
246
ajs274a4a42004-12-07 15:39:31 +0000247 zlog_default = openzlog (progname, ZLOG_ISIS,
hassof390d2c2004-09-10 20:48:21 +0000248 LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
jardineb5d44e2003-12-23 08:09:43 +0000249
jardineb5d44e2003-12-23 08:09:43 +0000250 /* for reload */
251 _argc = argc;
252 _argv = argv;
253 _envp = envp;
254 getcwd (_cwd, sizeof (_cwd));
255 if (*argv[0] == '.')
256 snprintf (_progpath, sizeof (_progpath), "%s/%s", _cwd, _argv[0]);
257 else
258 snprintf (_progpath, sizeof (_progpath), "%s", argv[0]);
hassof390d2c2004-09-10 20:48:21 +0000259
jardineb5d44e2003-12-23 08:09:43 +0000260 /* Command line argument treatment. */
hassof390d2c2004-09-10 20:48:21 +0000261 while (1)
jardineb5d44e2003-12-23 08:09:43 +0000262 {
Vyacheslav Trushkin48d8bea2011-11-25 18:51:48 +0400263 opt = getopt_long (argc, argv, "df:i:z:hA:p:P:u:g:vC", longopts, 0);
jardineb5d44e2003-12-23 08:09:43 +0000264
hassof390d2c2004-09-10 20:48:21 +0000265 if (opt == EOF)
266 break;
267
268 switch (opt)
269 {
270 case 0:
jardin9e867fe2003-12-23 08:56:18 +0000271 break;
hassof390d2c2004-09-10 20:48:21 +0000272 case 'd':
273 daemon_mode = 1;
274 break;
275 case 'f':
276 config_file = optarg;
277 break;
278 case 'i':
279 pid_file = optarg;
280 break;
Vyacheslav Trushkin48d8bea2011-11-25 18:51:48 +0400281 case 'z':
282 zclient_serv_path_set (optarg);
283 break;
hassof390d2c2004-09-10 20:48:21 +0000284 case 'A':
285 vty_addr = optarg;
286 break;
287 case 'P':
288 /* Deal with atoi() returning 0 on failure, and isisd not
289 listening on isisd port... */
290 if (strcmp (optarg, "0") == 0)
291 {
292 vty_port = 0;
293 break;
294 }
295 vty_port = atoi (optarg);
296 vty_port = (vty_port ? vty_port : ISISD_VTY_PORT);
297 break;
298 case 'u':
hassoc0652302004-11-25 19:33:48 +0000299 isisd_privs.user = optarg;
hassof390d2c2004-09-10 20:48:21 +0000300 break;
hassoc0652302004-11-25 19:33:48 +0000301 case 'g':
302 isisd_privs.group = optarg;
hassof390d2c2004-09-10 20:48:21 +0000303 break;
304 case 'v':
305 printf ("ISISd version %s\n", ISISD_VERSION);
306 printf ("Copyright (c) 2001-2002 Sampo Saaristo,"
307 " Ofer Wald and Hannes Gredler\n");
308 print_version ("Zebra");
309 exit (0);
310 break;
Paul Jakma876b8be2006-10-15 23:35:57 +0000311 case 'C':
312 dryrun = 1;
313 break;
hassof390d2c2004-09-10 20:48:21 +0000314 case 'h':
315 usage (0);
316 break;
317 default:
318 usage (1);
319 break;
320 }
jardineb5d44e2003-12-23 08:09:43 +0000321 }
hassof390d2c2004-09-10 20:48:21 +0000322
jardineb5d44e2003-12-23 08:09:43 +0000323 /* thread master */
324 master = thread_master_create ();
325
326 /* random seed from time */
Donald Sharpf31bab42015-06-19 19:26:19 -0400327 srandom (time (NULL));
jardineb5d44e2003-12-23 08:09:43 +0000328
329 /*
330 * initializations
331 */
jardin9e867fe2003-12-23 08:56:18 +0000332 zprivs_init (&isisd_privs);
Balaji.G837d16c2012-09-26 14:09:10 +0530333 signal_init (master, array_size (isisd_signals), isisd_signals);
jardineb5d44e2003-12-23 08:09:43 +0000334 cmd_init (1);
jardin9e867fe2003-12-23 08:56:18 +0000335 vty_init (master);
jardineb5d44e2003-12-23 08:09:43 +0000336 memory_init ();
hassoc729c652004-10-13 08:36:47 +0000337 access_list_init();
Feng Lu126215c2015-05-22 11:39:58 +0200338 vrf_init ();
Christian Frankeacf98652015-11-12 14:24:22 +0100339 prefix_list_init();
jardineb5d44e2003-12-23 08:09:43 +0000340 isis_init ();
Josh Bailey3f045a02012-03-24 08:35:20 -0700341 isis_circuit_init ();
342 isis_spf_cmds_init ();
Christian Frankeacf98652015-11-12 14:24:22 +0100343 isis_redist_init ();
344 isis_route_map_init();
Olivier Dugeon4f593572016-04-19 19:03:05 +0200345 isis_mpls_te_init();
Josh Bailey3f045a02012-03-24 08:35:20 -0700346
347 /* create the global 'isis' instance */
348 isis_new (1);
349
Donald Sharp71252932015-09-24 09:25:19 -0400350 isis_zebra_init (master);
Josh Bailey3f045a02012-03-24 08:35:20 -0700351
hassof390d2c2004-09-10 20:48:21 +0000352 /* parse config file */
jardineb5d44e2003-12-23 08:09:43 +0000353 /* this is needed three times! because we have interfaces before the areas */
hasso320ec102004-06-20 19:54:37 +0000354 vty_read_config (config_file, config_default);
hasso00995cf2004-05-19 13:43:50 +0000355
Paul Jakma876b8be2006-10-15 23:35:57 +0000356 /* Start execution only if not in dry-run mode */
357 if (dryrun)
358 return(0);
359
jardineb5d44e2003-12-23 08:09:43 +0000360 /* demonize */
Josh Bailey3f045a02012-03-24 08:35:20 -0700361 if (daemon_mode)
362 daemon (0, 0);
jardineb5d44e2003-12-23 08:09:43 +0000363
jardineb5d44e2003-12-23 08:09:43 +0000364 /* Process ID file creation. */
Josh Bailey3f045a02012-03-24 08:35:20 -0700365 if (pid_file[0] != '\0')
366 pid_output (pid_file);
jardineb5d44e2003-12-23 08:09:43 +0000367
368 /* Make isis vty socket. */
jardin9e867fe2003-12-23 08:56:18 +0000369 vty_serv_sock (vty_addr, vty_port, ISIS_VTYSH_PATH);
hassof390d2c2004-09-10 20:48:21 +0000370
jardineb5d44e2003-12-23 08:09:43 +0000371 /* Print banner. */
ajs887c44a2004-12-03 16:36:46 +0000372 zlog_notice ("Quagga-ISISd %s starting: vty@%d", QUAGGA_VERSION, vty_port);
hassoc89c05d2005-09-04 21:36:36 +0000373
jardineb5d44e2003-12-23 08:09:43 +0000374 /* Start finite state machine. */
375 while (thread_fetch (master, &thread))
376 thread_call (&thread);
377
378 /* Not reached. */
379 exit (0);
380}