1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 1998, 99 Kunihiro Ishiguro, Toshiaki Takada
9 #include <lib/version.h>
31 #include "ospfd/ospfd.h"
32 #include "ospfd/ospf_interface.h"
33 #include "ospfd/ospf_asbr.h"
34 #include "ospfd/ospf_lsa.h"
35 #include "ospfd/ospf_lsdb.h"
36 #include "ospfd/ospf_neighbor.h"
37 #include "ospfd/ospf_dump.h"
38 #include "ospfd/ospf_route.h"
39 #include "ospfd/ospf_zebra.h"
40 #include "ospfd/ospf_vty.h"
41 #include "ospfd/ospf_bfd.h"
42 #include "ospfd/ospf_gr.h"
43 #include "ospfd/ospf_errors.h"
44 #include "ospfd/ospf_ldp_sync.h"
45 #include "ospfd/ospf_routemap_nb.h"
47 /* ospfd privileges */
48 zebra_capabilities_t _caps_p
[] = {ZCAP_NET_RAW
, ZCAP_BIND
, ZCAP_NET_ADMIN
,
51 struct zebra_privs_t ospfd_privs
= {
52 #if defined(FRR_USER) && defined(FRR_GROUP)
56 #if defined(VTY_GROUP)
57 .vty_group
= VTY_GROUP
,
60 .cap_num_p
= array_size(_caps_p
),
64 const struct option longopts
[] = {
65 {"instance", required_argument
, NULL
, 'n'},
66 {"apiserver", no_argument
, NULL
, 'a'},
70 /* OSPFd program name */
72 /* Master of threads. */
73 struct thread_master
*master
;
75 #ifdef SUPPORT_OSPF_API
76 extern int ospf_apiserver_enable
;
77 #endif /* SUPPORT_OSPF_API */
80 static void sighup(void)
82 zlog_info("SIGHUP received");
85 /* SIGINT / SIGTERM handler. */
86 static void sigint(void)
88 zlog_notice("Terminating on signal");
89 bfd_protocol_integration_set_shutdown(true);
94 /* SIGUSR1 handler. */
95 static void sigusr1(void)
100 struct frr_signal_t ospf_signals
[] = {
119 static const struct frr_yang_module_info
*const ospfd_yang_modules
[] = {
124 &frr_ospf_route_map_info
,
127 FRR_DAEMON_INFO(ospfd
, OSPF
, .vty_port
= OSPF_VTY_PORT
,
129 .proghelp
= "Implementation of the OSPFv2 routing protocol.",
131 .signals
= ospf_signals
, .n_signals
= array_size(ospf_signals
),
133 .privs
= &ospfd_privs
, .yang_modules
= ospfd_yang_modules
,
134 .n_yang_modules
= array_size(ospfd_yang_modules
),
137 /* OSPFd main routine. */
138 int main(int argc
, char **argv
)
140 #ifdef SUPPORT_OSPF_API
141 /* OSPF apiserver is disabled by default. */
142 ospf_apiserver_enable
= 0;
143 #endif /* SUPPORT_OSPF_API */
145 frr_preinit(&ospfd_di
, argc
, argv
);
146 frr_opt_add("n:a", longopts
,
147 " -n, --instance Set the instance id\n"
148 " -a, --apiserver Enable OSPF apiserver\n");
153 opt
= frr_getopt(argc
, argv
, NULL
);
160 ospfd_di
.instance
= ospf_instance
= atoi(optarg
);
161 if (ospf_instance
< 1)
166 #ifdef SUPPORT_OSPF_API
168 ospf_apiserver_enable
= 1;
170 #endif /* SUPPORT_OSPF_API */
176 /* Invoked by a priviledged user? -- endo. */
177 if (geteuid() != 0) {
179 perror(ospfd_di
.progname
);
183 /* OSPF master init. */
184 ospf_master_init(frr_init());
186 /* Initializations. */
198 ospf_zebra_init(master
, ospf_instance
);
200 /* OSPF vty inits. */
202 ospf_vty_show_init();
203 ospf_vty_clear_init();
206 ospf_bfd_init(master
);
208 /* OSPF LDP IGP Sync init */
209 ospf_ldp_sync_init();
211 ospf_route_map_init();
214 ospf_gr_helper_init();
216 /* OSPF errors init */