]>
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" |
48d8bea8 | 37 | #include "zclient.h" |
6a69b354 | 38 | #include "vrf.h" |
66dd6fdb | 39 | #include "systemd.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" | |
51 | #include "isisd/isis_zebra.h" | |
eb5d44eb | 52 | |
53 | /* Default configuration file name */ | |
54 | #define ISISD_DEFAULT_CONFIG "isisd.conf" | |
55 | /* Default vty port */ | |
fc58e874 | 56 | #define ISISD_VTY_PORT 2608 |
eb5d44eb | 57 | |
9e867fe6 | 58 | /* isisd privileges */ |
f390d2c7 | 59 | zebra_capabilities_t _caps_p[] = { |
ceacedba | 60 | ZCAP_NET_RAW, |
9e867fe6 | 61 | ZCAP_BIND |
62 | }; | |
63 | ||
f390d2c7 | 64 | struct zebra_privs_t isisd_privs = { |
9e867fe6 | 65 | #if defined(QUAGGA_USER) |
66 | .user = QUAGGA_USER, | |
67 | #endif | |
68 | #if defined QUAGGA_GROUP | |
69 | .group = QUAGGA_GROUP, | |
70 | #endif | |
71 | #ifdef VTY_GROUP | |
72 | .vty_group = VTY_GROUP, | |
73 | #endif | |
74 | .caps_p = _caps_p, | |
3f045a08 | 75 | .cap_num_p = sizeof (_caps_p) / sizeof (*_caps_p), |
9e867fe6 | 76 | .cap_num_i = 0 |
77 | }; | |
78 | ||
eb5d44eb | 79 | /* isisd options */ |
f390d2c7 | 80 | struct option longopts[] = { |
1627b20f | 81 | {"daemon", no_argument, NULL, 'd'}, |
f390d2c7 | 82 | {"config_file", required_argument, NULL, 'f'}, |
1627b20f | 83 | {"pid_file", required_argument, NULL, 'i'}, |
48d8bea8 | 84 | {"socket", required_argument, NULL, 'z'}, |
1627b20f VT |
85 | {"vty_addr", required_argument, NULL, 'A'}, |
86 | {"vty_port", required_argument, NULL, 'P'}, | |
87 | {"user", required_argument, NULL, 'u'}, | |
88 | {"group", required_argument, NULL, 'g'}, | |
89 | {"version", no_argument, NULL, 'v'}, | |
90 | {"dryrun", no_argument, NULL, 'C'}, | |
91 | {"help", no_argument, NULL, 'h'}, | |
f390d2c7 | 92 | {0} |
eb5d44eb | 93 | }; |
94 | ||
95 | /* Configuration file and directory. */ | |
eb5d44eb | 96 | char config_default[] = SYSCONFDIR ISISD_DEFAULT_CONFIG; |
97 | char *config_file = NULL; | |
98 | ||
99 | /* isisd program name. */ | |
100 | char *progname; | |
101 | ||
102 | int daemon_mode = 0; | |
103 | ||
104 | /* Master of threads. */ | |
105 | struct thread_master *master; | |
106 | ||
c3aac6ff | 107 | /* Process ID saved for use by init system */ |
1cd80845 | 108 | const char *pid_file = PATH_ISISD_PID; |
eb5d44eb | 109 | |
110 | /* for reload */ | |
37da8c01 | 111 | char _cwd[MAXPATHLEN]; |
112 | char _progpath[MAXPATHLEN]; | |
eb5d44eb | 113 | int _argc; |
114 | char **_argv; | |
115 | char **_envp; | |
116 | ||
41b36e90 PJ |
117 | /* |
118 | * Prototypes. | |
119 | */ | |
120 | void reload(void); | |
121 | void sighup(void); | |
122 | void sigint(void); | |
123 | void sigterm(void); | |
124 | void sigusr1(void); | |
125 | ||
126 | ||
eb5d44eb | 127 | /* Help information display. */ |
128 | static void | |
129 | usage (int status) | |
130 | { | |
131 | if (status != 0) | |
132 | fprintf (stderr, "Try `%s --help' for more information.\n", progname); | |
133 | else | |
f390d2c7 | 134 | { |
eb5d44eb | 135 | printf ("Usage : %s [OPTION...]\n\n\ |
136 | Daemon which manages IS-IS routing\n\n\ | |
137 | -d, --daemon Runs in daemon mode\n\ | |
138 | -f, --config_file Set configuration file name\n\ | |
c3aac6ff | 139 | -i, --pid_file Set process identifier file name\n\ |
48d8bea8 | 140 | -z, --socket Set path of zebra socket\n\ |
c3aac6ff | 141 | -A, --vty_addr Set vty's bind address\n\ |
eb5d44eb | 142 | -P, --vty_port Set vty's port number\n\ |
c065230a | 143 | -u, --user User to run as\n\ |
144 | -g, --group Group to run as\n\ | |
eb5d44eb | 145 | -v, --version Print program version\n\ |
876b8be0 | 146 | -C, --dryrun Check configuration for validity and exit\n\ |
eb5d44eb | 147 | -h, --help Display this help and exit\n\ |
148 | \n\ | |
4ff3bcad | 149 | Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS); |
eb5d44eb | 150 | } |
151 | ||
152 | exit (status); | |
153 | } | |
154 | ||
155 | ||
156 | void | |
157 | reload () | |
158 | { | |
529d65b3 | 159 | zlog_debug ("Reload"); |
eb5d44eb | 160 | /* FIXME: Clean up func call here */ |
cdb6ee94 | 161 | vty_reset (); |
3f045a08 | 162 | (void) isisd_privs.change (ZPRIVS_RAISE); |
eb5d44eb | 163 | execve (_progpath, _argv, _envp); |
3f045a08 JB |
164 | zlog_err ("Reload failed: cannot exec %s: %s", _progpath, |
165 | safe_strerror (errno)); | |
eb5d44eb | 166 | } |
167 | ||
35dece84 | 168 | static __attribute__((__noreturn__)) void |
eb5d44eb | 169 | terminate (int i) |
170 | { | |
66dd6fdb | 171 | systemd_send_stopping (); |
eb5d44eb | 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); |
eb5d44eb | 247 | |
eb5d44eb | 248 | /* for reload */ |
249 | _argc = argc; | |
250 | _argv = argv; | |
251 | _envp = envp; | |
7a49a5b5 DS |
252 | if (getcwd (_cwd, sizeof (_cwd)) == NULL) |
253 | { | |
254 | zlog_err ("ISISd: Unable to determine CWD: %d", errno); | |
255 | exit (1); | |
256 | } | |
257 | ||
eb5d44eb | 258 | if (*argv[0] == '.') |
259 | snprintf (_progpath, sizeof (_progpath), "%s/%s", _cwd, _argv[0]); | |
260 | else | |
261 | snprintf (_progpath, sizeof (_progpath), "%s", argv[0]); | |
f390d2c7 | 262 | |
eb5d44eb | 263 | /* Command line argument treatment. */ |
f390d2c7 | 264 | while (1) |
eb5d44eb | 265 | { |
48d8bea8 | 266 | opt = getopt_long (argc, argv, "df:i:z:hA:p:P:u:g:vC", longopts, 0); |
f390d2c7 | 267 | |
eb5d44eb | 268 | if (opt == EOF) |
f390d2c7 | 269 | break; |
270 | ||
271 | switch (opt) | |
272 | { | |
273 | case 0: | |
274 | break; | |
275 | case 'd': | |
276 | daemon_mode = 1; | |
277 | break; | |
278 | case 'f': | |
279 | config_file = optarg; | |
280 | break; | |
281 | case 'i': | |
282 | pid_file = optarg; | |
283 | break; | |
48d8bea8 VT |
284 | case 'z': |
285 | zclient_serv_path_set (optarg); | |
286 | break; | |
f390d2c7 | 287 | case 'A': |
288 | vty_addr = optarg; | |
289 | break; | |
290 | case 'P': | |
291 | /* Deal with atoi() returning 0 on failure, and isisd not | |
292 | listening on isisd port... */ | |
293 | if (strcmp (optarg, "0") == 0) | |
294 | { | |
295 | vty_port = 0; | |
296 | break; | |
297 | } | |
298 | vty_port = atoi (optarg); | |
299 | vty_port = (vty_port ? vty_port : ISISD_VTY_PORT); | |
9e867fe6 | 300 | break; |
f390d2c7 | 301 | case 'u': |
c065230a | 302 | isisd_privs.user = optarg; |
f390d2c7 | 303 | break; |
c065230a | 304 | case 'g': |
305 | isisd_privs.group = optarg; | |
f390d2c7 | 306 | break; |
307 | case 'v': | |
308 | printf ("ISISd version %s\n", ISISD_VERSION); | |
309 | printf ("Copyright (c) 2001-2002 Sampo Saaristo," | |
310 | " Ofer Wald and Hannes Gredler\n"); | |
311 | print_version ("Zebra"); | |
312 | exit (0); | |
313 | break; | |
876b8be0 PJ |
314 | case 'C': |
315 | dryrun = 1; | |
316 | break; | |
f390d2c7 | 317 | case 'h': |
318 | usage (0); | |
319 | break; | |
320 | default: | |
321 | usage (1); | |
322 | break; | |
323 | } | |
eb5d44eb | 324 | } |
f390d2c7 | 325 | |
eb5d44eb | 326 | /* thread master */ |
327 | master = thread_master_create (); | |
328 | ||
329 | /* random seed from time */ | |
f390d2c7 | 330 | srand (time (NULL)); |
eb5d44eb | 331 | |
332 | /* | |
333 | * initializations | |
334 | */ | |
9e867fe6 | 335 | zprivs_init (&isisd_privs); |
837d16cc | 336 | signal_init (master, array_size (isisd_signals), isisd_signals); |
eb5d44eb | 337 | cmd_init (1); |
9e867fe6 | 338 | vty_init (master); |
eb5d44eb | 339 | memory_init (); |
c729c650 | 340 | access_list_init(); |
6a69b354 | 341 | vrf_init (); |
eb5d44eb | 342 | isis_init (); |
3f045a08 JB |
343 | isis_circuit_init (); |
344 | isis_spf_cmds_init (); | |
345 | ||
346 | /* create the global 'isis' instance */ | |
347 | isis_new (1); | |
348 | ||
4140ca4d | 349 | isis_zebra_init(master); |
3f045a08 | 350 | |
f390d2c7 | 351 | /* parse config file */ |
eb5d44eb | 352 | /* this is needed three times! because we have interfaces before the areas */ |
320ec10a | 353 | vty_read_config (config_file, config_default); |
00995cfc | 354 | |
876b8be0 PJ |
355 | /* Start execution only if not in dry-run mode */ |
356 | if (dryrun) | |
357 | return(0); | |
358 | ||
eb5d44eb | 359 | /* demonize */ |
7a49a5b5 DS |
360 | if (daemon_mode && daemon (0, 0) < 0) |
361 | { | |
362 | zlog_err("ISISd daemon failed: %s", strerror(errno)); | |
363 | return (1); | |
364 | } | |
eb5d44eb | 365 | |
eb5d44eb | 366 | /* Process ID file creation. */ |
3f045a08 JB |
367 | if (pid_file[0] != '\0') |
368 | pid_output (pid_file); | |
eb5d44eb | 369 | |
66dd6fdb DS |
370 | systemd_send_started (master); |
371 | ||
eb5d44eb | 372 | /* Make isis vty socket. */ |
9e867fe6 | 373 | vty_serv_sock (vty_addr, vty_port, ISIS_VTYSH_PATH); |
f390d2c7 | 374 | |
eb5d44eb | 375 | /* Print banner. */ |
887c44a4 | 376 | zlog_notice ("Quagga-ISISd %s starting: vty@%d", QUAGGA_VERSION, vty_port); |
c89c05dd | 377 | |
eb5d44eb | 378 | /* Start finite state machine. */ |
379 | while (thread_fetch (master, &thread)) | |
380 | thread_call (&thread); | |
381 | ||
382 | /* Not reached. */ | |
383 | exit (0); | |
384 | } |