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 /* Allow non-quagga entities to delete quagga routes */
51 /* zebra_rib's workqueue hold time. Private export for use by test code only */
52 extern int rib_process_hold_time
;
54 /* Pacify zclient.o in libzebra, which expects this variable. */
55 struct thread_master
*master
;
57 /* Command line options. */
58 struct option longopts
[] =
60 { "batch", no_argument
, NULL
, 'b'},
61 { "daemon", no_argument
, NULL
, 'd'},
62 { "allow_delete", no_argument
, NULL
, 'a'},
63 { "config_file", required_argument
, NULL
, 'f'},
64 { "help", no_argument
, NULL
, 'h'},
65 { "vty_addr", required_argument
, NULL
, 'A'},
66 { "vty_port", required_argument
, NULL
, 'P'},
67 { "version", no_argument
, NULL
, 'v'},
68 { "rib_hold", required_argument
, NULL
, 'r'},
72 zebra_capabilities_t _caps_p
[] =
79 /* Default configuration file path. */
80 char config_default
[] = SYSCONFDIR DEFAULT_CONFIG_FILE
;
82 /* Process ID saved for use by init system */
83 const char *pid_file
= PATH_ZEBRA_PID
;
85 /* Help information display. */
87 usage (char *progname
, int status
)
90 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
93 printf ("Usage : %s [OPTION...]\n\n"\
94 "Daemon which manages kernel routing table management and "\
95 "redistribution between different routing protocols.\n\n"\
96 "-b, --batch Runs in batch mode\n"\
97 "-d, --daemon Runs in daemon mode\n"\
98 "-a, --allow_delete Allow other processes to delete Quagga Routes\n" \
99 "-f, --config_file Set configuration file name\n"\
100 "-A, --vty_addr Set vty's bind address\n"\
101 "-P, --vty_port Set vty's port number\n"\
102 "-r, --rib_hold Set rib-queue hold time\n"\
103 "-v, --version Print program version\n"\
104 "-h, --help Display this help and exit\n"\
106 "Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
112 static unsigned int test_ifindex
= 0;
114 /* testrib commands */
115 DEFUN (test_interface_state
,
116 test_interface_state_cmd
,
118 "configure interface\n"
122 struct interface
*ifp
;
127 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
129 ifp
->ifindex
= ++test_ifindex
;
131 ifp
->flags
= IFF_BROADCAST
|IFF_MULTICAST
;
137 SET_FLAG (ifp
->flags
, IFF_UP
);
142 UNSET_FLAG (ifp
->flags
, IFF_UP
);
143 if_delete_update (ifp
);
155 install_element (INTERFACE_NODE
, &test_interface_state_cmd
);
158 /* SIGHUP handler. */
162 zlog_info ("SIGHUP received");
164 /* Reload of config file. */
168 /* SIGINT handler. */
172 zlog_notice ("Terminating on signal");
177 /* SIGUSR1 handler. */
184 struct quagga_signal_t zebra_signals
[] =
204 /* Main startup routine. */
206 main (int argc
, char **argv
)
209 char *vty_addr
= NULL
;
213 char *config_file
= NULL
;
215 struct thread thread
;
217 /* Set umask before anything for security */
220 /* preserve my name */
221 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
223 zlog_default
= openzlog (progname
, ZLOG_ZEBRA
, 0,
224 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
230 opt
= getopt_long (argc
, argv
, "bdaf:hA:P:r:v", longopts
, 0);
248 config_file
= optarg
;
254 /* Deal with atoi() returning 0 on failure, and zebra not
255 listening on zebra port... */
256 if (strcmp(optarg
, "0") == 0)
261 vty_port
= atoi (optarg
);
264 rib_process_hold_time
= atoi(optarg
);
267 print_version (progname
);
279 /* port and conf file mandatory */
280 if (!vty_port
|| !config_file
)
282 fprintf (stderr
, "Error: --vty_port and --config_file arguments"
283 " are both required\n");
287 /* Make master thread emulator. */
288 zebrad
.master
= thread_master_create ();
290 /* Vty related initialize. */
291 signal_init (zebrad
.master
, array_size(zebra_signals
), zebra_signals
);
293 vty_init (zebrad
.master
);
300 /* Zebra related initialize. */
304 /* Make kernel routing socket. */
309 /* Configuration file read*/
310 vty_read_config (config_file
, config_default
);
315 /* Exit when zebra is working in batch mode. */
320 if (daemon_mode
&& daemon (0, 0) < 0)
322 perror("daemon start failed");
326 /* Needed for BSD routing socket. */
329 /* Make vty server socket. */
330 vty_serv_sock (vty_addr
, vty_port
, "/tmp/test_zebra");
333 zlog_notice ("Zebra %s starting: vty@%d", QUAGGA_VERSION
, vty_port
);
335 while (thread_fetch (zebrad
.master
, &thread
))
336 thread_call (&thread
);