blob: 3a730879551ab40d2c4398d66c9cd5639c3639b1 [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"
jardineb5d44e2003-12-23 08:09:43 +000053
54/* Default configuration file name */
55#define ISISD_DEFAULT_CONFIG "isisd.conf"
56/* Default vty port */
jardinfc58e872003-12-23 10:42:45 +000057#define ISISD_VTY_PORT 2608
jardineb5d44e2003-12-23 08:09:43 +000058
jardin9e867fe2003-12-23 08:56:18 +000059/* isisd privileges */
hassof390d2c2004-09-10 20:48:21 +000060zebra_capabilities_t _caps_p[] = {
paulceacedb2005-09-29 14:39:32 +000061 ZCAP_NET_RAW,
jardin9e867fe2003-12-23 08:56:18 +000062 ZCAP_BIND
63};
64
hassof390d2c2004-09-10 20:48:21 +000065struct zebra_privs_t isisd_privs = {
jardin9e867fe2003-12-23 08:56:18 +000066#if defined(QUAGGA_USER)
67 .user = QUAGGA_USER,
68#endif
69#if defined QUAGGA_GROUP
70 .group = QUAGGA_GROUP,
71#endif
72#ifdef VTY_GROUP
73 .vty_group = VTY_GROUP,
74#endif
75 .caps_p = _caps_p,
Josh Bailey3f045a02012-03-24 08:35:20 -070076 .cap_num_p = sizeof (_caps_p) / sizeof (*_caps_p),
jardin9e867fe2003-12-23 08:56:18 +000077 .cap_num_i = 0
78};
79
jardineb5d44e2003-12-23 08:09:43 +000080/* isisd options */
hassof390d2c2004-09-10 20:48:21 +000081struct option longopts[] = {
Vyacheslav Trushkin1627b202011-11-25 17:56:21 +040082 {"daemon", no_argument, NULL, 'd'},
hassof390d2c2004-09-10 20:48:21 +000083 {"config_file", required_argument, NULL, 'f'},
Vyacheslav Trushkin1627b202011-11-25 17:56:21 +040084 {"pid_file", required_argument, NULL, 'i'},
Vyacheslav Trushkin48d8bea2011-11-25 18:51:48 +040085 {"socket", required_argument, NULL, 'z'},
Vyacheslav Trushkin1627b202011-11-25 17:56:21 +040086 {"vty_addr", required_argument, NULL, 'A'},
87 {"vty_port", required_argument, NULL, 'P'},
88 {"user", required_argument, NULL, 'u'},
89 {"group", required_argument, NULL, 'g'},
90 {"version", no_argument, NULL, 'v'},
91 {"dryrun", no_argument, NULL, 'C'},
92 {"help", no_argument, NULL, 'h'},
hassof390d2c2004-09-10 20:48:21 +000093 {0}
jardineb5d44e2003-12-23 08:09:43 +000094};
95
96/* Configuration file and directory. */
jardineb5d44e2003-12-23 08:09:43 +000097char config_default[] = SYSCONFDIR ISISD_DEFAULT_CONFIG;
98char *config_file = NULL;
99
100/* isisd program name. */
101char *progname;
102
103int daemon_mode = 0;
104
105/* Master of threads. */
106struct thread_master *master;
107
hassoc3aac6f2004-02-20 18:44:21 +0000108/* Process ID saved for use by init system */
hasso1cd80842004-10-07 20:07:40 +0000109const char *pid_file = PATH_ISISD_PID;
jardineb5d44e2003-12-23 08:09:43 +0000110
111/* for reload */
hasso37da8c02004-05-19 11:38:40 +0000112char _cwd[MAXPATHLEN];
113char _progpath[MAXPATHLEN];
jardineb5d44e2003-12-23 08:09:43 +0000114int _argc;
115char **_argv;
116char **_envp;
117
Paul Jakma41b36e92006-12-08 01:09:50 +0000118/*
119 * Prototypes.
120 */
121void reload(void);
122void sighup(void);
123void sigint(void);
124void sigterm(void);
125void sigusr1(void);
126
127
jardineb5d44e2003-12-23 08:09:43 +0000128/* Help information display. */
129static void
130usage (int status)
131{
132 if (status != 0)
133 fprintf (stderr, "Try `%s --help' for more information.\n", progname);
134 else
hassof390d2c2004-09-10 20:48:21 +0000135 {
jardineb5d44e2003-12-23 08:09:43 +0000136 printf ("Usage : %s [OPTION...]\n\n\
137Daemon which manages IS-IS routing\n\n\
138-d, --daemon Runs in daemon mode\n\
139-f, --config_file Set configuration file name\n\
hassoc3aac6f2004-02-20 18:44:21 +0000140-i, --pid_file Set process identifier file name\n\
Vyacheslav Trushkin48d8bea2011-11-25 18:51:48 +0400141-z, --socket Set path of zebra socket\n\
hassoc3aac6f2004-02-20 18:44:21 +0000142-A, --vty_addr Set vty's bind address\n\
jardineb5d44e2003-12-23 08:09:43 +0000143-P, --vty_port Set vty's port number\n\
hassoc0652302004-11-25 19:33:48 +0000144-u, --user User to run as\n\
145-g, --group Group to run as\n\
jardineb5d44e2003-12-23 08:09:43 +0000146-v, --version Print program version\n\
Paul Jakma876b8be2006-10-15 23:35:57 +0000147-C, --dryrun Check configuration for validity and exit\n\
jardineb5d44e2003-12-23 08:09:43 +0000148-h, --help Display this help and exit\n\
149\n\
Christian Franke4ff3bca2013-03-20 10:50:07 +0000150Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
jardineb5d44e2003-12-23 08:09:43 +0000151 }
152
153 exit (status);
154}
155
156
157void
158reload ()
159{
hasso529d65b2004-12-24 00:14:50 +0000160 zlog_debug ("Reload");
jardineb5d44e2003-12-23 08:09:43 +0000161 /* FIXME: Clean up func call here */
ajscdb6ee92005-02-23 15:48:32 +0000162 vty_reset ();
Josh Bailey3f045a02012-03-24 08:35:20 -0700163 (void) isisd_privs.change (ZPRIVS_RAISE);
jardineb5d44e2003-12-23 08:09:43 +0000164 execve (_progpath, _argv, _envp);
Josh Bailey3f045a02012-03-24 08:35:20 -0700165 zlog_err ("Reload failed: cannot exec %s: %s", _progpath,
166 safe_strerror (errno));
jardineb5d44e2003-12-23 08:09:43 +0000167}
168
ajs887c44a2004-12-03 16:36:46 +0000169static void
jardineb5d44e2003-12-23 08:09:43 +0000170terminate (int i)
171{
172 exit (i);
173}
174
175/*
176 * Signal handlers
177 */
paul2d75d052004-01-19 21:31:15 +0000178
hassof390d2c2004-09-10 20:48:21 +0000179void
paul2d75d052004-01-19 21:31:15 +0000180sighup (void)
jardineb5d44e2003-12-23 08:09:43 +0000181{
hasso529d65b2004-12-24 00:14:50 +0000182 zlog_debug ("SIGHUP received");
jardineb5d44e2003-12-23 08:09:43 +0000183 reload ();
184
185 return;
186}
187
188void
paul2d75d052004-01-19 21:31:15 +0000189sigint (void)
jardineb5d44e2003-12-23 08:09:43 +0000190{
ajs887c44a2004-12-03 16:36:46 +0000191 zlog_notice ("Terminating on signal SIGINT");
jardineb5d44e2003-12-23 08:09:43 +0000192 terminate (0);
jardineb5d44e2003-12-23 08:09:43 +0000193}
194
195void
paul2d75d052004-01-19 21:31:15 +0000196sigterm (void)
jardineb5d44e2003-12-23 08:09:43 +0000197{
ajs887c44a2004-12-03 16:36:46 +0000198 zlog_notice ("Terminating on signal SIGTERM");
jardineb5d44e2003-12-23 08:09:43 +0000199 terminate (0);
200}
201
202void
paul2d75d052004-01-19 21:31:15 +0000203sigusr1 (void)
jardineb5d44e2003-12-23 08:09:43 +0000204{
hasso529d65b2004-12-24 00:14:50 +0000205 zlog_debug ("SIGUSR1 received");
jardineb5d44e2003-12-23 08:09:43 +0000206 zlog_rotate (NULL);
207}
208
paul2d75d052004-01-19 21:31:15 +0000209struct quagga_signal_t isisd_signals[] =
hassof390d2c2004-09-10 20:48:21 +0000210{
paul2d75d052004-01-19 21:31:15 +0000211 {
hassof390d2c2004-09-10 20:48:21 +0000212 .signal = SIGHUP,
213 .handler = &sighup,
214 },
paul2d75d052004-01-19 21:31:15 +0000215 {
hassof390d2c2004-09-10 20:48:21 +0000216 .signal = SIGUSR1,
217 .handler = &sigusr1,
218 },
paul2d75d052004-01-19 21:31:15 +0000219 {
hassof390d2c2004-09-10 20:48:21 +0000220 .signal = SIGINT,
221 .handler = &sigint,
222 },
223 {
224 .signal = SIGTERM,
225 .handler = &sigterm,
226 },
paul2d75d052004-01-19 21:31:15 +0000227};
jardineb5d44e2003-12-23 08:09:43 +0000228
229/*
230 * Main routine of isisd. Parse arguments and handle IS-IS state machine.
231 */
hassof390d2c2004-09-10 20:48:21 +0000232int
jardineb5d44e2003-12-23 08:09:43 +0000233main (int argc, char **argv, char **envp)
234{
235 char *p;
236 int opt, vty_port = ISISD_VTY_PORT;
237 struct thread thread;
238 char *config_file = NULL;
239 char *vty_addr = NULL;
Paul Jakma876b8be2006-10-15 23:35:57 +0000240 int dryrun = 0;
jardineb5d44e2003-12-23 08:09:43 +0000241
242 /* Get the programname without the preceding path. */
243 progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
244
ajs274a4a42004-12-07 15:39:31 +0000245 zlog_default = openzlog (progname, ZLOG_ISIS,
hassof390d2c2004-09-10 20:48:21 +0000246 LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
jardineb5d44e2003-12-23 08:09:43 +0000247
jardineb5d44e2003-12-23 08:09:43 +0000248 /* for reload */
249 _argc = argc;
250 _argv = argv;
251 _envp = envp;
252 getcwd (_cwd, sizeof (_cwd));
253 if (*argv[0] == '.')
254 snprintf (_progpath, sizeof (_progpath), "%s/%s", _cwd, _argv[0]);
255 else
256 snprintf (_progpath, sizeof (_progpath), "%s", argv[0]);
hassof390d2c2004-09-10 20:48:21 +0000257
jardineb5d44e2003-12-23 08:09:43 +0000258 /* Command line argument treatment. */
hassof390d2c2004-09-10 20:48:21 +0000259 while (1)
jardineb5d44e2003-12-23 08:09:43 +0000260 {
Vyacheslav Trushkin48d8bea2011-11-25 18:51:48 +0400261 opt = getopt_long (argc, argv, "df:i:z:hA:p:P:u:g:vC", longopts, 0);
jardineb5d44e2003-12-23 08:09:43 +0000262
hassof390d2c2004-09-10 20:48:21 +0000263 if (opt == EOF)
264 break;
265
266 switch (opt)
267 {
268 case 0:
jardin9e867fe2003-12-23 08:56:18 +0000269 break;
hassof390d2c2004-09-10 20:48:21 +0000270 case 'd':
271 daemon_mode = 1;
272 break;
273 case 'f':
274 config_file = optarg;
275 break;
276 case 'i':
277 pid_file = optarg;
278 break;
Vyacheslav Trushkin48d8bea2011-11-25 18:51:48 +0400279 case 'z':
280 zclient_serv_path_set (optarg);
281 break;
hassof390d2c2004-09-10 20:48:21 +0000282 case 'A':
283 vty_addr = optarg;
284 break;
285 case 'P':
286 /* Deal with atoi() returning 0 on failure, and isisd not
287 listening on isisd port... */
288 if (strcmp (optarg, "0") == 0)
289 {
290 vty_port = 0;
291 break;
292 }
293 vty_port = atoi (optarg);
294 vty_port = (vty_port ? vty_port : ISISD_VTY_PORT);
295 break;
296 case 'u':
hassoc0652302004-11-25 19:33:48 +0000297 isisd_privs.user = optarg;
hassof390d2c2004-09-10 20:48:21 +0000298 break;
hassoc0652302004-11-25 19:33:48 +0000299 case 'g':
300 isisd_privs.group = optarg;
hassof390d2c2004-09-10 20:48:21 +0000301 break;
302 case 'v':
303 printf ("ISISd version %s\n", ISISD_VERSION);
304 printf ("Copyright (c) 2001-2002 Sampo Saaristo,"
305 " Ofer Wald and Hannes Gredler\n");
306 print_version ("Zebra");
307 exit (0);
308 break;
Paul Jakma876b8be2006-10-15 23:35:57 +0000309 case 'C':
310 dryrun = 1;
311 break;
hassof390d2c2004-09-10 20:48:21 +0000312 case 'h':
313 usage (0);
314 break;
315 default:
316 usage (1);
317 break;
318 }
jardineb5d44e2003-12-23 08:09:43 +0000319 }
hassof390d2c2004-09-10 20:48:21 +0000320
jardineb5d44e2003-12-23 08:09:43 +0000321 /* thread master */
322 master = thread_master_create ();
323
324 /* random seed from time */
Donald Sharpf31bab42015-06-19 19:26:19 -0400325 srandom (time (NULL));
jardineb5d44e2003-12-23 08:09:43 +0000326
327 /*
328 * initializations
329 */
jardin9e867fe2003-12-23 08:56:18 +0000330 zprivs_init (&isisd_privs);
Balaji.G837d16c2012-09-26 14:09:10 +0530331 signal_init (master, array_size (isisd_signals), isisd_signals);
jardineb5d44e2003-12-23 08:09:43 +0000332 cmd_init (1);
jardin9e867fe2003-12-23 08:56:18 +0000333 vty_init (master);
jardineb5d44e2003-12-23 08:09:43 +0000334 memory_init ();
hassoc729c652004-10-13 08:36:47 +0000335 access_list_init();
Feng Lu126215c2015-05-22 11:39:58 +0200336 vrf_init ();
Christian Frankeacf98652015-11-12 14:24:22 +0100337 prefix_list_init();
jardineb5d44e2003-12-23 08:09:43 +0000338 isis_init ();
Josh Bailey3f045a02012-03-24 08:35:20 -0700339 isis_circuit_init ();
340 isis_spf_cmds_init ();
Christian Frankeacf98652015-11-12 14:24:22 +0100341 isis_redist_init ();
342 isis_route_map_init();
Josh Bailey3f045a02012-03-24 08:35:20 -0700343
344 /* create the global 'isis' instance */
345 isis_new (1);
346
Donald Sharp71252932015-09-24 09:25:19 -0400347 isis_zebra_init (master);
Josh Bailey3f045a02012-03-24 08:35:20 -0700348
hassof390d2c2004-09-10 20:48:21 +0000349 /* parse config file */
jardineb5d44e2003-12-23 08:09:43 +0000350 /* this is needed three times! because we have interfaces before the areas */
hasso320ec102004-06-20 19:54:37 +0000351 vty_read_config (config_file, config_default);
hasso00995cf2004-05-19 13:43:50 +0000352
Paul Jakma876b8be2006-10-15 23:35:57 +0000353 /* Start execution only if not in dry-run mode */
354 if (dryrun)
355 return(0);
356
jardineb5d44e2003-12-23 08:09:43 +0000357 /* demonize */
Josh Bailey3f045a02012-03-24 08:35:20 -0700358 if (daemon_mode)
359 daemon (0, 0);
jardineb5d44e2003-12-23 08:09:43 +0000360
jardineb5d44e2003-12-23 08:09:43 +0000361 /* Process ID file creation. */
Josh Bailey3f045a02012-03-24 08:35:20 -0700362 if (pid_file[0] != '\0')
363 pid_output (pid_file);
jardineb5d44e2003-12-23 08:09:43 +0000364
365 /* Make isis vty socket. */
jardin9e867fe2003-12-23 08:56:18 +0000366 vty_serv_sock (vty_addr, vty_port, ISIS_VTYSH_PATH);
hassof390d2c2004-09-10 20:48:21 +0000367
jardineb5d44e2003-12-23 08:09:43 +0000368 /* Print banner. */
ajs887c44a2004-12-03 16:36:46 +0000369 zlog_notice ("Quagga-ISISd %s starting: vty@%d", QUAGGA_VERSION, vty_port);
hassoc89c05d2005-09-04 21:36:36 +0000370
jardineb5d44e2003-12-23 08:09:43 +0000371 /* Start finite state machine. */
372 while (thread_fetch (master, &thread))
373 thread_call (&thread);
374
375 /* Not reached. */
376 exit (0);
377}