blob: 51249c5d42b8f00a1782eb9da6f0a853d99eb42d [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
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"
jardin9e867fe2003-12-23 08:56:18 +000036#include "privs.h"
paul2d75d052004-01-19 21:31:15 +000037#include "sigevent.h"
jardineb5d44e2003-12-23 08:09:43 +000038
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 */
jardinfc58e872003-12-23 10:42:45 +000051#define ISISD_VTY_PORT 2608
jardineb5d44e2003-12-23 08:09:43 +000052
jardin9e867fe2003-12-23 08:56:18 +000053/* 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
jardineb5d44e2003-12-23 08:09:43 +000076/* isisd options */
77struct option longopts[] =
78{
79 { "daemon", no_argument, NULL, 'd'},
80 { "config_file", required_argument, NULL, 'f'},
81 { "vty_port", required_argument, NULL, 'P'},
jardin9e867fe2003-12-23 08:56:18 +000082 { "user", required_argument, NULL, 'u'},
jardineb5d44e2003-12-23 08:09:43 +000083 { "version", no_argument, NULL, 'v'},
84 { "help", no_argument, NULL, 'h'},
85 { 0 }
86};
87
88/* Configuration file and directory. */
89char config_current[] = ISISD_DEFAULT_CONFIG;
90char config_default[] = SYSCONFDIR ISISD_DEFAULT_CONFIG;
91char *config_file = NULL;
92
93/* isisd program name. */
94char *progname;
95
96int daemon_mode = 0;
97
98/* Master of threads. */
99struct thread_master *master;
100
101
102/* for reload */
103char _cwd[64];
104char _progpath[64];
105int _argc;
106char **_argv;
107char **_envp;
108
109
110/* Help information display. */
111static void
112usage (int status)
113{
114 if (status != 0)
115 fprintf (stderr, "Try `%s --help' for more information.\n", progname);
116 else
117 {
118 printf ("Usage : %s [OPTION...]\n\n\
119Daemon which manages IS-IS routing\n\n\
120-d, --daemon Runs in daemon mode\n\
121-f, --config_file Set configuration file name\n\
122-P, --vty_port Set vty's port number\n\
jardin9e867fe2003-12-23 08:56:18 +0000123-u, --user User and group to run as\n\
jardineb5d44e2003-12-23 08:09:43 +0000124-v, --version Print program version\n\
125-h, --help Display this help and exit\n\
126\n\
127Report bugs to sambo@cs.tut.fi\n", progname);
128 }
129
130 exit (status);
131}
132
133
134void
135reload ()
136{
137 zlog_info ("Reload");
138 /* FIXME: Clean up func call here */
139 vty_finish ();
140 execve (_progpath, _argv, _envp);
141}
142
143void
144terminate (int i)
145{
146 exit (i);
147}
148
149/*
150 * Signal handlers
151 */
paul2d75d052004-01-19 21:31:15 +0000152
jardineb5d44e2003-12-23 08:09:43 +0000153void
paul2d75d052004-01-19 21:31:15 +0000154sighup (void)
jardineb5d44e2003-12-23 08:09:43 +0000155{
156 zlog_info ("SIGHUP received");
157 reload ();
158
159 return;
160}
161
162void
paul2d75d052004-01-19 21:31:15 +0000163sigint (void)
jardineb5d44e2003-12-23 08:09:43 +0000164{
165 zlog_info ("SIGINT received");
166 terminate (0);
167
168 return;
169}
170
171void
paul2d75d052004-01-19 21:31:15 +0000172sigterm (void)
jardineb5d44e2003-12-23 08:09:43 +0000173{
174 zlog_info ("SIGTERM received");
175 terminate (0);
176}
177
178void
paul2d75d052004-01-19 21:31:15 +0000179sigusr1 (void)
jardineb5d44e2003-12-23 08:09:43 +0000180{
181 zlog_info ("SIGUSR1 received");
182 zlog_rotate (NULL);
183}
184
paul2d75d052004-01-19 21:31:15 +0000185struct quagga_signal_t isisd_signals[] =
186{
187 {
188 .signal = SIGHUP,
189 .handler = &sighup,
190 },
191 {
192 .signal = SIGUSR1,
193 .handler = &sigusr1,
194 },
195 {
196 .signal = SIGINT,
197 .handler = &sigint,
198 },
199 {
200 .signal = SIGTERM,
201 .handler = &sigterm,
202 },
203};
jardineb5d44e2003-12-23 08:09:43 +0000204
205/*
206 * Main routine of isisd. Parse arguments and handle IS-IS state machine.
207 */
208int
209main (int argc, char **argv, char **envp)
210{
211 char *p;
212 int opt, vty_port = ISISD_VTY_PORT;
213 struct thread thread;
214 char *config_file = NULL;
215 char *vty_addr = NULL;
216
217 /* Get the programname without the preceding path. */
218 progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
219
220 zlog_default = openzlog (progname, ZLOG_NOLOG, ZLOG_ISIS,
221 LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
222
223
224 /* for reload */
225 _argc = argc;
226 _argv = argv;
227 _envp = envp;
228 getcwd (_cwd, sizeof (_cwd));
229 if (*argv[0] == '.')
230 snprintf (_progpath, sizeof (_progpath), "%s/%s", _cwd, _argv[0]);
231 else
232 snprintf (_progpath, sizeof (_progpath), "%s", argv[0]);
233
234 /* Command line argument treatment. */
235 while (1)
236 {
jardin9e867fe2003-12-23 08:56:18 +0000237 opt = getopt_long (argc, argv, "df:hAp:P:u:v", longopts, 0);
jardineb5d44e2003-12-23 08:09:43 +0000238
239 if (opt == EOF)
240 break;
241
242 switch (opt)
243 {
244 case 0:
245 break;
246 case 'd':
247 daemon_mode = 1;
248 break;
249 case 'f':
250 config_file = optarg;
251 break;
252 case 'A':
253 vty_addr = optarg;
254 break;
255 case 'P':
jardin9e867fe2003-12-23 08:56:18 +0000256 /* Deal with atoi() returning 0 on failure, and isisd not
257 listening on isisd port... */
258 if (strcmp(optarg, "0") == 0)
259 {
260 vty_port = 0;
261 break;
262 }
jardineb5d44e2003-12-23 08:09:43 +0000263 vty_port = atoi (optarg);
jardin9e867fe2003-12-23 08:56:18 +0000264 vty_port = (vty_port ? vty_port : ISISD_VTY_PORT);
265 break;
266 case 'u':
267 isisd_privs.user = isisd_privs.group = optarg;
268 break;
jardineb5d44e2003-12-23 08:09:43 +0000269 break;
270 case 'v':
271 printf("ISISd version %s\n", ISISD_VERSION);
272 printf("Copyright (c) 2001-2002 Sampo Saaristo,"
273 " Ofer Wald and Hannes Gredler\n");
274 print_version ("Zebra");
275 exit (0);
276 break;
277 case 'h':
278 usage (0);
279 break;
280 default:
281 usage (1);
282 break;
283 }
284 }
285
286 /* thread master */
287 master = thread_master_create ();
288
289 /* random seed from time */
290 srand(time(NULL));
291
292 /*
293 * initializations
294 */
jardin9e867fe2003-12-23 08:56:18 +0000295 zprivs_init (&isisd_privs);
paul2d75d052004-01-19 21:31:15 +0000296 signal_init (master, Q_SIGC(isisd_signals), isisd_signals);
jardineb5d44e2003-12-23 08:09:43 +0000297 cmd_init (1);
jardin9e867fe2003-12-23 08:56:18 +0000298 vty_init (master);
jardineb5d44e2003-12-23 08:09:43 +0000299 memory_init ();
300 isis_init ();
301 dyn_cache_init ();
302 sort_node ();
303
304 /* parse config file */
305 /* this is needed three times! because we have interfaces before the areas */
306 vty_read_config (config_file, config_current, config_default);
307#if 0
308 vty_read_config (config_file, config_current, config_default);
309 vty_read_config (config_file, config_current, config_default);
310#endif
311 /* demonize */
312 if (daemon_mode)
313 daemon (0, 0);
314
jardineb5d44e2003-12-23 08:09:43 +0000315 /* Process ID file creation. */
316 pid_output (PATH_ISISD_PID);
317
318 /* Make isis vty socket. */
jardin9e867fe2003-12-23 08:56:18 +0000319 vty_serv_sock (vty_addr, vty_port, ISIS_VTYSH_PATH);
jardineb5d44e2003-12-23 08:09:43 +0000320
321 /* Print banner. */
jardin9e867fe2003-12-23 08:56:18 +0000322#if defined(ZEBRA_VERSION)
jardineb5d44e2003-12-23 08:09:43 +0000323 zlog_info ("ISISd %s starting: vty@%d", ZEBRA_VERSION, vty_port);
jardin9e867fe2003-12-23 08:56:18 +0000324#elif defined(QUAGGA_VERSION)
325 zlog_info ("Quagga-ISISd %s starting: vty@%d", QUAGGA_VERSION, vty_port);
326#endif
jardineb5d44e2003-12-23 08:09:43 +0000327#ifdef HAVE_IPV6
328 zlog_info ("IPv6 enabled");
329#endif
330 /* Start finite state machine. */
331 while (thread_fetch (master, &thread))
332 thread_call (&thread);
333
334 /* Not reached. */
335 exit (0);
336}
337
338
339
340
341
342
343
344
345
346