blob: e1af71f7e7403e05b60e0f4f066c1347d5a7ba49 [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"
Vyacheslav Trushkin48d8bea2011-11-25 18:51:48 +040037#include "zclient.h"
Feng Lu126215c2015-05-22 11:39:58 +020038#include "vrf.h"
jardineb5d44e2003-12-23 08:09:43 +000039
40#include "isisd/dict.h"
41#include "include-netbsd/iso.h"
42#include "isisd/isis_constants.h"
43#include "isisd/isis_common.h"
44#include "isisd/isis_flags.h"
45#include "isisd/isis_circuit.h"
46#include "isisd/isisd.h"
47#include "isisd/isis_dynhn.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070048#include "isisd/isis_spf.h"
49#include "isisd/isis_route.h"
50#include "isisd/isis_zebra.h"
jardineb5d44e2003-12-23 08:09:43 +000051
52/* Default configuration file name */
53#define ISISD_DEFAULT_CONFIG "isisd.conf"
54/* Default vty port */
jardinfc58e872003-12-23 10:42:45 +000055#define ISISD_VTY_PORT 2608
jardineb5d44e2003-12-23 08:09:43 +000056
jardin9e867fe2003-12-23 08:56:18 +000057/* isisd privileges */
hassof390d2c2004-09-10 20:48:21 +000058zebra_capabilities_t _caps_p[] = {
paulceacedb2005-09-29 14:39:32 +000059 ZCAP_NET_RAW,
jardin9e867fe2003-12-23 08:56:18 +000060 ZCAP_BIND
61};
62
hassof390d2c2004-09-10 20:48:21 +000063struct zebra_privs_t isisd_privs = {
jardin9e867fe2003-12-23 08:56:18 +000064#if defined(QUAGGA_USER)
65 .user = QUAGGA_USER,
66#endif
67#if defined QUAGGA_GROUP
68 .group = QUAGGA_GROUP,
69#endif
70#ifdef VTY_GROUP
71 .vty_group = VTY_GROUP,
72#endif
73 .caps_p = _caps_p,
Josh Bailey3f045a02012-03-24 08:35:20 -070074 .cap_num_p = sizeof (_caps_p) / sizeof (*_caps_p),
jardin9e867fe2003-12-23 08:56:18 +000075 .cap_num_i = 0
76};
77
jardineb5d44e2003-12-23 08:09:43 +000078/* isisd options */
hassof390d2c2004-09-10 20:48:21 +000079struct option longopts[] = {
Vyacheslav Trushkin1627b202011-11-25 17:56:21 +040080 {"daemon", no_argument, NULL, 'd'},
hassof390d2c2004-09-10 20:48:21 +000081 {"config_file", required_argument, NULL, 'f'},
Vyacheslav Trushkin1627b202011-11-25 17:56:21 +040082 {"pid_file", required_argument, NULL, 'i'},
Vyacheslav Trushkin48d8bea2011-11-25 18:51:48 +040083 {"socket", required_argument, NULL, 'z'},
Vyacheslav Trushkin1627b202011-11-25 17:56:21 +040084 {"vty_addr", required_argument, NULL, 'A'},
85 {"vty_port", required_argument, NULL, 'P'},
86 {"user", required_argument, NULL, 'u'},
87 {"group", required_argument, NULL, 'g'},
88 {"version", no_argument, NULL, 'v'},
89 {"dryrun", no_argument, NULL, 'C'},
90 {"help", no_argument, NULL, 'h'},
hassof390d2c2004-09-10 20:48:21 +000091 {0}
jardineb5d44e2003-12-23 08:09:43 +000092};
93
94/* Configuration file and directory. */
jardineb5d44e2003-12-23 08:09:43 +000095char config_default[] = SYSCONFDIR ISISD_DEFAULT_CONFIG;
96char *config_file = NULL;
97
98/* isisd program name. */
99char *progname;
100
101int daemon_mode = 0;
102
103/* Master of threads. */
104struct thread_master *master;
105
hassoc3aac6f2004-02-20 18:44:21 +0000106/* Process ID saved for use by init system */
hasso1cd80842004-10-07 20:07:40 +0000107const char *pid_file = PATH_ISISD_PID;
jardineb5d44e2003-12-23 08:09:43 +0000108
109/* for reload */
hasso37da8c02004-05-19 11:38:40 +0000110char _cwd[MAXPATHLEN];
111char _progpath[MAXPATHLEN];
jardineb5d44e2003-12-23 08:09:43 +0000112int _argc;
113char **_argv;
114char **_envp;
115
Paul Jakma41b36e92006-12-08 01:09:50 +0000116/*
117 * Prototypes.
118 */
119void reload(void);
120void sighup(void);
121void sigint(void);
122void sigterm(void);
123void sigusr1(void);
124
125
jardineb5d44e2003-12-23 08:09:43 +0000126/* Help information display. */
127static void
128usage (int status)
129{
130 if (status != 0)
131 fprintf (stderr, "Try `%s --help' for more information.\n", progname);
132 else
hassof390d2c2004-09-10 20:48:21 +0000133 {
jardineb5d44e2003-12-23 08:09:43 +0000134 printf ("Usage : %s [OPTION...]\n\n\
135Daemon which manages IS-IS routing\n\n\
136-d, --daemon Runs in daemon mode\n\
137-f, --config_file Set configuration file name\n\
hassoc3aac6f2004-02-20 18:44:21 +0000138-i, --pid_file Set process identifier file name\n\
Vyacheslav Trushkin48d8bea2011-11-25 18:51:48 +0400139-z, --socket Set path of zebra socket\n\
hassoc3aac6f2004-02-20 18:44:21 +0000140-A, --vty_addr Set vty's bind address\n\
jardineb5d44e2003-12-23 08:09:43 +0000141-P, --vty_port Set vty's port number\n\
hassoc0652302004-11-25 19:33:48 +0000142-u, --user User to run as\n\
143-g, --group Group to run as\n\
jardineb5d44e2003-12-23 08:09:43 +0000144-v, --version Print program version\n\
Paul Jakma876b8be2006-10-15 23:35:57 +0000145-C, --dryrun Check configuration for validity and exit\n\
jardineb5d44e2003-12-23 08:09:43 +0000146-h, --help Display this help and exit\n\
147\n\
Christian Franke4ff3bca2013-03-20 10:50:07 +0000148Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
jardineb5d44e2003-12-23 08:09:43 +0000149 }
150
151 exit (status);
152}
153
154
155void
156reload ()
157{
hasso529d65b2004-12-24 00:14:50 +0000158 zlog_debug ("Reload");
jardineb5d44e2003-12-23 08:09:43 +0000159 /* FIXME: Clean up func call here */
ajscdb6ee92005-02-23 15:48:32 +0000160 vty_reset ();
Josh Bailey3f045a02012-03-24 08:35:20 -0700161 (void) isisd_privs.change (ZPRIVS_RAISE);
jardineb5d44e2003-12-23 08:09:43 +0000162 execve (_progpath, _argv, _envp);
Josh Bailey3f045a02012-03-24 08:35:20 -0700163 zlog_err ("Reload failed: cannot exec %s: %s", _progpath,
164 safe_strerror (errno));
jardineb5d44e2003-12-23 08:09:43 +0000165}
166
ajs887c44a2004-12-03 16:36:46 +0000167static void
jardineb5d44e2003-12-23 08:09:43 +0000168terminate (int i)
169{
170 exit (i);
171}
172
173/*
174 * Signal handlers
175 */
paul2d75d052004-01-19 21:31:15 +0000176
hassof390d2c2004-09-10 20:48:21 +0000177void
paul2d75d052004-01-19 21:31:15 +0000178sighup (void)
jardineb5d44e2003-12-23 08:09:43 +0000179{
hasso529d65b2004-12-24 00:14:50 +0000180 zlog_debug ("SIGHUP received");
jardineb5d44e2003-12-23 08:09:43 +0000181 reload ();
182
183 return;
184}
185
186void
paul2d75d052004-01-19 21:31:15 +0000187sigint (void)
jardineb5d44e2003-12-23 08:09:43 +0000188{
ajs887c44a2004-12-03 16:36:46 +0000189 zlog_notice ("Terminating on signal SIGINT");
jardineb5d44e2003-12-23 08:09:43 +0000190 terminate (0);
jardineb5d44e2003-12-23 08:09:43 +0000191}
192
193void
paul2d75d052004-01-19 21:31:15 +0000194sigterm (void)
jardineb5d44e2003-12-23 08:09:43 +0000195{
ajs887c44a2004-12-03 16:36:46 +0000196 zlog_notice ("Terminating on signal SIGTERM");
jardineb5d44e2003-12-23 08:09:43 +0000197 terminate (0);
198}
199
200void
paul2d75d052004-01-19 21:31:15 +0000201sigusr1 (void)
jardineb5d44e2003-12-23 08:09:43 +0000202{
hasso529d65b2004-12-24 00:14:50 +0000203 zlog_debug ("SIGUSR1 received");
jardineb5d44e2003-12-23 08:09:43 +0000204 zlog_rotate (NULL);
205}
206
paul2d75d052004-01-19 21:31:15 +0000207struct quagga_signal_t isisd_signals[] =
hassof390d2c2004-09-10 20:48:21 +0000208{
paul2d75d052004-01-19 21:31:15 +0000209 {
hassof390d2c2004-09-10 20:48:21 +0000210 .signal = SIGHUP,
211 .handler = &sighup,
212 },
paul2d75d052004-01-19 21:31:15 +0000213 {
hassof390d2c2004-09-10 20:48:21 +0000214 .signal = SIGUSR1,
215 .handler = &sigusr1,
216 },
paul2d75d052004-01-19 21:31:15 +0000217 {
hassof390d2c2004-09-10 20:48:21 +0000218 .signal = SIGINT,
219 .handler = &sigint,
220 },
221 {
222 .signal = SIGTERM,
223 .handler = &sigterm,
224 },
paul2d75d052004-01-19 21:31:15 +0000225};
jardineb5d44e2003-12-23 08:09:43 +0000226
227/*
228 * Main routine of isisd. Parse arguments and handle IS-IS state machine.
229 */
hassof390d2c2004-09-10 20:48:21 +0000230int
jardineb5d44e2003-12-23 08:09:43 +0000231main (int argc, char **argv, char **envp)
232{
233 char *p;
234 int opt, vty_port = ISISD_VTY_PORT;
235 struct thread thread;
236 char *config_file = NULL;
237 char *vty_addr = NULL;
Paul Jakma876b8be2006-10-15 23:35:57 +0000238 int dryrun = 0;
jardineb5d44e2003-12-23 08:09:43 +0000239
240 /* Get the programname without the preceding path. */
241 progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
242
ajs274a4a42004-12-07 15:39:31 +0000243 zlog_default = openzlog (progname, ZLOG_ISIS,
hassof390d2c2004-09-10 20:48:21 +0000244 LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
jardineb5d44e2003-12-23 08:09:43 +0000245
jardineb5d44e2003-12-23 08:09:43 +0000246 /* for reload */
247 _argc = argc;
248 _argv = argv;
249 _envp = envp;
250 getcwd (_cwd, sizeof (_cwd));
251 if (*argv[0] == '.')
252 snprintf (_progpath, sizeof (_progpath), "%s/%s", _cwd, _argv[0]);
253 else
254 snprintf (_progpath, sizeof (_progpath), "%s", argv[0]);
hassof390d2c2004-09-10 20:48:21 +0000255
jardineb5d44e2003-12-23 08:09:43 +0000256 /* Command line argument treatment. */
hassof390d2c2004-09-10 20:48:21 +0000257 while (1)
jardineb5d44e2003-12-23 08:09:43 +0000258 {
Vyacheslav Trushkin48d8bea2011-11-25 18:51:48 +0400259 opt = getopt_long (argc, argv, "df:i:z:hA:p:P:u:g:vC", longopts, 0);
jardineb5d44e2003-12-23 08:09:43 +0000260
hassof390d2c2004-09-10 20:48:21 +0000261 if (opt == EOF)
262 break;
263
264 switch (opt)
265 {
266 case 0:
jardin9e867fe2003-12-23 08:56:18 +0000267 break;
hassof390d2c2004-09-10 20:48:21 +0000268 case 'd':
269 daemon_mode = 1;
270 break;
271 case 'f':
272 config_file = optarg;
273 break;
274 case 'i':
275 pid_file = optarg;
276 break;
Vyacheslav Trushkin48d8bea2011-11-25 18:51:48 +0400277 case 'z':
278 zclient_serv_path_set (optarg);
279 break;
hassof390d2c2004-09-10 20:48:21 +0000280 case 'A':
281 vty_addr = optarg;
282 break;
283 case 'P':
284 /* Deal with atoi() returning 0 on failure, and isisd not
285 listening on isisd port... */
286 if (strcmp (optarg, "0") == 0)
287 {
288 vty_port = 0;
289 break;
290 }
291 vty_port = atoi (optarg);
292 vty_port = (vty_port ? vty_port : ISISD_VTY_PORT);
293 break;
294 case 'u':
hassoc0652302004-11-25 19:33:48 +0000295 isisd_privs.user = optarg;
hassof390d2c2004-09-10 20:48:21 +0000296 break;
hassoc0652302004-11-25 19:33:48 +0000297 case 'g':
298 isisd_privs.group = optarg;
hassof390d2c2004-09-10 20:48:21 +0000299 break;
300 case 'v':
301 printf ("ISISd version %s\n", ISISD_VERSION);
302 printf ("Copyright (c) 2001-2002 Sampo Saaristo,"
303 " Ofer Wald and Hannes Gredler\n");
304 print_version ("Zebra");
305 exit (0);
306 break;
Paul Jakma876b8be2006-10-15 23:35:57 +0000307 case 'C':
308 dryrun = 1;
309 break;
hassof390d2c2004-09-10 20:48:21 +0000310 case 'h':
311 usage (0);
312 break;
313 default:
314 usage (1);
315 break;
316 }
jardineb5d44e2003-12-23 08:09:43 +0000317 }
hassof390d2c2004-09-10 20:48:21 +0000318
jardineb5d44e2003-12-23 08:09:43 +0000319 /* thread master */
320 master = thread_master_create ();
321
322 /* random seed from time */
Donald Sharpf31bab42015-06-19 19:26:19 -0400323 srandom (time (NULL));
jardineb5d44e2003-12-23 08:09:43 +0000324
325 /*
326 * initializations
327 */
jardin9e867fe2003-12-23 08:56:18 +0000328 zprivs_init (&isisd_privs);
Balaji.G837d16c2012-09-26 14:09:10 +0530329 signal_init (master, array_size (isisd_signals), isisd_signals);
jardineb5d44e2003-12-23 08:09:43 +0000330 cmd_init (1);
jardin9e867fe2003-12-23 08:56:18 +0000331 vty_init (master);
jardineb5d44e2003-12-23 08:09:43 +0000332 memory_init ();
hassoc729c652004-10-13 08:36:47 +0000333 access_list_init();
Feng Lu126215c2015-05-22 11:39:58 +0200334 vrf_init ();
jardineb5d44e2003-12-23 08:09:43 +0000335 isis_init ();
Josh Bailey3f045a02012-03-24 08:35:20 -0700336 isis_circuit_init ();
337 isis_spf_cmds_init ();
338
339 /* create the global 'isis' instance */
340 isis_new (1);
341
342 isis_zebra_init ();
343
hassof390d2c2004-09-10 20:48:21 +0000344 /* parse config file */
jardineb5d44e2003-12-23 08:09:43 +0000345 /* this is needed three times! because we have interfaces before the areas */
hasso320ec102004-06-20 19:54:37 +0000346 vty_read_config (config_file, config_default);
hasso00995cf2004-05-19 13:43:50 +0000347
Paul Jakma876b8be2006-10-15 23:35:57 +0000348 /* Start execution only if not in dry-run mode */
349 if (dryrun)
350 return(0);
351
jardineb5d44e2003-12-23 08:09:43 +0000352 /* demonize */
Josh Bailey3f045a02012-03-24 08:35:20 -0700353 if (daemon_mode)
354 daemon (0, 0);
jardineb5d44e2003-12-23 08:09:43 +0000355
jardineb5d44e2003-12-23 08:09:43 +0000356 /* Process ID file creation. */
Josh Bailey3f045a02012-03-24 08:35:20 -0700357 if (pid_file[0] != '\0')
358 pid_output (pid_file);
jardineb5d44e2003-12-23 08:09:43 +0000359
360 /* Make isis vty socket. */
jardin9e867fe2003-12-23 08:56:18 +0000361 vty_serv_sock (vty_addr, vty_port, ISIS_VTYSH_PATH);
hassof390d2c2004-09-10 20:48:21 +0000362
jardineb5d44e2003-12-23 08:09:43 +0000363 /* Print banner. */
ajs887c44a2004-12-03 16:36:46 +0000364 zlog_notice ("Quagga-ISISd %s starting: vty@%d", QUAGGA_VERSION, vty_port);
hassoc89c05d2005-09-04 21:36:36 +0000365
jardineb5d44e2003-12-23 08:09:43 +0000366 /* Start finite state machine. */
367 while (thread_fetch (master, &thread))
368 thread_call (&thread);
369
370 /* Not reached. */
371 exit (0);
372}