3 * Copyright (C) 1998, 99 Kunihiro Ishiguro, Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
40 #include "ospfd/ospfd.h"
41 #include "ospfd/ospf_interface.h"
42 #include "ospfd/ospf_asbr.h"
43 #include "ospfd/ospf_lsa.h"
44 #include "ospfd/ospf_lsdb.h"
45 #include "ospfd/ospf_neighbor.h"
46 #include "ospfd/ospf_dump.h"
47 #include "ospfd/ospf_zebra.h"
48 #include "ospfd/ospf_vty.h"
50 /* Configuration filename and directory. */
51 char config_current
[] = OSPF_DEFAULT_CONFIG
;
52 char config_default
[] = SYSCONFDIR OSPF_DEFAULT_CONFIG
;
55 struct option longopts
[] =
57 { "daemon", no_argument
, NULL
, 'd'},
58 { "config_file", required_argument
, NULL
, 'f'},
59 { "pid_file", required_argument
, NULL
, 'i'},
60 { "log_mode", no_argument
, NULL
, 'l'},
61 { "help", no_argument
, NULL
, 'h'},
62 { "vty_addr", required_argument
, NULL
, 'A'},
63 { "vty_port", required_argument
, NULL
, 'P'},
64 { "version", no_argument
, NULL
, 'v'},
68 /* OSPFd program name */
70 /* Master of threads. */
71 struct thread_master
*master
;
73 /* Process ID saved for use by init system */
74 char *pid_file
= PATH_OSPFD_PID
;
76 /* Help information display. */
78 usage (char *progname
, int status
)
81 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
84 printf ("Usage : %s [OPTION...]\n\
85 Daemon which manages OSPF.\n\n\
86 -d, --daemon Runs in daemon mode\n\
87 -f, --config_file Set configuration file name\n\
88 -i, --pid_file Set process identifier file name\n\
89 -A, --vty_addr Set vty's bind address\n\
90 -P, --vty_port Set vty's port number\n\
91 -v, --version Print program version\n\
92 -h, --help Display this help and exit\n\
94 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
103 zlog (NULL
, LOG_INFO
, "SIGHUP received");
106 /* SIGINT handler. */
110 zlog (NULL
, LOG_INFO
, "Terminating on signal");
117 /* SIGUSR1 handler. */
124 /* Signal wrapper. */
126 signal_set (int signo
, void (*func
)(int))
129 struct sigaction sig
;
130 struct sigaction osig
;
132 sig
.sa_handler
= func
;
133 sigemptyset (&sig
.sa_mask
);
136 sig
.sa_flags
|= SA_RESTART
;
137 #endif /* SA_RESTART */
139 ret
= sigaction (signo
, &sig
, &osig
);
144 return (osig
.sa_handler
);
147 /* Initialization of signal handles. */
151 signal_set (SIGHUP
, sighup
);
152 signal_set (SIGINT
, sigint
);
153 signal_set (SIGTERM
, sigint
);
154 signal_set (SIGPIPE
, SIG_IGN
);
156 signal_set (SIGTSTP
, SIG_IGN
);
159 signal_set (SIGTTIN
, SIG_IGN
);
162 signal_set (SIGTTOU
, SIG_IGN
);
164 signal_set (SIGUSR1
, sigusr1
);
167 /* OSPFd main routine. */
169 main (int argc
, char **argv
)
172 char *vty_addr
= NULL
;
173 int vty_port
= OSPF_VTY_PORT
;
175 char *config_file
= NULL
;
177 struct thread thread
;
179 /* Set umask before anything for security */
182 /* get program name */
183 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
185 /* Invoked by a priviledged user? -- endo. */
193 zlog_default
= openzlog (progname
, ZLOG_NOLOG
, ZLOG_OSPF
,
194 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
200 opt
= getopt_long (argc
, argv
, "dlf:hA:P:v", longopts
, 0);
213 config_file
= optarg
;
222 /* Deal with atoi() returning 0 on failure, and ospfd not
223 listening on ospfd port... */
224 if (strcmp(optarg
, "0") == 0)
229 vty_port
= atoi (optarg
);
230 vty_port
= (vty_port
? vty_port
: OSPF_VTY_PORT
);
233 print_version (progname
);
245 /* Initializations. */
246 master
= thread_master_create ();
263 /* OSPF vty inits. */
265 ospf_vty_show_init ();
267 ospf_route_map_init ();
270 #endif /* HAVE_SNMP */
271 #ifdef HAVE_OPAQUE_LSA
273 #endif /* HAVE_OPAQUE_LSA */
277 /* Get configuration file. */
278 vty_read_config (config_file
, config_current
, config_default
);
280 /* Change to the daemon program. */
284 /* Process id file create. */
285 pid_output (pid_file
);
287 /* Create VTY socket */
288 vty_serv_sock (vty_addr
, vty_port
, OSPF_VTYSH_PATH
);
291 zlog (NULL
, LOG_INFO
, "OSPFd (%s) starts", ZEBRA_VERSION
);
293 /* Fetch next active thread. */
294 while (thread_fetch (master
, &thread
))
295 thread_call (&thread
);