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.
38 /* Default configuration file name for ospf6d. */
39 #define OSPF6_DEFAULT_CONFIG "ospf6d.conf"
41 /* Default port values. */
42 #define OSPF6_VTY_PORT 2606
43 #define OSPF6_VTYSH_PATH "/tmp/.ospf6d"
45 /* ospf6d options, we use GNU getopt library. */
46 struct option longopts
[] =
48 { "daemon", no_argument
, NULL
, 'd'},
49 { "config_file", required_argument
, NULL
, 'f'},
50 { "pid_file", required_argument
, NULL
, 'i'},
51 { "vty_addr", required_argument
, NULL
, 'A'},
52 { "vty_port", required_argument
, NULL
, 'P'},
53 { "version", no_argument
, NULL
, 'v'},
54 { "help", no_argument
, NULL
, 'h'},
58 /* Configuration file and directory. */
59 char config_current
[] = OSPF6_DEFAULT_CONFIG
;
60 char config_default
[] = SYSCONFDIR OSPF6_DEFAULT_CONFIG
;
62 /* ospf6d program name. */
68 /* Master of threads. */
69 struct thread_master
*master
;
71 /* Process ID saved for use by init system */
72 char *pid_file
= PATH_OSPF6D_PID
;
74 /* Help information display. */
76 usage (char *progname
, int status
)
79 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
82 printf ("Usage : %s [OPTION...]\n\n\
83 Daemon which manages OSPF version 3.\n\n\
84 -d, --daemon Runs in daemon mode\n\
85 -f, --config_file Set configuration file name\n\
86 -i, --pid_file Set process identifier file name\n\
87 -A, --vty_addr Set vty's bind address\n\
88 -P, --vty_port Set vty's port number\n\
89 -v, --version Print program version\n\
90 -h, --help Display this help and exit\n\
92 Report bugs to zebra@zebra.org\n", progname
);
102 zlog_info ("SIGHUP received");
105 /* SIGINT handler. */
109 zlog_info ("SIGINT received");
113 /* SIGTERM handler. */
117 zlog_info ("SIGTERM received");
121 /* SIGUSR1 handler. */
125 zlog_info ("SIGUSR1 received");
129 /* Signale wrapper. */
131 signal_set (int signo
, void (*func
)(int))
134 struct sigaction sig
;
135 struct sigaction osig
;
137 sig
.sa_handler
= func
;
138 sigemptyset (&sig
.sa_mask
);
141 sig
.sa_flags
|= SA_RESTART
;
142 #endif /* SA_RESTART */
144 ret
= sigaction (signo
, &sig
, &osig
);
149 return (osig
.sa_handler
);
152 /* Initialization of signal handles. */
156 signal_set (SIGHUP
, sighup
);
157 signal_set (SIGINT
, sigint
);
158 signal_set (SIGTERM
, sigterm
);
159 signal_set (SIGPIPE
, SIG_IGN
);
161 signal_set (SIGTSTP
, SIG_IGN
);
164 signal_set (SIGTTIN
, SIG_IGN
);
167 signal_set (SIGTTOU
, SIG_IGN
);
169 signal_set (SIGUSR1
, sigusr1
);
172 /* Main routine of ospf6d. Treatment of argument and starting ospf finite
173 state machine is handled here. */
175 main (int argc
, char *argv
[], char *envp
[])
179 char *vty_addr
= NULL
;
181 char *config_file
= NULL
;
182 struct thread thread
;
185 /* Set umask before anything for security */
188 /* Preserve name of myself. */
189 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
191 /* Command line argument treatment. */
194 opt
= getopt_long (argc
, argv
, "df:hp:A:P:v", longopts
, 0);
207 config_file
= optarg
;
216 vty_port
= atoi (optarg
);
219 print_version (progname
);
232 master
= thread_master_create ();
234 /* Initializations. */
240 zlog_default
= openzlog (progname
, flag
, ZLOG_OSPF6
,
241 LOG_CONS
|LOG_NDELAY
|LOG_PERROR
|LOG_PID
,
244 /* initialize zebra libraries */
253 /* initialize ospf6 */
256 /* sort command vector */
259 /* parse config file */
260 vty_read_config (config_file
, config_current
, config_default
);
265 /* pid file create */
267 pid_output_lock (pid_file
);
269 pid_output (pid_file
);
272 /* Make ospf6 vty socket. */
273 vty_serv_sock (vty_addr
,
274 vty_port
? vty_port
: OSPF6_VTY_PORT
, OSPF6_VTYSH_PATH
);
276 /* Print start message */
277 zlog_notice ("OSPF6d (Zebra-%s ospf6d-%s) starts",
278 ZEBRA_VERSION
, OSPF6_DAEMON_VERSION
);
280 /* Start finite state machine, here we go! */
281 while (thread_fetch (master
, &thread
))
282 thread_call (&thread
);
284 /* Log in case thread failed */
285 zlog_warn ("Thread failed");