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_ptm.h"
47 #include "zebra/zebra_ns.h"
48 #include "zebra/redistribute.h"
49 #include "zebra/zebra_mpls.h"
50 #include "zebra/label_manager.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 { "socket", required_argument
, NULL
, 'z'},
87 { "ecmp", required_argument
, NULL
, 'e'},
88 { "label_socket", no_argument
, NULL
, 'l'},
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
);
176 /* SIGUSR1 handler. */
183 struct quagga_signal_t zebra_signals
[] =
203 FRR_DAEMON_INFO(zebra
, ZEBRA
,
204 .vty_port
= ZEBRA_VTY_PORT
,
205 .flags
= FRR_NO_ZCLIENT
,
207 .proghelp
= "Daemon which manages kernel routing table management "
208 "and\nredistribution between different routing protocols.",
210 .signals
= zebra_signals
,
211 .n_signals
= array_size(zebra_signals
),
213 .privs
= &zserv_privs
,
216 /* Main startup routine. */
218 main (int argc
, char **argv
)
220 // int batch_mode = 0;
221 char *zserv_path
= NULL
;
222 /* Socket to external label manager */
223 char *lblmgr_path
= NULL
;
225 frr_preinit(&zebra_di
, argc
, argv
);
227 frr_opt_add("bakz:e:l:r"
232 " -b, --batch Runs in batch mode\n"
233 " -a, --allow_delete Allow other processes to delete zebra routes\n"
234 " -z, --socket Set path of zebra socket\n"
235 " -e, --ecmp Specify ECMP to use.\n"
236 " -l, --label_socket Socket to external label manager\n"\
237 " -k, --keep_kernel Don't delete old routes which installed by zebra.\n"
238 " -r, --retain When program terminates, retain added route by zebra.\n"
240 " -s, --nl-bufsize Set netlink receive buffer size\n"
241 #endif /* HAVE_NETLINK */
246 int opt
= frr_getopt(argc
, argv
, NULL
);
262 keep_kernel_mode
= 1;
265 multipath_num
= atoi (optarg
);
266 if (multipath_num
> MULTIPATH_NUM
|| multipath_num
<= 0)
268 zlog_err ("Multipath Number specified must be less than %d and greater than 0", MULTIPATH_NUM
);
276 lblmgr_path
= optarg
;
283 nl_rcvbufsize
= atoi (optarg
);
285 #endif /* HAVE_NETLINK */
292 vty_config_lockless ();
293 zebrad
.master
= frr_init();
295 /* Zebra related initialize. */
300 router_id_cmd_init ();
304 #if defined (HAVE_RTADV)
311 #ifdef ZEBRA_PTM_SUPPORT
316 zebra_mpls_vty_init ();
318 /* For debug purpose. */
319 /* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */
321 /* Initialize NS( and implicitly the VRF module), and make kernel routing socket. */
324 /* Process the configuration file. Among other configuration
325 * directives we can meet those installing static routes. Such
326 * requests will not be executed immediately, but queued in
327 * zebra->ribq structure until we enter the main execution loop.
328 * The notifications from kernel will show originating PID equal
329 * to that after daemon() completes (if ever called).
333 /* Clean up rib -- before fork (?) */
334 /* rib_weed_tables (); */
336 /* After we have successfully acquired the pidfile, we can be sure
337 * about being the only copy of zebra process, which is submitting
338 * changes to the FIB.
339 * Clean up zebra-originated routes. The requests will be sent to OS
340 * immediately, so originating PID in notifications from kernel
341 * will be equal to the current getpid(). To know about such routes,
342 * we have to have route_read() called before.
344 if (! keep_kernel_mode
)
347 /* Needed for BSD routing socket. */
350 /* This must be done only after locking pidfile (bug #403). */
351 zebra_zserv_socket_init (zserv_path
);
353 /* Init label manager */
354 label_manager_init (lblmgr_path
);
356 frr_run (zebrad
.master
);