]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_main.c
isisd: don't overrun list of protocols
[mirror_frr.git] / isisd / isis_main.c
CommitLineData
eb5d44eb 1/*
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
eb5d44eb 23#include <zebra.h>
eb5d44eb 24
25#include "getopt.h"
26#include "thread.h"
27#include "log.h"
5e4fa164 28#include <lib/version.h>
eb5d44eb 29#include "command.h"
30#include "vty.h"
31#include "memory.h"
32#include "stream.h"
33#include "if.h"
9e867fe6 34#include "privs.h"
2d75d052 35#include "sigevent.h"
c729c650 36#include "filter.h"
48d8bea8 37#include "zclient.h"
eb5d44eb 38
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"
3f045a08
JB
47#include "isisd/isis_spf.h"
48#include "isisd/isis_route.h"
49#include "isisd/isis_zebra.h"
eb5d44eb 50
51/* Default configuration file name */
52#define ISISD_DEFAULT_CONFIG "isisd.conf"
53/* Default vty port */
fc58e874 54#define ISISD_VTY_PORT 2608
eb5d44eb 55
9e867fe6 56/* isisd privileges */
f390d2c7 57zebra_capabilities_t _caps_p[] = {
ceacedba 58 ZCAP_NET_RAW,
9e867fe6 59 ZCAP_BIND
60};
61
f390d2c7 62struct zebra_privs_t isisd_privs = {
9e867fe6 63#if defined(QUAGGA_USER)
64 .user = QUAGGA_USER,
65#endif
66#if defined QUAGGA_GROUP
67 .group = QUAGGA_GROUP,
68#endif
69#ifdef VTY_GROUP
70 .vty_group = VTY_GROUP,
71#endif
72 .caps_p = _caps_p,
3f045a08 73 .cap_num_p = sizeof (_caps_p) / sizeof (*_caps_p),
9e867fe6 74 .cap_num_i = 0
75};
76
eb5d44eb 77/* isisd options */
f390d2c7 78struct option longopts[] = {
1627b20f 79 {"daemon", no_argument, NULL, 'd'},
f390d2c7 80 {"config_file", required_argument, NULL, 'f'},
1627b20f 81 {"pid_file", required_argument, NULL, 'i'},
48d8bea8 82 {"socket", required_argument, NULL, 'z'},
1627b20f
VT
83 {"vty_addr", required_argument, NULL, 'A'},
84 {"vty_port", required_argument, NULL, 'P'},
85 {"user", required_argument, NULL, 'u'},
86 {"group", required_argument, NULL, 'g'},
87 {"version", no_argument, NULL, 'v'},
88 {"dryrun", no_argument, NULL, 'C'},
89 {"help", no_argument, NULL, 'h'},
f390d2c7 90 {0}
eb5d44eb 91};
92
93/* Configuration file and directory. */
eb5d44eb 94char config_default[] = SYSCONFDIR ISISD_DEFAULT_CONFIG;
95char *config_file = NULL;
96
97/* isisd program name. */
98char *progname;
99
100int daemon_mode = 0;
101
102/* Master of threads. */
103struct thread_master *master;
104
c3aac6ff 105/* Process ID saved for use by init system */
1cd80845 106const char *pid_file = PATH_ISISD_PID;
eb5d44eb 107
108/* for reload */
37da8c01 109char _cwd[MAXPATHLEN];
110char _progpath[MAXPATHLEN];
eb5d44eb 111int _argc;
112char **_argv;
113char **_envp;
114
41b36e90
PJ
115/*
116 * Prototypes.
117 */
118void reload(void);
119void sighup(void);
120void sigint(void);
121void sigterm(void);
122void sigusr1(void);
123
124
eb5d44eb 125/* Help information display. */
126static void
127usage (int status)
128{
129 if (status != 0)
130 fprintf (stderr, "Try `%s --help' for more information.\n", progname);
131 else
f390d2c7 132 {
eb5d44eb 133 printf ("Usage : %s [OPTION...]\n\n\
134Daemon which manages IS-IS routing\n\n\
135-d, --daemon Runs in daemon mode\n\
136-f, --config_file Set configuration file name\n\
c3aac6ff 137-i, --pid_file Set process identifier file name\n\
48d8bea8 138-z, --socket Set path of zebra socket\n\
c3aac6ff 139-A, --vty_addr Set vty's bind address\n\
eb5d44eb 140-P, --vty_port Set vty's port number\n\
c065230a 141-u, --user User to run as\n\
142-g, --group Group to run as\n\
eb5d44eb 143-v, --version Print program version\n\
876b8be0 144-C, --dryrun Check configuration for validity and exit\n\
eb5d44eb 145-h, --help Display this help and exit\n\
146\n\
aa0b9f91 147Report bugs to http://bugzilla.quagga.net\n", progname);
eb5d44eb 148 }
149
150 exit (status);
151}
152
153
154void
155reload ()
156{
529d65b3 157 zlog_debug ("Reload");
eb5d44eb 158 /* FIXME: Clean up func call here */
cdb6ee94 159 vty_reset ();
3f045a08 160 (void) isisd_privs.change (ZPRIVS_RAISE);
eb5d44eb 161 execve (_progpath, _argv, _envp);
3f045a08
JB
162 zlog_err ("Reload failed: cannot exec %s: %s", _progpath,
163 safe_strerror (errno));
eb5d44eb 164}
165
887c44a4 166static void
eb5d44eb 167terminate (int i)
168{
169 exit (i);
170}
171
172/*
173 * Signal handlers
174 */
2d75d052 175
f390d2c7 176void
2d75d052 177sighup (void)
eb5d44eb 178{
529d65b3 179 zlog_debug ("SIGHUP received");
eb5d44eb 180 reload ();
181
182 return;
183}
184
185void
2d75d052 186sigint (void)
eb5d44eb 187{
887c44a4 188 zlog_notice ("Terminating on signal SIGINT");
eb5d44eb 189 terminate (0);
eb5d44eb 190}
191
192void
2d75d052 193sigterm (void)
eb5d44eb 194{
887c44a4 195 zlog_notice ("Terminating on signal SIGTERM");
eb5d44eb 196 terminate (0);
197}
198
199void
2d75d052 200sigusr1 (void)
eb5d44eb 201{
529d65b3 202 zlog_debug ("SIGUSR1 received");
eb5d44eb 203 zlog_rotate (NULL);
204}
205
2d75d052 206struct quagga_signal_t isisd_signals[] =
f390d2c7 207{
208 {
209 .signal = SIGHUP,
210 .handler = &sighup,
211 },
2d75d052 212 {
f390d2c7 213 .signal = SIGUSR1,
214 .handler = &sigusr1,
215 },
2d75d052 216 {
f390d2c7 217 .signal = SIGINT,
218 .handler = &sigint,
219 },
2d75d052 220 {
f390d2c7 221 .signal = SIGTERM,
222 .handler = &sigterm,
223 },
2d75d052 224};
eb5d44eb 225
226/*
227 * Main routine of isisd. Parse arguments and handle IS-IS state machine.
228 */
f390d2c7 229int
eb5d44eb 230main (int argc, char **argv, char **envp)
231{
232 char *p;
233 int opt, vty_port = ISISD_VTY_PORT;
234 struct thread thread;
235 char *config_file = NULL;
236 char *vty_addr = NULL;
876b8be0 237 int dryrun = 0;
eb5d44eb 238
239 /* Get the programname without the preceding path. */
240 progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
241
274a4a44 242 zlog_default = openzlog (progname, ZLOG_ISIS,
f390d2c7 243 LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
eb5d44eb 244
eb5d44eb 245 /* for reload */
246 _argc = argc;
247 _argv = argv;
248 _envp = envp;
249 getcwd (_cwd, sizeof (_cwd));
250 if (*argv[0] == '.')
251 snprintf (_progpath, sizeof (_progpath), "%s/%s", _cwd, _argv[0]);
252 else
253 snprintf (_progpath, sizeof (_progpath), "%s", argv[0]);
f390d2c7 254
eb5d44eb 255 /* Command line argument treatment. */
f390d2c7 256 while (1)
eb5d44eb 257 {
48d8bea8 258 opt = getopt_long (argc, argv, "df:i:z:hA:p:P:u:g:vC", longopts, 0);
f390d2c7 259
eb5d44eb 260 if (opt == EOF)
f390d2c7 261 break;
262
263 switch (opt)
264 {
265 case 0:
266 break;
267 case 'd':
268 daemon_mode = 1;
269 break;
270 case 'f':
271 config_file = optarg;
272 break;
273 case 'i':
274 pid_file = optarg;
275 break;
48d8bea8
VT
276 case 'z':
277 zclient_serv_path_set (optarg);
278 break;
f390d2c7 279 case 'A':
280 vty_addr = optarg;
281 break;
282 case 'P':
283 /* Deal with atoi() returning 0 on failure, and isisd not
284 listening on isisd port... */
285 if (strcmp (optarg, "0") == 0)
286 {
287 vty_port = 0;
288 break;
289 }
290 vty_port = atoi (optarg);
291 vty_port = (vty_port ? vty_port : ISISD_VTY_PORT);
9e867fe6 292 break;
f390d2c7 293 case 'u':
c065230a 294 isisd_privs.user = optarg;
f390d2c7 295 break;
c065230a 296 case 'g':
297 isisd_privs.group = optarg;
f390d2c7 298 break;
299 case 'v':
300 printf ("ISISd version %s\n", ISISD_VERSION);
301 printf ("Copyright (c) 2001-2002 Sampo Saaristo,"
302 " Ofer Wald and Hannes Gredler\n");
303 print_version ("Zebra");
304 exit (0);
305 break;
876b8be0
PJ
306 case 'C':
307 dryrun = 1;
308 break;
f390d2c7 309 case 'h':
310 usage (0);
311 break;
312 default:
313 usage (1);
314 break;
315 }
eb5d44eb 316 }
f390d2c7 317
eb5d44eb 318 /* thread master */
319 master = thread_master_create ();
320
321 /* random seed from time */
f390d2c7 322 srand (time (NULL));
eb5d44eb 323
324 /*
325 * initializations
326 */
9e867fe6 327 zprivs_init (&isisd_privs);
f390d2c7 328 signal_init (master, Q_SIGC (isisd_signals), isisd_signals);
eb5d44eb 329 cmd_init (1);
9e867fe6 330 vty_init (master);
eb5d44eb 331 memory_init ();
c729c650 332 access_list_init();
eb5d44eb 333 isis_init ();
3f045a08
JB
334 isis_circuit_init ();
335 isis_spf_cmds_init ();
336
337 /* create the global 'isis' instance */
338 isis_new (1);
339
340 isis_zebra_init ();
341
eb5d44eb 342 sort_node ();
343
f390d2c7 344 /* parse config file */
eb5d44eb 345 /* this is needed three times! because we have interfaces before the areas */
320ec10a 346 vty_read_config (config_file, config_default);
00995cfc 347
876b8be0
PJ
348 /* Start execution only if not in dry-run mode */
349 if (dryrun)
350 return(0);
351
eb5d44eb 352 /* demonize */
3f045a08
JB
353 if (daemon_mode)
354 daemon (0, 0);
eb5d44eb 355
eb5d44eb 356 /* Process ID file creation. */
3f045a08
JB
357 if (pid_file[0] != '\0')
358 pid_output (pid_file);
eb5d44eb 359
360 /* Make isis vty socket. */
9e867fe6 361 vty_serv_sock (vty_addr, vty_port, ISIS_VTYSH_PATH);
f390d2c7 362
eb5d44eb 363 /* Print banner. */
887c44a4 364 zlog_notice ("Quagga-ISISd %s starting: vty@%d", QUAGGA_VERSION, vty_port);
c89c05dd 365
eb5d44eb 366 /* Start finite state machine. */
367 while (thread_fetch (master, &thread))
368 thread_call (&thread);
369
370 /* Not reached. */
371 exit (0);
372}