2 * IS-IS Rout(e)ing protocol - isis_main.c
4 * Copyright (C) 2001,2002 Sampo Saaristo
5 * Tampere University of Technology
6 * Institute of Communications Engineering
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)
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
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.
28 #include <lib/version.h>
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"
49 #include "isisd/isis_spf.h"
50 #include "isisd/isis_route.h"
51 #include "isisd/isis_routemap.h"
52 #include "isisd/isis_zebra.h"
53 #include "isisd/isis_tlv.h"
54 #include "isisd/isis_te.h"
56 /* Default configuration file name */
57 #define ISISD_DEFAULT_CONFIG "isisd.conf"
58 /* Default vty port */
59 #define ISISD_VTY_PORT 2608
61 /* isisd privileges */
62 zebra_capabilities_t _caps_p[] = {
67 struct zebra_privs_t isisd_privs = {
68 #if defined(QUAGGA_USER)
71 #if defined QUAGGA_GROUP
72 .group = QUAGGA_GROUP,
75 .vty_group = VTY_GROUP,
78 .cap_num_p = sizeof (_caps_p) / sizeof (*_caps_p),
83 struct option longopts[] = {
84 {"daemon", no_argument, NULL, 'd'},
85 {"config_file", required_argument, NULL, 'f'},
86 {"pid_file", required_argument, NULL, 'i'},
87 {"socket", required_argument, NULL, 'z'},
88 {"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'},
98 /* Configuration file and directory. */
99 char config_default[] = SYSCONFDIR ISISD_DEFAULT_CONFIG;
100 char *config_file = NULL;
102 /* isisd program name. */
107 /* Master of threads. */
108 struct thread_master *master;
110 /* Process ID saved for use by init system */
111 const char *pid_file = PATH_ISISD_PID;
114 char _cwd[MAXPATHLEN];
115 char _progpath[MAXPATHLEN];
130 /* Help information display. */
135 fprintf (stderr, "Try `%s --help' for more information.\n", progname);
138 printf ("Usage : %s [OPTION...]\n\n\
139 Daemon which manages IS-IS routing\n\n\
140 -d, --daemon Runs in daemon mode\n\
141 -f, --config_file Set configuration file name\n\
142 -i, --pid_file Set process identifier file name\n\
143 -z, --socket Set path of zebra socket\n\
144 -A, --vty_addr Set vty's bind address\n\
145 -P, --vty_port Set vty's port number\n\
146 -u, --user User to run as\n\
147 -g, --group Group to run as\n\
148 -v, --version Print program version\n\
149 -C, --dryrun Check configuration for validity and exit\n\
150 -h, --help Display this help and exit\n\
152 Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
162 zlog_debug ("Reload");
163 /* FIXME: Clean up func call here */
165 (void) isisd_privs.change (ZPRIVS_RAISE);
166 execve (_progpath, _argv, _envp);
167 zlog_err ("Reload failed: cannot exec %s: %s", _progpath,
168 safe_strerror (errno));
184 zlog_debug ("SIGHUP received");
193 zlog_notice ("Terminating on signal SIGINT");
200 zlog_notice ("Terminating on signal SIGTERM");
207 zlog_debug ("SIGUSR1 received");
211 struct quagga_signal_t isisd_signals[] =
232 * Main routine of isisd. Parse arguments and handle IS-IS state machine.
235 main (int argc, char **argv, char **envp)
238 int opt, vty_port = ISISD_VTY_PORT;
239 struct thread thread;
240 char *config_file = NULL;
241 char *vty_addr = NULL;
244 /* Get the programname without the preceding path. */
245 progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
247 zlog_default = openzlog (progname, ZLOG_ISIS,
248 LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
254 getcwd (_cwd, sizeof (_cwd));
256 snprintf (_progpath, sizeof (_progpath), "%s/%s", _cwd, _argv[0]);
258 snprintf (_progpath, sizeof (_progpath), "%s", argv[0]);
260 /* Command line argument treatment. */
263 opt = getopt_long (argc, argv, "df:i:z:hA:p:P:u:g:vC", longopts, 0);
276 config_file = optarg;
282 zclient_serv_path_set (optarg);
288 /* Deal with atoi() returning 0 on failure, and isisd not
289 listening on isisd port... */
290 if (strcmp (optarg, "0") == 0)
295 vty_port = atoi (optarg);
296 vty_port = (vty_port ? vty_port : ISISD_VTY_PORT);
299 isisd_privs.user = optarg;
302 isisd_privs.group = optarg;
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");
324 master = thread_master_create ();
326 /* random seed from time */
327 srandom (time (NULL));
332 zprivs_init (&isisd_privs);
333 signal_init (master, array_size (isisd_signals), isisd_signals);
341 isis_circuit_init ();
342 isis_spf_cmds_init ();
344 isis_route_map_init();
347 /* create the global 'isis' instance */
350 isis_zebra_init (master);
352 /* parse config file */
353 /* this is needed three times! because we have interfaces before the areas */
354 vty_read_config (config_file, config_default);
356 /* Start execution only if not in dry-run mode */
361 if (daemon_mode && daemon (0, 0) < 0)
363 zlog_err("IS-IS daemon failed: %s", strerror(errno));
367 /* Process ID file creation. */
368 if (pid_file[0] != '\0')
369 pid_output (pid_file);
371 /* Make isis vty socket. */
372 vty_serv_sock (vty_addr, vty_port, ISIS_VTYSH_PATH);
375 zlog_notice ("Quagga-ISISd %s starting: vty@%d", QUAGGA_VERSION, vty_port);
377 /* Start finite state machine. */
378 while (thread_fetch (master, &thread))
379 thread_call (&thread);