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