1 /* zebra daemon main routine.
2 * Copyright (C) 1997, 98 Kunihiro Ishiguro
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
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 Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 #include <lib/version.h>
35 #include "zebra/rib.h"
36 #include "zebra/zserv.h"
37 #include "zebra/debug.h"
38 #include "zebra/rib.h"
39 #include "zebra/irdp.h"
42 struct zebra_t zebrad
=
44 .rtm_table_default
= 0,
51 /* Pacify zclient.o in libzebra, which expects this variable. */
52 struct thread_master
*master
;
54 /* Route retain mode flag. */
57 /* Don't delete kernel route. */
58 int keep_kernel_mode
= 0;
60 /* Command line options. */
61 struct option longopts
[] =
63 { "batch", no_argument
, NULL
, 'b'},
64 { "daemon", no_argument
, NULL
, 'd'},
65 { "keep_kernel", no_argument
, NULL
, 'k'},
66 { "log_mode", no_argument
, NULL
, 'l'},
67 { "config_file", required_argument
, NULL
, 'f'},
68 { "pid_file", required_argument
, NULL
, 'i'},
69 { "help", no_argument
, NULL
, 'h'},
70 { "vty_addr", required_argument
, NULL
, 'A'},
71 { "vty_port", required_argument
, NULL
, 'P'},
72 { "retain", no_argument
, NULL
, 'r'},
73 { "user", required_argument
, NULL
, 'u'},
74 { "version", no_argument
, NULL
, 'v'},
78 zebra_capabilities_t _caps_p
[] =
85 /* zebra privileges to run with */
86 struct zebra_privs_t zserv_privs
=
88 #if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
90 .group
= QUAGGA_GROUP
,
93 .vty_group
= VTY_GROUP
,
96 .cap_num_p
= sizeof(_caps_p
)/sizeof(_caps_p
[0]),
100 /* Default configuration file path. */
101 char config_default
[] = SYSCONFDIR DEFAULT_CONFIG_FILE
;
103 /* Process ID saved for use by init system */
104 char *pid_file
= PATH_ZEBRA_PID
;
106 /* Help information display. */
108 usage (char *progname
, int status
)
111 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
114 printf ("Usage : %s [OPTION...]\n\n\
115 Daemon which manages kernel routing table management and \
116 redistribution between different routing protocols.\n\n\
117 -b, --batch Runs in batch mode\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 -k, --keep_kernel Don't delete old routes which installed by zebra.\n\
122 -l, --log_mode Set verbose log mode flag\n\
123 -A, --vty_addr Set vty's bind address\n\
124 -P, --vty_port Set vty's port number\n\
125 -r, --retain When program terminates, retain added route by zebra.\n\
126 -u, --user User and group to run as\n\
127 -v, --version Print program version\n\
128 -h, --help Display this help and exit\n\
130 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
136 /* SIGHUP handler. */
140 zlog_info ("SIGHUP received");
142 /* Reload of config file. */
146 /* SIGINT handler. */
150 /* Decrared in rib.c */
153 zlog_info ("Terminating on signal");
164 /* SIGUSR1 handler. */
171 struct quagga_signal_t zebra_signals
[] =
191 /* Main startup routine. */
193 main (int argc
, char **argv
)
196 char *vty_addr
= NULL
;
197 int vty_port
= ZEBRA_VTY_PORT
;
200 char *config_file
= NULL
;
202 struct thread thread
;
203 void rib_weed_tables ();
204 void zebra_vty_init ();
206 /* Set umask before anything for security */
209 /* preserve my name */
210 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
212 zlog_default
= openzlog (progname
, ZLOG_STDOUT
, ZLOG_ZEBRA
,
213 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
219 opt
= getopt_long (argc
, argv
, "bdklf:i:hA:P:ru:v", longopts
, 0);
234 keep_kernel_mode
= 1;
240 config_file
= optarg
;
249 /* Deal with atoi() returning 0 on failure, and zebra not
250 listening on zebra port... */
251 if (strcmp(optarg
, "0") == 0)
256 vty_port
= atoi (optarg
);
257 vty_port
= (vty_port
? vty_port
: ZEBRA_VTY_PORT
);
263 zserv_privs
.user
= zserv_privs
.group
= optarg
;
266 print_version (progname
);
278 /* Make master thread emulator. */
279 zebrad
.master
= thread_master_create ();
281 /* privs initialise */
282 zprivs_init (&zserv_privs
);
284 /* Vty related initialize. */
285 signal_init (zebrad
.master
, Q_SIGC(zebra_signals
), zebra_signals
);
287 vty_init (zebrad
.master
);
290 /* Zebra related initialize. */
302 /* For debug purpose. */
303 /* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */
305 /* Make kernel routing socket. */
310 /* Sort VTY commands. */
315 #endif /* HAVE_SNMP */
317 /* Clean up self inserted route. */
318 if (! keep_kernel_mode
)
321 /* Configuration file read*/
322 vty_read_config (config_file
, config_default
);
327 /* Exit when zebra is working in batch mode. */
331 /* Needed for BSD routing socket. */
338 /* Output pid of zebra. */
339 pid_output (pid_file
);
341 /* Needed for BSD routing socket. */
344 /* Make vty server socket. */
345 vty_serv_sock (vty_addr
, vty_port
, ZEBRA_VTYSH_PATH
);
347 while (thread_fetch (zebrad
.master
, &thread
))
348 thread_call (&thread
);