cmds.c 2.42 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*
 *	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"
10
#include "nest/protocol.h"
11
#include "nest/route.h"
12 13 14 15
#include "nest/cli.h"
#include "conf/conf.h"
#include "nest/cmds.h"
#include "lib/string.h"
16
#include "lib/resource.h"
17
#include "filter/filter.h"
18

19 20 21
extern int shutting_down;
extern int configuring;

22 23 24
void
cmd_show_status(void)
{
25 26 27
  byte tim[TM_DATETIME_BUFFER_SIZE];

  cli_msg(-1000, "BIRD " BIRD_VERSION);
28
  tm_format_time(tim, &config->tf_base, current_time());
29
  cli_msg(-1011, "Router ID is %R", config->router_id);
30
  cli_msg(-1011, "Current server time is %s", tim);
31
  tm_format_time(tim, &config->tf_base, boot_time);
32
  cli_msg(-1011, "Last reboot on %s", tim);
33
  tm_format_time(tim, &config->tf_base, config->load_time);
34
  cli_msg(-1011, "Last reconfiguration on %s", tim);
35

36 37
  graceful_restart_show_status();

38 39
  if (shutting_down)
    cli_msg(13, "Shutdown in progress");
40
  else if (configuring)
41 42 43
    cli_msg(13, "Reconfiguration in progress");
  else
    cli_msg(13, "Daemon is up and running");
44 45 46
}

void
47
cmd_show_symbols(struct sym_show_data *sd)
48
{
49 50
  if (sd->sym)
    cli_msg(1010, "%-8s\t%s", sd->sym->name, cf_symbol_class_name(sd->sym));
51
  else
52 53
  {
    HASH_WALK(config->sym_hash, next, sym)
54
    {
55 56 57 58 59 60 61
      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));
62
    }
63 64 65 66
    HASH_WALK_END;

    cli_msg(0, "");
  }
67
}
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

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, "");
}
96 97 98 99 100 101 102 103 104 105 106 107

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;
    }

108 109 110 111
  buffer buf;
  LOG_BUFFER_INIT(buf);
  val_format(v, &buf);
  cli_msg(23, "%s", buf.start);
112
}