2000-01-19 12:30:19 +00:00
|
|
|
/*
|
|
|
|
* BIRD Internet Routing Daemon -- CLI Commands Which Don't Fit Anywhere Else
|
|
|
|
*
|
|
|
|
* (c) 2000 Martin Mares <mj@ucw.cz>
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
2014-03-20 13:07:12 +00:00
|
|
|
#include "nest/protocol.h"
|
2012-03-16 11:47:12 +00:00
|
|
|
#include "nest/route.h"
|
2000-01-19 12:30:19 +00:00
|
|
|
#include "nest/cli.h"
|
|
|
|
#include "conf/conf.h"
|
|
|
|
#include "nest/cmds.h"
|
|
|
|
#include "lib/string.h"
|
2010-06-02 20:20:40 +00:00
|
|
|
#include "lib/resource.h"
|
2013-07-25 11:15:32 +00:00
|
|
|
#include "filter/filter.h"
|
2016-04-15 09:41:08 +00:00
|
|
|
#include "client/reply_codes.h"
|
|
|
|
#include "nest/iface.h"
|
2000-01-19 12:30:19 +00:00
|
|
|
|
2012-12-26 11:40:48 +00:00
|
|
|
extern int shutting_down;
|
|
|
|
extern int configuring;
|
|
|
|
|
2000-01-19 12:30:19 +00:00
|
|
|
void
|
|
|
|
cmd_show_status(void)
|
|
|
|
{
|
2000-03-12 22:44:54 +00:00
|
|
|
byte tim[TM_DATETIME_BUFFER_SIZE];
|
|
|
|
|
|
|
|
cli_msg(-1000, "BIRD " BIRD_VERSION);
|
2010-02-02 23:19:24 +00:00
|
|
|
tm_format_datetime(tim, &config->tf_base, now);
|
2009-07-23 14:06:25 +00:00
|
|
|
cli_msg(-1011, "Router ID is %R", config->router_id);
|
2000-03-12 22:44:54 +00:00
|
|
|
cli_msg(-1011, "Current server time is %s", tim);
|
2010-02-02 23:19:24 +00:00
|
|
|
tm_format_datetime(tim, &config->tf_base, boot_time);
|
2000-03-12 22:44:54 +00:00
|
|
|
cli_msg(-1011, "Last reboot on %s", tim);
|
2010-02-02 23:19:24 +00:00
|
|
|
tm_format_datetime(tim, &config->tf_base, config->load_time);
|
2000-03-12 22:44:54 +00:00
|
|
|
cli_msg(-1011, "Last reconfiguration on %s", tim);
|
2012-12-26 11:40:48 +00:00
|
|
|
|
2014-03-20 13:07:12 +00:00
|
|
|
graceful_restart_show_status();
|
|
|
|
|
2000-03-12 22:44:54 +00:00
|
|
|
if (shutting_down)
|
|
|
|
cli_msg(13, "Shutdown in progress");
|
2012-12-26 11:40:48 +00:00
|
|
|
else if (configuring)
|
2000-03-12 22:44:54 +00:00
|
|
|
cli_msg(13, "Reconfiguration in progress");
|
|
|
|
else
|
|
|
|
cli_msg(13, "Daemon is up and running");
|
2000-01-19 12:30:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 11:47:12 +00:00
|
|
|
cmd_show_symbols(struct sym_show_data *sd)
|
2000-01-19 12:30:19 +00:00
|
|
|
{
|
|
|
|
int pos = 0;
|
2012-03-16 11:47:12 +00:00
|
|
|
struct symbol *sym = sd->sym;
|
2000-01-19 12:30:19 +00:00
|
|
|
|
|
|
|
if (sym)
|
2012-03-16 11:47:12 +00:00
|
|
|
cli_msg(1010, "%-8s\t%s", sym->name, cf_symbol_class_name(sym));
|
2000-01-19 12:30:19 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while (sym = cf_walk_symbols(config, sym, &pos))
|
2012-03-16 11:47:12 +00:00
|
|
|
{
|
|
|
|
if (sd->type && (sym->class != sd->type))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cli_msg(-1010, "%-8s\t%s", sym->name, cf_symbol_class_name(sym));
|
|
|
|
}
|
2000-01-19 12:30:19 +00:00
|
|
|
cli_msg(0, "");
|
|
|
|
}
|
|
|
|
}
|
2010-06-02 20:20:40 +00:00
|
|
|
|
2016-04-15 09:41:08 +00:00
|
|
|
static int
|
|
|
|
get_cli_code_for_sym(struct symbol *sym)
|
|
|
|
{
|
|
|
|
if (cf_symbol_is_constant(sym))
|
|
|
|
return RC_CONSTANT_NAME;
|
|
|
|
|
|
|
|
if (cf_symbol_is_variable(sym))
|
|
|
|
return RC_VARIABLE_NAME;
|
|
|
|
|
|
|
|
switch (sym->class & 0xff)
|
|
|
|
{
|
|
|
|
case SYM_PROTO: return RC_PROTOCOL_NAME;
|
|
|
|
case SYM_TEMPLATE: return RC_TEMPLATE_NAME;
|
|
|
|
case SYM_FUNCTION: return RC_FUNCTION_NAME;
|
|
|
|
case SYM_FILTER: return RC_FILTER_NAME;
|
|
|
|
case SYM_TABLE: return RC_TABLE_NAME;
|
|
|
|
default:
|
|
|
|
log(L_ERR "Undefined class %d of %s", sym->class, sym->name);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cmd_send_symbols - send all symbols for auto-completion interactive CLI
|
|
|
|
*
|
|
|
|
* This function sends all known symbols for auto-completion interactive BIRD's
|
|
|
|
* CLI. The first symbol is version of BIRD.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cmd_send_symbols(void)
|
|
|
|
{
|
|
|
|
int code, pos = 0;
|
|
|
|
struct symbol *sym = NULL;
|
|
|
|
|
|
|
|
cli_msg(RC_BIRD_VERSION_NUM, "%s", BIRD_VERSION);
|
|
|
|
|
|
|
|
while (sym = cf_walk_symbols(config, sym, &pos))
|
|
|
|
{
|
|
|
|
code = get_cli_code_for_sym(sym);
|
|
|
|
cli_msg(code, "%s", sym->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct iface *i;
|
|
|
|
WALK_LIST(i, iface_list)
|
|
|
|
if (!(i->flags & IF_SHUTDOWN))
|
|
|
|
cli_msg(RC_INTERFACE_NAME, "\"%s\"", i->name);
|
|
|
|
|
2017-07-12 10:43:32 +00:00
|
|
|
cli_msg(RC_DUMP_DONE, "");
|
2016-04-15 09:41:08 +00:00
|
|
|
}
|
|
|
|
|
2010-06-02 20:20:40 +00:00
|
|
|
static void
|
|
|
|
print_size(char *dsc, size_t val)
|
|
|
|
{
|
|
|
|
char *px = " kMG";
|
|
|
|
int i = 0;
|
|
|
|
while ((val >= 10000) && (i < 3))
|
|
|
|
{
|
|
|
|
val = (val + 512) / 1024;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
cli_msg(-1018, "%-17s %4u %cB", dsc, (unsigned) val, px[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern pool *rt_table_pool;
|
|
|
|
extern pool *rta_pool;
|
|
|
|
|
|
|
|
void
|
|
|
|
cmd_show_memory(void)
|
|
|
|
{
|
|
|
|
cli_msg(-1018, "BIRD memory usage");
|
|
|
|
print_size("Routing tables:", rmemsize(rt_table_pool));
|
|
|
|
print_size("Route attributes:", rmemsize(rta_pool));
|
|
|
|
print_size("Protocols:", rmemsize(proto_pool));
|
|
|
|
print_size("Total:", rmemsize(&root_pool));
|
|
|
|
cli_msg(0, "");
|
|
|
|
}
|
2013-07-25 11:15:32 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
cmd_eval(struct f_inst *expr)
|
|
|
|
{
|
|
|
|
struct f_val v = f_eval(expr, this_cli->parser_pool);
|
|
|
|
|
|
|
|
if (v.type == T_RETURN)
|
|
|
|
{
|
|
|
|
cli_msg(8008, "runtime error");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-05 18:12:28 +00:00
|
|
|
buffer buf;
|
|
|
|
LOG_BUFFER_INIT(buf);
|
|
|
|
val_format(v, &buf);
|
|
|
|
cli_msg(23, "%s", buf.start);
|
2013-07-25 11:15:32 +00:00
|
|
|
}
|