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