2
* Copyright (C) 1999 Yasuhiro Ohara
4
* This file is part of GNU Zebra.
6
* GNU Zebra is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License as published by the
8
* Free Software Foundation; either version 2, or (at your option) any
11
* GNU Zebra is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with GNU Zebra; see the file COPYING. If not, write to the
18
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
23
#include <lib/version.h>
40
/* Default configuration file name for ospf6d. */
41
#define OSPF6_DEFAULT_CONFIG "ospf6d.conf"
43
/* Default port values. */
44
#define OSPF6_VTY_PORT 2606
46
/* ospf6d privileges */
47
zebra_capabilities_t _caps_p [] =
53
struct zebra_privs_t ospf6d_privs =
55
#if defined(QUAGGA_USER)
58
#if defined QUAGGA_GROUP
59
.group = QUAGGA_GROUP,
62
.vty_group = VTY_GROUP,
69
/* ospf6d options, we use GNU getopt library. */
70
struct option longopts[] =
72
{ "daemon", no_argument, NULL, 'd'},
73
{ "config_file", required_argument, NULL, 'f'},
74
{ "pid_file", required_argument, NULL, 'i'},
75
{ "vty_addr", required_argument, NULL, 'A'},
76
{ "vty_port", required_argument, NULL, 'P'},
77
{ "user", required_argument, NULL, 'u'},
78
{ "group", required_argument, NULL, 'g'},
79
{ "version", no_argument, NULL, 'v'},
80
{ "help", no_argument, NULL, 'h'},
84
/* Configuration file and directory. */
85
char config_default[] = SYSCONFDIR OSPF6_DEFAULT_CONFIG;
87
/* ospf6d program name. */
93
/* Master of threads. */
94
struct thread_master *master;
96
/* Process ID saved for use by init system */
97
const char *pid_file = PATH_OSPF6D_PID;
99
/* Help information display. */
101
usage (char *progname, int status)
104
fprintf (stderr, "Try `%s --help' for more information.\n", progname);
107
printf ("Usage : %s [OPTION...]\n\n\
108
Daemon which manages OSPF version 3.\n\n\
109
-d, --daemon Runs in daemon mode\n\
110
-f, --config_file Set configuration file name\n\
111
-i, --pid_file Set process identifier file name\n\
112
-A, --vty_addr Set vty's bind address\n\
113
-P, --vty_port Set vty's port number\n\
114
-u, --user User to run as\n\
115
-g, --group Group to run as\n\
116
-v, --version Print program version\n\
117
-h, --help Display this help and exit\n\
119
Report bugs to zebra@zebra.org\n", progname);
125
/* SIGHUP handler. */
129
zlog_info ("SIGHUP received");
132
/* SIGINT handler. */
136
zlog_notice ("Terminating on signal SIGINT");
140
/* SIGTERM handler. */
144
zlog_notice ("Terminating on signal SIGTERM");
148
/* SIGUSR1 handler. */
152
zlog_info ("SIGUSR1 received");
156
struct quagga_signal_t ospf6_signals[] =
176
/* Main routine of ospf6d. Treatment of argument and starting ospf finite
177
state machine is handled here. */
179
main (int argc, char *argv[], char *envp[])
183
char *vty_addr = NULL;
185
char *config_file = NULL;
186
struct thread thread;
188
/* Set umask before anything for security */
191
/* Preserve name of myself. */
192
progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
194
/* Command line argument treatment. */
197
opt = getopt_long (argc, argv, "df:i:hp:A:P:u:g:v", longopts, 0);
210
config_file = optarg;
219
/* Deal with atoi() returning 0 on failure, and ospf6d not
220
listening on ospf6d port... */
221
if (strcmp(optarg, "0") == 0)
226
vty_port = atoi (optarg);
227
vty_port = (vty_port ? vty_port : OSPF6_VTY_PORT);
230
ospf6d_privs.user = optarg;
233
ospf6d_privs.group = optarg;
236
print_version (progname);
249
master = thread_master_create ();
251
/* Initializations. */
252
zlog_default = openzlog (progname, ZLOG_OSPF6,
253
LOG_CONS|LOG_NDELAY|LOG_PID,
255
zprivs_init (&ospf6d_privs);
256
/* initialize zebra libraries */
257
signal_init (master, Q_SIGC(ospf6_signals), ospf6_signals);
265
/* initialize ospf6 */
268
/* sort command vector */
271
/* parse config file */
272
vty_read_config (config_file, config_default);
277
/* pid file create */
278
pid_output (pid_file);
280
/* Make ospf6 vty socket. */
282
vty_port = OSPF6_VTY_PORT;
283
vty_serv_sock (vty_addr, vty_port, OSPF6_VTYSH_PATH);
285
/* Print start message */
286
zlog_notice ("OSPF6d (Quagga-%s ospf6d-%s) starts: vty@%d",
287
QUAGGA_VERSION, OSPF6_DAEMON_VERSION,vty_port);
289
/* Start finite state machine, here we go! */
290
while (thread_fetch (master, &thread))
291
thread_call (&thread);
293
/* Log in case thread failed */
294
zlog_warn ("Thread failed");