]>
Commit | Line | Data |
---|---|---|
edd7c245 | 1 | /* zebra daemon main routine. |
718e3744 | 2 | * Copyright (C) 1997, 98 Kunihiro Ishiguro |
3 | * | |
4 | * This file is part of GNU Zebra. | |
5 | * | |
6 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2, or (at your option) any | |
9 | * later version. | |
10 | * | |
11 | * GNU Zebra is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free | |
18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
19 | * 02111-1307, USA. | |
20 | */ | |
21 | ||
22 | #include <zebra.h> | |
23 | ||
5e4fa164 | 24 | #include <lib/version.h> |
718e3744 | 25 | #include "getopt.h" |
26 | #include "command.h" | |
27 | #include "thread.h" | |
28 | #include "filter.h" | |
29 | #include "memory.h" | |
4a1ab8e4 | 30 | #include "zebra_memory.h" |
fc7948fa | 31 | #include "memory_vty.h" |
718e3744 | 32 | #include "prefix.h" |
33 | #include "log.h" | |
7514fb77 | 34 | #include "plist.h" |
edd7c245 | 35 | #include "privs.h" |
2d75d052 | 36 | #include "sigevent.h" |
b72ede27 | 37 | #include "vrf.h" |
4f04a76b | 38 | #include "libfrr.h" |
718e3744 | 39 | |
40 | #include "zebra/rib.h" | |
41 | #include "zebra/zserv.h" | |
42 | #include "zebra/debug.h" | |
18a6dce6 | 43 | #include "zebra/router-id.h" |
ca776988 | 44 | #include "zebra/irdp.h" |
a1ac18c4 | 45 | #include "zebra/rtadv.h" |
5adc2528 | 46 | #include "zebra/zebra_fpm.h" |
244c1cdc | 47 | #include "zebra/zebra_ptm.h" |
fe18ee2d | 48 | #include "zebra/zebra_ns.h" |
e2b1be64 | 49 | #include "zebra/redistribute.h" |
7758e3f3 | 50 | #include "zebra/zebra_mpls.h" |
244c1cdc DS |
51 | |
52 | #define ZEBRA_PTM_SUPPORT | |
718e3744 | 53 | |
b21b19c5 | 54 | /* Zebra instance */ |
55 | struct zebra_t zebrad = | |
56 | { | |
57 | .rtm_table_default = 0, | |
58 | }; | |
718e3744 | 59 | |
60 | /* process id. */ | |
718e3744 | 61 | pid_t pid; |
62 | ||
55c72803 | 63 | /* Pacify zclient.o in libfrr, which expects this variable. */ |
87efd646 | 64 | struct thread_master *master; |
65 | ||
718e3744 | 66 | /* Route retain mode flag. */ |
67 | int retain_mode = 0; | |
68 | ||
6baf7bb8 DS |
69 | /* Allow non-quagga entities to delete quagga routes */ |
70 | int allow_delete = 0; | |
71 | ||
718e3744 | 72 | /* Don't delete kernel route. */ |
73 | int keep_kernel_mode = 0; | |
74 | ||
c34b6b57 | 75 | #ifdef HAVE_NETLINK |
76 | /* Receive buffer size for netlink socket */ | |
b6286c70 | 77 | u_int32_t nl_rcvbufsize = 4194304; |
c34b6b57 | 78 | #endif /* HAVE_NETLINK */ |
79 | ||
718e3744 | 80 | /* Command line options. */ |
81 | struct option longopts[] = | |
82 | { | |
6baf7bb8 | 83 | { "batch", no_argument, NULL, 'b'}, |
6baf7bb8 DS |
84 | { "allow_delete", no_argument, NULL, 'a'}, |
85 | { "keep_kernel", no_argument, NULL, 'k'}, | |
fb0aa886 | 86 | { "fpm_format", required_argument, NULL, 'F'}, |
6baf7bb8 | 87 | { "socket", required_argument, NULL, 'z'}, |
37fe7731 | 88 | { "ecmp", required_argument, NULL, 'e'}, |
6baf7bb8 | 89 | { "retain", no_argument, NULL, 'r'}, |
c34b6b57 | 90 | #ifdef HAVE_NETLINK |
6baf7bb8 | 91 | { "nl-bufsize", required_argument, NULL, 's'}, |
c34b6b57 | 92 | #endif /* HAVE_NETLINK */ |
718e3744 | 93 | { 0 } |
94 | }; | |
95 | ||
edd7c245 | 96 | zebra_capabilities_t _caps_p [] = |
97 | { | |
ceacedba | 98 | ZCAP_NET_ADMIN, |
edd7c245 | 99 | ZCAP_SYS_ADMIN, |
ceacedba | 100 | ZCAP_NET_RAW, |
edd7c245 | 101 | }; |
102 | ||
103 | /* zebra privileges to run with */ | |
104 | struct zebra_privs_t zserv_privs = | |
105 | { | |
b2f36157 DL |
106 | #if defined(FRR_USER) && defined(FRR_GROUP) |
107 | .user = FRR_USER, | |
108 | .group = FRR_GROUP, | |
edd7c245 | 109 | #endif |
110 | #ifdef VTY_GROUP | |
111 | .vty_group = VTY_GROUP, | |
112 | #endif | |
113 | .caps_p = _caps_p, | |
837d16cc | 114 | .cap_num_p = array_size(_caps_p), |
edd7c245 | 115 | .cap_num_i = 0 |
116 | }; | |
117 | ||
37fe7731 DS |
118 | unsigned int multipath_num = MULTIPATH_NUM; |
119 | ||
718e3744 | 120 | /* SIGHUP handler. */ |
a1ac18c4 | 121 | static void |
2d75d052 | 122 | sighup (void) |
718e3744 | 123 | { |
124 | zlog_info ("SIGHUP received"); | |
125 | ||
126 | /* Reload of config file. */ | |
127 | ; | |
128 | } | |
129 | ||
130 | /* SIGINT handler. */ | |
a1ac18c4 | 131 | static void |
2d75d052 | 132 | sigint (void) |
718e3744 | 133 | { |
5a8dfcd8 RW |
134 | struct vrf *vrf; |
135 | struct zebra_vrf *zvrf; | |
fe18ee2d DS |
136 | struct zebra_ns *zns; |
137 | ||
887c44a4 | 138 | zlog_notice ("Terminating on signal"); |
718e3744 | 139 | |
ca776988 | 140 | #ifdef HAVE_IRDP |
141 | irdp_finish(); | |
142 | #endif | |
718e3744 | 143 | |
c8ed14dd | 144 | zebra_ptm_finish(); |
5a8dfcd8 RW |
145 | list_delete_all_node (zebrad.client_list); |
146 | ||
147 | if (retain_mode) | |
148 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) | |
149 | { | |
150 | zvrf = vrf->info; | |
151 | if (zvrf) | |
152 | SET_FLAG (zvrf->flags, ZEBRA_VRF_RETAIN); | |
153 | } | |
154 | vrf_terminate (); | |
fe18ee2d DS |
155 | |
156 | zns = zebra_ns_lookup (NS_DEFAULT); | |
157 | zebra_ns_disable (0, (void **)&zns); | |
58ac32e2 RW |
158 | |
159 | access_list_reset (); | |
160 | prefix_list_reset (); | |
161 | route_map_finish (); | |
162 | cmd_terminate (); | |
163 | vty_terminate (); | |
164 | zprivs_terminate (&zserv_privs); | |
165 | list_delete (zebrad.client_list); | |
5a8dfcd8 RW |
166 | work_queue_free (zebrad.ribq); |
167 | if (zebrad.lsp_process_q) | |
168 | work_queue_free (zebrad.lsp_process_q); | |
169 | meta_queue_free (zebrad.mq); | |
58ac32e2 | 170 | thread_master_free (zebrad.master); |
bf1013e6 | 171 | closezlog (); |
58ac32e2 | 172 | |
718e3744 | 173 | exit (0); |
174 | } | |
175 | ||
176 | /* SIGUSR1 handler. */ | |
a1ac18c4 | 177 | static void |
2d75d052 | 178 | sigusr1 (void) |
718e3744 | 179 | { |
dd8376fe | 180 | zlog_rotate(); |
718e3744 | 181 | } |
182 | ||
2d75d052 | 183 | struct quagga_signal_t zebra_signals[] = |
718e3744 | 184 | { |
2d75d052 | 185 | { |
186 | .signal = SIGHUP, | |
187 | .handler = &sighup, | |
188 | }, | |
189 | { | |
190 | .signal = SIGUSR1, | |
191 | .handler = &sigusr1, | |
192 | }, | |
193 | { | |
194 | .signal = SIGINT, | |
8c903fbb | 195 | .handler = &sigint, |
2d75d052 | 196 | }, |
f571dab0 | 197 | { |
198 | .signal = SIGTERM, | |
199 | .handler = &sigint, | |
200 | }, | |
2d75d052 | 201 | }; |
b72ede27 | 202 | |
4f04a76b DL |
203 | FRR_DAEMON_INFO(zebra, ZEBRA, |
204 | .vty_port = ZEBRA_VTY_PORT, | |
eb05883f | 205 | .flags = FRR_NO_ZCLIENT, |
4f04a76b DL |
206 | |
207 | .proghelp = "Daemon which manages kernel routing table management " | |
208 | "and\nredistribution between different routing protocols.", | |
209 | ||
210 | .signals = zebra_signals, | |
211 | .n_signals = array_size(zebra_signals), | |
212 | ||
213 | .privs = &zserv_privs, | |
214 | ) | |
215 | ||
718e3744 | 216 | /* Main startup routine. */ |
217 | int | |
218 | main (int argc, char **argv) | |
219 | { | |
eb05883f | 220 | // int batch_mode = 0; |
b5114685 | 221 | char *zserv_path = NULL; |
fb0aa886 | 222 | char *fpm_format = NULL; |
718e3744 | 223 | |
4f04a76b | 224 | frr_preinit(&zebra_di, argc, argv); |
718e3744 | 225 | |
2fcc7988 | 226 | frr_opt_add("bakF:z:e:r" |
4f04a76b DL |
227 | #ifdef HAVE_NETLINK |
228 | "s:" | |
c05795b1 | 229 | #endif |
4f04a76b | 230 | , longopts, |
2fcc7988 | 231 | " -b, --batch Runs in batch mode\n" |
4487fc74 | 232 | " -a, --allow_delete Allow other processes to delete zebra routes\n" |
2fcc7988 DL |
233 | " -F, --fpm_format Set fpm format to 'netlink' or 'protobuf'\n" |
234 | " -z, --socket Set path of zebra socket\n" | |
235 | " -e, --ecmp Specify ECMP to use.\n" | |
236 | " -k, --keep_kernel Don't delete old routes which installed by zebra.\n" | |
237 | " -r, --retain When program terminates, retain added route by zebra.\n" | |
4f04a76b | 238 | #ifdef HAVE_NETLINK |
2fcc7988 | 239 | " -s, --nl-bufsize Set netlink receive buffer size\n" |
4f04a76b DL |
240 | #endif /* HAVE_NETLINK */ |
241 | ); | |
718e3744 | 242 | |
4f04a76b | 243 | while (1) |
718e3744 | 244 | { |
4f04a76b | 245 | int opt = frr_getopt(argc, argv, NULL); |
718e3744 | 246 | |
247 | if (opt == EOF) | |
248 | break; | |
249 | ||
250 | switch (opt) | |
251 | { | |
252 | case 0: | |
253 | break; | |
254 | case 'b': | |
eb05883f | 255 | // batch_mode = 1; |
718e3744 | 256 | break; |
6baf7bb8 DS |
257 | case 'a': |
258 | allow_delete = 1; | |
259 | break; | |
718e3744 | 260 | case 'k': |
261 | keep_kernel_mode = 1; | |
262 | break; | |
fb0aa886 AS |
263 | case 'F': |
264 | fpm_format = optarg; | |
265 | break; | |
37fe7731 DS |
266 | case 'e': |
267 | multipath_num = atoi (optarg); | |
268 | if (multipath_num > MULTIPATH_NUM || multipath_num <= 0) | |
269 | { | |
270 | zlog_err ("Multipath Number specified must be less than %d and greater than 0", MULTIPATH_NUM); | |
271 | return 1; | |
272 | } | |
273 | break; | |
b5114685 VT |
274 | case 'z': |
275 | zserv_path = optarg; | |
276 | break; | |
718e3744 | 277 | case 'r': |
278 | retain_mode = 1; | |
279 | break; | |
c34b6b57 | 280 | #ifdef HAVE_NETLINK |
281 | case 's': | |
282 | nl_rcvbufsize = atoi (optarg); | |
283 | break; | |
284 | #endif /* HAVE_NETLINK */ | |
718e3744 | 285 | default: |
4f04a76b | 286 | frr_help_exit (1); |
718e3744 | 287 | break; |
288 | } | |
289 | } | |
290 | ||
3ddccf18 | 291 | vty_config_lockless (); |
857b5446 | 292 | zebrad.master = frr_init(); |
718e3744 | 293 | |
294 | /* Zebra related initialize. */ | |
295 | zebra_init (); | |
296 | rib_init (); | |
297 | zebra_if_init (); | |
298 | zebra_debug_init (); | |
c6ffe645 | 299 | router_id_cmd_init (); |
718e3744 | 300 | zebra_vty_init (); |
301 | access_list_init (); | |
7514fb77 | 302 | prefix_list_init (); |
8da4e946 | 303 | #if defined (HAVE_RTADV) |
cd80d74f | 304 | rtadv_cmd_init (); |
36735ed9 | 305 | #endif |
ca776988 | 306 | #ifdef HAVE_IRDP |
307 | irdp_init(); | |
308 | #endif | |
244c1cdc DS |
309 | /* PTM socket */ |
310 | #ifdef ZEBRA_PTM_SUPPORT | |
311 | zebra_ptm_init(); | |
312 | #endif | |
718e3744 | 313 | |
7758e3f3 | 314 | zebra_mpls_init (); |
fe6c7157 | 315 | zebra_mpls_vty_init (); |
7758e3f3 | 316 | |
718e3744 | 317 | /* For debug purpose. */ |
318 | /* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */ | |
319 | ||
fe18ee2d DS |
320 | /* Initialize NS( and implicitly the VRF module), and make kernel routing socket. */ |
321 | zebra_ns_init (); | |
718e3744 | 322 | |
718e3744 | 323 | #ifdef HAVE_SNMP |
324 | zebra_snmp_init (); | |
325 | #endif /* HAVE_SNMP */ | |
326 | ||
5adc2528 | 327 | #ifdef HAVE_FPM |
fb0aa886 | 328 | zfpm_init (zebrad.master, 1, 0, fpm_format); |
5adc2528 | 329 | #else |
fb0aa886 | 330 | zfpm_init (zebrad.master, 0, 0, fpm_format); |
5adc2528 AS |
331 | #endif |
332 | ||
91b7351d DO |
333 | /* Process the configuration file. Among other configuration |
334 | * directives we can meet those installing static routes. Such | |
335 | * requests will not be executed immediately, but queued in | |
336 | * zebra->ribq structure until we enter the main execution loop. | |
337 | * The notifications from kernel will show originating PID equal | |
338 | * to that after daemon() completes (if ever called). | |
339 | */ | |
eb05883f | 340 | frr_config_fork(); |
718e3744 | 341 | |
eb05883f | 342 | /* Clean up rib -- before fork (?) */ |
7a4bb9c5 | 343 | /* rib_weed_tables (); */ |
718e3744 | 344 | |
91b7351d DO |
345 | /* After we have successfully acquired the pidfile, we can be sure |
346 | * about being the only copy of zebra process, which is submitting | |
347 | * changes to the FIB. | |
348 | * Clean up zebra-originated routes. The requests will be sent to OS | |
349 | * immediately, so originating PID in notifications from kernel | |
350 | * will be equal to the current getpid(). To know about such routes, | |
351 | * we have to have route_read() called before. | |
352 | */ | |
353 | if (! keep_kernel_mode) | |
354 | rib_sweep_route (); | |
355 | ||
718e3744 | 356 | /* Needed for BSD routing socket. */ |
357 | pid = getpid (); | |
358 | ||
97be79f9 | 359 | /* This must be done only after locking pidfile (bug #403). */ |
b5114685 | 360 | zebra_zserv_socket_init (zserv_path); |
97be79f9 | 361 | |
16077f2f | 362 | frr_run (zebrad.master); |
718e3744 | 363 | |
364 | /* Not reached... */ | |
e8e1946e | 365 | return 0; |
718e3744 | 366 | } |