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