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
25 #include <lib/version.h>
43 #include "ospfd/ospfd.h"
44 #include "ospfd/ospf_interface.h"
45 #include "ospfd/ospf_asbr.h"
46 #include "ospfd/ospf_lsa.h"
47 #include "ospfd/ospf_lsdb.h"
48 #include "ospfd/ospf_neighbor.h"
49 #include "ospfd/ospf_dump.h"
50 #include "ospfd/ospf_zebra.h"
51 #include "ospfd/ospf_vty.h"
53 /* ospfd privileges */
54 zebra_capabilities_t _caps_p
[] =
61 struct zebra_privs_t ospfd_privs
=
63 #if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
65 .group
= QUAGGA_GROUP
,
67 #if defined(VTY_GROUP)
68 .vty_group
= VTY_GROUP
,
71 .cap_num_p
= array_size(_caps_p
),
75 /* Configuration filename and directory. */
76 char config_default
[] = SYSCONFDIR OSPF_DEFAULT_CONFIG
;
79 struct option longopts
[] =
81 { "daemon", no_argument
, NULL
, 'd'},
82 { "config_file", required_argument
, NULL
, 'f'},
83 { "pid_file", required_argument
, NULL
, 'i'},
84 { "socket", required_argument
, NULL
, 'z'},
85 { "dryrun", no_argument
, NULL
, 'C'},
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 { "group", required_argument
, NULL
, 'g'},
91 { "apiserver", no_argument
, NULL
, 'a'},
92 { "version", no_argument
, NULL
, 'v'},
96 /* OSPFd program name */
98 /* Master of threads. */
99 struct thread_master
*master
;
101 /* Process ID saved for use by init system */
102 const char *pid_file
= PATH_OSPFD_PID
;
104 #ifdef SUPPORT_OSPF_API
105 extern int ospf_apiserver_enable
;
106 #endif /* SUPPORT_OSPF_API */
108 /* Help information display. */
109 static void __attribute__ ((noreturn
))
110 usage (char *progname
, int status
)
113 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
116 printf ("Usage : %s [OPTION...]\n\
117 Daemon which manages OSPF.\n\n\
118 -d, --daemon Runs in daemon mode\n\
119 -f, --config_file Set configuration file name\n\
120 -i, --pid_file Set process identifier file name\n\
121 -z, --socket Set path of zebra socket\n\
122 -A, --vty_addr Set vty's bind address\n\
123 -P, --vty_port Set vty's port number\n\
124 -u, --user User to run as\n\
125 -g, --group Group to run as\n\
126 -a. --apiserver Enable OSPF apiserver\n\
127 -v, --version Print program version\n\
128 -C, --dryrun Check configuration for validity and exit\n\
129 -h, --help Display this help and exit\n\
131 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
136 /* SIGHUP handler. */
140 zlog (NULL
, LOG_INFO
, "SIGHUP received");
143 /* SIGINT / SIGTERM handler. */
147 zlog_notice ("Terminating on signal");
151 /* SIGUSR1 handler. */
158 struct quagga_signal_t ospf_signals
[] =
178 /* OSPFd main routine. */
180 main (int argc
, char **argv
)
183 char *vty_addr
= NULL
;
184 int vty_port
= OSPF_VTY_PORT
;
186 char *config_file
= NULL
;
188 struct thread thread
;
191 /* Set umask before anything for security */
194 #ifdef SUPPORT_OSPF_API
195 /* OSPF apiserver is disabled by default. */
196 ospf_apiserver_enable
= 0;
197 #endif /* SUPPORT_OSPF_API */
199 /* get program name */
200 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
206 opt
= getopt_long (argc
, argv
, "df:i:z:hA:P:u:g:avC", longopts
, 0);
219 config_file
= optarg
;
228 zclient_serv_path_set (optarg
);
231 /* Deal with atoi() returning 0 on failure, and ospfd not
232 listening on ospfd port... */
233 if (strcmp(optarg
, "0") == 0)
238 vty_port
= atoi (optarg
);
239 if (vty_port
<= 0 || vty_port
> 0xffff)
240 vty_port
= OSPF_VTY_PORT
;
243 ospfd_privs
.user
= optarg
;
246 ospfd_privs
.group
= optarg
;
248 #ifdef SUPPORT_OSPF_API
250 ospf_apiserver_enable
= 1;
252 #endif /* SUPPORT_OSPF_API */
254 print_version (progname
);
269 /* Invoked by a priviledged user? -- endo. */
277 zlog_default
= openzlog (progname
, ZLOG_OSPF
,
278 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
280 /* OSPF master init. */
283 /* Initializations. */
287 zprivs_init (&ospfd_privs
);
288 signal_init (master
, array_size(ospf_signals
), ospf_signals
);
301 /* OSPF vty inits. */
303 ospf_vty_show_init ();
305 ospf_route_map_init ();
308 #endif /* HAVE_SNMP */
309 #ifdef HAVE_OPAQUE_LSA
311 #endif /* HAVE_OPAQUE_LSA */
313 /* Need to initialize the default ospf structure, so the interface mode
314 commands can be duly processed if they are received before 'router ospf',
315 when quagga(ospfd) is restarted */
318 zlog_err("OSPF instance init failed: %s", strerror(errno
));
322 /* Get configuration file. */
323 vty_read_config (config_file
, config_default
);
325 /* Start execution only if not in dry-run mode */
329 /* Change to the daemon program. */
330 if (daemon_mode
&& daemon (0, 0) < 0)
332 zlog_err("OSPFd daemon failed: %s", strerror(errno
));
336 /* Process id file create. */
337 pid_output (pid_file
);
339 /* Create VTY socket */
340 vty_serv_sock (vty_addr
, vty_port
, OSPF_VTYSH_PATH
);
343 zlog_notice ("OSPFd %s starting: vty@%d", QUAGGA_VERSION
, vty_port
);
345 /* Fetch next active thread. */
346 while (thread_fetch (master
, &thread
))
347 thread_call (&thread
);