]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_main.c
lib, zebra: add "vrf_id" into the "struct interface"
[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\
4ff3bcad 147Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
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
7c8ff89e 242 zlog_default = openzlog (progname, ZLOG_ISIS, 0,
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;
7a49a5b5
DS
249 if (getcwd (_cwd, sizeof (_cwd)) == NULL)
250 {
251 zlog_err ("ISISd: Unable to determine CWD: %d", errno);
252 exit (1);
253 }
254
eb5d44eb 255 if (*argv[0] == '.')
256 snprintf (_progpath, sizeof (_progpath), "%s/%s", _cwd, _argv[0]);
257 else
258 snprintf (_progpath, sizeof (_progpath), "%s", argv[0]);
f390d2c7 259
eb5d44eb 260 /* Command line argument treatment. */
f390d2c7 261 while (1)
eb5d44eb 262 {
48d8bea8 263 opt = getopt_long (argc, argv, "df:i:z:hA:p:P:u:g:vC", longopts, 0);
f390d2c7 264
eb5d44eb 265 if (opt == EOF)
f390d2c7 266 break;
267
268 switch (opt)
269 {
270 case 0:
271 break;
272 case 'd':
273 daemon_mode = 1;
274 break;
275 case 'f':
276 config_file = optarg;
277 break;
278 case 'i':
279 pid_file = optarg;
280 break;
48d8bea8
VT
281 case 'z':
282 zclient_serv_path_set (optarg);
283 break;
f390d2c7 284 case 'A':
285 vty_addr = optarg;
286 break;
287 case 'P':
288 /* Deal with atoi() returning 0 on failure, and isisd not
289 listening on isisd port... */
290 if (strcmp (optarg, "0") == 0)
291 {
292 vty_port = 0;
293 break;
294 }
295 vty_port = atoi (optarg);
296 vty_port = (vty_port ? vty_port : ISISD_VTY_PORT);
9e867fe6 297 break;
f390d2c7 298 case 'u':
c065230a 299 isisd_privs.user = optarg;
f390d2c7 300 break;
c065230a 301 case 'g':
302 isisd_privs.group = optarg;
f390d2c7 303 break;
304 case 'v':
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");
309 exit (0);
310 break;
876b8be0
PJ
311 case 'C':
312 dryrun = 1;
313 break;
f390d2c7 314 case 'h':
315 usage (0);
316 break;
317 default:
318 usage (1);
319 break;
320 }
eb5d44eb 321 }
f390d2c7 322
eb5d44eb 323 /* thread master */
324 master = thread_master_create ();
325
326 /* random seed from time */
f390d2c7 327 srand (time (NULL));
eb5d44eb 328
329 /*
330 * initializations
331 */
9e867fe6 332 zprivs_init (&isisd_privs);
837d16cc 333 signal_init (master, array_size (isisd_signals), isisd_signals);
eb5d44eb 334 cmd_init (1);
9e867fe6 335 vty_init (master);
eb5d44eb 336 memory_init ();
c729c650 337 access_list_init();
eb5d44eb 338 isis_init ();
3f045a08
JB
339 isis_circuit_init ();
340 isis_spf_cmds_init ();
341
342 /* create the global 'isis' instance */
343 isis_new (1);
344
4140ca4d 345 isis_zebra_init(master);
3f045a08 346
f390d2c7 347 /* parse config file */
eb5d44eb 348 /* this is needed three times! because we have interfaces before the areas */
320ec10a 349 vty_read_config (config_file, config_default);
00995cfc 350
876b8be0
PJ
351 /* Start execution only if not in dry-run mode */
352 if (dryrun)
353 return(0);
354
eb5d44eb 355 /* demonize */
7a49a5b5
DS
356 if (daemon_mode && daemon (0, 0) < 0)
357 {
358 zlog_err("ISISd daemon failed: %s", strerror(errno));
359 return (1);
360 }
eb5d44eb 361
eb5d44eb 362 /* Process ID file creation. */
3f045a08
JB
363 if (pid_file[0] != '\0')
364 pid_output (pid_file);
eb5d44eb 365
366 /* Make isis vty socket. */
9e867fe6 367 vty_serv_sock (vty_addr, vty_port, ISIS_VTYSH_PATH);
f390d2c7 368
eb5d44eb 369 /* Print banner. */
887c44a4 370 zlog_notice ("Quagga-ISISd %s starting: vty@%d", QUAGGA_VERSION, vty_port);
c89c05dd 371
eb5d44eb 372 /* Start finite state machine. */
373 while (thread_fetch (master, &thread))
374 thread_call (&thread);
375
376 /* Not reached. */
377 exit (0);
378}