]> git.ipfire.org Git - thirdparty/bird.git/blame - nest/cmds.c
Formalized our contribution policy which we're currently applying
[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);
71423871 30 cli_msg(-1011, "Hostname is %s", config->hostname);
43270902 31 cli_msg(-1011, "Current server time is %s", tim);
f047271c 32 tm_format_time(tim, &config->tf_base, boot_time);
43270902 33 cli_msg(-1011, "Last reboot on %s", tim);
f047271c 34 tm_format_time(tim, &config->tf_base, config->load_time);
43270902 35 cli_msg(-1011, "Last reconfiguration on %s", tim);
a92cf57d 36
0c791f87
OZ
37 graceful_restart_show_status();
38
43270902
MM
39 if (shutting_down)
40 cli_msg(13, "Shutdown in progress");
a92cf57d 41 else if (configuring)
43270902
MM
42 cli_msg(13, "Reconfiguration in progress");
43 else
44 cli_msg(13, "Daemon is up and running");
4b87e256
MM
45}
46
47void
0f808c06 48cmd_show_symbols(struct sym_show_data *sd)
4b87e256 49{
b7761af3
OZ
50 if (sd->sym)
51 cli_msg(1010, "%-8s\t%s", sd->sym->name, cf_symbol_class_name(sd->sym));
4b87e256 52 else
b7761af3 53 {
8e177cf3
MM
54 for (const struct sym_scope *scope = config->root_scope; scope; scope = scope->next)
55 HASH_WALK(scope->hash, next, sym)
56 {
57 if (!sym->scope->active)
58 continue;
59
60 if (sd->type && (sym->class != sd->type))
61 continue;
62
63 cli_msg(-1010, "%-8s\t%s", sym->name, cf_symbol_class_name(sym));
64 }
65 HASH_WALK_END;
b7761af3
OZ
66
67 cli_msg(0, "");
68 }
4b87e256 69}
acb60628 70
f772afc5
MM
71#define SIZE_SUFFIX " kMGT"
72#define SIZE_FORMAT "% 4u.%1u % 1cB"
73#define SIZE_ARGS(a) (a).val, (a).decimal, SIZE_SUFFIX[(a).magnitude]
74
75struct size_args {
76 u64 val:48;
77 u64 decimal:8;
78 u64 magnitude:8;
79};
80
81static struct size_args
82get_size_args(u64 val)
acb60628 83{
f772afc5
MM
84#define VALDEC 10 /* One decimal place */
85 val *= VALDEC;
86
87 uint i = 0;
88 while ((val >= 10000 * VALDEC) && (i < 4))
acb60628
OZ
89 {
90 val = (val + 512) / 1024;
91 i++;
92 }
93
f772afc5
MM
94 return (struct size_args) {
95 .val = (val / VALDEC),
96 .decimal = (val % VALDEC),
97 .magnitude = i,
98 };
99}
100
101static void
102print_size(char *dsc, struct resmem vals)
103{
104 struct size_args effective = get_size_args(vals.effective);
105 struct size_args overhead = get_size_args(vals.overhead);
106
107 cli_msg(-1018, "%-17s " SIZE_FORMAT " " SIZE_FORMAT, dsc, SIZE_ARGS(effective), SIZE_ARGS(overhead));
acb60628
OZ
108}
109
110extern pool *rt_table_pool;
111extern pool *rta_pool;
c78247f9 112extern uint *pages_kept;
acb60628
OZ
113
114void
115cmd_show_memory(void)
116{
117 cli_msg(-1018, "BIRD memory usage");
f772afc5 118 cli_msg(-1018, "%-17s Effective Overhead", "");
acb60628
OZ
119 print_size("Routing tables:", rmemsize(rt_table_pool));
120 print_size("Route attributes:", rmemsize(rta_pool));
121 print_size("Protocols:", rmemsize(proto_pool));
37b64441 122 print_size("Current config:", rmemsize(config_pool));
f772afc5 123 struct resmem total = rmemsize(&root_pool);
644e9ca9 124#ifdef HAVE_MMAP
c78247f9
MM
125 print_size("Standby memory:", (struct resmem) { .overhead = page_size * *pages_kept });
126 total.overhead += page_size * *pages_kept;
644e9ca9
MM
127#endif
128 print_size("Total:", total);
acb60628
OZ
129 cli_msg(0, "");
130}
508d9360 131
508d9360 132void
4c553c5a 133cmd_eval(const struct f_line *expr)
508d9360 134{
52893045
MM
135 buffer buf;
136 LOG_BUFFER_INIT(buf);
137
138 if (f_eval_buf(expr, this_cli->parser_pool, &buf) > F_RETURN)
508d9360
OZ
139 {
140 cli_msg(8008, "runtime error");
141 return;
142 }
143
0e175f9f 144 cli_msg(23, "%s", buf.start);
508d9360 145}