3 * Copyright (C) 1998, 99 Kunihiro Ishiguro, Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <lib/version.h>
45 #include "ospfd/ospfd.h"
46 #include "ospfd/ospf_interface.h"
47 #include "ospfd/ospf_asbr.h"
48 #include "ospfd/ospf_lsa.h"
49 #include "ospfd/ospf_lsdb.h"
50 #include "ospfd/ospf_neighbor.h"
51 #include "ospfd/ospf_dump.h"
52 #include "ospfd/ospf_route.h"
53 #include "ospfd/ospf_zebra.h"
54 #include "ospfd/ospf_vty.h"
55 #include "ospfd/ospf_bfd.h"
56 #include "ospfd/ospf_errors.h"
57 #include "ospfd/ospf_ldp_sync.h"
59 /* ospfd privileges */
60 zebra_capabilities_t _caps_p
[] = {ZCAP_NET_RAW
, ZCAP_BIND
, ZCAP_NET_ADMIN
,
63 struct zebra_privs_t ospfd_privs
= {
64 #if defined(FRR_USER) && defined(FRR_GROUP)
68 #if defined(VTY_GROUP)
69 .vty_group
= VTY_GROUP
,
72 .cap_num_p
= array_size(_caps_p
),
76 const struct option longopts
[] = {
77 {"instance", required_argument
, NULL
, 'n'},
78 {"apiserver", no_argument
, NULL
, 'a'},
82 /* OSPFd program name */
84 /* Master of threads. */
85 struct thread_master
*master
;
87 #ifdef SUPPORT_OSPF_API
88 extern int ospf_apiserver_enable
;
89 #endif /* SUPPORT_OSPF_API */
92 static void sighup(void)
94 zlog_info("SIGHUP received");
97 /* SIGINT / SIGTERM handler. */
98 static void sigint(void)
100 zlog_notice("Terminating on signal");
105 /* SIGUSR1 handler. */
106 static void sigusr1(void)
111 struct quagga_signal_t ospf_signals
[] = {
130 static const struct frr_yang_module_info
*const ospfd_yang_modules
[] = {
137 FRR_DAEMON_INFO(ospfd
, OSPF
, .vty_port
= OSPF_VTY_PORT
,
139 .proghelp
= "Implementation of the OSPFv2 routing protocol.",
141 .signals
= ospf_signals
, .n_signals
= array_size(ospf_signals
),
143 .privs
= &ospfd_privs
, .yang_modules
= ospfd_yang_modules
,
144 .n_yang_modules
= array_size(ospfd_yang_modules
), )
146 /* OSPFd main routine. */
147 int main(int argc
, char **argv
)
149 unsigned short instance
= 0;
150 bool created
= false;
152 #ifdef SUPPORT_OSPF_API
153 /* OSPF apiserver is disabled by default. */
154 ospf_apiserver_enable
= 0;
155 #endif /* SUPPORT_OSPF_API */
157 frr_preinit(&ospfd_di
, argc
, argv
);
158 frr_opt_add("n:a", longopts
,
159 " -n, --instance Set the instance id\n"
160 " -a, --apiserver Enable OSPF apiserver\n");
165 opt
= frr_getopt(argc
, argv
, NULL
);
172 ospfd_di
.instance
= instance
= atoi(optarg
);
178 #ifdef SUPPORT_OSPF_API
180 ospf_apiserver_enable
= 1;
182 #endif /* SUPPORT_OSPF_API */
189 /* Invoked by a priviledged user? -- endo. */
190 if (geteuid() != 0) {
192 perror(ospfd_di
.progname
);
196 /* OSPF master init. */
197 ospf_master_init(frr_init());
199 /* Initializations. */
211 ospf_zebra_init(master
, instance
);
213 /* OSPF vty inits. */
215 ospf_vty_show_init();
216 ospf_vty_clear_init();
221 /* OSPF LDP IGP Sync init */
222 ospf_ldp_sync_init();
224 ospf_route_map_init();
227 /* OSPF errors init */
231 * Need to initialize the default ospf structure, so the interface mode
232 * commands can be duly processed if they are received before 'router
233 * ospf', when ospfd is restarted
235 if (instance
&& !ospf_get_instance(instance
, &created
)) {
236 flog_err(EC_OSPF_INIT_FAIL
, "OSPF instance init failed: %s",