]> git.ipfire.org Git - thirdparty/bird.git/blame - nest/cmds.c
Bison: A bit more verbose error messages in config.
[thirdparty/bird.git] / nest / cmds.c
CommitLineData
4b87e256
MM
1/*
2 * BIRD Internet Routing Daemon -- CLI Commands Which Don't Fit Anywhere Else
3 *
4 * (c) 2000 Martin Mares <mj@ucw.cz>
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9#include "nest/bird.h"
0c791f87 10#include "nest/protocol.h"
0f808c06 11#include "nest/route.h"
4b87e256
MM
12#include "nest/cli.h"
13#include "conf/conf.h"
14#include "nest/cmds.h"
15#include "lib/string.h"
acb60628 16#include "lib/resource.h"
508d9360 17#include "filter/filter.h"
4b87e256 18
a92cf57d
OZ
19extern int shutting_down;
20extern int configuring;
21
4b87e256
MM
22void
23cmd_show_status(void)
24{
43270902
MM
25 byte tim[TM_DATETIME_BUFFER_SIZE];
26
27 cli_msg(-1000, "BIRD " BIRD_VERSION);
f047271c 28 tm_format_time(tim, &config->tf_base, current_time());
2f6483cd 29 cli_msg(-1011, "Router ID is %R", config->router_id);
43270902 30 cli_msg(-1011, "Current server time is %s", tim);
f047271c 31 tm_format_time(tim, &config->tf_base, boot_time);
43270902 32 cli_msg(-1011, "Last reboot on %s", tim);
f047271c 33 tm_format_time(tim, &config->tf_base, config->load_time);
43270902 34 cli_msg(-1011, "Last reconfiguration on %s", tim);
a92cf57d 35
0c791f87
OZ
36 graceful_restart_show_status();
37
43270902
MM
38 if (shutting_down)
39 cli_msg(13, "Shutdown in progress");
a92cf57d 40 else if (configuring)
43270902
MM
41 cli_msg(13, "Reconfiguration in progress");
42 else
43 cli_msg(13, "Daemon is up and running");
4b87e256
MM
44}
45
46void
0f808c06 47cmd_show_symbols(struct sym_show_data *sd)
4b87e256 48{
b7761af3
OZ
49 if (sd->sym)
50 cli_msg(1010, "%-8s\t%s", sd->sym->name, cf_symbol_class_name(sd->sym));
4b87e256 51 else
b7761af3
OZ
52 {
53 HASH_WALK(config->sym_hash, next, sym)
4b87e256 54 {
b7761af3
OZ
55 if (!sym->scope->active)
56 continue;
57
58 if (sd->type && (sym->class != sd->type))
59 continue;
60
61 cli_msg(-1010, "%-8s\t%s", sym->name, cf_symbol_class_name(sym));
4b87e256 62 }
b7761af3
OZ
63 HASH_WALK_END;
64
65 cli_msg(0, "");
66 }
4b87e256 67}
acb60628
OZ
68
69static void
70print_size(char *dsc, size_t val)
71{
72 char *px = " kMG";
73 int i = 0;
74 while ((val >= 10000) && (i < 3))
75 {
76 val = (val + 512) / 1024;
77 i++;
78 }
79
80 cli_msg(-1018, "%-17s %4u %cB", dsc, (unsigned) val, px[i]);
81}
82
83extern pool *rt_table_pool;
84extern pool *rta_pool;
acb60628
OZ
85
86void
87cmd_show_memory(void)
88{
89 cli_msg(-1018, "BIRD memory usage");
90 print_size("Routing tables:", rmemsize(rt_table_pool));
91 print_size("Route attributes:", rmemsize(rta_pool));
92 print_size("Protocols:", rmemsize(proto_pool));
93 print_size("Total:", rmemsize(&root_pool));
94 cli_msg(0, "");
95}
508d9360 96
508d9360
OZ
97void
98cmd_eval(struct f_inst *expr)
99{
100 struct f_val v = f_eval(expr, this_cli->parser_pool);
508d9360
OZ
101
102 if (v.type == T_RETURN)
103 {
104 cli_msg(8008, "runtime error");
105 return;
106 }
107
0e175f9f
OZ
108 buffer buf;
109 LOG_BUFFER_INIT(buf);
110 val_format(v, &buf);
111 cli_msg(23, "%s", buf.start);
508d9360 112}