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