]>
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" | |
fc7948fa | 32 | #include "memory_vty.h" |
eb5d44eb | 33 | #include "stream.h" |
34 | #include "if.h" | |
9e867fe6 | 35 | #include "privs.h" |
2d75d052 | 36 | #include "sigevent.h" |
c729c650 | 37 | #include "filter.h" |
f3ccedaa | 38 | #include "plist.h" |
48d8bea8 | 39 | #include "zclient.h" |
6a69b354 | 40 | #include "vrf.h" |
676a4ea3 | 41 | #include "qobj.h" |
4f04a76b | 42 | #include "libfrr.h" |
eb5d44eb | 43 | |
44 | #include "isisd/dict.h" | |
eb5d44eb | 45 | #include "isisd/isis_constants.h" |
46 | #include "isisd/isis_common.h" | |
47 | #include "isisd/isis_flags.h" | |
48 | #include "isisd/isis_circuit.h" | |
49 | #include "isisd/isisd.h" | |
50 | #include "isisd/isis_dynhn.h" | |
3f045a08 JB |
51 | #include "isisd/isis_spf.h" |
52 | #include "isisd/isis_route.h" | |
f3ccedaa | 53 | #include "isisd/isis_routemap.h" |
3f045a08 | 54 | #include "isisd/isis_zebra.h" |
f8c06e2c OD |
55 | #include "isisd/isis_tlv.h" |
56 | #include "isisd/isis_te.h" | |
eb5d44eb | 57 | |
58 | /* Default configuration file name */ | |
59 | #define ISISD_DEFAULT_CONFIG "isisd.conf" | |
60 | /* Default vty port */ | |
fc58e874 | 61 | #define ISISD_VTY_PORT 2608 |
eb5d44eb | 62 | |
9e867fe6 | 63 | /* isisd privileges */ |
f390d2c7 | 64 | zebra_capabilities_t _caps_p[] = { |
ceacedba | 65 | ZCAP_NET_RAW, |
9e867fe6 | 66 | ZCAP_BIND |
67 | }; | |
68 | ||
f390d2c7 | 69 | struct zebra_privs_t isisd_privs = { |
b2f36157 DL |
70 | #if defined(FRR_USER) |
71 | .user = FRR_USER, | |
9e867fe6 | 72 | #endif |
b2f36157 DL |
73 | #if defined FRR_GROUP |
74 | .group = FRR_GROUP, | |
9e867fe6 | 75 | #endif |
76 | #ifdef VTY_GROUP | |
77 | .vty_group = VTY_GROUP, | |
78 | #endif | |
79 | .caps_p = _caps_p, | |
3f045a08 | 80 | .cap_num_p = sizeof (_caps_p) / sizeof (*_caps_p), |
9e867fe6 | 81 | .cap_num_i = 0 |
82 | }; | |
83 | ||
eb5d44eb | 84 | /* isisd options */ |
f390d2c7 | 85 | struct option longopts[] = { |
f390d2c7 | 86 | {0} |
eb5d44eb | 87 | }; |
88 | ||
eb5d44eb | 89 | /* Master of threads. */ |
90 | struct thread_master *master; | |
91 | ||
eb5d44eb | 92 | /* for reload */ |
37da8c01 | 93 | char _cwd[MAXPATHLEN]; |
94 | char _progpath[MAXPATHLEN]; | |
eb5d44eb | 95 | int _argc; |
96 | char **_argv; | |
97 | char **_envp; | |
98 | ||
41b36e90 PJ |
99 | /* |
100 | * Prototypes. | |
101 | */ | |
102 | void reload(void); | |
103 | void sighup(void); | |
104 | void sigint(void); | |
105 | void sigterm(void); | |
106 | void sigusr1(void); | |
107 | ||
108 | ||
eb5d44eb | 109 | void |
110 | reload () | |
111 | { | |
529d65b3 | 112 | zlog_debug ("Reload"); |
eb5d44eb | 113 | /* FIXME: Clean up func call here */ |
cdb6ee94 | 114 | vty_reset (); |
3f045a08 | 115 | (void) isisd_privs.change (ZPRIVS_RAISE); |
eb5d44eb | 116 | execve (_progpath, _argv, _envp); |
3f045a08 JB |
117 | zlog_err ("Reload failed: cannot exec %s: %s", _progpath, |
118 | safe_strerror (errno)); | |
eb5d44eb | 119 | } |
120 | ||
35dece84 | 121 | static __attribute__((__noreturn__)) void |
eb5d44eb | 122 | terminate (int i) |
123 | { | |
124 | exit (i); | |
125 | } | |
126 | ||
127 | /* | |
128 | * Signal handlers | |
129 | */ | |
2d75d052 | 130 | |
f390d2c7 | 131 | void |
2d75d052 | 132 | sighup (void) |
eb5d44eb | 133 | { |
529d65b3 | 134 | zlog_debug ("SIGHUP received"); |
eb5d44eb | 135 | reload (); |
136 | ||
137 | return; | |
138 | } | |
139 | ||
35dece84 | 140 | __attribute__((__noreturn__)) void |
2d75d052 | 141 | sigint (void) |
eb5d44eb | 142 | { |
887c44a4 | 143 | zlog_notice ("Terminating on signal SIGINT"); |
eb5d44eb | 144 | terminate (0); |
eb5d44eb | 145 | } |
146 | ||
35dece84 | 147 | __attribute__((__noreturn__)) void |
2d75d052 | 148 | sigterm (void) |
eb5d44eb | 149 | { |
887c44a4 | 150 | zlog_notice ("Terminating on signal SIGTERM"); |
eb5d44eb | 151 | terminate (0); |
152 | } | |
153 | ||
154 | void | |
2d75d052 | 155 | sigusr1 (void) |
eb5d44eb | 156 | { |
529d65b3 | 157 | zlog_debug ("SIGUSR1 received"); |
eb5d44eb | 158 | zlog_rotate (NULL); |
159 | } | |
160 | ||
2d75d052 | 161 | struct quagga_signal_t isisd_signals[] = |
f390d2c7 | 162 | { |
163 | { | |
164 | .signal = SIGHUP, | |
165 | .handler = &sighup, | |
166 | }, | |
2d75d052 | 167 | { |
f390d2c7 | 168 | .signal = SIGUSR1, |
169 | .handler = &sigusr1, | |
170 | }, | |
2d75d052 | 171 | { |
f390d2c7 | 172 | .signal = SIGINT, |
173 | .handler = &sigint, | |
174 | }, | |
2d75d052 | 175 | { |
f390d2c7 | 176 | .signal = SIGTERM, |
177 | .handler = &sigterm, | |
178 | }, | |
2d75d052 | 179 | }; |
eb5d44eb | 180 | |
4f04a76b DL |
181 | FRR_DAEMON_INFO(isisd, ISIS, |
182 | .vty_port = ISISD_VTY_PORT, | |
183 | ||
184 | .proghelp = "Implementation of the IS-IS routing protocol.", | |
185 | .copyright = "Copyright (c) 2001-2002 Sampo Saaristo," | |
186 | " Ofer Wald and Hannes Gredler", | |
187 | ||
188 | .signals = isisd_signals, | |
189 | .n_signals = array_size(isisd_signals), | |
190 | ||
191 | .privs = &isisd_privs, | |
192 | ) | |
193 | ||
eb5d44eb | 194 | /* |
195 | * Main routine of isisd. Parse arguments and handle IS-IS state machine. | |
196 | */ | |
f390d2c7 | 197 | int |
eb5d44eb | 198 | main (int argc, char **argv, char **envp) |
199 | { | |
4f04a76b | 200 | int opt; |
eb5d44eb | 201 | struct thread thread; |
eb5d44eb | 202 | |
eb5d44eb | 203 | /* for reload */ |
204 | _argc = argc; | |
205 | _argv = argv; | |
206 | _envp = envp; | |
7a49a5b5 DS |
207 | if (getcwd (_cwd, sizeof (_cwd)) == NULL) |
208 | { | |
209 | zlog_err ("ISISd: Unable to determine CWD: %d", errno); | |
210 | exit (1); | |
211 | } | |
212 | ||
eb5d44eb | 213 | if (*argv[0] == '.') |
214 | snprintf (_progpath, sizeof (_progpath), "%s/%s", _cwd, _argv[0]); | |
215 | else | |
216 | snprintf (_progpath, sizeof (_progpath), "%s", argv[0]); | |
f390d2c7 | 217 | |
4f04a76b | 218 | frr_preinit (&isisd_di, argc, argv); |
eb05883f | 219 | frr_opt_add ("", longopts, ""); |
4f04a76b | 220 | |
eb5d44eb | 221 | /* Command line argument treatment. */ |
f390d2c7 | 222 | while (1) |
eb5d44eb | 223 | { |
4f04a76b | 224 | opt = frr_getopt (argc, argv, NULL); |
f390d2c7 | 225 | |
eb5d44eb | 226 | if (opt == EOF) |
f390d2c7 | 227 | break; |
228 | ||
229 | switch (opt) | |
230 | { | |
231 | case 0: | |
232 | break; | |
f390d2c7 | 233 | default: |
4f04a76b | 234 | frr_help_exit (1); |
f390d2c7 | 235 | break; |
236 | } | |
eb5d44eb | 237 | } |
f390d2c7 | 238 | |
857b5446 | 239 | vty_config_lockless (); |
eb5d44eb | 240 | /* thread master */ |
4f04a76b | 241 | master = frr_init (); |
eb5d44eb | 242 | |
243 | /* | |
244 | * initializations | |
245 | */ | |
c729c650 | 246 | access_list_init(); |
6a69b354 | 247 | vrf_init (); |
f3ccedaa | 248 | prefix_list_init(); |
eb5d44eb | 249 | isis_init (); |
3f045a08 JB |
250 | isis_circuit_init (); |
251 | isis_spf_cmds_init (); | |
f3ccedaa CF |
252 | isis_redist_init (); |
253 | isis_route_map_init(); | |
f8c06e2c | 254 | isis_mpls_te_init(); |
3f045a08 JB |
255 | |
256 | /* create the global 'isis' instance */ | |
257 | isis_new (1); | |
258 | ||
4140ca4d | 259 | isis_zebra_init(master); |
3f045a08 | 260 | |
eb05883f | 261 | frr_config_fork (); |
eb5d44eb | 262 | |
263 | /* Make isis vty socket. */ | |
eb05883f | 264 | frr_vty_serv (); |
f390d2c7 | 265 | |
eb5d44eb | 266 | /* Print banner. */ |
4f04a76b | 267 | zlog_notice ("Quagga-ISISd %s starting: vty@%d", FRR_VERSION, isisd_di.vty_port); |
c89c05dd | 268 | |
eb5d44eb | 269 | /* Start finite state machine. */ |
270 | while (thread_fetch (master, &thread)) | |
271 | thread_call (&thread); | |
272 | ||
273 | /* Not reached. */ | |
274 | exit (0); | |
275 | } |