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
= {
55 .rtm_table_default
= 0,
61 /* Pacify zclient.o in libfrr, which expects this variable. */
62 struct thread_master
*master
;
64 /* Route retain mode flag. */
67 /* Allow non-quagga entities to delete quagga routes */
70 /* Don't delete kernel route. */
71 int keep_kernel_mode
= 0;
74 /* Receive buffer size for netlink socket */
75 u_int32_t nl_rcvbufsize
= 4194304;
76 #endif /* HAVE_NETLINK */
78 /* Command line options. */
79 struct option longopts
[] = {{"batch", no_argument
, NULL
, 'b'},
80 {"allow_delete", no_argument
, NULL
, 'a'},
81 {"keep_kernel", no_argument
, NULL
, 'k'},
82 {"socket", required_argument
, NULL
, 'z'},
83 {"ecmp", required_argument
, NULL
, 'e'},
84 {"label_socket", no_argument
, NULL
, 'l'},
85 {"retain", no_argument
, NULL
, 'r'},
87 {"nl-bufsize", required_argument
, NULL
, 's'},
88 #endif /* HAVE_NETLINK */
91 zebra_capabilities_t _caps_p
[] = {
92 ZCAP_NET_ADMIN
, ZCAP_SYS_ADMIN
, ZCAP_NET_RAW
,
95 /* zebra privileges to run with */
96 struct zebra_privs_t zserv_privs
= {
97 #if defined(FRR_USER) && defined(FRR_GROUP)
102 .vty_group
= VTY_GROUP
,
105 .cap_num_p
= array_size(_caps_p
),
108 unsigned int multipath_num
= MULTIPATH_NUM
;
110 /* SIGHUP handler. */
111 static void sighup(void)
113 zlog_info("SIGHUP received");
115 /* Reload of config file. */
119 /* SIGINT handler. */
120 static void sigint(void)
123 struct zebra_vrf
*zvrf
;
124 struct zebra_ns
*zns
;
126 zlog_notice("Terminating on signal");
131 list_delete_all_node(zebrad
.client_list
);
134 RB_FOREACH(vrf
, vrf_name_head
, &vrfs_by_name
)
138 SET_FLAG(zvrf
->flags
, ZEBRA_VRF_RETAIN
);
142 zns
= zebra_ns_lookup(NS_DEFAULT
);
143 zebra_ns_disable(0, (void **)&zns
);
149 list_delete(zebrad
.client_list
);
150 work_queue_free(zebrad
.ribq
);
151 if (zebrad
.lsp_process_q
)
152 work_queue_free(zebrad
.lsp_process_q
);
153 meta_queue_free(zebrad
.mq
);
159 /* SIGUSR1 handler. */
160 static void sigusr1(void)
165 struct quagga_signal_t zebra_signals
[] = {
185 zebra
, ZEBRA
, .vty_port
= ZEBRA_VTY_PORT
, .flags
= FRR_NO_ZCLIENT
,
188 "Daemon which manages kernel routing table management "
189 "and\nredistribution between different routing protocols.",
191 .signals
= zebra_signals
, .n_signals
= array_size(zebra_signals
),
193 .privs
= &zserv_privs
, )
195 /* Main startup routine. */
196 int main(int argc
, char **argv
)
198 // int batch_mode = 0;
199 char *zserv_path
= NULL
;
200 /* Socket to external label manager */
201 char *lblmgr_path
= NULL
;
202 struct sockaddr_storage dummy
;
205 frr_preinit(&zebra_di
, argc
, argv
);
214 " -b, --batch Runs in batch mode\n"
215 " -a, --allow_delete Allow other processes to delete zebra routes\n"
216 " -z, --socket Set path of zebra socket\n"
217 " -e, --ecmp Specify ECMP to use.\n"
218 " -l, --label_socket Socket to external label manager\n"
219 " -k, --keep_kernel Don't delete old routes which installed by zebra.\n"
220 " -r, --retain When program terminates, retain added route by zebra.\n"
222 " -s, --nl-bufsize Set netlink receive buffer size\n"
223 #endif /* HAVE_NETLINK */
227 int opt
= frr_getopt(argc
, argv
, NULL
);
242 keep_kernel_mode
= 1;
245 multipath_num
= atoi(optarg
);
246 if (multipath_num
> MULTIPATH_NUM
247 || multipath_num
<= 0) {
249 "Multipath Number specified must be less than %d and greater than 0",
256 if (!frr_zclient_addr(&dummy
, &dummylen
, optarg
)) {
258 "Invalid zserv socket path: %s\n",
264 lblmgr_path
= optarg
;
271 nl_rcvbufsize
= atoi(optarg
);
273 #endif /* HAVE_NETLINK */
280 vty_config_lockless();
281 zebrad
.master
= frr_init();
283 /* Zebra related initialize. */
288 router_id_cmd_init();
292 #if defined(HAVE_RTADV)
296 #ifdef ZEBRA_PTM_SUPPORT
301 zebra_mpls_vty_init();
304 /* For debug purpose. */
305 /* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */
307 /* Initialize NS( and implicitly the VRF module), and make kernel
311 /* Process the configuration file. Among other configuration
312 * directives we can meet those installing static routes. Such
313 * requests will not be executed immediately, but queued in
314 * zebra->ribq structure until we enter the main execution loop.
315 * The notifications from kernel will show originating PID equal
316 * to that after daemon() completes (if ever called).
320 /* Clean up rib -- before fork (?) */
321 /* rib_weed_tables (); */
323 /* After we have successfully acquired the pidfile, we can be sure
324 * about being the only copy of zebra process, which is submitting
325 * changes to the FIB.
326 * Clean up zebra-originated routes. The requests will be sent to OS
327 * immediately, so originating PID in notifications from kernel
328 * will be equal to the current getpid(). To know about such routes,
329 * we have to have route_read() called before.
331 if (!keep_kernel_mode
)
334 /* Needed for BSD routing socket. */
337 /* This must be done only after locking pidfile (bug #403). */
338 zebra_zserv_socket_init(zserv_path
);
340 /* Init label manager */
341 label_manager_init(lblmgr_path
);
343 frr_run(zebrad
.master
);