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>
39 #include "isisd/dict.h"
40 #include "include-netbsd/iso.h"
41 #include "isisd/isis_constants.h"
42 #include "isisd/isis_common.h"
43 #include "isisd/isis_flags.h"
44 #include "isisd/isis_circuit.h"
45 #include "isisd/isisd.h"
46 #include "isisd/isis_dynhn.h"
48 /* Default configuration file name */
49 #define ISISD_DEFAULT_CONFIG "isisd.conf"
50 /* Default vty port */
51 #define ISISD_VTY_PORT 2608
53 /* isisd privileges */
54 zebra_capabilities_t _caps_p
[] = {
59 struct zebra_privs_t isisd_privs
= {
60 #if defined(QUAGGA_USER)
63 #if defined QUAGGA_GROUP
64 .group
= QUAGGA_GROUP
,
67 .vty_group
= VTY_GROUP
,
75 struct option longopts
[] = {
76 {"daemon", no_argument
, NULL
, 'd'},
77 {"config_file", required_argument
, NULL
, 'f'},
78 {"pid_file", required_argument
, NULL
, 'i'},
79 {"socket", required_argument
, NULL
, 'z'},
80 {"vty_addr", required_argument
, NULL
, 'A'},
81 {"vty_port", required_argument
, NULL
, 'P'},
82 {"user", required_argument
, NULL
, 'u'},
83 {"group", required_argument
, NULL
, 'g'},
84 {"version", no_argument
, NULL
, 'v'},
85 {"dryrun", no_argument
, NULL
, 'C'},
86 {"help", no_argument
, NULL
, 'h'},
90 /* Configuration file and directory. */
91 char config_default
[] = SYSCONFDIR ISISD_DEFAULT_CONFIG
;
92 char *config_file
= NULL
;
94 /* isisd program name. */
99 /* Master of threads. */
100 struct thread_master
*master
;
102 /* Process ID saved for use by init system */
103 const char *pid_file
= PATH_ISISD_PID
;
106 char _cwd
[MAXPATHLEN
];
107 char _progpath
[MAXPATHLEN
];
122 /* Help information display. */
127 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
130 printf ("Usage : %s [OPTION...]\n\n\
131 Daemon which manages IS-IS routing\n\n\
132 -d, --daemon Runs in daemon mode\n\
133 -f, --config_file Set configuration file name\n\
134 -i, --pid_file Set process identifier file name\n\
135 -z, --socket Set path of zebra socket\n\
136 -A, --vty_addr Set vty's bind address\n\
137 -P, --vty_port Set vty's port number\n\
138 -u, --user User to run as\n\
139 -g, --group Group to run as\n\
140 -v, --version Print program version\n\
141 -C, --dryrun Check configuration for validity and exit\n\
142 -h, --help Display this help and exit\n\
144 Report bugs to http://bugzilla.quagga.net\n", progname
);
154 zlog_debug ("Reload");
155 /* FIXME: Clean up func call here */
157 execve (_progpath
, _argv
, _envp
);
173 zlog_debug ("SIGHUP received");
182 zlog_notice ("Terminating on signal SIGINT");
189 zlog_notice ("Terminating on signal SIGTERM");
196 zlog_debug ("SIGUSR1 received");
200 struct quagga_signal_t isisd_signals
[] =
221 * Main routine of isisd. Parse arguments and handle IS-IS state machine.
224 main (int argc
, char **argv
, char **envp
)
227 int opt
, vty_port
= ISISD_VTY_PORT
;
228 struct thread thread
;
229 char *config_file
= NULL
;
230 char *vty_addr
= NULL
;
233 /* Get the programname without the preceding path. */
234 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
236 zlog_default
= openzlog (progname
, ZLOG_ISIS
,
237 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
243 getcwd (_cwd
, sizeof (_cwd
));
245 snprintf (_progpath
, sizeof (_progpath
), "%s/%s", _cwd
, _argv
[0]);
247 snprintf (_progpath
, sizeof (_progpath
), "%s", argv
[0]);
249 /* Command line argument treatment. */
252 opt
= getopt_long (argc
, argv
, "df:i:z:hA:p:P:u:g:vC", longopts
, 0);
265 config_file
= optarg
;
271 zclient_serv_path_set (optarg
);
277 /* Deal with atoi() returning 0 on failure, and isisd not
278 listening on isisd port... */
279 if (strcmp (optarg
, "0") == 0)
284 vty_port
= atoi (optarg
);
285 vty_port
= (vty_port
? vty_port
: ISISD_VTY_PORT
);
288 isisd_privs
.user
= optarg
;
291 isisd_privs
.group
= optarg
;
294 printf ("ISISd version %s\n", ISISD_VERSION
);
295 printf ("Copyright (c) 2001-2002 Sampo Saaristo,"
296 " Ofer Wald and Hannes Gredler\n");
297 print_version ("Zebra");
313 master
= thread_master_create ();
315 /* random seed from time */
321 zprivs_init (&isisd_privs
);
322 signal_init (master
, Q_SIGC (isisd_signals
), isisd_signals
);
331 /* parse config file */
332 /* this is needed three times! because we have interfaces before the areas */
333 vty_read_config (config_file
, config_default
);
334 vty_read_config (config_file
, config_default
);
335 vty_read_config (config_file
, config_default
);
337 /* Start execution only if not in dry-run mode */
342 if (daemon_mode
&& daemon (0, 0) < 0)
344 zlog_err("ISISd daemon failed: %s", strerror(errno
));
348 /* Process ID file creation. */
349 pid_output (pid_file
);
351 /* Make isis vty socket. */
352 vty_serv_sock (vty_addr
, vty_port
, ISIS_VTYSH_PATH
);
355 zlog_notice ("Quagga-ISISd %s starting: vty@%d", QUAGGA_VERSION
, vty_port
);
357 /* Start finite state machine. */
358 while (thread_fetch (master
, &thread
))
359 thread_call (&thread
);