3 * Copyright (C) 1998, 99 Kunihiro Ishiguro, Toshiaki Takada
5 * This file is part of GNU Zebra.
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
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.
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
25 #include <lib/version.h>
42 #include "ospfd/ospfd.h"
43 #include "ospfd/ospf_interface.h"
44 #include "ospfd/ospf_asbr.h"
45 #include "ospfd/ospf_lsa.h"
46 #include "ospfd/ospf_lsdb.h"
47 #include "ospfd/ospf_neighbor.h"
48 #include "ospfd/ospf_dump.h"
49 #include "ospfd/ospf_zebra.h"
50 #include "ospfd/ospf_vty.h"
52 /* ospfd privileges */
53 zebra_capabilities_t _caps_p
[] =
60 struct zebra_privs_t ospfd_privs
=
62 #if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
64 .group
= QUAGGA_GROUP
,
66 #if defined(VTY_GROUP)
67 .vty_group
= VTY_GROUP
,
70 .cap_num_p
= sizeof(_caps_p
)/sizeof(_caps_p
[0]),
74 /* Configuration filename and directory. */
75 char config_default
[] = SYSCONFDIR OSPF_DEFAULT_CONFIG
;
78 struct option longopts
[] =
80 { "daemon", no_argument
, NULL
, 'd'},
81 { "config_file", required_argument
, NULL
, 'f'},
82 { "pid_file", required_argument
, NULL
, 'i'},
83 { "dryrun", no_argument
, NULL
, 'C'},
84 { "help", no_argument
, NULL
, 'h'},
85 { "vty_addr", required_argument
, NULL
, 'A'},
86 { "vty_port", required_argument
, NULL
, 'P'},
87 { "user", required_argument
, NULL
, 'u'},
88 { "group", required_argument
, NULL
, 'g'},
89 { "apiserver", no_argument
, NULL
, 'a'},
90 { "version", no_argument
, NULL
, 'v'},
94 /* OSPFd program name */
96 /* Master of threads. */
97 struct thread_master
*master
;
99 /* Process ID saved for use by init system */
100 const char *pid_file
= PATH_OSPFD_PID
;
102 #ifdef SUPPORT_OSPF_API
103 extern int ospf_apiserver_enable
;
104 #endif /* SUPPORT_OSPF_API */
106 /* Help information display. */
107 static void __attribute__ ((noreturn
))
108 usage (char *progname
, int status
)
111 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
114 printf ("Usage : %s [OPTION...]\n\
115 Daemon which manages OSPF.\n\n\
116 -d, --daemon Runs in daemon mode\n\
117 -f, --config_file Set configuration file name\n\
118 -i, --pid_file Set process identifier file name\n\
119 -A, --vty_addr Set vty's bind address\n\
120 -P, --vty_port Set vty's port number\n\
121 -u, --user User to run as\n\
122 -g, --group Group to run as\n\
123 -a. --apiserver Enable OSPF apiserver\n\
124 -v, --version Print program version\n\
125 -C, --dryrun Check configuration for validity and exit\n\
126 -h, --help Display this help and exit\n\
128 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
133 /* SIGHUP handler. */
137 zlog (NULL
, LOG_INFO
, "SIGHUP received");
140 /* SIGINT / SIGTERM handler. */
144 zlog_notice ("Terminating on signal");
148 /* SIGUSR1 handler. */
155 struct quagga_signal_t ospf_signals
[] =
175 /* OSPFd main routine. */
177 main (int argc
, char **argv
)
180 char *vty_addr
= NULL
;
181 int vty_port
= OSPF_VTY_PORT
;
183 char *config_file
= NULL
;
185 struct thread thread
;
188 /* Set umask before anything for security */
191 /* get program name */
192 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
194 /* Invoked by a priviledged user? -- endo. */
202 zlog_default
= openzlog (progname
, ZLOG_OSPF
,
203 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
205 /* OSPF master init. */
208 #ifdef SUPPORT_OSPF_API
209 /* OSPF apiserver is disabled by default. */
210 ospf_apiserver_enable
= 0;
211 #endif /* SUPPORT_OSPF_API */
217 opt
= getopt_long (argc
, argv
, "df:i:hA:P:u:g:avC", longopts
, 0);
230 config_file
= optarg
;
239 /* Deal with atoi() returning 0 on failure, and ospfd not
240 listening on ospfd port... */
241 if (strcmp(optarg
, "0") == 0)
246 vty_port
= atoi (optarg
);
247 if (vty_port
<= 0 || vty_port
> 0xffff)
248 vty_port
= OSPF_VTY_PORT
;
251 ospfd_privs
.user
= optarg
;
254 ospfd_privs
.group
= optarg
;
256 #ifdef SUPPORT_OSPF_API
258 ospf_apiserver_enable
= 1;
260 #endif /* SUPPORT_OSPF_API */
262 print_version (progname
);
277 /* Initializations. */
281 zprivs_init (&ospfd_privs
);
282 signal_init (master
, Q_SIGC(ospf_signals
), ospf_signals
);
295 /* OSPF vty inits. */
297 ospf_vty_show_init ();
299 ospf_route_map_init ();
302 #endif /* HAVE_SNMP */
303 #ifdef HAVE_OPAQUE_LSA
305 #endif /* HAVE_OPAQUE_LSA */
309 /* Get configuration file. */
310 vty_read_config (config_file
, config_default
);
312 /* Start execution only if not in dry-run mode */
316 /* Change to the daemon program. */
317 if (daemon_mode
&& daemon (0, 0) < 0)
319 zlog_err("OSPFd daemon failed: %s", strerror(errno
));
323 /* Process id file create. */
324 pid_output (pid_file
);
326 /* Create VTY socket */
327 vty_serv_sock (vty_addr
, vty_port
, OSPF_VTYSH_PATH
);
330 zlog_notice ("OSPFd %s starting: vty@%d", QUAGGA_VERSION
, vty_port
);
332 /* Fetch next active thread. */
333 while (thread_fetch (master
, &thread
))
334 thread_call (&thread
);