1 /* zebra daemon main routine.
2 * Copyright (C) 1997, 98 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
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
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.
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
24 #include <lib/version.h>
30 #include "zebra_memory.h"
31 #include "memory_vty.h"
40 #include "zebra/rib.h"
41 #include "zebra/zserv.h"
42 #include "zebra/debug.h"
43 #include "zebra/router-id.h"
44 #include "zebra/irdp.h"
45 #include "zebra/rtadv.h"
46 #include "zebra/zebra_fpm.h"
47 #include "zebra/zebra_ptm.h"
48 #include "zebra/zebra_ns.h"
49 #include "zebra/redistribute.h"
50 #include "zebra/zebra_mpls.h"
52 #define ZEBRA_PTM_SUPPORT
55 struct zebra_t zebrad
=
57 .rtm_table_default
= 0,
63 /* Pacify zclient.o in libfrr, which expects this variable. */
64 struct thread_master
*master
;
66 /* Route retain mode flag. */
69 /* Allow non-quagga entities to delete quagga routes */
72 /* Don't delete kernel route. */
73 int keep_kernel_mode
= 0;
76 /* Receive buffer size for netlink socket */
77 u_int32_t nl_rcvbufsize
= 4194304;
78 #endif /* HAVE_NETLINK */
80 /* Command line options. */
81 struct option longopts
[] =
83 { "batch", no_argument
, NULL
, 'b'},
84 { "allow_delete", no_argument
, NULL
, 'a'},
85 { "keep_kernel", no_argument
, NULL
, 'k'},
86 { "fpm_format", required_argument
, NULL
, 'F'},
87 { "socket", required_argument
, NULL
, 'z'},
88 { "ecmp", required_argument
, NULL
, 'e'},
89 { "retain", no_argument
, NULL
, 'r'},
91 { "nl-bufsize", required_argument
, NULL
, 's'},
92 #endif /* HAVE_NETLINK */
96 zebra_capabilities_t _caps_p
[] =
103 /* zebra privileges to run with */
104 struct zebra_privs_t zserv_privs
=
106 #if defined(FRR_USER) && defined(FRR_GROUP)
111 .vty_group
= VTY_GROUP
,
114 .cap_num_p
= array_size(_caps_p
),
118 unsigned int multipath_num
= MULTIPATH_NUM
;
120 /* SIGHUP handler. */
124 zlog_info ("SIGHUP received");
126 /* Reload of config file. */
130 /* SIGINT handler. */
135 struct zebra_vrf
*zvrf
;
136 struct zebra_ns
*zns
;
138 zlog_notice ("Terminating on signal");
145 list_delete_all_node (zebrad
.client_list
);
148 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
152 SET_FLAG (zvrf
->flags
, ZEBRA_VRF_RETAIN
);
156 zns
= zebra_ns_lookup (NS_DEFAULT
);
157 zebra_ns_disable (0, (void **)&zns
);
159 access_list_reset ();
160 prefix_list_reset ();
164 zprivs_terminate (&zserv_privs
);
165 list_delete (zebrad
.client_list
);
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
);
170 thread_master_free (zebrad
.master
);
172 closezlog (zlog_default
);
177 /* SIGUSR1 handler. */
184 struct quagga_signal_t zebra_signals
[] =
204 FRR_DAEMON_INFO(zebra
, ZEBRA
,
205 .vty_port
= ZEBRA_VTY_PORT
,
206 .flags
= FRR_NO_ZCLIENT
,
208 .proghelp
= "Daemon which manages kernel routing table management "
209 "and\nredistribution between different routing protocols.",
211 .signals
= zebra_signals
,
212 .n_signals
= array_size(zebra_signals
),
214 .privs
= &zserv_privs
,
217 /* Main startup routine. */
219 main (int argc
, char **argv
)
221 // int batch_mode = 0;
222 char *zserv_path
= NULL
;
223 char *fpm_format
= NULL
;
225 frr_preinit(&zebra_di
, argc
, argv
);
227 frr_opt_add("bakF:z:r"
232 "-b, --batch Runs in batch mode\n"
233 "-a, --allow_delete Allow other processes to delete Quagga Routes\n"
234 "-F, --fpm_format Set fpm format to 'netlink' or 'protobuf'\n"
235 "-z, --socket Set path of zebra socket\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"
239 "-s, --nl-bufsize Set netlink receive buffer size\n"
240 #endif /* HAVE_NETLINK */
245 int opt
= frr_getopt(argc
, argv
, NULL
);
261 keep_kernel_mode
= 1;
267 multipath_num
= atoi (optarg
);
268 if (multipath_num
> MULTIPATH_NUM
|| multipath_num
<= 0)
270 zlog_err ("Multipath Number specified must be less than %d and greater than 0", MULTIPATH_NUM
);
282 nl_rcvbufsize
= atoi (optarg
);
284 #endif /* HAVE_NETLINK */
291 vty_config_lockless ();
292 zebrad
.master
= frr_init();
294 /* Zebra related initialize. */
299 router_id_cmd_init ();
303 #if defined (HAVE_RTADV)
310 #ifdef ZEBRA_PTM_SUPPORT
315 zebra_mpls_vty_init ();
317 /* For debug purpose. */
318 /* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */
320 /* Initialize NS( and implicitly the VRF module), and make kernel routing socket. */
325 #endif /* HAVE_SNMP */
328 zfpm_init (zebrad
.master
, 1, 0, fpm_format
);
330 zfpm_init (zebrad
.master
, 0, 0, fpm_format
);
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).
342 /* Clean up rib -- before fork (?) */
343 /* rib_weed_tables (); */
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.
353 if (! keep_kernel_mode
)
356 /* Needed for BSD routing socket. */
359 /* This must be done only after locking pidfile (bug #403). */
360 zebra_zserv_socket_init (zserv_path
);
362 frr_run (zebrad
.master
);