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