]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_main.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / ospfd / ospf_main.c
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
718e3744 2/*
3 * OSPFd main routine.
4 * Copyright (C) 1998, 99 Kunihiro Ishiguro, Toshiaki Takada
718e3744 5 */
6
7#include <zebra.h>
8
5e4fa164 9#include <lib/version.h>
659f4e40 10#include "bfd.h"
718e3744 11#include "getopt.h"
24a58196 12#include "frrevent.h"
718e3744 13#include "prefix.h"
14#include "linklist.h"
15#include "if.h"
16#include "vector.h"
17#include "vty.h"
18#include "command.h"
19#include "filter.h"
20#include "plist.h"
21#include "stream.h"
22#include "log.h"
23#include "memory.h"
edd7c245 24#include "privs.h"
2d75d052 25#include "sigevent.h"
b5114685 26#include "zclient.h"
6a69b354 27#include "vrf.h"
4f04a76b 28#include "libfrr.h"
91835f1f 29#include "routemap.h"
718e3744 30
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"
19c0412a 38#include "ospfd/ospf_route.h"
718e3744 39#include "ospfd/ospf_zebra.h"
40#include "ospfd/ospf_vty.h"
7f342629 41#include "ospfd/ospf_bfd.h"
10514170 42#include "ospfd/ospf_gr.h"
313d7993 43#include "ospfd/ospf_errors.h"
132a782e 44#include "ospfd/ospf_ldp_sync.h"
a623b526 45#include "ospfd/ospf_routemap_nb.h"
718e3744 46
edd7c245 47/* ospfd privileges */
996c9314
LB
48zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN,
49 ZCAP_SYS_ADMIN};
edd7c245 50
d62a17ae 51struct zebra_privs_t ospfd_privs = {
b2f36157 52#if defined(FRR_USER) && defined(FRR_GROUP)
d62a17ae 53 .user = FRR_USER,
54 .group = FRR_GROUP,
edd7c245 55#endif
56#if defined(VTY_GROUP)
d62a17ae 57 .vty_group = VTY_GROUP,
edd7c245 58#endif
d62a17ae 59 .caps_p = _caps_p,
60 .cap_num_p = array_size(_caps_p),
61 .cap_num_i = 0};
edd7c245 62
718e3744 63/* OSPFd options. */
2b64873d
DL
64const struct option longopts[] = {
65 {"instance", required_argument, NULL, 'n'},
66 {"apiserver", no_argument, NULL, 'a'},
67 {0}
68};
718e3744 69
70/* OSPFd program name */
71
72/* Master of threads. */
cd9d0537 73struct event_loop *master;
718e3744 74
d68614db 75#ifdef SUPPORT_OSPF_API
f4d58ce5 76extern int ospf_apiserver_enable;
d68614db 77#endif /* SUPPORT_OSPF_API */
c3abdb72 78
718e3744 79/* SIGHUP handler. */
d62a17ae 80static void sighup(void)
718e3744 81{
d62a17ae 82 zlog_info("SIGHUP received");
718e3744 83}
84
88d6cf37 85/* SIGINT / SIGTERM handler. */
d62a17ae 86static void sigint(void)
718e3744 87{
d62a17ae 88 zlog_notice("Terminating on signal");
659f4e40 89 bfd_protocol_integration_set_shutdown(true);
d62a17ae 90 ospf_terminate();
41b21bfa 91 exit(0);
718e3744 92}
93
94/* SIGUSR1 handler. */
d62a17ae 95static void sigusr1(void)
718e3744 96{
d62a17ae 97 zlog_rotate();
718e3744 98}
99
7cc91e67 100struct frr_signal_t ospf_signals[] = {
d62a17ae 101 {
102 .signal = SIGHUP,
103 .handler = &sighup,
104 },
105 {
106 .signal = SIGUSR1,
107 .handler = &sigusr1,
108 },
109 {
110 .signal = SIGINT,
111 .handler = &sigint,
112 },
113 {
114 .signal = SIGTERM,
115 .handler = &sigint,
116 },
2d75d052 117};
6b0655a2 118
0d8c7a26 119static const struct frr_yang_module_info *const ospfd_yang_modules[] = {
c2aab693 120 &frr_filter_info,
a4bed468 121 &frr_interface_info,
91835f1f 122 &frr_route_map_info,
6fd8972a 123 &frr_vrf_info,
a623b526 124 &frr_ospf_route_map_info,
8fcdd0d6
RW
125};
126
d62a17ae 127FRR_DAEMON_INFO(ospfd, OSPF, .vty_port = OSPF_VTY_PORT,
4f04a76b 128
d62a17ae 129 .proghelp = "Implementation of the OSPFv2 routing protocol.",
4f04a76b 130
d62a17ae 131 .signals = ospf_signals, .n_signals = array_size(ospf_signals),
4f04a76b 132
8fcdd0d6 133 .privs = &ospfd_privs, .yang_modules = ospfd_yang_modules,
80413c20
DL
134 .n_yang_modules = array_size(ospfd_yang_modules),
135);
4f04a76b 136
718e3744 137/* OSPFd main routine. */
d62a17ae 138int main(int argc, char **argv)
718e3744 139{
822d8f55 140#ifdef SUPPORT_OSPF_API
d62a17ae 141 /* OSPF apiserver is disabled by default. */
142 ospf_apiserver_enable = 0;
822d8f55
DL
143#endif /* SUPPORT_OSPF_API */
144
d62a17ae 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");
718e3744 149
d62a17ae 150 while (1) {
151 int opt;
718e3744 152
d62a17ae 153 opt = frr_getopt(argc, argv, NULL);
718e3744 154
d62a17ae 155 if (opt == EOF)
156 break;
157
158 switch (opt) {
159 case 'n':
409f98ab
IR
160 ospfd_di.instance = ospf_instance = atoi(optarg);
161 if (ospf_instance < 1)
d62a17ae 162 exit(0);
163 break;
164 case 0:
165 break;
d68614db 166#ifdef SUPPORT_OSPF_API
d62a17ae 167 case 'a':
168 ospf_apiserver_enable = 1;
169 break;
d68614db 170#endif /* SUPPORT_OSPF_API */
d62a17ae 171 default:
172 frr_help_exit(1);
d62a17ae 173 }
718e3744 174 }
718e3744 175
d62a17ae 176 /* Invoked by a priviledged user? -- endo. */
177 if (geteuid() != 0) {
178 errno = EPERM;
179 perror(ospfd_di.progname);
180 exit(1);
181 }
182
183 /* OSPF master init. */
184 ospf_master_init(frr_init());
185
186 /* Initializations. */
187 master = om->master;
188
189 /* Library inits. */
6243a7b5 190 ospf_debug_init();
b5a8894d 191 ospf_vrf_init();
d62a17ae 192
193 access_list_init();
194 prefix_list_init();
195
196 /* OSPFd inits. */
197 ospf_if_init();
409f98ab 198 ospf_zebra_init(master, ospf_instance);
d62a17ae 199
200 /* OSPF vty inits. */
201 ospf_vty_init();
202 ospf_vty_show_init();
203 ospf_vty_clear_init();
204
205 /* OSPF BFD init */
659f4e40 206 ospf_bfd_init(master);
d62a17ae 207
132a782e 208 /* OSPF LDP IGP Sync init */
209 ospf_ldp_sync_init();
210
d62a17ae 211 ospf_route_map_init();
212 ospf_opaque_init();
10514170 213 ospf_gr_init();
51f8588e 214 ospf_gr_helper_init();
d62a17ae 215
5ad4c39c
QY
216 /* OSPF errors init */
217 ospf_error_init();
218
d62a17ae 219 frr_config_fork();
220 frr_run(master);
221
222 /* Not reached. */
95f7965d 223 return 0;
d62a17ae 224}