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>
34 #include "zebra/rib.h"
35 #include "zebra/zserv.h"
36 #include "zebra/debug.h"
37 #include "zebra/router-id.h"
38 #include "zebra/interface.h"
41 struct zebra_t zebrad
=
43 .rtm_table_default
= 0,
49 /* Allow non-quagga entities to delete quagga routes */
52 /* zebra_rib's workqueue hold time. Private export for use by test code only */
53 extern int rib_process_hold_time
;
55 /* Pacify zclient.o in libzebra, which expects this variable. */
56 struct thread_master
*master
;
58 /* Command line options. */
59 struct option longopts
[] =
61 { "batch", no_argument
, NULL
, 'b'},
62 { "daemon", no_argument
, NULL
, 'd'},
63 { "allow_delete", no_argument
, NULL
, 'a'},
64 { "config_file", required_argument
, NULL
, 'f'},
65 { "help", no_argument
, NULL
, 'h'},
66 { "vty_addr", required_argument
, NULL
, 'A'},
67 { "vty_port", required_argument
, NULL
, 'P'},
68 { "version", no_argument
, NULL
, 'v'},
69 { "rib_hold", required_argument
, NULL
, 'r'},
73 zebra_capabilities_t _caps_p
[] =
80 /* Default configuration file path. */
81 char config_default
[] = SYSCONFDIR DEFAULT_CONFIG_FILE
;
83 /* Process ID saved for use by init system */
84 const char *pid_file
= PATH_ZEBRA_PID
;
86 /* Help information display. */
88 usage (char *progname
, int status
)
91 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
94 printf ("Usage : %s [OPTION...]\n\n"\
95 "Daemon which manages kernel routing table management and "\
96 "redistribution between different routing protocols.\n\n"\
97 "-b, --batch Runs in batch mode\n"\
98 "-d, --daemon Runs in daemon mode\n"\
99 "-a, --allow_delete Allow other processes to delete Quagga Routes\n" \
100 "-f, --config_file Set configuration file name\n"\
101 "-A, --vty_addr Set vty's bind address\n"\
102 "-P, --vty_port Set vty's port number\n"\
103 "-r, --rib_hold Set rib-queue hold time\n"\
104 "-v, --version Print program version\n"\
105 "-h, --help Display this help and exit\n"\
107 "Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
113 static unsigned int test_ifindex
= 0;
115 /* testrib commands */
116 DEFUN (test_interface_state
,
117 test_interface_state_cmd
,
119 "configure interface\n"
123 struct interface
*ifp
;
128 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
130 ifp
->ifindex
= ++test_ifindex
;
132 ifp
->flags
= IFF_BROADCAST
|IFF_MULTICAST
;
138 SET_FLAG (ifp
->flags
, IFF_UP
);
143 UNSET_FLAG (ifp
->flags
, IFF_UP
);
144 if_delete_update (ifp
);
156 install_element (INTERFACE_NODE
, &test_interface_state_cmd
);
159 /* SIGHUP handler. */
163 zlog_info ("SIGHUP received");
165 /* Reload of config file. */
169 /* SIGINT handler. */
173 zlog_notice ("Terminating on signal");
178 /* SIGUSR1 handler. */
185 struct quagga_signal_t zebra_signals
[] =
205 /* Callback upon creating a new VRF. */
207 zebra_vrf_new (vrf_id_t vrf_id
, const char *name
, void **info
)
209 struct zebra_vrf
*zvrf
= *info
;
213 zvrf
= zebra_vrf_alloc (vrf_id
, name
);
214 *info
= (void *)zvrf
;
220 /* Callback upon enabling a VRF. */
222 zebra_vrf_enable (vrf_id_t vrf_id
, const char *name
, void **info
)
224 struct zebra_vrf
*zvrf
= (struct zebra_vrf
*) (*info
);
231 /* Callback upon disabling a VRF. */
233 zebra_vrf_disable (vrf_id_t vrf_id
, const char *name
, void **info
)
235 struct zebra_vrf
*zvrf
= (struct zebra_vrf
*) (*info
);
236 struct listnode
*list_node
;
237 struct interface
*ifp
;
241 rib_close_table (zvrf
->table
[AFI_IP
][SAFI_UNICAST
]);
242 rib_close_table (zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
244 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id
), list_node
, ifp
))
246 int operative
= if_is_operative (ifp
);
247 UNSET_FLAG (ifp
->flags
, IFF_UP
);
255 /* Zebra VRF initialization. */
257 zebra_vrf_init (void)
259 vrf_add_hook (VRF_NEW_HOOK
, zebra_vrf_new
);
260 vrf_add_hook (VRF_ENABLE_HOOK
, zebra_vrf_enable
);
261 vrf_add_hook (VRF_DISABLE_HOOK
, zebra_vrf_disable
);
265 /* Main startup routine. */
267 main (int argc
, char **argv
)
270 char *vty_addr
= NULL
;
274 char *config_file
= NULL
;
276 struct thread thread
;
278 /* Set umask before anything for security */
281 /* preserve my name */
282 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
284 zlog_default
= openzlog (progname
, ZLOG_ZEBRA
, 0,
285 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
291 opt
= getopt_long (argc
, argv
, "bdaf:hA:P:r:v", longopts
, 0);
309 config_file
= optarg
;
315 /* Deal with atoi() returning 0 on failure, and zebra not
316 listening on zebra port... */
317 if (strcmp(optarg
, "0") == 0)
322 vty_port
= atoi (optarg
);
325 rib_process_hold_time
= atoi(optarg
);
328 print_version (progname
);
340 /* port and conf file mandatory */
341 if (!vty_port
|| !config_file
)
343 fprintf (stderr
, "Error: --vty_port and --config_file arguments"
344 " are both required\n");
348 /* Make master thread emulator. */
349 zebrad
.master
= thread_master_create ();
351 /* Vty related initialize. */
352 signal_init (zebrad
.master
, array_size(zebra_signals
), zebra_signals
);
354 vty_init (zebrad
.master
);
360 /* Zebra related initialize. */
364 /* Make kernel routing socket. */
368 /* Configuration file read*/
369 vty_read_config (config_file
, config_default
);
374 /* Exit when zebra is working in batch mode. */
379 if (daemon_mode
&& daemon (0, 0) < 0)
381 perror("daemon start failed");
385 /* Needed for BSD routing socket. */
388 /* Make vty server socket. */
389 vty_serv_sock (vty_addr
, vty_port
, "/tmp/test_zebra");
392 zlog_notice ("Zebra %s starting: vty@%d", QUAGGA_VERSION
, vty_port
);
394 while (thread_fetch (zebrad
.master
, &thread
))
395 thread_call (&thread
);