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 /* Route retain mode flag. */
54 /* Don't delete kernel route. */
55 int keep_kernel_mode
= 0;
57 /* Command line options. */
58 struct option longopts
[] =
60 { "batch", no_argument
, NULL
, 'b'},
61 { "daemon", no_argument
, NULL
, 'd'},
62 { "keep_kernel", no_argument
, NULL
, 'k'},
63 { "log_mode", no_argument
, NULL
, 'l'},
64 { "config_file", required_argument
, NULL
, 'f'},
65 { "pid_file", required_argument
, NULL
, 'i'},
66 { "help", no_argument
, NULL
, 'h'},
67 { "vty_addr", required_argument
, NULL
, 'A'},
68 { "vty_port", required_argument
, NULL
, 'P'},
69 { "retain", no_argument
, NULL
, 'r'},
70 { "user", required_argument
, NULL
, 'u'},
71 { "version", no_argument
, NULL
, 'v'},
75 zebra_capabilities_t _caps_p
[] =
82 /* zebra privileges to run with */
83 struct zebra_privs_t zserv_privs
=
85 #if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
87 .group
= QUAGGA_GROUP
,
90 .vty_group
= VTY_GROUP
,
93 .cap_num_p
= sizeof(_caps_p
)/sizeof(_caps_p
[0]),
97 /* Default configuration file path. */
98 char config_default
[] = SYSCONFDIR DEFAULT_CONFIG_FILE
;
100 /* Process ID saved for use by init system */
101 char *pid_file
= PATH_ZEBRA_PID
;
103 /* Help information display. */
105 usage (char *progname
, int status
)
108 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
111 printf ("Usage : %s [OPTION...]\n\n\
112 Daemon which manages kernel routing table management and \
113 redistribution between different routing protocols.\n\n\
114 -b, --batch Runs in batch mode\n\
115 -d, --daemon Runs in daemon mode\n\
116 -f, --config_file Set configuration file name\n\
117 -i, --pid_file Set process identifier file name\n\
118 -k, --keep_kernel Don't delete old routes which installed by zebra.\n\
119 -l, --log_mode Set verbose log mode flag\n\
120 -A, --vty_addr Set vty's bind address\n\
121 -P, --vty_port Set vty's port number\n\
122 -r, --retain When program terminates, retain added route by zebra.\n\
123 -u, --user User and group to run as\n\
124 -v, --version Print program version\n\
125 -h, --help Display this help and exit\n\
127 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
133 /* SIGHUP handler. */
137 zlog_info ("SIGHUP received");
139 /* Reload of config file. */
143 /* SIGINT handler. */
147 /* Decrared in rib.c */
150 zlog_info ("Terminating on signal");
161 /* SIGUSR1 handler. */
168 struct quagga_signal_t zebra_signals
[] =
188 /* Main startup routine. */
190 main (int argc
, char **argv
)
193 char *vty_addr
= NULL
;
194 int vty_port
= ZEBRA_VTY_PORT
;
197 char *config_file
= NULL
;
199 struct thread thread
;
200 void rib_weed_tables ();
201 void zebra_vty_init ();
203 /* Set umask before anything for security */
206 /* preserve my name */
207 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
209 zlog_default
= openzlog (progname
, ZLOG_STDOUT
, ZLOG_ZEBRA
,
210 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
216 opt
= getopt_long (argc
, argv
, "bdklf:i:hA:P:ru:v", longopts
, 0);
231 keep_kernel_mode
= 1;
237 config_file
= optarg
;
246 /* Deal with atoi() returning 0 on failure, and zebra not
247 listening on zebra port... */
248 if (strcmp(optarg
, "0") == 0)
253 vty_port
= atoi (optarg
);
254 vty_port
= (vty_port
? vty_port
: ZEBRA_VTY_PORT
);
260 zserv_privs
.user
= zserv_privs
.group
= optarg
;
263 print_version (progname
);
275 /* Make master thread emulator. */
276 zebrad
.master
= thread_master_create ();
278 /* privs initialise */
279 zprivs_init (&zserv_privs
);
281 /* Vty related initialize. */
282 signal_init (zebrad
.master
, Q_SIGC(zebra_signals
), zebra_signals
);
284 vty_init (zebrad
.master
);
287 /* Zebra related initialize. */
299 /* For debug purpose. */
300 /* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */
302 /* Make kernel routing socket. */
307 /* Sort VTY commands. */
312 #endif /* HAVE_SNMP */
314 /* Clean up self inserted route. */
315 if (! keep_kernel_mode
)
318 /* Configuration file read*/
319 vty_read_config (config_file
, config_default
);
324 /* Exit when zebra is working in batch mode. */
328 /* Needed for BSD routing socket. */
335 /* Output pid of zebra. */
336 pid_output (pid_file
);
338 /* Needed for BSD routing socket. */
341 /* Make vty server socket. */
342 vty_serv_sock (vty_addr
, vty_port
, ZEBRA_VTYSH_PATH
);
344 while (thread_fetch (zebrad
.master
, &thread
))
345 thread_call (&thread
);