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
42 #include "ospfd/ospfd.h"
43 #include "ospfd/ospf_interface.h"
44 #include "ospfd/ospf_asbr.h"
45 #include "ospfd/ospf_lsa.h"
46 #include "ospfd/ospf_lsdb.h"
47 #include "ospfd/ospf_neighbor.h"
48 #include "ospfd/ospf_dump.h"
49 #include "ospfd/ospf_zebra.h"
50 #include "ospfd/ospf_vty.h"
52 /* ospfd privileges */
53 zebra_capabilities_t _caps_p
[] =
61 struct zebra_privs_t ospfd_privs
=
63 #if defined(ZEBRA_USER) && defined(ZEBRA_GROUP)
67 #if defined(VTY_GROUP)
68 .vty_group
= VTY_GROUP
,
71 .cap_num_p
= sizeof(_caps_p
)/sizeof(_caps_p
[0]),
75 /* Configuration filename and directory. */
76 char config_current
[] = OSPF_DEFAULT_CONFIG
;
77 char config_default
[] = SYSCONFDIR OSPF_DEFAULT_CONFIG
;
80 struct option longopts
[] =
82 { "daemon", no_argument
, NULL
, 'd'},
83 { "config_file", required_argument
, NULL
, 'f'},
84 { "pid_file", required_argument
, NULL
, 'i'},
85 { "log_mode", no_argument
, NULL
, 'l'},
86 { "help", no_argument
, NULL
, 'h'},
87 { "vty_addr", required_argument
, NULL
, 'A'},
88 { "vty_port", required_argument
, NULL
, 'P'},
89 { "user", required_argument
, NULL
, 'u'},
90 { "version", no_argument
, NULL
, 'v'},
94 /* OSPFd program name */
96 /* Master of threads. */
97 struct thread_master
*master
;
99 /* Process ID saved for use by init system */
100 char *pid_file
= PATH_OSPFD_PID
;
102 /* Help information display. */
104 usage (char *progname
, int status
)
107 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
110 printf ("Usage : %s [OPTION...]\n\
111 Daemon which manages OSPF.\n\n\
112 -d, --daemon Runs in daemon mode\n\
113 -f, --config_file Set configuration file name\n\
114 -i, --pid_file Set process identifier file name\n\
115 -A, --vty_addr Set vty's bind address\n\
116 -P, --vty_port Set vty's port number\n\
117 -u, --user User and group to run as\n\
118 -v, --version Print program version\n\
119 -h, --help Display this help and exit\n\
121 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
126 /* SIGHUP handler. */
130 zlog (NULL
, LOG_INFO
, "SIGHUP received");
133 /* SIGINT handler. */
137 zlog (NULL
, LOG_INFO
, "Terminating on signal");
144 /* SIGUSR1 handler. */
151 /* Signal wrapper. */
153 signal_set (int signo
, void (*func
)(int))
156 struct sigaction sig
;
157 struct sigaction osig
;
159 sig
.sa_handler
= func
;
160 sigemptyset (&sig
.sa_mask
);
163 sig
.sa_flags
|= SA_RESTART
;
164 #endif /* SA_RESTART */
166 ret
= sigaction (signo
, &sig
, &osig
);
171 return (osig
.sa_handler
);
174 /* Initialization of signal handles. */
178 signal_set (SIGHUP
, sighup
);
179 signal_set (SIGINT
, sigint
);
180 signal_set (SIGTERM
, sigint
);
181 signal_set (SIGPIPE
, SIG_IGN
);
183 signal_set (SIGTSTP
, SIG_IGN
);
186 signal_set (SIGTTIN
, SIG_IGN
);
189 signal_set (SIGTTOU
, SIG_IGN
);
191 signal_set (SIGUSR1
, sigusr1
);
192 #ifdef HAVE_GLIBC_BACKTRACE
193 signal_set (SIGBUS
, debug_print_trace
);
194 signal_set (SIGSEGV
, debug_print_trace
);
195 signal_set (SIGILL
, debug_print_trace
);
196 #endif /* HAVE_GLIBC_BACKTRACE */
199 /* OSPFd main routine. */
201 main (int argc
, char **argv
)
204 char *vty_addr
= NULL
;
205 int vty_port
= OSPF_VTY_PORT
;
207 char *config_file
= NULL
;
209 struct thread thread
;
211 /* Set umask before anything for security */
214 /* get program name */
215 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
217 /* Invoked by a priviledged user? -- endo. */
225 zlog_default
= openzlog (progname
, ZLOG_NOLOG
, ZLOG_OSPF
,
226 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
228 /* OSPF master init. */
235 opt
= getopt_long (argc
, argv
, "dlf:hA:P:u:v", longopts
, 0);
248 config_file
= optarg
;
257 /* Deal with atoi() returning 0 on failure, and ospfd not
258 listening on ospfd port... */
259 if (strcmp(optarg
, "0") == 0)
264 vty_port
= atoi (optarg
);
265 vty_port
= (vty_port
? vty_port
: OSPF_VTY_PORT
);
268 ospfd_privs
.group
= ospfd_privs
.user
= optarg
;
271 print_version (progname
);
283 /* Initializations. */
287 zprivs_init (&ospfd_privs
);
302 /* OSPF vty inits. */
304 ospf_vty_show_init ();
306 ospf_route_map_init ();
309 #endif /* HAVE_SNMP */
310 #ifdef HAVE_OPAQUE_LSA
312 #endif /* HAVE_OPAQUE_LSA */
316 /* Get configuration file. */
317 vty_read_config (config_file
, config_current
, config_default
);
319 /* Change to the daemon program. */
323 /* Process id file create. */
324 pid_output (pid_file
);
326 /* Create VTY socket */
327 vty_serv_sock (vty_addr
, vty_port
, OSPF_VTYSH_PATH
);
331 zlog (NULL
, LOG_INFO
, "OSPFd (%s) starts", ZEBRA_VERSION
);
334 /* Fetch next active thread. */
335 while (thread_fetch (master
, &thread
))
336 thread_call (&thread
);