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 { "config_file", required_argument
, NULL
, 'f'},
60 { "help", no_argument
, NULL
, 'h'},
61 { "vty_addr", required_argument
, NULL
, 'A'},
62 { "vty_port", required_argument
, NULL
, 'P'},
63 { "version", no_argument
, NULL
, 'v'},
64 { "rib_hold", required_argument
, NULL
, 'r'},
68 zebra_capabilities_t _caps_p
[] =
75 /* Default configuration file path. */
76 char config_default
[] = SYSCONFDIR DEFAULT_CONFIG_FILE
;
78 /* Process ID saved for use by init system */
79 const char *pid_file
= PATH_ZEBRA_PID
;
81 /* Help information display. */
83 usage (char *progname
, int status
)
86 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
89 printf ("Usage : %s [OPTION...]\n\n"\
90 "Daemon which manages kernel routing table management and "\
91 "redistribution between different routing protocols.\n\n"\
92 "-b, --batch Runs in batch mode\n"\
93 "-d, --daemon Runs in daemon mode\n"\
94 "-f, --config_file Set configuration file name\n"\
95 "-A, --vty_addr Set vty's bind address\n"\
96 "-P, --vty_port Set vty's port number\n"\
97 "-r, --rib_hold Set rib-queue hold time\n"\
98 "-v, --version Print program version\n"\
99 "-h, --help Display this help and exit\n"\
101 "Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
107 static unsigned int test_ifindex
= 0;
109 /* testrib commands */
110 DEFUN (test_interface_state
,
111 test_interface_state_cmd
,
113 "configure interface\n"
117 struct interface
*ifp
;
122 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
124 ifp
->ifindex
= ++test_ifindex
;
126 ifp
->flags
= IFF_BROADCAST
|IFF_MULTICAST
;
132 SET_FLAG (ifp
->flags
, IFF_UP
);
137 UNSET_FLAG (ifp
->flags
, IFF_UP
);
138 if_delete_update (ifp
);
150 install_element (INTERFACE_NODE
, &test_interface_state_cmd
);
153 /* SIGHUP handler. */
157 zlog_info ("SIGHUP received");
159 /* Reload of config file. */
163 /* SIGINT handler. */
167 zlog_notice ("Terminating on signal");
172 /* SIGUSR1 handler. */
179 struct quagga_signal_t zebra_signals
[] =
199 /* Main startup routine. */
201 main (int argc
, char **argv
)
204 char *vty_addr
= NULL
;
208 char *config_file
= NULL
;
210 struct thread thread
;
212 /* Set umask before anything for security */
215 /* preserve my name */
216 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
218 zlog_default
= openzlog (progname
, ZLOG_ZEBRA
,
219 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
225 opt
= getopt_long (argc
, argv
, "bdf:hA:P:r:v", longopts
, 0);
240 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
);
256 rib_process_hold_time
= atoi(optarg
);
259 print_version (progname
);
271 /* port and conf file mandatory */
272 if (!vty_port
|| !config_file
)
275 /* Make master thread emulator. */
276 zebrad
.master
= thread_master_create ();
278 /* Vty related initialize. */
279 signal_init (zebrad
.master
, Q_SIGC(zebra_signals
), zebra_signals
);
281 vty_init (zebrad
.master
);
288 /* Zebra related initialize. */
292 /* Make kernel routing socket. */
297 /* Sort VTY commands. */
300 /* Configuration file read*/
301 vty_read_config (config_file
, config_default
);
306 /* Exit when zebra is working in batch mode. */
311 if (daemon_mode
&& daemon (0, 0) < 0)
313 perror("daemon start failed");
317 /* Needed for BSD routing socket. */
320 /* Make vty server socket. */
321 vty_serv_sock (vty_addr
, vty_port
, "/tmp/test_zebra");
324 zlog_notice ("Zebra %s starting: vty@%d", QUAGGA_VERSION
, vty_port
);
326 while (thread_fetch (zebrad
.master
, &thread
))
327 thread_call (&thread
);