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>
32 #include "memory_vty.h"
43 #include "isisd/dict.h"
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_tlv.h"
55 #include "isisd/isis_te.h"
57 /* Default configuration file name */
58 #define ISISD_DEFAULT_CONFIG "isisd.conf"
59 /* Default vty port */
60 #define ISISD_VTY_PORT 2608
62 /* isisd privileges */
63 zebra_capabilities_t _caps_p
[] = {
68 struct zebra_privs_t isisd_privs
= {
76 .vty_group
= VTY_GROUP
,
79 .cap_num_p
= sizeof (_caps_p
) / sizeof (*_caps_p
),
84 struct option longopts
[] = {
85 {"daemon", no_argument
, NULL
, 'd'},
86 {"config_file", required_argument
, NULL
, 'f'},
87 {"pid_file", required_argument
, NULL
, 'i'},
88 {"socket", required_argument
, NULL
, 'z'},
89 {"vty_addr", required_argument
, NULL
, 'A'},
90 {"vty_port", required_argument
, NULL
, 'P'},
91 {"user", required_argument
, NULL
, 'u'},
92 {"group", required_argument
, NULL
, 'g'},
93 {"version", no_argument
, NULL
, 'v'},
94 {"dryrun", no_argument
, NULL
, 'C'},
95 {"help", no_argument
, NULL
, 'h'},
99 /* Configuration file and directory. */
100 char config_default
[] = SYSCONFDIR ISISD_DEFAULT_CONFIG
;
101 char *config_file
= NULL
;
103 /* isisd program name. */
108 /* Master of threads. */
109 struct thread_master
*master
;
111 /* Process ID saved for use by init system */
112 const char *pid_file
= PATH_ISISD_PID
;
115 char _cwd
[MAXPATHLEN
];
116 char _progpath
[MAXPATHLEN
];
131 /* Help information display. */
136 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
139 printf ("Usage : %s [OPTION...]\n\n\
140 Daemon which manages IS-IS routing\n\n\
141 -d, --daemon Runs in daemon mode\n\
142 -f, --config_file Set configuration file name\n\
143 -i, --pid_file Set process identifier file name\n\
144 -z, --socket Set path of zebra socket\n\
145 -A, --vty_addr Set vty's bind address\n\
146 -P, --vty_port Set vty's port number\n\
147 -u, --user User to run as\n\
148 -g, --group Group to run as\n\
149 -v, --version Print program version\n\
150 -C, --dryrun Check configuration for validity and exit\n\
151 -h, --help Display this help and exit\n\
153 Report bugs to %s\n", progname
, FRR_BUG_ADDRESS
);
163 zlog_debug ("Reload");
164 /* FIXME: Clean up func call here */
166 (void) isisd_privs
.change (ZPRIVS_RAISE
);
167 execve (_progpath
, _argv
, _envp
);
168 zlog_err ("Reload failed: cannot exec %s: %s", _progpath
,
169 safe_strerror (errno
));
172 static __attribute__((__noreturn__
)) void
185 zlog_debug ("SIGHUP received");
191 __attribute__((__noreturn__
)) void
194 zlog_notice ("Terminating on signal SIGINT");
198 __attribute__((__noreturn__
)) void
201 zlog_notice ("Terminating on signal SIGTERM");
208 zlog_debug ("SIGUSR1 received");
212 struct quagga_signal_t isisd_signals
[] =
233 * Main routine of isisd. Parse arguments and handle IS-IS state machine.
236 main (int argc
, char **argv
, char **envp
)
239 int opt
, vty_port
= ISISD_VTY_PORT
;
240 struct thread thread
;
241 char *config_file
= NULL
;
242 char *vty_addr
= NULL
;
245 /* Get the programname without the preceding path. */
246 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
248 zlog_default
= openzlog (progname
, ZLOG_ISIS
, 0,
249 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
250 zprivs_init (&isisd_privs
);
251 #if defined(HAVE_CUMULUS)
252 zlog_set_level (NULL
, ZLOG_DEST_SYSLOG
, zlog_default
->default_lvl
);
259 if (getcwd (_cwd
, sizeof (_cwd
)) == NULL
)
261 zlog_err ("ISISd: Unable to determine CWD: %d", errno
);
266 snprintf (_progpath
, sizeof (_progpath
), "%s/%s", _cwd
, _argv
[0]);
268 snprintf (_progpath
, sizeof (_progpath
), "%s", argv
[0]);
270 /* Command line argument treatment. */
273 opt
= getopt_long (argc
, argv
, "df:i:z:hA:p:P:u:g:vC", longopts
, 0);
286 config_file
= optarg
;
292 zclient_serv_path_set (optarg
);
298 /* Deal with atoi() returning 0 on failure, and isisd not
299 listening on isisd port... */
300 if (strcmp (optarg
, "0") == 0)
305 vty_port
= atoi (optarg
);
306 vty_port
= (vty_port
? vty_port
: ISISD_VTY_PORT
);
309 isisd_privs
.user
= optarg
;
312 isisd_privs
.group
= optarg
;
315 printf ("ISISd version %s\n", ISISD_VERSION
);
316 printf ("Copyright (c) 2001-2002 Sampo Saaristo,"
317 " Ofer Wald and Hannes Gredler\n");
318 print_version ("Zebra");
334 master
= thread_master_create ();
336 /* random seed from time */
337 srandom (time (NULL
));
342 signal_init (master
, array_size (isisd_signals
), isisd_signals
);
344 vty_config_lockless ();
351 isis_circuit_init ();
352 isis_spf_cmds_init ();
354 isis_route_map_init();
357 /* create the global 'isis' instance */
360 isis_zebra_init(master
);
362 /* parse config file */
363 /* this is needed three times! because we have interfaces before the areas */
364 vty_read_config (config_file
, config_default
);
366 /* Start execution only if not in dry-run mode */
371 if (daemon_mode
&& daemon (0, 0) < 0)
373 zlog_err("ISISd daemon failed: %s", strerror(errno
));
377 /* Process ID file creation. */
378 if (pid_file
[0] != '\0')
379 pid_output (pid_file
);
381 /* Make isis vty socket. */
382 vty_serv_sock (vty_addr
, vty_port
, ISIS_VTYSH_PATH
);
385 zlog_notice ("Quagga-ISISd %s starting: vty@%d", FRR_VERSION
, vty_port
);
387 /* Start finite state machine. */
388 while (thread_fetch (master
, &thread
))
389 thread_call (&thread
);