]> git.ipfire.org Git - thirdparty/bird.git/blob - nest/cmds.c
Merge branch 'master' into add-path
[thirdparty/bird.git] / nest / cmds.c
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"
10 #include "nest/route.h"
11 #include "nest/cli.h"
12 #include "conf/conf.h"
13 #include "nest/cmds.h"
14 #include "lib/string.h"
15 #include "lib/resource.h"
16 #include "filter/filter.h"
17
18 extern int shutting_down;
19 extern int configuring;
20
21 void
22 cmd_show_status(void)
23 {
24 byte tim[TM_DATETIME_BUFFER_SIZE];
25
26 cli_msg(-1000, "BIRD " BIRD_VERSION);
27 tm_format_datetime(tim, &config->tf_base, now);
28 cli_msg(-1011, "Router ID is %R", config->router_id);
29 cli_msg(-1011, "Current server time is %s", tim);
30 tm_format_datetime(tim, &config->tf_base, boot_time);
31 cli_msg(-1011, "Last reboot on %s", tim);
32 tm_format_datetime(tim, &config->tf_base, config->load_time);
33 cli_msg(-1011, "Last reconfiguration on %s", tim);
34
35 if (shutting_down)
36 cli_msg(13, "Shutdown in progress");
37 else if (configuring)
38 cli_msg(13, "Reconfiguration in progress");
39 else
40 cli_msg(13, "Daemon is up and running");
41 }
42
43 void
44 cmd_show_symbols(struct sym_show_data *sd)
45 {
46 int pos = 0;
47 struct symbol *sym = sd->sym;
48
49 if (sym)
50 cli_msg(1010, "%-8s\t%s", sym->name, cf_symbol_class_name(sym));
51 else
52 {
53 while (sym = cf_walk_symbols(config, sym, &pos))
54 {
55 if (sd->type && (sym->class != sd->type))
56 continue;
57
58 cli_msg(-1010, "%-8s\t%s", sym->name, cf_symbol_class_name(sym));
59 }
60 cli_msg(0, "");
61 }
62 }
63
64 static void
65 print_size(char *dsc, size_t val)
66 {
67 char *px = " kMG";
68 int i = 0;
69 while ((val >= 10000) && (i < 3))
70 {
71 val = (val + 512) / 1024;
72 i++;
73 }
74
75 cli_msg(-1018, "%-17s %4u %cB", dsc, (unsigned) val, px[i]);
76 }
77
78 extern pool *rt_table_pool;
79 extern pool *rta_pool;
80 extern pool *roa_pool;
81 extern pool *proto_pool;
82
83 void
84 cmd_show_memory(void)
85 {
86 cli_msg(-1018, "BIRD memory usage");
87 print_size("Routing tables:", rmemsize(rt_table_pool));
88 print_size("Route attributes:", rmemsize(rta_pool));
89 print_size("ROA tables:", rmemsize(roa_pool));
90 print_size("Protocols:", rmemsize(proto_pool));
91 print_size("Total:", rmemsize(&root_pool));
92 cli_msg(0, "");
93 }
94
95 void
96 cmd_eval(struct f_inst *expr)
97 {
98 struct f_val v = f_eval(expr, this_cli->parser_pool);
99
100 if (v.type == T_RETURN)
101 {
102 cli_msg(8008, "runtime error");
103 return;
104 }
105
106 buffer buf;
107 LOG_BUFFER_INIT(buf);
108 val_format(v, &buf);
109 cli_msg(23, "%s", buf.start);
110 }