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 "zebra_memory.h"
29 #include "memory_vty.h"
36 #include "zebra/rib.h"
37 #include "zebra/zebra_ns.h"
38 #include "zebra/zserv.h"
39 #include "zebra/zebra_vrf.h"
40 #include "zebra/debug.h"
41 #include "zebra/router-id.h"
42 #include "zebra/interface.h"
45 struct zebra_t zebrad
=
47 .rtm_table_default
= 0,
53 /* Allow non-quagga entities to delete quagga routes */
56 /* zebra_rib's workqueue hold time. Private export for use by test code only */
57 extern int rib_process_hold_time
;
59 /* Pacify zclient.o in libfrr, which expects this variable. */
60 struct thread_master
*master
;
62 /* Command line options. */
63 struct option longopts
[] =
65 { "batch", no_argument
, NULL
, 'b'},
66 { "daemon", no_argument
, NULL
, 'd'},
67 { "allow_delete", no_argument
, NULL
, 'a'},
68 { "config_file", required_argument
, NULL
, 'f'},
69 { "help", no_argument
, NULL
, 'h'},
70 { "vty_addr", required_argument
, NULL
, 'A'},
71 { "vty_port", required_argument
, NULL
, 'P'},
72 { "version", no_argument
, NULL
, 'v'},
73 { "rib_hold", required_argument
, NULL
, 'r'},
77 zebra_capabilities_t _caps_p
[] =
84 /* Default configuration file path. */
85 char config_default
[] = SYSCONFDIR DEFAULT_CONFIG_FILE
;
87 /* Process ID saved for use by init system */
88 const char *pid_file
= "testzebra.pid";
90 /* Help information display. */
92 usage (char *progname
, int status
)
95 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
98 printf ("Usage : %s [OPTION...]\n\n"\
99 "Daemon which manages kernel routing table management and "\
100 "redistribution between different routing protocols.\n\n"\
101 "-b, --batch Runs in batch mode\n"\
102 "-d, --daemon Runs in daemon mode\n"\
103 "-a, --allow_delete Allow other processes to delete zebra routes\n" \
104 "-f, --config_file Set configuration file name\n"\
105 "-A, --vty_addr Set vty's bind address\n"\
106 "-P, --vty_port Set vty's port number\n"\
107 "-r, --rib_hold Set rib-queue hold time\n"\
108 "-v, --version Print program version\n"\
109 "-h, --help Display this help and exit\n"\
111 "Report bugs to %s\n", progname
, FRR_BUG_ADDRESS
);
117 static ifindex_t test_ifindex
= 0;
119 /* testrib commands */
120 DEFUN (test_interface_state
,
121 test_interface_state_cmd
,
123 "configure interface\n"
128 VTY_DECLVAR_CONTEXT (interface
, ifp
);
130 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
132 ifp
->ifindex
= ++test_ifindex
;
134 ifp
->flags
= IFF_BROADCAST
|IFF_MULTICAST
;
137 switch (argv
[idx_up_down
]->arg
[0])
140 SET_FLAG (ifp
->flags
, IFF_UP
);
145 UNSET_FLAG (ifp
->flags
, IFF_UP
);
146 if_delete_update (ifp
);
158 install_element (INTERFACE_NODE
, &test_interface_state_cmd
);
161 /* SIGHUP handler. */
165 zlog_info ("SIGHUP received");
167 /* Reload of config file. */
171 /* SIGINT handler. */
175 zlog_notice ("Terminating on signal");
180 /* SIGUSR1 handler. */
187 struct quagga_signal_t zebra_signals
[] =
206 /* Main startup routine. */
208 main (int argc
, char **argv
)
211 char *vty_addr
= NULL
;
215 char *config_file
= NULL
;
217 struct thread thread
;
219 /* Set umask before anything for security */
222 /* preserve my name */
223 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
225 openzlog(progname
, "ZEBRA", 0, LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
231 opt
= getopt_long (argc
, argv
, "bdaf:hA:P:r:v", longopts
, 0);
249 config_file
= optarg
;
255 /* Deal with atoi() returning 0 on failure, and zebra not
256 listening on zebra port... */
257 if (strcmp(optarg
, "0") == 0)
262 vty_port
= atoi (optarg
);
265 rib_process_hold_time
= atoi(optarg
);
268 print_version (progname
);
280 /* port and conf file mandatory */
281 if (!vty_port
|| !config_file
)
283 fprintf (stderr
, "Error: --vty_port and --config_file arguments"
284 " are both required\n");
288 /* Make master thread emulator. */
289 zebrad
.master
= thread_master_create ();
291 /* Vty related initialize. */
292 signal_init (zebrad
.master
, array_size(zebra_signals
), zebra_signals
);
294 vty_config_lockless ();
295 vty_init (zebrad
.master
);
301 /* Zebra related initialize. */
305 /* 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", FRR_VERSION
, vty_port
);
335 while (thread_fetch (zebrad
.master
, &thread
))
336 thread_call (&thread
);