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>
32 #include "memory_vty.h"
44 #include "ospf6_top.h"
45 #include "ospf6_message.h"
46 #include "ospf6_asbr.h"
47 #include "ospf6_lsa.h"
48 #include "ospf6_interface.h"
49 #include "ospf6_zebra.h"
51 /* Default configuration file name for ospf6d. */
52 #define OSPF6_DEFAULT_CONFIG "ospf6d.conf"
54 /* Default port values. */
55 #define OSPF6_VTY_PORT 2606
57 /* ospf6d privileges */
58 zebra_capabilities_t _caps_p
[] =
64 struct zebra_privs_t ospf6d_privs
=
73 .vty_group
= VTY_GROUP
,
80 /* ospf6d options, we use GNU getopt library. */
81 struct option longopts
[] =
83 { "daemon", no_argument
, NULL
, 'd'},
84 { "config_file", required_argument
, NULL
, 'f'},
85 { "pid_file", required_argument
, NULL
, 'i'},
86 { "socket", required_argument
, NULL
, 'z'},
87 { "vty_addr", required_argument
, NULL
, 'A'},
88 { "vty_port", required_argument
, NULL
, 'P'},
89 { "user", required_argument
, NULL
, 'u'},
90 { "group", required_argument
, NULL
, 'g'},
91 { "version", no_argument
, NULL
, 'v'},
92 { "dryrun", no_argument
, NULL
, 'C'},
93 { "help", no_argument
, NULL
, 'h'},
97 /* Configuration file and directory. */
98 char config_default
[] = SYSCONFDIR OSPF6_DEFAULT_CONFIG
;
100 /* ospf6d program name. */
106 /* Master of threads. */
107 struct thread_master
*master
;
109 /* Process ID saved for use by init system */
110 const char *pid_file
= PATH_OSPF6D_PID
;
112 /* Help information display. */
114 usage (char *progname
, int status
)
117 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
120 printf ("Usage : %s [OPTION...]\n\n\
121 Daemon which manages OSPF version 3.\n\n\
122 -d, --daemon Runs in daemon mode\n\
123 -f, --config_file Set configuration file name\n\
124 -i, --pid_file Set process identifier file name\n\
125 -z, --socket Set path of zebra socket\n\
126 -A, --vty_addr Set vty's bind address\n\
127 -P, --vty_port Set vty's port number\n\
128 -u, --user User to run as\n\
129 -g, --group Group to run as\n\
130 -v, --version Print program version\n\
131 -C, --dryrun Check configuration for validity and exit\n\
132 -h, --help Display this help and exit\n\
134 Report bugs to %s\n", progname
, FRR_BUG_ADDRESS
);
140 static void __attribute__ ((noreturn
))
141 ospf6_exit (int status
)
143 struct listnode
*node
;
144 struct interface
*ifp
;
147 ospf6_delete (ospf6
);
151 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
152 if (ifp
->info
!= NULL
)
153 ospf6_interface_delete(ifp
->info
);
155 ospf6_message_terminate ();
156 ospf6_asbr_terminate ();
157 ospf6_lsa_terminate ();
164 zclient_free (zclient
);
167 thread_master_free (master
);
170 closezlog (zlog_default
);
175 /* SIGHUP handler. */
179 zlog_info ("SIGHUP received");
182 /* SIGINT handler. */
186 zlog_notice ("Terminating on signal SIGINT");
190 /* SIGTERM handler. */
194 zlog_notice ("Terminating on signal SIGTERM");
199 /* SIGUSR1 handler. */
203 zlog_info ("SIGUSR1 received");
207 struct quagga_signal_t ospf6_signals
[] =
227 /* Main routine of ospf6d. Treatment of argument and starting ospf finite
228 state machine is handled here. */
230 main (int argc
, char *argv
[], char *envp
[])
234 char *vty_addr
= NULL
;
236 char *config_file
= NULL
;
237 struct thread thread
;
240 /* Set umask before anything for security */
243 /* Preserve name of myself. */
244 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
246 /* Seed random number for LSA ID */
247 srandom (time(NULL
));
249 /* Command line argument treatment. */
252 opt
= getopt_long (argc
, argv
, "df:i:z:hp:A:P:u:g:vC", longopts
, 0);
265 config_file
= optarg
;
274 zclient_serv_path_set (optarg
);
277 /* Deal with atoi() returning 0 on failure, and ospf6d not
278 listening on ospf6d port... */
279 if (strcmp(optarg
, "0") == 0)
284 vty_port
= atoi (optarg
);
285 if (vty_port
<= 0 || vty_port
> 0xffff)
286 vty_port
= OSPF6_VTY_PORT
;
289 ospf6d_privs
.user
= optarg
;
292 ospf6d_privs
.group
= optarg
;
295 print_version (progname
);
318 master
= thread_master_create ();
320 /* Initializations. */
321 zlog_default
= openzlog (progname
, ZLOG_OSPF6
, 0,
322 LOG_CONS
|LOG_NDELAY
|LOG_PID
,
324 zprivs_init (&ospf6d_privs
);
325 #if defined(HAVE_CUMULUS)
326 zlog_set_level (NULL
, ZLOG_DEST_SYSLOG
, zlog_default
->default_lvl
);
329 /* initialize zebra libraries */
330 signal_init (master
, array_size(ospf6_signals
), ospf6_signals
);
338 /* initialize ospf6 */
341 /* parse config file */
342 vty_read_config (config_file
, config_default
);
344 /* Start execution only if not in dry-run mode */
348 if (daemon_mode
&& daemon (0, 0) < 0)
350 zlog_err("OSPF6d daemon failed: %s", strerror(errno
));
354 /* pid file create */
355 pid_output (pid_file
);
357 /* Make ospf6 vty socket. */
359 vty_port
= OSPF6_VTY_PORT
;
360 vty_serv_sock (vty_addr
, vty_port
, OSPF6_VTYSH_PATH
);
362 /* Print start message */
363 zlog_notice ("OSPF6d (Quagga-%s ospf6d-%s) starts: vty@%d",
364 FRR_VERSION
, OSPF6_DAEMON_VERSION
,vty_port
);
366 /* Start finite state machine, here we go! */
367 while (thread_fetch (master
, &thread
))
368 thread_call (&thread
);
370 /* Log in case thread failed */
371 zlog_warn ("Thread failed");