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>
38 #include "memory_vty.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"
58 /* ospfd privileges */
59 zebra_capabilities_t _caps_p
[] = {ZCAP_NET_RAW
, ZCAP_BIND
, ZCAP_NET_ADMIN
,
62 struct zebra_privs_t ospfd_privs
= {
63 #if defined(FRR_USER) && defined(FRR_GROUP)
67 #if defined(VTY_GROUP)
68 .vty_group
= VTY_GROUP
,
71 .cap_num_p
= array_size(_caps_p
),
75 struct option longopts
[] = {{"instance", required_argument
, NULL
, 'n'},
76 {"apiserver", no_argument
, NULL
, 'a'},
79 /* OSPFd program name */
81 /* Master of threads. */
82 struct thread_master
*master
;
84 #ifdef SUPPORT_OSPF_API
85 extern int ospf_apiserver_enable
;
86 #endif /* SUPPORT_OSPF_API */
89 static void sighup(void)
91 zlog_info("SIGHUP received");
94 /* SIGINT / SIGTERM handler. */
95 static void sigint(void)
97 zlog_notice("Terminating on signal");
101 /* SIGUSR1 handler. */
102 static void sigusr1(void)
107 struct quagga_signal_t ospf_signals
[] = {
126 FRR_DAEMON_INFO(ospfd
, OSPF
, .vty_port
= OSPF_VTY_PORT
,
128 .proghelp
= "Implementation of the OSPFv2 routing protocol.",
130 .signals
= ospf_signals
, .n_signals
= array_size(ospf_signals
),
132 .privs
= &ospfd_privs
, )
134 /* OSPFd main routine. */
135 int main(int argc
, char **argv
)
137 unsigned short instance
= 0;
139 #ifdef SUPPORT_OSPF_API
140 /* OSPF apiserver is disabled by default. */
141 ospf_apiserver_enable
= 0;
142 #endif /* SUPPORT_OSPF_API */
144 frr_preinit(&ospfd_di
, argc
, argv
);
145 frr_opt_add("n:a", longopts
,
146 " -n, --instance Set the instance id\n"
147 " -a, --apiserver Enable OSPF apiserver\n");
152 opt
= frr_getopt(argc
, argv
, NULL
);
159 ospfd_di
.instance
= instance
= atoi(optarg
);
165 #ifdef SUPPORT_OSPF_API
167 ospf_apiserver_enable
= 1;
169 #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
, instance
);
200 /* OSPF vty inits. */
202 ospf_vty_show_init();
203 ospf_vty_clear_init();
208 ospf_route_map_init();
211 /* OSPF errors init */
214 /* Need to initialize the default ospf structure, so the interface mode
215 commands can be duly processed if they are received before 'router
217 when quagga(ospfd) is restarted */
218 if (!ospf_get_instance(instance
)) {
219 flog_err(OSPF_ERR_INIT_FAIL
, "OSPF instance init failed: %s",