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>
39 #include "memory_vty.h"
45 #include "ospfd/ospfd.h"
46 #include "ospfd/ospf_interface.h"
47 #include "ospfd/ospf_asbr.h"
48 #include "ospfd/ospf_lsa.h"
49 #include "ospfd/ospf_lsdb.h"
50 #include "ospfd/ospf_neighbor.h"
51 #include "ospfd/ospf_dump.h"
52 #include "ospfd/ospf_zebra.h"
53 #include "ospfd/ospf_vty.h"
54 #include "ospfd/ospf_bfd.h"
56 /* ospfd privileges */
57 zebra_capabilities_t _caps_p
[] =
64 struct zebra_privs_t ospfd_privs
=
66 #if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
68 .group
= QUAGGA_GROUP
,
70 #if defined(VTY_GROUP)
71 .vty_group
= VTY_GROUP
,
74 .cap_num_p
= array_size(_caps_p
),
78 /* Configuration filename and directory. */
79 char config_default
[100];
82 struct option longopts
[] =
84 { "daemon", no_argument
, NULL
, 'd'},
85 { "instance", required_argument
, NULL
, 'n'},
86 { "config_file", required_argument
, NULL
, 'f'},
87 { "pid_file", required_argument
, NULL
, 'i'},
88 { "socket", required_argument
, NULL
, 'z'},
89 { "dryrun", no_argument
, NULL
, 'C'},
90 { "help", no_argument
, NULL
, 'h'},
91 { "vty_addr", required_argument
, NULL
, 'A'},
92 { "vty_port", required_argument
, NULL
, 'P'},
93 { "user", required_argument
, NULL
, 'u'},
94 { "group", required_argument
, NULL
, 'g'},
95 { "apiserver", no_argument
, NULL
, 'a'},
96 { "version", no_argument
, NULL
, 'v'},
100 /* OSPFd program name */
102 /* Master of threads. */
103 struct thread_master
*master
;
105 /* Process ID saved for use by init system */
108 #ifdef SUPPORT_OSPF_API
109 extern int ospf_apiserver_enable
;
110 #endif /* SUPPORT_OSPF_API */
112 /* Help information display. */
113 static void __attribute__ ((noreturn
))
114 usage (char *progname
, int status
)
117 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
120 printf ("Usage : %s [OPTION...]\n\
121 Daemon which manages OSPF.\n\n\
122 -d, --daemon Runs in daemon mode\n\
123 -n, --instance Set the instance id\n\
124 -f, --config_file Set configuration file name\n\
125 -i, --pid_file Set process identifier file name\n\
126 -z, --socket Set path of zebra socket\n\
127 -A, --vty_addr Set vty's bind address\n\
128 -P, --vty_port Set vty's port number\n\
129 -u, --user User to run as\n\
130 -g, --group Group to run as\n\
131 -a. --apiserver Enable OSPF apiserver\n\
132 -v, --version Print program version\n\
133 -C, --dryrun Check configuration for validity and exit\n\
134 -h, --help Display this help and exit\n\
136 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
141 /* SIGHUP handler. */
145 zlog (NULL
, LOG_INFO
, "SIGHUP received");
148 /* SIGINT / SIGTERM handler. */
152 zlog_notice ("Terminating on signal");
156 /* SIGUSR1 handler. */
163 struct quagga_signal_t ospf_signals
[] =
183 /* OSPFd main routine. */
185 main (int argc
, char **argv
)
188 char *vty_addr
= NULL
;
189 int vty_port
= OSPF_VTY_PORT
;
192 char *config_file
= NULL
;
194 u_short instance
= 0;
195 struct thread thread
;
198 /* Set umask before anything for security */
201 #ifdef SUPPORT_OSPF_API
202 /* OSPF apiserver is disabled by default. */
203 ospf_apiserver_enable
= 0;
204 #endif /* SUPPORT_OSPF_API */
206 /* get program name */
207 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
213 opt
= getopt_long (argc
, argv
, "df:i:n:z:hA:P:u:g:avC", longopts
, 0);
221 instance
= atoi(optarg
);
231 config_file
= optarg
;
237 strcpy(pid_file
,optarg
);
240 zclient_serv_path_set (optarg
);
243 /* Deal with atoi() returning 0 on failure, and ospfd not
244 listening on ospfd port... */
245 if (strcmp(optarg
, "0") == 0)
250 vty_port
= atoi (optarg
);
251 if (vty_port
<= 0 || vty_port
> 0xffff)
252 vty_port
= OSPF_VTY_PORT
;
255 ospfd_privs
.user
= optarg
;
258 ospfd_privs
.group
= optarg
;
260 #ifdef SUPPORT_OSPF_API
262 ospf_apiserver_enable
= 1;
264 #endif /* SUPPORT_OSPF_API */
266 print_version (progname
);
281 /* Invoked by a priviledged user? -- endo. */
289 zlog_default
= openzlog (progname
, ZLOG_OSPF
, instance
,
290 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
291 zprivs_init (&ospfd_privs
);
292 #if defined(HAVE_CUMULUS)
293 zlog_set_level (NULL
, ZLOG_DEST_SYSLOG
, zlog_default
->default_lvl
);
296 /* OSPF master init. */
299 /* Initializations. */
303 signal_init (master
, array_size(ospf_signals
), ospf_signals
);
315 ospf_zebra_init(master
, instance
);
317 /* OSPF vty inits. */
319 ospf_vty_show_init ();
320 ospf_vty_clear_init ();
325 ospf_route_map_init ();
328 #endif /* HAVE_SNMP */
331 /* Need to initialize the default ospf structure, so the interface mode
332 commands can be duly processed if they are received before 'router ospf',
333 when quagga(ospfd) is restarted */
334 if (!ospf_get_instance(instance
))
336 zlog_err("OSPF instance init failed: %s", strerror(errno
));
340 /* Get configuration file. */
342 sprintf(config_default
, "%sospfd-%d.conf", SYSCONFDIR
, instance
);
344 sprintf(config_default
, "%s%s", SYSCONFDIR
, OSPF_DEFAULT_CONFIG
);
345 vty_read_config (config_file
, config_default
);
347 /* Start execution only if not in dry-run mode */
351 /* Change to the daemon program. */
352 if (daemon_mode
&& daemon (0, 0) < 0)
354 zlog_err("OSPFd daemon failed: %s", strerror(errno
));
358 /* Create VTY socket */
361 sprintf(pid_file
, "/var/run/quagga/ospfd-%d.pid", instance
);
362 sprintf(vty_path
, "/var/run/quagga/ospfd-%d.vty", instance
);
366 strcpy(pid_file
, PATH_OSPFD_PID
);
367 strcpy(vty_path
, OSPF_VTYSH_PATH
);
369 /* Process id file create. */
370 pid_output (pid_file
);
372 vty_serv_sock (vty_addr
, vty_port
, vty_path
);
375 zlog_notice ("OSPFd %s starting: vty@%d, %s", QUAGGA_VERSION
, vty_port
, vty_path
);
377 /* Fetch next active thread. */
378 while (thread_fetch (master
, &thread
))
379 thread_call (&thread
);