]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_main.c
*: make consistent & update GPLv2 file headers
[mirror_frr.git] / ospfd / ospf_main.c
CommitLineData
718e3744 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 *
896014f4
DL
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
718e3744 20 */
21
22#include <zebra.h>
23
5e4fa164 24#include <lib/version.h>
718e3744 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"
fc7948fa 38#include "memory_vty.h"
edd7c245 39#include "privs.h"
2d75d052 40#include "sigevent.h"
b5114685 41#include "zclient.h"
6a69b354 42#include "vrf.h"
4f04a76b 43#include "libfrr.h"
718e3744 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_zebra.h"
53#include "ospfd/ospf_vty.h"
7f342629 54#include "ospfd/ospf_bfd.h"
718e3744 55
edd7c245 56/* ospfd privileges */
57zebra_capabilities_t _caps_p [] =
58{
ceacedba 59 ZCAP_NET_RAW,
edd7c245 60 ZCAP_BIND,
ceacedba 61 ZCAP_NET_ADMIN,
edd7c245 62};
63
64struct zebra_privs_t ospfd_privs =
65{
b2f36157
DL
66#if defined(FRR_USER) && defined(FRR_GROUP)
67 .user = FRR_USER,
68 .group = FRR_GROUP,
edd7c245 69#endif
70#if defined(VTY_GROUP)
71 .vty_group = VTY_GROUP,
72#endif
73 .caps_p = _caps_p,
837d16cc 74 .cap_num_p = array_size(_caps_p),
edd7c245 75 .cap_num_i = 0
76};
77
718e3744 78/* OSPFd options. */
79struct option longopts[] =
80{
7c8ff89e 81 { "instance", required_argument, NULL, 'n'},
c3abdb72 82 { "apiserver", no_argument, NULL, 'a'},
718e3744 83 { 0 }
84};
85
86/* OSPFd program name */
87
88/* Master of threads. */
89struct thread_master *master;
90
d68614db 91#ifdef SUPPORT_OSPF_API
f4d58ce5 92extern int ospf_apiserver_enable;
d68614db 93#endif /* SUPPORT_OSPF_API */
c3abdb72 94
718e3744 95/* SIGHUP handler. */
4dadc291 96static void
2d75d052 97sighup (void)
718e3744 98{
4525281a 99 zlog_info("SIGHUP received");
718e3744 100}
101
88d6cf37 102/* SIGINT / SIGTERM handler. */
103static void
2d75d052 104sigint (void)
718e3744 105{
887c44a4 106 zlog_notice ("Terminating on signal");
718e3744 107 ospf_terminate ();
718e3744 108}
109
110/* SIGUSR1 handler. */
4dadc291 111static void
2d75d052 112sigusr1 (void)
718e3744 113{
dd8376fe 114 zlog_rotate();
718e3744 115}
116
2d75d052 117struct quagga_signal_t ospf_signals[] =
718e3744 118{
2d75d052 119 {
120 .signal = SIGHUP,
121 .handler = &sighup,
122 },
123 {
124 .signal = SIGUSR1,
125 .handler = &sigusr1,
126 },
127 {
128 .signal = SIGINT,
129 .handler = &sigint,
130 },
f571dab0 131 {
132 .signal = SIGTERM,
133 .handler = &sigint,
134 },
2d75d052 135};
6b0655a2 136
4f04a76b
DL
137FRR_DAEMON_INFO(ospfd, OSPF,
138 .vty_port = OSPF_VTY_PORT,
139
140 .proghelp = "Implementation of the OSPFv2 routing protocol.",
141
142 .signals = ospf_signals,
143 .n_signals = array_size(ospf_signals),
144
145 .privs = &ospfd_privs,
146)
147
718e3744 148/* OSPFd main routine. */
149int
150main (int argc, char **argv)
151{
7c8ff89e 152 u_short instance = 0;
718e3744 153
822d8f55
DL
154#ifdef SUPPORT_OSPF_API
155 /* OSPF apiserver is disabled by default. */
156 ospf_apiserver_enable = 0;
157#endif /* SUPPORT_OSPF_API */
158
4f04a76b 159 frr_preinit (&ospfd_di, argc, argv);
eb05883f 160 frr_opt_add ("n:a", longopts,
4f04a76b 161 " -n, --instance Set the instance id\n"
2fcc7988 162 " -a, --apiserver Enable OSPF apiserver\n");
718e3744 163
718e3744 164 while (1)
165 {
166 int opt;
167
4f04a76b 168 opt = frr_getopt (argc, argv, NULL);
718e3744 169
170 if (opt == EOF)
171 break;
172
173 switch (opt)
174 {
7c8ff89e 175 case 'n':
4f04a76b 176 ospfd_di.instance = instance = atoi(optarg);
988225dd 177 if (instance < 1)
7c8ff89e
DS
178 exit(0);
179 break;
718e3744 180 case 0:
181 break;
d68614db 182#ifdef SUPPORT_OSPF_API
c3abdb72 183 case 'a':
184 ospf_apiserver_enable = 1;
185 break;
d68614db 186#endif /* SUPPORT_OSPF_API */
718e3744 187 default:
4f04a76b 188 frr_help_exit (1);
718e3744 189 break;
190 }
191 }
192
b5114685
VT
193 /* Invoked by a priviledged user? -- endo. */
194 if (geteuid () != 0)
195 {
196 errno = EPERM;
4f04a76b 197 perror (ospfd_di.progname);
b5114685
VT
198 exit (1);
199 }
200
b5114685 201 /* OSPF master init. */
4f04a76b 202 ospf_master_init (frr_init ());
b5114685 203
718e3744 204 /* Initializations. */
020709f9 205 master = om->master;
718e3744 206
207 /* Library inits. */
718e3744 208 debug_init ();
6a69b354 209 vrf_init ();
718e3744 210
211 access_list_init ();
212 prefix_list_init ();
213
214 /* OSPFd inits. */
718e3744 215 ospf_if_init ();
4140ca4d 216 ospf_zebra_init(master, instance);
718e3744 217
218 /* OSPF vty inits. */
219 ospf_vty_init ();
220 ospf_vty_show_init ();
09f35f8c 221 ospf_vty_clear_init ();
718e3744 222
7f342629
DS
223 /* OSPF BFD init */
224 ospf_bfd_init();
225
718e3744 226 ospf_route_map_init ();
718e3744 227 ospf_opaque_init ();
718e3744 228
6dae198f
DS
229 /* Need to initialize the default ospf structure, so the interface mode
230 commands can be duly processed if they are received before 'router ospf',
231 when quagga(ospfd) is restarted */
7c8ff89e 232 if (!ospf_get_instance(instance))
6dae198f
DS
233 {
234 zlog_err("OSPF instance init failed: %s", strerror(errno));
235 exit (1);
236 }
237
16077f2f
DL
238 frr_config_fork();
239 frr_run (master);
718e3744 240
241 /* Not reached. */
e8e1946e 242 return (0);
718e3744 243}
244