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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <lib/version.h>
29 #include "zebra_memory.h"
30 #include "memory_vty.h"
39 #include "zebra/rib.h"
40 #include "zebra/zserv.h"
41 #include "zebra/debug.h"
42 #include "zebra/router-id.h"
43 #include "zebra/irdp.h"
44 #include "zebra/rtadv.h"
45 #include "zebra/zebra_ptm.h"
46 #include "zebra/zebra_ns.h"
47 #include "zebra/redistribute.h"
48 #include "zebra/zebra_mpls.h"
49 #include "zebra/label_manager.h"
51 #define ZEBRA_PTM_SUPPORT
54 struct zebra_t zebrad
=
56 .rtm_table_default
= 0,
62 /* Pacify zclient.o in libfrr, which expects this variable. */
63 struct thread_master
*master
;
65 /* Route retain mode flag. */
68 /* Allow non-quagga entities to delete quagga routes */
71 /* Don't delete kernel route. */
72 int keep_kernel_mode
= 0;
75 /* Receive buffer size for netlink socket */
76 u_int32_t nl_rcvbufsize
= 4194304;
77 #endif /* HAVE_NETLINK */
79 /* Command line options. */
80 struct option longopts
[] =
82 { "batch", no_argument
, NULL
, 'b'},
83 { "allow_delete", no_argument
, NULL
, 'a'},
84 { "keep_kernel", no_argument
, NULL
, 'k'},
85 { "socket", required_argument
, NULL
, 'z'},
86 { "ecmp", required_argument
, NULL
, 'e'},
87 { "label_socket", no_argument
, NULL
, 'l'},
88 { "retain", no_argument
, NULL
, 'r'},
90 { "nl-bufsize", required_argument
, NULL
, 's'},
91 #endif /* HAVE_NETLINK */
95 zebra_capabilities_t _caps_p
[] =
102 /* zebra privileges to run with */
103 struct zebra_privs_t zserv_privs
=
105 #if defined(FRR_USER) && defined(FRR_GROUP)
110 .vty_group
= VTY_GROUP
,
113 .cap_num_p
= array_size(_caps_p
),
117 unsigned int multipath_num
= MULTIPATH_NUM
;
119 /* SIGHUP handler. */
123 zlog_info ("SIGHUP received");
125 /* Reload of config file. */
129 /* SIGINT handler. */
134 struct zebra_vrf
*zvrf
;
135 struct zebra_ns
*zns
;
137 zlog_notice ("Terminating on signal");
144 list_delete_all_node (zebrad
.client_list
);
147 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
151 SET_FLAG (zvrf
->flags
, ZEBRA_VRF_RETAIN
);
155 zns
= zebra_ns_lookup (NS_DEFAULT
);
156 zebra_ns_disable (0, (void **)&zns
);
158 access_list_reset ();
159 prefix_list_reset ();
163 zprivs_terminate (&zserv_privs
);
164 list_delete (zebrad
.client_list
);
165 work_queue_free (zebrad
.ribq
);
166 if (zebrad
.lsp_process_q
)
167 work_queue_free (zebrad
.lsp_process_q
);
168 meta_queue_free (zebrad
.mq
);
169 thread_master_free (zebrad
.master
);
175 /* SIGUSR1 handler. */
182 struct quagga_signal_t zebra_signals
[] =
202 FRR_DAEMON_INFO(zebra
, ZEBRA
,
203 .vty_port
= ZEBRA_VTY_PORT
,
204 .flags
= FRR_NO_ZCLIENT
,
206 .proghelp
= "Daemon which manages kernel routing table management "
207 "and\nredistribution between different routing protocols.",
209 .signals
= zebra_signals
,
210 .n_signals
= array_size(zebra_signals
),
212 .privs
= &zserv_privs
,
215 /* Main startup routine. */
217 main (int argc
, char **argv
)
219 // int batch_mode = 0;
220 char *zserv_path
= NULL
;
221 /* Socket to external label manager */
222 char *lblmgr_path
= NULL
;
224 frr_preinit(&zebra_di
, argc
, argv
);
226 frr_opt_add("bakz:e:l:r"
231 " -b, --batch Runs in batch mode\n"
232 " -a, --allow_delete Allow other processes to delete zebra routes\n"
233 " -z, --socket Set path of zebra socket\n"
234 " -e, --ecmp Specify ECMP to use.\n"
235 " -l, --label_socket Socket to external label manager\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;
264 multipath_num
= atoi (optarg
);
265 if (multipath_num
> MULTIPATH_NUM
|| multipath_num
<= 0)
267 zlog_err ("Multipath Number specified must be less than %d and greater than 0", MULTIPATH_NUM
);
275 lblmgr_path
= optarg
;
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. */
323 /* Process the configuration file. Among other configuration
324 * directives we can meet those installing static routes. Such
325 * requests will not be executed immediately, but queued in
326 * zebra->ribq structure until we enter the main execution loop.
327 * The notifications from kernel will show originating PID equal
328 * to that after daemon() completes (if ever called).
332 /* Clean up rib -- before fork (?) */
333 /* rib_weed_tables (); */
335 /* After we have successfully acquired the pidfile, we can be sure
336 * about being the only copy of zebra process, which is submitting
337 * changes to the FIB.
338 * Clean up zebra-originated routes. The requests will be sent to OS
339 * immediately, so originating PID in notifications from kernel
340 * will be equal to the current getpid(). To know about such routes,
341 * we have to have route_read() called before.
343 if (! keep_kernel_mode
)
346 /* Needed for BSD routing socket. */
349 /* This must be done only after locking pidfile (bug #403). */
350 zebra_zserv_socket_init (zserv_path
);
352 /* Init label manager */
353 label_manager_init (lblmgr_path
);
355 frr_run (zebrad
.master
);