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