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"
45 #include "ospf6_top.h"
46 #include "ospf6_message.h"
47 #include "ospf6_asbr.h"
48 #include "ospf6_lsa.h"
49 #include "ospf6_interface.h"
50 #include "ospf6_zebra.h"
52 /* Default configuration file name for ospf6d. */
53 #define OSPF6_DEFAULT_CONFIG "ospf6d.conf"
55 /* VTY Socket prefix */
56 char vty_sock_path
[MAXPATHLEN
] = OSPF6_VTYSH_PATH
;
58 /* Default port values. */
59 #define OSPF6_VTY_PORT 2606
61 /* ospf6d privileges */
62 zebra_capabilities_t _caps_p
[] =
68 struct zebra_privs_t ospf6d_privs
=
77 .vty_group
= VTY_GROUP
,
84 /* ospf6d options, we use GNU getopt library. */
85 #define OPTION_VTYSOCK 1000
86 struct option longopts
[] =
88 { "daemon", no_argument
, NULL
, 'd'},
89 { "config_file", required_argument
, NULL
, 'f'},
90 { "pid_file", required_argument
, NULL
, 'i'},
91 { "socket", required_argument
, NULL
, 'z'},
92 { "vty_addr", required_argument
, NULL
, 'A'},
93 { "vty_port", required_argument
, NULL
, 'P'},
94 { "vty_socket", required_argument
, NULL
, OPTION_VTYSOCK
},
95 { "user", required_argument
, NULL
, 'u'},
96 { "group", required_argument
, NULL
, 'g'},
97 { "version", no_argument
, NULL
, 'v'},
98 { "dryrun", no_argument
, NULL
, 'C'},
99 { "help", no_argument
, NULL
, 'h'},
103 /* Configuration file and directory. */
104 char config_default
[] = SYSCONFDIR OSPF6_DEFAULT_CONFIG
;
106 /* ospf6d program name. */
112 /* Master of threads. */
113 struct thread_master
*master
;
115 /* Process ID saved for use by init system */
116 const char *pid_file
= PATH_OSPF6D_PID
;
118 /* Help information display. */
120 usage (char *progname
, int status
)
123 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
126 printf ("Usage : %s [OPTION...]\n\n\
127 Daemon which manages OSPF version 3.\n\n\
128 -d, --daemon Runs in daemon mode\n\
129 -f, --config_file Set configuration file name\n\
130 -i, --pid_file Set process identifier file name\n\
131 -z, --socket Set path of zebra socket\n\
132 -A, --vty_addr Set vty's bind address\n\
133 -P, --vty_port Set vty's port number\n\
134 --vty_socket Override vty socket path\n\
135 -u, --user User to run as\n\
136 -g, --group Group to run as\n\
137 -v, --version Print program version\n\
138 -C, --dryrun Check configuration for validity and exit\n\
139 -h, --help Display this help and exit\n\
141 Report bugs to %s\n", progname
, FRR_BUG_ADDRESS
);
147 static void __attribute__ ((noreturn
))
148 ospf6_exit (int status
)
150 struct listnode
*node
;
151 struct interface
*ifp
;
154 ospf6_delete (ospf6
);
158 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
159 if (ifp
->info
!= NULL
)
160 ospf6_interface_delete(ifp
->info
);
162 ospf6_message_terminate ();
163 ospf6_asbr_terminate ();
164 ospf6_lsa_terminate ();
171 zclient_free (zclient
);
174 thread_master_free (master
);
177 closezlog (zlog_default
);
182 /* SIGHUP handler. */
186 zlog_info ("SIGHUP received");
189 /* SIGINT handler. */
193 zlog_notice ("Terminating on signal SIGINT");
197 /* SIGTERM handler. */
201 zlog_notice ("Terminating on signal SIGTERM");
206 /* SIGUSR1 handler. */
210 zlog_info ("SIGUSR1 received");
214 struct quagga_signal_t ospf6_signals
[] =
234 /* Main routine of ospf6d. Treatment of argument and starting ospf finite
235 state machine is handled here. */
237 main (int argc
, char *argv
[], char *envp
[])
241 char *vty_addr
= NULL
;
243 char *config_file
= NULL
;
244 struct thread thread
;
247 /* Set umask before anything for security */
250 /* Preserve name of myself. */
251 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
253 /* Seed random number for LSA ID */
254 srandom (time(NULL
));
256 /* Command line argument treatment. */
259 opt
= getopt_long (argc
, argv
, "df:i:z:hp:A:P:u:g:vC", longopts
, 0);
272 config_file
= optarg
;
281 zclient_serv_path_set (optarg
);
284 /* Deal with atoi() returning 0 on failure, and ospf6d not
285 listening on ospf6d port... */
286 if (strcmp(optarg
, "0") == 0)
291 vty_port
= atoi (optarg
);
292 if (vty_port
<= 0 || vty_port
> 0xffff)
293 vty_port
= OSPF6_VTY_PORT
;
296 set_socket_path(vty_sock_path
, OSPF6_VTYSH_PATH
, optarg
, sizeof (vty_sock_path
));
299 ospf6d_privs
.user
= optarg
;
302 ospf6d_privs
.group
= optarg
;
305 print_version (progname
);
328 master
= thread_master_create ();
330 /* Initializations. */
331 zlog_default
= openzlog (progname
, ZLOG_OSPF6
, 0,
332 LOG_CONS
|LOG_NDELAY
|LOG_PID
,
334 zprivs_init (&ospf6d_privs
);
335 #if defined(HAVE_CUMULUS)
336 zlog_set_level (NULL
, ZLOG_DEST_SYSLOG
, zlog_default
->default_lvl
);
339 /* initialize zebra libraries */
340 signal_init (master
, array_size(ospf6_signals
), ospf6_signals
);
348 /* initialize ospf6 */
351 /* parse config file */
352 vty_read_config (config_file
, config_default
);
354 /* Start execution only if not in dry-run mode */
358 if (daemon_mode
&& daemon (0, 0) < 0)
360 zlog_err("OSPF6d daemon failed: %s", strerror(errno
));
364 /* pid file create */
365 pid_output (pid_file
);
367 /* Make ospf6 vty socket. */
369 vty_port
= OSPF6_VTY_PORT
;
370 vty_serv_sock (vty_addr
, vty_port
, vty_sock_path
);
372 /* Print start message */
373 zlog_notice ("OSPF6d (Quagga-%s ospf6d-%s) starts: vty@%d",
374 FRR_VERSION
, OSPF6_DAEMON_VERSION
,vty_port
);
376 /* Start finite state machine, here we go! */
377 while (thread_fetch (master
, &thread
))
378 thread_call (&thread
);
380 /* Log in case thread failed */
381 zlog_warn ("Thread failed");