2000-01-19 20:30:19 +08: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 21:07:12 +08:00
|
|
|
#include "nest/protocol.h"
|
2012-03-16 19:47:12 +08:00
|
|
|
#include "nest/route.h"
|
2000-01-19 20:30:19 +08:00
|
|
|
#include "nest/cli.h"
|
|
|
|
#include "conf/conf.h"
|
|
|
|
#include "nest/cmds.h"
|
|
|
|
#include "lib/string.h"
|
2010-06-03 04:20:40 +08:00
|
|
|
#include "lib/resource.h"
|
2013-07-25 19:15:32 +08:00
|
|
|
#include "filter/filter.h"
|
2019-02-08 20:38:12 +08:00
|
|
|
#include "filter/data.h"
|
2000-01-19 20:30:19 +08:00
|
|
|
|
2012-12-26 19:40:48 +08:00
|
|
|
extern int shutting_down;
|
|
|
|
extern int configuring;
|
|
|
|
|
2000-01-19 20:30:19 +08:00
|
|
|
void
|
|
|
|
cmd_show_status(void)
|
|
|
|
{
|
2000-03-13 06:44:54 +08:00
|
|
|
byte tim[TM_DATETIME_BUFFER_SIZE];
|
|
|
|
|
|
|
|
cli_msg(-1000, "BIRD " BIRD_VERSION);
|
2017-06-06 22:47:30 +08:00
|
|
|
tm_format_time(tim, &config->tf_base, current_time());
|
2009-07-23 22:06:25 +08:00
|
|
|
cli_msg(-1011, "Router ID is %R", config->router_id);
|
2000-03-13 06:44:54 +08:00
|
|
|
cli_msg(-1011, "Current server time is %s", tim);
|
2017-06-06 22:47:30 +08:00
|
|
|
tm_format_time(tim, &config->tf_base, boot_time);
|
2000-03-13 06:44:54 +08:00
|
|
|
cli_msg(-1011, "Last reboot on %s", tim);
|
2017-06-06 22:47:30 +08:00
|
|
|
tm_format_time(tim, &config->tf_base, config->load_time);
|
2000-03-13 06:44:54 +08:00
|
|
|
cli_msg(-1011, "Last reconfiguration on %s", tim);
|
2012-12-26 19:40:48 +08:00
|
|
|
|
2014-03-20 21:07:12 +08:00
|
|
|
graceful_restart_show_status();
|
|
|
|
|
2000-03-13 06:44:54 +08:00
|
|
|
if (shutting_down)
|
|
|
|
cli_msg(13, "Shutdown in progress");
|
2012-12-26 19:40:48 +08:00
|
|
|
else if (configuring)
|
2000-03-13 06:44:54 +08:00
|
|
|
cli_msg(13, "Reconfiguration in progress");
|
|
|
|
else
|
|
|
|
cli_msg(13, "Daemon is up and running");
|
2000-01-19 20:30:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 19:47:12 +08:00
|
|
|
cmd_show_symbols(struct sym_show_data *sd)
|
2000-01-19 20:30:19 +08:00
|
|
|
{
|
2017-05-26 05:30:39 +08:00
|
|
|
if (sd->sym)
|
|
|
|
cli_msg(1010, "%-8s\t%s", sd->sym->name, cf_symbol_class_name(sd->sym));
|
2000-01-19 20:30:19 +08:00
|
|
|
else
|
2017-05-26 05:30:39 +08:00
|
|
|
{
|
|
|
|
HASH_WALK(config->sym_hash, next, sym)
|
2000-01-19 20:30:19 +08:00
|
|
|
{
|
2017-05-26 05:30:39 +08:00
|
|
|
if (!sym->scope->active)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sd->type && (sym->class != sd->type))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cli_msg(-1010, "%-8s\t%s", sym->name, cf_symbol_class_name(sym));
|
2000-01-19 20:30:19 +08:00
|
|
|
}
|
2017-05-26 05:30:39 +08:00
|
|
|
HASH_WALK_END;
|
|
|
|
|
|
|
|
cli_msg(0, "");
|
|
|
|
}
|
2000-01-19 20:30:19 +08:00
|
|
|
}
|
2010-06-03 04:20:40 +08: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 19:15:32 +08:00
|
|
|
|
|
|
|
void
|
2018-12-27 21:26:11 +08:00
|
|
|
cmd_eval(const struct f_line *expr)
|
2013-07-25 19:15:32 +08:00
|
|
|
{
|
2018-12-27 21:26:11 +08:00
|
|
|
/* TODO: Return directly the string from eval */
|
2018-12-17 20:51:11 +08:00
|
|
|
struct f_val v;
|
|
|
|
if (f_eval(expr, this_cli->parser_pool, &v) > F_RETURN)
|
2013-07-25 19:15:32 +08:00
|
|
|
{
|
|
|
|
cli_msg(8008, "runtime error");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-06 02:12:28 +08:00
|
|
|
buffer buf;
|
|
|
|
LOG_BUFFER_INIT(buf);
|
2018-12-27 21:26:11 +08:00
|
|
|
val_format(&v, &buf);
|
2013-10-06 02:12:28 +08:00
|
|
|
cli_msg(23, "%s", buf.start);
|
2013-07-25 19:15:32 +08:00
|
|
|
}
|