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 #include "ospf6_top.h"
41 #include "ospf6_message.h"
42 #include "ospf6_asbr.h"
43 #include "ospf6_lsa.h"
44 #include "ospf6_interface.h"
45 #include "ospf6_zebra.h"
47 /* Default configuration file name for ospf6d. */
48 #define OSPF6_DEFAULT_CONFIG "ospf6d.conf"
50 /* Default port values. */
51 #define OSPF6_VTY_PORT 2606
53 /* ospf6d privileges */
54 zebra_capabilities_t _caps_p
[] =
60 struct zebra_privs_t ospf6d_privs
=
62 #if defined(QUAGGA_USER)
65 #if defined QUAGGA_GROUP
66 .group
= QUAGGA_GROUP
,
69 .vty_group
= VTY_GROUP
,
76 /* ospf6d options, we use GNU getopt library. */
77 struct option longopts
[] =
79 { "daemon", no_argument
, NULL
, 'd'},
80 { "config_file", required_argument
, NULL
, 'f'},
81 { "pid_file", required_argument
, NULL
, 'i'},
82 { "socket", required_argument
, NULL
, 'z'},
83 { "vty_addr", required_argument
, NULL
, 'A'},
84 { "vty_port", required_argument
, NULL
, 'P'},
85 { "user", required_argument
, NULL
, 'u'},
86 { "group", required_argument
, NULL
, 'g'},
87 { "version", no_argument
, NULL
, 'v'},
88 { "dryrun", no_argument
, NULL
, 'C'},
89 { "help", no_argument
, NULL
, 'h'},
93 /* Configuration file and directory. */
94 char config_default
[] = SYSCONFDIR OSPF6_DEFAULT_CONFIG
;
96 /* ospf6d program name. */
102 /* Master of threads. */
103 struct thread_master
*master
;
105 /* Process ID saved for use by init system */
106 const char *pid_file
= PATH_OSPF6D_PID
;
108 /* Help information display. */
110 usage (char *progname
, int status
)
113 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
116 printf ("Usage : %s [OPTION...]\n\n\
117 Daemon which manages OSPF version 3.\n\n\
118 -d, --daemon Runs in daemon mode\n\
119 -f, --config_file Set configuration file name\n\
120 -i, --pid_file Set process identifier file name\n\
121 -z, --socket Set path of zebra socket\n\
122 -A, --vty_addr Set vty's bind address\n\
123 -P, --vty_port Set vty's port number\n\
124 -u, --user User to run as\n\
125 -g, --group Group to run as\n\
126 -v, --version Print program version\n\
127 -C, --dryrun Check configuration for validity and exit\n\
128 -h, --help Display this help and exit\n\
130 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
136 static void __attribute__ ((noreturn
))
137 ospf6_exit (int status
)
139 struct listnode
*node
;
140 struct interface
*ifp
;
143 ospf6_delete (ospf6
);
145 for (ALL_LIST_ELEMENTS_RO(iflist
, node
, ifp
))
146 if (ifp
->info
!= NULL
)
147 ospf6_interface_delete(ifp
->info
);
149 ospf6_message_terminate ();
150 ospf6_asbr_terminate ();
151 ospf6_lsa_terminate ();
158 zclient_free (zclient
);
161 thread_master_free (master
);
164 closezlog (zlog_default
);
169 /* SIGHUP handler. */
173 zlog_info ("SIGHUP received");
176 /* SIGINT handler. */
180 zlog_notice ("Terminating on signal SIGINT");
184 /* SIGTERM handler. */
188 zlog_notice ("Terminating on signal SIGTERM");
193 /* SIGUSR1 handler. */
197 zlog_info ("SIGUSR1 received");
201 struct quagga_signal_t ospf6_signals
[] =
221 /* Main routine of ospf6d. Treatment of argument and starting ospf finite
222 state machine is handled here. */
224 main (int argc
, char *argv
[], char *envp
[])
228 char *vty_addr
= NULL
;
230 char *config_file
= NULL
;
231 struct thread thread
;
234 /* Set umask before anything for security */
237 /* Preserve name of myself. */
238 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
240 /* Command line argument treatment. */
243 opt
= getopt_long (argc
, argv
, "df:i:z:hp:A:P:u:g:vC", longopts
, 0);
256 config_file
= optarg
;
265 zclient_serv_path_set (optarg
);
268 /* Deal with atoi() returning 0 on failure, and ospf6d not
269 listening on ospf6d port... */
270 if (strcmp(optarg
, "0") == 0)
275 vty_port
= atoi (optarg
);
276 if (vty_port
<= 0 || vty_port
> 0xffff)
277 vty_port
= OSPF6_VTY_PORT
;
280 ospf6d_privs
.user
= optarg
;
283 ospf6d_privs
.group
= optarg
;
286 print_version (progname
);
309 master
= thread_master_create ();
311 /* Initializations. */
312 zlog_default
= openzlog (progname
, ZLOG_OSPF6
,
313 LOG_CONS
|LOG_NDELAY
|LOG_PID
,
315 zprivs_init (&ospf6d_privs
);
316 /* initialize zebra libraries */
317 signal_init (master
, array_size(ospf6_signals
), ospf6_signals
);
325 /* initialize ospf6 */
328 /* sort command vector */
331 /* parse config file */
332 vty_read_config (config_file
, config_default
);
334 /* Start execution only if not in dry-run mode */
338 if (daemon_mode
&& daemon (0, 0) < 0)
340 zlog_err("OSPF6d daemon failed: %s", strerror(errno
));
344 /* pid file create */
345 pid_output (pid_file
);
347 /* Make ospf6 vty socket. */
349 vty_port
= OSPF6_VTY_PORT
;
350 vty_serv_sock (vty_addr
, vty_port
, OSPF6_VTYSH_PATH
);
352 /* Print start message */
353 zlog_notice ("OSPF6d (Quagga-%s ospf6d-%s) starts: vty@%d",
354 QUAGGA_VERSION
, OSPF6_DAEMON_VERSION
,vty_port
);
356 /* Start finite state machine, here we go! */
357 while (thread_fetch (master
, &thread
))
358 thread_call (&thread
);
360 /* Log in case thread failed */
361 zlog_warn ("Thread failed");