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