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