[lib] add mising UL qualifier to numerical constant
[jleu-quagga.git] / ospf6d / ospf6_main.c
blob8380bc89bdc3898910810d185798e311e714618f
1 /*
2 * Copyright (C) 1999 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include <zebra.h>
23 #include <lib/version.h>
25 #include "getopt.h"
26 #include "thread.h"
27 #include "log.h"
28 #include "command.h"
29 #include "vty.h"
30 #include "memory.h"
31 #include "if.h"
32 #include "filter.h"
33 #include "prefix.h"
34 #include "plist.h"
35 #include "privs.h"
36 #include "sigevent.h"
38 #include "ospf6d.h"
40 /* Default configuration file name for ospf6d. */
41 #define OSPF6_DEFAULT_CONFIG "ospf6d.conf"
43 /* Default port values. */
44 #define OSPF6_VTY_PORT 2606
46 /* ospf6d privileges */
47 zebra_capabilities_t _caps_p [] =
49 ZCAP_NET_RAW,
50 ZCAP_BIND
53 struct zebra_privs_t ospf6d_privs =
55 #if defined(QUAGGA_USER)
56 .user = QUAGGA_USER,
57 #endif
58 #if defined QUAGGA_GROUP
59 .group = QUAGGA_GROUP,
60 #endif
61 #ifdef VTY_GROUP
62 .vty_group = VTY_GROUP,
63 #endif
64 .caps_p = _caps_p,
65 .cap_num_p = 2,
66 .cap_num_i = 0
69 /* ospf6d options, we use GNU getopt library. */
70 struct option longopts[] =
72 { "daemon", no_argument, NULL, 'd'},
73 { "config_file", required_argument, NULL, 'f'},
74 { "pid_file", required_argument, NULL, 'i'},
75 { "vty_addr", required_argument, NULL, 'A'},
76 { "vty_port", required_argument, NULL, 'P'},
77 { "user", required_argument, NULL, 'u'},
78 { "group", required_argument, NULL, 'g'},
79 { "version", no_argument, NULL, 'v'},
80 { "dryrun", no_argument, NULL, 'C'},
81 { "help", no_argument, NULL, 'h'},
82 { 0 }
85 /* Configuration file and directory. */
86 char config_default[] = SYSCONFDIR OSPF6_DEFAULT_CONFIG;
88 /* ospf6d program name. */
89 char *progname;
91 /* is daemon? */
92 int daemon_mode = 0;
94 /* Master of threads. */
95 struct thread_master *master;
97 /* Process ID saved for use by init system */
98 const char *pid_file = PATH_OSPF6D_PID;
100 /* Help information display. */
101 static void
102 usage (char *progname, int status)
104 if (status != 0)
105 fprintf (stderr, "Try `%s --help' for more information.\n", progname);
106 else
108 printf ("Usage : %s [OPTION...]\n\n\
109 Daemon which manages OSPF version 3.\n\n\
110 -d, --daemon Runs in daemon mode\n\
111 -f, --config_file Set configuration file name\n\
112 -i, --pid_file Set process identifier file name\n\
113 -A, --vty_addr Set vty's bind address\n\
114 -P, --vty_port Set vty's port number\n\
115 -u, --user User to run as\n\
116 -g, --group Group to run as\n\
117 -v, --version Print program version\n\
118 -C, --dryrun Check configuration for validity and exit\n\
119 -h, --help Display this help and exit\n\
121 Report bugs to zebra@zebra.org\n", progname);
124 exit (status);
127 /* SIGHUP handler. */
128 void
129 sighup (void)
131 zlog_info ("SIGHUP received");
134 /* SIGINT handler. */
135 void
136 sigint (void)
138 zlog_notice ("Terminating on signal SIGINT");
139 exit (0);
142 /* SIGTERM handler. */
143 void
144 sigterm (void)
146 zlog_notice ("Terminating on signal SIGTERM");
147 exit (0);
150 /* SIGUSR1 handler. */
151 void
152 sigusr1 (void)
154 zlog_info ("SIGUSR1 received");
155 zlog_rotate (NULL);
158 struct quagga_signal_t ospf6_signals[] =
161 .signal = SIGHUP,
162 .handler = &sighup,
165 .signal = SIGINT,
166 .handler = &sigint,
169 .signal = SIGTERM,
170 .handler = &sigterm,
173 .signal = SIGUSR1,
174 .handler = &sigusr1,
178 /* Main routine of ospf6d. Treatment of argument and starting ospf finite
179 state machine is handled here. */
181 main (int argc, char *argv[], char *envp[])
183 char *p;
184 int opt;
185 char *vty_addr = NULL;
186 int vty_port = 0;
187 char *config_file = NULL;
188 struct thread thread;
189 int dryrun = 0;
191 /* Set umask before anything for security */
192 umask (0027);
194 /* Preserve name of myself. */
195 progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
197 /* Command line argument treatment. */
198 while (1)
200 opt = getopt_long (argc, argv, "df:i:hp:A:P:u:g:vC", longopts, 0);
202 if (opt == EOF)
203 break;
205 switch (opt)
207 case 0:
208 break;
209 case 'd':
210 daemon_mode = 1;
211 break;
212 case 'f':
213 config_file = optarg;
214 break;
215 case 'A':
216 vty_addr = optarg;
217 break;
218 case 'i':
219 pid_file = optarg;
220 break;
221 case 'P':
222 /* Deal with atoi() returning 0 on failure, and ospf6d not
223 listening on ospf6d port... */
224 if (strcmp(optarg, "0") == 0)
226 vty_port = 0;
227 break;
229 vty_port = atoi (optarg);
230 vty_port = (vty_port ? vty_port : OSPF6_VTY_PORT);
231 break;
232 case 'u':
233 ospf6d_privs.user = optarg;
234 break;
235 case 'g':
236 ospf6d_privs.group = optarg;
237 break;
238 case 'v':
239 print_version (progname);
240 exit (0);
241 break;
242 case 'C':
243 dryrun = 1;
244 break;
245 case 'h':
246 usage (progname, 0);
247 break;
248 default:
249 usage (progname, 1);
250 break;
254 /* thread master */
255 master = thread_master_create ();
257 /* Initializations. */
258 zlog_default = openzlog (progname, ZLOG_OSPF6,
259 LOG_CONS|LOG_NDELAY|LOG_PID,
260 LOG_DAEMON);
261 zprivs_init (&ospf6d_privs);
262 /* initialize zebra libraries */
263 signal_init (master, Q_SIGC(ospf6_signals), ospf6_signals);
264 cmd_init (1);
265 vty_init (master);
266 memory_init ();
267 if_init ();
268 access_list_init ();
269 prefix_list_init ();
271 /* initialize ospf6 */
272 ospf6_init ();
274 /* sort command vector */
275 sort_node ();
277 /* parse config file */
278 vty_read_config (config_file, config_default);
280 /* Start execution only if not in dry-run mode */
281 if (dryrun)
282 return(0);
284 if (daemon_mode)
285 daemon (0, 0);
287 /* pid file create */
288 pid_output (pid_file);
290 /* Make ospf6 vty socket. */
291 if (!vty_port)
292 vty_port = OSPF6_VTY_PORT;
293 vty_serv_sock (vty_addr, vty_port, OSPF6_VTYSH_PATH);
295 /* Print start message */
296 zlog_notice ("OSPF6d (Quagga-%s ospf6d-%s) starts: vty@%d",
297 QUAGGA_VERSION, OSPF6_DAEMON_VERSION,vty_port);
299 /* Start finite state machine, here we go! */
300 while (thread_fetch (master, &thread))
301 thread_call (&thread);
303 /* Log in case thread failed */
304 zlog_warn ("Thread failed");
306 /* Not reached. */
307 exit (0);