]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_main.c
Merge pull request #8754 from louis-oui/bgp-summary-filter
[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 #include "ospfd/ospf_routemap_nb.h"
60
61 /* ospfd privileges */
62 zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN,
63 ZCAP_SYS_ADMIN};
64
65 struct zebra_privs_t ospfd_privs = {
66 #if defined(FRR_USER) && defined(FRR_GROUP)
67 .user = FRR_USER,
68 .group = FRR_GROUP,
69 #endif
70 #if defined(VTY_GROUP)
71 .vty_group = VTY_GROUP,
72 #endif
73 .caps_p = _caps_p,
74 .cap_num_p = array_size(_caps_p),
75 .cap_num_i = 0};
76
77 /* OSPFd options. */
78 const struct option longopts[] = {
79 {"instance", required_argument, NULL, 'n'},
80 {"apiserver", no_argument, NULL, 'a'},
81 {0}
82 };
83
84 /* OSPFd program name */
85
86 /* Master of threads. */
87 struct thread_master *master;
88
89 #ifdef SUPPORT_OSPF_API
90 extern int ospf_apiserver_enable;
91 #endif /* SUPPORT_OSPF_API */
92
93 /* SIGHUP handler. */
94 static void sighup(void)
95 {
96 zlog_info("SIGHUP received");
97 }
98
99 /* SIGINT / SIGTERM handler. */
100 static void sigint(void)
101 {
102 zlog_notice("Terminating on signal");
103 bfd_protocol_integration_set_shutdown(true);
104 ospf_terminate();
105 exit(0);
106 }
107
108 /* SIGUSR1 handler. */
109 static void sigusr1(void)
110 {
111 zlog_rotate();
112 }
113
114 struct quagga_signal_t ospf_signals[] = {
115 {
116 .signal = SIGHUP,
117 .handler = &sighup,
118 },
119 {
120 .signal = SIGUSR1,
121 .handler = &sigusr1,
122 },
123 {
124 .signal = SIGINT,
125 .handler = &sigint,
126 },
127 {
128 .signal = SIGTERM,
129 .handler = &sigint,
130 },
131 };
132
133 static const struct frr_yang_module_info *const ospfd_yang_modules[] = {
134 &frr_filter_info,
135 &frr_interface_info,
136 &frr_route_map_info,
137 &frr_vrf_info,
138 &frr_ospf_route_map_info,
139 };
140
141 FRR_DAEMON_INFO(ospfd, OSPF, .vty_port = OSPF_VTY_PORT,
142
143 .proghelp = "Implementation of the OSPFv2 routing protocol.",
144
145 .signals = ospf_signals, .n_signals = array_size(ospf_signals),
146
147 .privs = &ospfd_privs, .yang_modules = ospfd_yang_modules,
148 .n_yang_modules = array_size(ospfd_yang_modules),
149 );
150
151 /* OSPFd main routine. */
152 int main(int argc, char **argv)
153 {
154 #ifdef SUPPORT_OSPF_API
155 /* OSPF apiserver is disabled by default. */
156 ospf_apiserver_enable = 0;
157 #endif /* SUPPORT_OSPF_API */
158
159 frr_preinit(&ospfd_di, argc, argv);
160 frr_opt_add("n:a", longopts,
161 " -n, --instance Set the instance id\n"
162 " -a, --apiserver Enable OSPF apiserver\n");
163
164 while (1) {
165 int opt;
166
167 opt = frr_getopt(argc, argv, NULL);
168
169 if (opt == EOF)
170 break;
171
172 switch (opt) {
173 case 'n':
174 ospfd_di.instance = ospf_instance = atoi(optarg);
175 if (ospf_instance < 1)
176 exit(0);
177 break;
178 case 0:
179 break;
180 #ifdef SUPPORT_OSPF_API
181 case 'a':
182 ospf_apiserver_enable = 1;
183 break;
184 #endif /* SUPPORT_OSPF_API */
185 default:
186 frr_help_exit(1);
187 break;
188 }
189 }
190
191 /* Invoked by a priviledged user? -- endo. */
192 if (geteuid() != 0) {
193 errno = EPERM;
194 perror(ospfd_di.progname);
195 exit(1);
196 }
197
198 /* OSPF master init. */
199 ospf_master_init(frr_init());
200
201 /* Initializations. */
202 master = om->master;
203
204 /* Library inits. */
205 ospf_debug_init();
206 ospf_vrf_init();
207
208 access_list_init();
209 prefix_list_init();
210
211 /* OSPFd inits. */
212 ospf_if_init();
213 ospf_zebra_init(master, ospf_instance);
214
215 /* OSPF vty inits. */
216 ospf_vty_init();
217 ospf_vty_show_init();
218 ospf_vty_clear_init();
219
220 /* OSPF BFD init */
221 ospf_bfd_init(master);
222
223 /* OSPF LDP IGP Sync init */
224 ospf_ldp_sync_init();
225
226 ospf_route_map_init();
227 ospf_opaque_init();
228 ospf_gr_helper_init();
229
230 /* OSPF errors init */
231 ospf_error_init();
232
233 frr_config_fork();
234 frr_run(master);
235
236 /* Not reached. */
237 return 0;
238 }