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>
44 #include "ospfd/ospfd.h"
45 #include "ospfd/ospf_interface.h"
46 #include "ospfd/ospf_asbr.h"
47 #include "ospfd/ospf_lsa.h"
48 #include "ospfd/ospf_lsdb.h"
49 #include "ospfd/ospf_neighbor.h"
50 #include "ospfd/ospf_dump.h"
51 #include "ospfd/ospf_zebra.h"
52 #include "ospfd/ospf_vty.h"
53 #include "ospfd/ospf_bfd.h"
55 /* ospfd privileges */
56 zebra_capabilities_t _caps_p
[] =
63 struct zebra_privs_t ospfd_privs
=
65 #if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
67 .group
= QUAGGA_GROUP
,
69 #if defined(VTY_GROUP)
70 .vty_group
= VTY_GROUP
,
73 .cap_num_p
= array_size(_caps_p
),
77 /* Configuration filename and directory. */
78 char config_default
[100];
81 struct option longopts
[] =
83 { "daemon", no_argument
, NULL
, 'd'},
84 { "instance", required_argument
, NULL
, 'n'},
85 { "config_file", required_argument
, NULL
, 'f'},
86 { "pid_file", required_argument
, NULL
, 'i'},
87 { "socket", required_argument
, NULL
, 'z'},
88 { "dryrun", no_argument
, NULL
, 'C'},
89 { "help", no_argument
, NULL
, 'h'},
90 { "vty_addr", required_argument
, NULL
, 'A'},
91 { "vty_port", required_argument
, NULL
, 'P'},
92 { "user", required_argument
, NULL
, 'u'},
93 { "group", required_argument
, NULL
, 'g'},
94 { "apiserver", no_argument
, NULL
, 'a'},
95 { "version", no_argument
, NULL
, 'v'},
99 /* OSPFd program name */
101 /* Master of threads. */
102 struct thread_master
*master
;
104 /* Process ID saved for use by init system */
107 #ifdef SUPPORT_OSPF_API
108 extern int ospf_apiserver_enable
;
109 #endif /* SUPPORT_OSPF_API */
111 /* Help information display. */
112 static void __attribute__ ((noreturn
))
113 usage (char *progname
, int status
)
116 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
119 printf ("Usage : %s [OPTION...]\n\
120 Daemon which manages OSPF.\n\n\
121 -d, --daemon Runs in daemon mode\n\
122 -n, --instance Set the instance id\n\
123 -f, --config_file Set configuration file name\n\
124 -i, --pid_file Set process identifier file name\n\
125 -z, --socket Set path of zebra socket\n\
126 -A, --vty_addr Set vty's bind address\n\
127 -P, --vty_port Set vty's port number\n\
128 -u, --user User to run as\n\
129 -g, --group Group to run as\n\
130 -a. --apiserver Enable OSPF apiserver\n\
131 -v, --version Print program version\n\
132 -C, --dryrun Check configuration for validity and exit\n\
133 -h, --help Display this help and exit\n\
135 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
140 /* SIGHUP handler. */
144 zlog (NULL
, LOG_INFO
, "SIGHUP received");
147 /* SIGINT / SIGTERM handler. */
151 zlog_notice ("Terminating on signal");
155 /* SIGUSR1 handler. */
162 struct quagga_signal_t ospf_signals
[] =
182 /* OSPFd main routine. */
184 main (int argc
, char **argv
)
187 char *vty_addr
= NULL
;
188 int vty_port
= OSPF_VTY_PORT
;
191 char *config_file
= NULL
;
193 u_short instance
= 0;
194 struct thread thread
;
197 /* Set umask before anything for security */
200 #ifdef SUPPORT_OSPF_API
201 /* OSPF apiserver is disabled by default. */
202 ospf_apiserver_enable
= 0;
203 #endif /* SUPPORT_OSPF_API */
205 /* get program name */
206 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
212 opt
= getopt_long (argc
, argv
, "df:i:n:z:hA:P:u:g:avC", longopts
, 0);
220 instance
= atoi(optarg
);
230 config_file
= optarg
;
236 strcpy(pid_file
,optarg
);
239 zclient_serv_path_set (optarg
);
242 /* Deal with atoi() returning 0 on failure, and ospfd not
243 listening on ospfd port... */
244 if (strcmp(optarg
, "0") == 0)
249 vty_port
= atoi (optarg
);
250 if (vty_port
<= 0 || vty_port
> 0xffff)
251 vty_port
= OSPF_VTY_PORT
;
254 ospfd_privs
.user
= optarg
;
257 ospfd_privs
.group
= optarg
;
259 #ifdef SUPPORT_OSPF_API
261 ospf_apiserver_enable
= 1;
263 #endif /* SUPPORT_OSPF_API */
265 print_version (progname
);
280 /* Invoked by a priviledged user? -- endo. */
288 zlog_default
= openzlog (progname
, ZLOG_OSPF
, instance
,
289 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
291 /* OSPF master init. */
294 /* Initializations. */
298 zprivs_init (&ospfd_privs
);
299 signal_init (master
, array_size(ospf_signals
), ospf_signals
);
311 ospf_zebra_init(master
, instance
);
313 /* OSPF vty inits. */
315 ospf_vty_show_init ();
316 ospf_vty_clear_init ();
321 ospf_route_map_init ();
324 #endif /* HAVE_SNMP */
325 #ifdef HAVE_OPAQUE_LSA
327 #endif /* HAVE_OPAQUE_LSA */
329 /* Need to initialize the default ospf structure, so the interface mode
330 commands can be duly processed if they are received before 'router ospf',
331 when quagga(ospfd) is restarted */
332 if (!ospf_get_instance(instance
))
334 zlog_err("OSPF instance init failed: %s", strerror(errno
));
338 /* Get configuration file. */
340 sprintf(config_default
, "%sospfd-%d.conf", SYSCONFDIR
, instance
);
342 sprintf(config_default
, "%s%s", SYSCONFDIR
, OSPF_DEFAULT_CONFIG
);
343 vty_read_config (config_file
, config_default
);
345 /* Start execution only if not in dry-run mode */
349 /* Change to the daemon program. */
350 if (daemon_mode
&& daemon (0, 0) < 0)
352 zlog_err("OSPFd daemon failed: %s", strerror(errno
));
356 /* Create VTY socket */
359 sprintf(pid_file
, "/var/run/quagga/ospfd-%d.pid", instance
);
360 sprintf(vty_path
, "/var/run/quagga/ospfd-%d.vty", instance
);
364 strcpy(pid_file
, PATH_OSPFD_PID
);
365 strcpy(vty_path
, OSPF_VTYSH_PATH
);
367 /* Process id file create. */
368 pid_output (pid_file
);
370 vty_serv_sock (vty_addr
, vty_port
, vty_path
);
373 zlog_notice ("OSPFd %s starting: vty@%d, %s", QUAGGA_VERSION
, vty_port
, vty_path
);
375 /* Fetch next active thread. */
376 while (thread_fetch (master
, &thread
))
377 thread_call (&thread
);