2 * Copyright (C) 1997, 98 Kunihiro Ishiguro
4 * GNU Zebra is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2, or (at your option) any
9 * GNU Zebra is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with GNU Zebra; see the file COPYING. If not, write to the Free
16 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 #include <lib/version.h>
33 #include "zebra/rib.h"
34 #include "zebra/zserv.h"
35 #include "zebra/debug.h"
36 #include "zebra/router-id.h"
37 #include "zebra/interface.h"
40 struct zebra_t zebrad
=
42 .rtm_table_default
= 0,
48 /* zebra_rib's workqueue hold time. Private export for use by test code only */
49 extern int rib_process_hold_time
;
51 /* Pacify zclient.o in libzebra, which expects this variable. */
52 struct thread_master
*master
;
54 /* Command line options. */
55 struct option longopts
[] =
57 { "batch", no_argument
, NULL
, 'b'},
58 { "daemon", no_argument
, NULL
, 'd'},
59 { "log_mode", no_argument
, NULL
, 'l'},
60 { "config_file", required_argument
, NULL
, 'f'},
61 { "help", no_argument
, NULL
, 'h'},
62 { "vty_addr", required_argument
, NULL
, 'A'},
63 { "vty_port", required_argument
, NULL
, 'P'},
64 { "version", no_argument
, NULL
, 'v'},
65 { "rib_hold", required_argument
, NULL
, 'r'},
69 zebra_capabilities_t _caps_p
[] =
76 /* Default configuration file path. */
77 char config_default
[] = SYSCONFDIR DEFAULT_CONFIG_FILE
;
79 /* Process ID saved for use by init system */
80 const char *pid_file
= PATH_ZEBRA_PID
;
82 /* Help information display. */
84 usage (char *progname
, int status
)
87 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
90 printf ("Usage : %s [OPTION...]\n\n"\
91 "Daemon which manages kernel routing table management and "\
92 "redistribution between different routing protocols.\n\n"\
93 "-b, --batch Runs in batch mode\n"\
94 "-d, --daemon Runs in daemon mode\n"\
95 "-f, --config_file Set configuration file name\n"\
96 "-l, --log_mode Set verbose log mode flag\n"\
97 "-A, --vty_addr Set vty's bind address\n"\
98 "-P, --vty_port Set vty's port number\n"\
99 "-r, --rib_hold Set rib-queue hold time\n"\
100 "-v, --version Print program version\n"\
101 "-h, --help Display this help and exit\n"\
103 "Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
109 static unsigned int test_ifindex
= 0;
111 /* testrib commands */
112 DEFUN (test_interface_state
,
113 test_interface_state_cmd
,
115 "configure interface\n"
119 struct interface
*ifp
;
124 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
126 ifp
->ifindex
= ++test_ifindex
;
128 ifp
->flags
= IFF_BROADCAST
|IFF_MULTICAST
;
134 SET_FLAG (ifp
->flags
, IFF_UP
);
139 UNSET_FLAG (ifp
->flags
, IFF_UP
);
140 if_delete_update (ifp
);
152 install_element (INTERFACE_NODE
, &test_interface_state_cmd
);
155 /* SIGHUP handler. */
159 zlog_info ("SIGHUP received");
161 /* Reload of config file. */
165 /* SIGINT handler. */
169 zlog_notice ("Terminating on signal");
174 /* SIGUSR1 handler. */
181 struct quagga_signal_t zebra_signals
[] =
201 /* Main startup routine. */
203 main (int argc
, char **argv
)
206 char *vty_addr
= NULL
;
210 char *config_file
= NULL
;
212 struct thread thread
;
214 /* Set umask before anything for security */
217 /* preserve my name */
218 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
220 zlog_default
= openzlog (progname
, ZLOG_ZEBRA
,
221 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
227 opt
= getopt_long (argc
, argv
, "bdlf:hA:P:r:v", longopts
, 0);
245 config_file
= optarg
;
251 /* Deal with atoi() returning 0 on failure, and zebra not
252 listening on zebra port... */
253 if (strcmp(optarg
, "0") == 0)
258 vty_port
= atoi (optarg
);
261 rib_process_hold_time
= atoi(optarg
);
264 print_version (progname
);
276 /* port and conf file mandatory */
277 if (!vty_port
|| !config_file
)
280 /* Make master thread emulator. */
281 zebrad
.master
= thread_master_create ();
283 /* Vty related initialize. */
284 signal_init (zebrad
.master
, Q_SIGC(zebra_signals
), zebra_signals
);
286 vty_init (zebrad
.master
);
293 /* Zebra related initialize. */
297 /* Make kernel routing socket. */
302 /* Sort VTY commands. */
305 /* Configuration file read*/
306 vty_read_config (config_file
, config_default
);
311 /* Exit when zebra is working in batch mode. */
319 /* Needed for BSD routing socket. */
322 /* Make vty server socket. */
323 vty_serv_sock (vty_addr
, vty_port
, "/tmp/test_zebra");
326 zlog_notice ("Zebra %s starting: vty@%d", QUAGGA_VERSION
, vty_port
);
328 while (thread_fetch (zebrad
.master
, &thread
))
329 thread_call (&thread
);