]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_main.c
Merge pull request #8325 from idryzhov/fix-ip-router-isis
[mirror_frr.git] / ospfd / ospf_main.c
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 *
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
20 */
21
22 #include <zebra.h>
23
24 #include <lib/version.h>
25 #include "bfd.h"
26 #include "getopt.h"
27 #include "thread.h"
28 #include "prefix.h"
29 #include "linklist.h"
30 #include "if.h"
31 #include "vector.h"
32 #include "vty.h"
33 #include "command.h"
34 #include "filter.h"
35 #include "plist.h"
36 #include "stream.h"
37 #include "log.h"
38 #include "memory.h"
39 #include "privs.h"
40 #include "sigevent.h"
41 #include "zclient.h"
42 #include "vrf.h"
43 #include "libfrr.h"
44 #include "routemap.h"
45
46 #include "ospfd/ospfd.h"
47 #include "ospfd/ospf_interface.h"
48 #include "ospfd/ospf_asbr.h"
49 #include "ospfd/ospf_lsa.h"
50 #include "ospfd/ospf_lsdb.h"
51 #include "ospfd/ospf_neighbor.h"
52 #include "ospfd/ospf_dump.h"
53 #include "ospfd/ospf_route.h"
54 #include "ospfd/ospf_zebra.h"
55 #include "ospfd/ospf_vty.h"
56 #include "ospfd/ospf_bfd.h"
57 #include "ospfd/ospf_errors.h"
58 #include "ospfd/ospf_ldp_sync.h"
59
60 /* ospfd privileges */
61 zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN,
62 ZCAP_SYS_ADMIN};
63
64 struct zebra_privs_t ospfd_privs = {
65 #if defined(FRR_USER) && defined(FRR_GROUP)
66 .user = FRR_USER,
67 .group = FRR_GROUP,
68 #endif
69 #if defined(VTY_GROUP)
70 .vty_group = VTY_GROUP,
71 #endif
72 .caps_p = _caps_p,
73 .cap_num_p = array_size(_caps_p),
74 .cap_num_i = 0};
75
76 /* OSPFd options. */
77 const struct option longopts[] = {
78 {"instance", required_argument, NULL, 'n'},
79 {"apiserver", no_argument, NULL, 'a'},
80 {0}
81 };
82
83 /* OSPFd program name */
84
85 /* Master of threads. */
86 struct thread_master *master;
87
88 #ifdef SUPPORT_OSPF_API
89 extern int ospf_apiserver_enable;
90 #endif /* SUPPORT_OSPF_API */
91
92 /* SIGHUP handler. */
93 static void sighup(void)
94 {
95 zlog_info("SIGHUP received");
96 }
97
98 /* SIGINT / SIGTERM handler. */
99 static void sigint(void)
100 {
101 zlog_notice("Terminating on signal");
102 bfd_protocol_integration_set_shutdown(true);
103 ospf_terminate();
104 exit(0);
105 }
106
107 /* SIGUSR1 handler. */
108 static void sigusr1(void)
109 {
110 zlog_rotate();
111 }
112
113 struct quagga_signal_t ospf_signals[] = {
114 {
115 .signal = SIGHUP,
116 .handler = &sighup,
117 },
118 {
119 .signal = SIGUSR1,
120 .handler = &sigusr1,
121 },
122 {
123 .signal = SIGINT,
124 .handler = &sigint,
125 },
126 {
127 .signal = SIGTERM,
128 .handler = &sigint,
129 },
130 };
131
132 static const struct frr_yang_module_info *const ospfd_yang_modules[] = {
133 &frr_filter_info,
134 &frr_interface_info,
135 &frr_route_map_info,
136 &frr_vrf_info,
137 };
138
139 FRR_DAEMON_INFO(ospfd, OSPF, .vty_port = OSPF_VTY_PORT,
140
141 .proghelp = "Implementation of the OSPFv2 routing protocol.",
142
143 .signals = ospf_signals, .n_signals = array_size(ospf_signals),
144
145 .privs = &ospfd_privs, .yang_modules = ospfd_yang_modules,
146 .n_yang_modules = array_size(ospfd_yang_modules),
147 );
148
149 /* OSPFd main routine. */
150 int main(int argc, char **argv)
151 {
152 #ifdef SUPPORT_OSPF_API
153 /* OSPF apiserver is disabled by default. */
154 ospf_apiserver_enable = 0;
155 #endif /* SUPPORT_OSPF_API */
156
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");
161
162 while (1) {
163 int opt;
164
165 opt = frr_getopt(argc, argv, NULL);
166
167 if (opt == EOF)
168 break;
169
170 switch (opt) {
171 case 'n':
172 ospfd_di.instance = ospf_instance = atoi(optarg);
173 if (ospf_instance < 1)
174 exit(0);
175 break;
176 case 0:
177 break;
178 #ifdef SUPPORT_OSPF_API
179 case 'a':
180 ospf_apiserver_enable = 1;
181 break;
182 #endif /* SUPPORT_OSPF_API */
183 default:
184 frr_help_exit(1);
185 break;
186 }
187 }
188
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. */
203 ospf_debug_init();
204 ospf_vrf_init();
205
206 access_list_init();
207 prefix_list_init();
208
209 /* OSPFd inits. */
210 ospf_if_init();
211 ospf_zebra_init(master, ospf_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(master);
220
221 /* OSPF LDP IGP Sync init */
222 ospf_ldp_sync_init();
223
224 ospf_route_map_init();
225 ospf_opaque_init();
226
227 /* OSPF errors init */
228 ospf_error_init();
229
230 frr_config_fork();
231 frr_run(master);
232
233 /* Not reached. */
234 return 0;
235 }