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/router-id.h"
39 #include "zebra/irdp.h"
40 #include "zebra/rtadv.h"
43 struct zebra_t zebrad
=
45 .rtm_table_default
= 0,
52 /* Pacify zclient.o in libzebra, which expects this variable. */
53 struct thread_master
*master
;
55 /* Route retain mode flag. */
58 /* Don't delete kernel route. */
59 int keep_kernel_mode
= 0;
62 /* Receive buffer size for netlink socket */
63 u_int32_t nl_rcvbufsize
= 0;
64 #endif /* HAVE_NETLINK */
66 /* Command line options. */
67 struct option longopts
[] =
69 { "batch", no_argument
, NULL
, 'b'},
70 { "daemon", no_argument
, NULL
, 'd'},
71 { "keep_kernel", no_argument
, NULL
, 'k'},
72 { "log_mode", no_argument
, NULL
, 'l'},
73 { "config_file", required_argument
, NULL
, 'f'},
74 { "pid_file", required_argument
, NULL
, 'i'},
75 { "help", no_argument
, NULL
, 'h'},
76 { "vty_addr", required_argument
, NULL
, 'A'},
77 { "vty_port", required_argument
, NULL
, 'P'},
78 { "retain", no_argument
, NULL
, 'r'},
80 { "nl-bufsize", required_argument
, NULL
, 's'},
81 #endif /* HAVE_NETLINK */
82 { "user", required_argument
, NULL
, 'u'},
83 { "group", required_argument
, NULL
, 'g'},
84 { "version", no_argument
, NULL
, 'v'},
88 zebra_capabilities_t _caps_p
[] =
95 /* zebra privileges to run with */
96 struct zebra_privs_t zserv_privs
=
98 #if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
100 .group
= QUAGGA_GROUP
,
103 .vty_group
= VTY_GROUP
,
106 .cap_num_p
= sizeof(_caps_p
)/sizeof(_caps_p
[0]),
110 /* Default configuration file path. */
111 char config_default
[] = SYSCONFDIR DEFAULT_CONFIG_FILE
;
113 /* Process ID saved for use by init system */
114 const char *pid_file
= PATH_ZEBRA_PID
;
116 /* Help information display. */
118 usage (char *progname
, int status
)
121 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
124 printf ("Usage : %s [OPTION...]\n\n"\
125 "Daemon which manages kernel routing table management and "\
126 "redistribution between different routing protocols.\n\n"\
127 "-b, --batch Runs in batch mode\n"\
128 "-d, --daemon Runs in daemon mode\n"\
129 "-f, --config_file Set configuration file name\n"\
130 "-i, --pid_file Set process identifier file name\n"\
131 "-k, --keep_kernel Don't delete old routes which installed by "\
133 "-l, --log_mode Set verbose log mode flag\n"\
134 "-A, --vty_addr Set vty's bind address\n"\
135 "-P, --vty_port Set vty's port number\n"\
136 "-r, --retain When program terminates, retain added route "\
138 "-u, --user User to run as\n"\
139 "-g, --group Group to run as\n", progname
);
141 printf ("-s, --nl-bufsize Set netlink receive buffer size\n");
142 #endif /* HAVE_NETLINK */
143 printf ("-v, --version Print program version\n"\
144 "-h, --help Display this help and exit\n"\
146 "Report bugs to %s\n", ZEBRA_BUG_ADDRESS
);
152 /* SIGHUP handler. */
156 zlog_info ("SIGHUP received");
158 /* Reload of config file. */
162 /* SIGINT handler. */
166 /* Decrared in rib.c */
169 zlog_notice ("Terminating on signal");
180 /* SIGUSR1 handler. */
187 struct quagga_signal_t zebra_signals
[] =
207 /* Main startup routine. */
209 main (int argc
, char **argv
)
212 char *vty_addr
= NULL
;
213 int vty_port
= ZEBRA_VTY_PORT
;
216 char *config_file
= NULL
;
218 struct thread thread
;
220 /* Set umask before anything for security */
223 /* preserve my name */
224 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
226 zlog_default
= openzlog (progname
, ZLOG_ZEBRA
,
227 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
234 opt
= getopt_long (argc
, argv
, "bdklf:i:hA:P:ru:g:vs:", longopts
, 0);
236 opt
= getopt_long (argc
, argv
, "bdklf:i:hA:P:ru:g:v", longopts
, 0);
237 #endif /* HAVE_NETLINK */
252 keep_kernel_mode
= 1;
258 config_file
= optarg
;
267 /* Deal with atoi() returning 0 on failure, and zebra not
268 listening on zebra port... */
269 if (strcmp(optarg
, "0") == 0)
274 vty_port
= atoi (optarg
);
275 vty_port
= (vty_port
? vty_port
: ZEBRA_VTY_PORT
);
282 nl_rcvbufsize
= atoi (optarg
);
284 #endif /* HAVE_NETLINK */
286 zserv_privs
.user
= optarg
;
289 zserv_privs
.group
= optarg
;
292 print_version (progname
);
304 /* Make master thread emulator. */
305 zebrad
.master
= thread_master_create ();
307 /* privs initialise */
308 zprivs_init (&zserv_privs
);
310 /* Vty related initialize. */
311 signal_init (zebrad
.master
, Q_SIGC(zebra_signals
), zebra_signals
);
313 vty_init (zebrad
.master
);
316 /* Zebra related initialize. */
329 /* For debug purpose. */
330 /* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */
332 /* Make kernel routing socket. */
337 /* Sort VTY commands. */
342 #endif /* HAVE_SNMP */
344 /* Clean up self inserted route. */
345 if (! keep_kernel_mode
)
348 /* Configuration file read*/
349 vty_read_config (config_file
, config_default
);
354 /* Exit when zebra is working in batch mode. */
358 /* Needed for BSD routing socket. */
365 /* Output pid of zebra. */
366 pid_output (pid_file
);
368 /* Needed for BSD routing socket. */
371 /* Make vty server socket. */
372 vty_serv_sock (vty_addr
, vty_port
, ZEBRA_VTYSH_PATH
);
375 zlog_notice ("Zebra %s starting: vty@%d", QUAGGA_VERSION
, vty_port
);
377 while (thread_fetch (zebrad
.master
, &thread
))
378 thread_call (&thread
);