]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_main.c
Fixing ospf6d as well and move Changelog entry from ospfd to general one.
[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 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23#include <zebra.h>
24
5e4fa164 25#include <lib/version.h>
718e3744 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"
edd7c245 39#include "privs.h"
40#include "debug.h"
2d75d052 41#include "sigevent.h"
718e3744 42
43#include "ospfd/ospfd.h"
44#include "ospfd/ospf_interface.h"
45#include "ospfd/ospf_asbr.h"
46#include "ospfd/ospf_lsa.h"
47#include "ospfd/ospf_lsdb.h"
48#include "ospfd/ospf_neighbor.h"
49#include "ospfd/ospf_dump.h"
50#include "ospfd/ospf_zebra.h"
51#include "ospfd/ospf_vty.h"
52
edd7c245 53/* ospfd privileges */
54zebra_capabilities_t _caps_p [] =
55{
56 ZCAP_RAW,
57 ZCAP_BIND,
58 ZCAP_BROADCAST,
59 ZCAP_ADMIN,
60};
61
62struct zebra_privs_t ospfd_privs =
63{
d81fadfd 64#if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
65 .user = QUAGGA_USER,
66 .group = QUAGGA_GROUP,
edd7c245 67#endif
68#if defined(VTY_GROUP)
69 .vty_group = VTY_GROUP,
70#endif
71 .caps_p = _caps_p,
72 .cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]),
73 .cap_num_i = 0
74};
75
718e3744 76/* Configuration filename and directory. */
77char config_current[] = OSPF_DEFAULT_CONFIG;
78char config_default[] = SYSCONFDIR OSPF_DEFAULT_CONFIG;
79
80/* OSPFd options. */
81struct option longopts[] =
82{
83 { "daemon", no_argument, NULL, 'd'},
84 { "config_file", required_argument, NULL, 'f'},
85 { "pid_file", required_argument, NULL, 'i'},
86 { "log_mode", no_argument, NULL, 'l'},
87 { "help", no_argument, NULL, 'h'},
88 { "vty_addr", required_argument, NULL, 'A'},
89 { "vty_port", required_argument, NULL, 'P'},
edd7c245 90 { "user", required_argument, NULL, 'u'},
718e3744 91 { "version", no_argument, NULL, 'v'},
92 { 0 }
93};
94
95/* OSPFd program name */
96
97/* Master of threads. */
98struct thread_master *master;
99
100/* Process ID saved for use by init system */
101char *pid_file = PATH_OSPFD_PID;
102
103/* Help information display. */
104static void
105usage (char *progname, int status)
106{
107 if (status != 0)
108 fprintf (stderr, "Try `%s --help' for more information.\n", progname);
109 else
110 {
111 printf ("Usage : %s [OPTION...]\n\
112Daemon which manages OSPF.\n\n\
113-d, --daemon Runs in daemon mode\n\
114-f, --config_file Set configuration file name\n\
115-i, --pid_file Set process identifier file name\n\
116-A, --vty_addr Set vty's bind address\n\
117-P, --vty_port Set vty's port number\n\
edd7c245 118-u, --user User and group to run as\n\
718e3744 119-v, --version Print program version\n\
120-h, --help Display this help and exit\n\
121\n\
122Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
123 }
124 exit (status);
125}
126\f
127/* SIGHUP handler. */
128void
2d75d052 129sighup (void)
718e3744 130{
131 zlog (NULL, LOG_INFO, "SIGHUP received");
132}
133
134/* SIGINT handler. */
135void
2d75d052 136sigint (void)
718e3744 137{
138 zlog (NULL, LOG_INFO, "Terminating on signal");
139
140 ospf_terminate ();
141
142 exit (0);
143}
144
145/* SIGUSR1 handler. */
146void
2d75d052 147sigusr1 (void)
718e3744 148{
149 zlog_rotate (NULL);
150}
151
2d75d052 152struct quagga_signal_t ospf_signals[] =
718e3744 153{
2d75d052 154 {
155 .signal = SIGHUP,
156 .handler = &sighup,
157 },
158 {
159 .signal = SIGUSR1,
160 .handler = &sigusr1,
161 },
162 {
163 .signal = SIGINT,
164 .handler = &sigint,
165 },
166};
718e3744 167\f
168/* OSPFd main routine. */
169int
170main (int argc, char **argv)
171{
172 char *p;
173 char *vty_addr = NULL;
4fc4e7ab 174 int vty_port = OSPF_VTY_PORT;
718e3744 175 int daemon_mode = 0;
176 char *config_file = NULL;
177 char *progname;
178 struct thread thread;
179
180 /* Set umask before anything for security */
181 umask (0027);
182
183 /* get program name */
184 progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
185
186 /* Invoked by a priviledged user? -- endo. */
b3516a79 187 if (geteuid () != 0)
718e3744 188 {
189 errno = EPERM;
190 perror (progname);
191 exit (1);
192 }
193
194 zlog_default = openzlog (progname, ZLOG_NOLOG, ZLOG_OSPF,
195 LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
196
020709f9 197 /* OSPF master init. */
198 ospf_master_init ();
199
718e3744 200 while (1)
201 {
202 int opt;
203
96735eea 204 opt = getopt_long (argc, argv, "dlf:i:hA:P:u:v", longopts, 0);
718e3744 205
206 if (opt == EOF)
207 break;
208
209 switch (opt)
210 {
211 case 0:
212 break;
213 case 'd':
214 daemon_mode = 1;
215 break;
216 case 'f':
217 config_file = optarg;
218 break;
219 case 'A':
220 vty_addr = optarg;
221 break;
222 case 'i':
223 pid_file = optarg;
224 break;
225 case 'P':
4fc4e7ab 226 /* Deal with atoi() returning 0 on failure, and ospfd not
227 listening on ospfd port... */
228 if (strcmp(optarg, "0") == 0)
229 {
230 vty_port = 0;
231 break;
232 }
233 vty_port = atoi (optarg);
234 vty_port = (vty_port ? vty_port : OSPF_VTY_PORT);
235 break;
edd7c245 236 case 'u':
237 ospfd_privs.group = ospfd_privs.user = optarg;
238 break;
718e3744 239 case 'v':
240 print_version (progname);
241 exit (0);
242 break;
243 case 'h':
244 usage (progname, 0);
245 break;
246 default:
247 usage (progname, 1);
248 break;
249 }
250 }
251
252 /* Initializations. */
020709f9 253 master = om->master;
718e3744 254
255 /* Library inits. */
edd7c245 256 zprivs_init (&ospfd_privs);
2d75d052 257 signal_init (master, Q_SIGC(ospf_signals), ospf_signals);
718e3744 258 cmd_init (1);
259 debug_init ();
b21b19c5 260 vty_init (master);
718e3744 261 memory_init ();
262
263 access_list_init ();
264 prefix_list_init ();
265
266 /* OSPFd inits. */
267 ospf_init ();
268 ospf_if_init ();
269 ospf_zebra_init ();
270
271 /* OSPF vty inits. */
272 ospf_vty_init ();
273 ospf_vty_show_init ();
274
275 ospf_route_map_init ();
276#ifdef HAVE_SNMP
277 ospf_snmp_init ();
278#endif /* HAVE_SNMP */
279#ifdef HAVE_OPAQUE_LSA
280 ospf_opaque_init ();
281#endif /* HAVE_OPAQUE_LSA */
282
283 sort_node ();
284
285 /* Get configuration file. */
286 vty_read_config (config_file, config_current, config_default);
287
288 /* Change to the daemon program. */
289 if (daemon_mode)
290 daemon (0, 0);
291
292 /* Process id file create. */
293 pid_output (pid_file);
294
295 /* Create VTY socket */
4fc4e7ab 296 vty_serv_sock (vty_addr, vty_port, OSPF_VTYSH_PATH);
718e3744 297
b3516a79 298#ifdef DEBUG
718e3744 299 /* Print banner. */
e8f2984c 300 zlog (NULL, LOG_INFO, "OSPFd (%s) starts", QUAGGA_VERSION);
b3516a79 301#endif
718e3744 302
303 /* Fetch next active thread. */
304 while (thread_fetch (master, &thread))
305 thread_call (&thread);
306
307 /* Not reached. */
308 exit (0);
309}
310