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.
29 #include <lib/version.h>
38 #include "isisd/dict.h"
39 #include "include-netbsd/iso.h"
40 #include "isisd/isis_constants.h"
41 #include "isisd/isis_common.h"
42 #include "isisd/isis_flags.h"
43 #include "isisd/isis_circuit.h"
44 #include "isisd/isisd.h"
45 #include "isisd/isis_dynhn.h"
47 /* Default configuration file name */
48 #define ISISD_DEFAULT_CONFIG "isisd.conf"
49 /* Default vty port */
50 #define ISISD_VTY_PORT 2608
52 /* isisd privileges */
53 zebra_capabilities_t _caps_p
[] = {
58 struct zebra_privs_t isisd_privs
= {
59 #if defined(QUAGGA_USER)
62 #if defined QUAGGA_GROUP
63 .group
= QUAGGA_GROUP
,
66 .vty_group
= VTY_GROUP
,
74 struct option longopts
[] = {
75 {"daemon", no_argument
, NULL
, 'd'},
76 {"config_file", required_argument
, NULL
, 'f'},
77 {"pid_file", required_argument
, NULL
, 'i'},
78 {"vty_addr", required_argument
, NULL
, 'A'},
79 {"vty_port", required_argument
, NULL
, 'P'},
80 {"user", required_argument
, NULL
, 'u'},
81 {"version", no_argument
, NULL
, 'v'},
82 {"help", no_argument
, NULL
, 'h'},
86 /* Configuration file and directory. */
87 char config_default
[] = SYSCONFDIR ISISD_DEFAULT_CONFIG
;
88 char *config_file
= NULL
;
90 /* isisd program name. */
95 /* Master of threads. */
96 struct thread_master
*master
;
98 /* Process ID saved for use by init system */
99 char *pid_file
= PATH_ISISD_PID
;
102 char _cwd
[MAXPATHLEN
];
103 char _progpath
[MAXPATHLEN
];
108 /* Help information display. */
113 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
116 printf ("Usage : %s [OPTION...]\n\n\
117 Daemon which manages IS-IS routing\n\n\
118 -d, --daemon Runs in daemon mode\n\
119 -f, --config_file Set configuration file name\n\
120 -i, --pid_file Set process identifier file name\n\
121 -A, --vty_addr Set vty's bind address\n\
122 -P, --vty_port Set vty's port number\n\
123 -u, --user User and group to run as\n\
124 -v, --version Print program version\n\
125 -h, --help Display this help and exit\n\
127 Report bugs to sambo@cs.tut.fi\n", progname
);
137 zlog_info ("Reload");
138 /* FIXME: Clean up func call here */
140 execve (_progpath
, _argv
, _envp
);
156 zlog_info ("SIGHUP received");
165 zlog_info ("SIGINT received");
174 zlog_info ("SIGTERM received");
181 zlog_info ("SIGUSR1 received");
185 struct quagga_signal_t isisd_signals
[] =
206 * Main routine of isisd. Parse arguments and handle IS-IS state machine.
209 main (int argc
, char **argv
, char **envp
)
212 int opt
, vty_port
= ISISD_VTY_PORT
;
213 struct thread thread
;
214 char *config_file
= NULL
;
215 char *vty_addr
= NULL
;
217 /* Get the programname without the preceding path. */
218 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
220 zlog_default
= openzlog (progname
, ZLOG_NOLOG
, ZLOG_ISIS
,
221 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
227 getcwd (_cwd
, sizeof (_cwd
));
229 snprintf (_progpath
, sizeof (_progpath
), "%s/%s", _cwd
, _argv
[0]);
231 snprintf (_progpath
, sizeof (_progpath
), "%s", argv
[0]);
233 /* Command line argument treatment. */
236 opt
= getopt_long (argc
, argv
, "df:i:hA:p:P:u:v", longopts
, 0);
249 config_file
= optarg
;
258 /* Deal with atoi() returning 0 on failure, and isisd not
259 listening on isisd port... */
260 if (strcmp (optarg
, "0") == 0)
265 vty_port
= atoi (optarg
);
266 vty_port
= (vty_port
? vty_port
: ISISD_VTY_PORT
);
269 isisd_privs
.user
= isisd_privs
.group
= optarg
;
273 printf ("ISISd version %s\n", ISISD_VERSION
);
274 printf ("Copyright (c) 2001-2002 Sampo Saaristo,"
275 " Ofer Wald and Hannes Gredler\n");
276 print_version ("Zebra");
289 master
= thread_master_create ();
291 /* random seed from time */
297 zprivs_init (&isisd_privs
);
298 signal_init (master
, Q_SIGC (isisd_signals
), isisd_signals
);
306 /* parse config file */
307 /* this is needed three times! because we have interfaces before the areas */
308 vty_read_config (config_file
, config_default
);
309 vty_read_config (config_file
, config_default
);
310 vty_read_config (config_file
, config_default
);
316 /* Process ID file creation. */
317 pid_output (pid_file
);
319 /* Make isis vty socket. */
320 vty_serv_sock (vty_addr
, vty_port
, ISIS_VTYSH_PATH
);
323 #if defined(ZEBRA_VERSION)
324 zlog_info ("ISISd %s starting: vty@%d", ZEBRA_VERSION
, vty_port
);
325 #elif defined(QUAGGA_VERSION)
326 zlog_info ("Quagga-ISISd %s starting: vty@%d", QUAGGA_VERSION
, vty_port
);
329 zlog_info ("IPv6 enabled");
331 /* Start finite state machine. */
332 while (thread_fetch (master
, &thread
))
333 thread_call (&thread
);