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>
28 #include "memory_vty.h"
35 #include "zebra/rib.h"
36 #include "zebra/zebra_ns.h"
37 #include "zebra/zserv.h"
38 #include "zebra/zebra_vrf.h"
39 #include "zebra/debug.h"
40 #include "zebra/router-id.h"
41 #include "zebra/interface.h"
44 struct zebra_t zebrad
=
46 .rtm_table_default
= 0,
52 /* Allow non-quagga entities to delete quagga routes */
55 /* zebra_rib's workqueue hold time. Private export for use by test code only */
56 extern int rib_process_hold_time
;
58 /* Pacify zclient.o in libzebra, which expects this variable. */
59 struct thread_master
*master
;
61 /* Command line options. */
62 struct option longopts
[] =
64 { "batch", no_argument
, NULL
, 'b'},
65 { "daemon", no_argument
, NULL
, 'd'},
66 { "allow_delete", no_argument
, NULL
, 'a'},
67 { "config_file", required_argument
, NULL
, 'f'},
68 { "help", no_argument
, NULL
, 'h'},
69 { "vty_addr", required_argument
, NULL
, 'A'},
70 { "vty_port", required_argument
, NULL
, 'P'},
71 { "version", no_argument
, NULL
, 'v'},
72 { "rib_hold", required_argument
, NULL
, 'r'},
76 zebra_capabilities_t _caps_p
[] =
83 /* Default configuration file path. */
84 char config_default
[] = SYSCONFDIR DEFAULT_CONFIG_FILE
;
86 /* Process ID saved for use by init system */
87 const char *pid_file
= PATH_ZEBRA_PID
;
89 /* Help information display. */
91 usage (char *progname
, int status
)
94 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
97 printf ("Usage : %s [OPTION...]\n\n"\
98 "Daemon which manages kernel routing table management and "\
99 "redistribution between different routing protocols.\n\n"\
100 "-b, --batch Runs in batch mode\n"\
101 "-d, --daemon Runs in daemon mode\n"\
102 "-a, --allow_delete Allow other processes to delete Quagga Routes\n" \
103 "-f, --config_file Set configuration file name\n"\
104 "-A, --vty_addr Set vty's bind address\n"\
105 "-P, --vty_port Set vty's port number\n"\
106 "-r, --rib_hold Set rib-queue hold time\n"\
107 "-v, --version Print program version\n"\
108 "-h, --help Display this help and exit\n"\
110 "Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
116 static ifindex_t test_ifindex
= 0;
118 /* testrib commands */
119 DEFUN (test_interface_state
,
120 test_interface_state_cmd
,
122 "configure interface\n"
126 struct interface
*ifp
;
131 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
133 ifp
->ifindex
= ++test_ifindex
;
135 ifp
->flags
= IFF_BROADCAST
|IFF_MULTICAST
;
141 SET_FLAG (ifp
->flags
, IFF_UP
);
146 UNSET_FLAG (ifp
->flags
, IFF_UP
);
147 if_delete_update (ifp
);
159 install_element (INTERFACE_NODE
, &test_interface_state_cmd
);
162 /* SIGHUP handler. */
166 zlog_info ("SIGHUP received");
168 /* Reload of config file. */
172 /* SIGINT handler. */
176 zlog_notice ("Terminating on signal");
181 /* SIGUSR1 handler. */
188 struct quagga_signal_t zebra_signals
[] =
207 /* Main startup routine. */
209 main (int argc
, char **argv
)
212 char *vty_addr
= NULL
;
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
, 0,
227 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
233 opt
= getopt_long (argc
, argv
, "bdaf:hA:P:r:v", longopts
, 0);
251 config_file
= optarg
;
257 /* Deal with atoi() returning 0 on failure, and zebra not
258 listening on zebra port... */
259 if (strcmp(optarg
, "0") == 0)
264 vty_port
= atoi (optarg
);
267 rib_process_hold_time
= atoi(optarg
);
270 print_version (progname
);
282 /* port and conf file mandatory */
283 if (!vty_port
|| !config_file
)
285 fprintf (stderr
, "Error: --vty_port and --config_file arguments"
286 " are both required\n");
290 /* Make master thread emulator. */
291 zebrad
.master
= thread_master_create ();
293 /* Vty related initialize. */
294 signal_init (zebrad
.master
, array_size(zebra_signals
), zebra_signals
);
296 vty_init (zebrad
.master
);
302 /* Zebra related initialize. */
306 /* Make kernel routing socket. */
310 /* Configuration file read*/
311 vty_read_config (config_file
, config_default
);
316 /* Exit when zebra is working in batch mode. */
321 if (daemon_mode
&& daemon (0, 0) < 0)
323 perror("daemon start failed");
327 /* Needed for BSD routing socket. */
330 /* Make vty server socket. */
331 vty_serv_sock (vty_addr
, vty_port
, "/tmp/test_zebra");
334 zlog_notice ("Zebra %s starting: vty@%d", QUAGGA_VERSION
, vty_port
);
336 while (thread_fetch (zebrad
.master
, &thread
))
337 thread_call (&thread
);