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