]>
Commit | Line | Data |
---|---|---|
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 |
19 | extern int shutting_down; |
20 | extern int configuring; | |
21 | ||
4b87e256 MM |
22 | void |
23 | cmd_show_status(void) | |
24 | { | |
43270902 MM |
25 | byte tim[TM_DATETIME_BUFFER_SIZE]; |
26 | ||
27 | cli_msg(-1000, "BIRD " BIRD_VERSION); | |
c37e7851 | 28 | tm_format_datetime(tim, &config->tf_base, now); |
2f6483cd | 29 | cli_msg(-1011, "Router ID is %R", config->router_id); |
43270902 | 30 | cli_msg(-1011, "Current server time is %s", tim); |
c37e7851 | 31 | tm_format_datetime(tim, &config->tf_base, boot_time); |
43270902 | 32 | cli_msg(-1011, "Last reboot on %s", tim); |
c37e7851 | 33 | tm_format_datetime(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 | ||
46 | void | |
0f808c06 | 47 | cmd_show_symbols(struct sym_show_data *sd) |
4b87e256 MM |
48 | { |
49 | int pos = 0; | |
0f808c06 | 50 | struct symbol *sym = sd->sym; |
4b87e256 MM |
51 | |
52 | if (sym) | |
0f808c06 | 53 | cli_msg(1010, "%-8s\t%s", sym->name, cf_symbol_class_name(sym)); |
4b87e256 MM |
54 | else |
55 | { | |
56 | while (sym = cf_walk_symbols(config, sym, &pos)) | |
0f808c06 OZ |
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)); | |
62 | } | |
4b87e256 MM |
63 | cli_msg(0, ""); |
64 | } | |
65 | } | |
acb60628 OZ |
66 | |
67 | static void | |
68 | print_size(char *dsc, size_t val) | |
69 | { | |
70 | char *px = " kMG"; | |
71 | int i = 0; | |
72 | while ((val >= 10000) && (i < 3)) | |
73 | { | |
74 | val = (val + 512) / 1024; | |
75 | i++; | |
76 | } | |
77 | ||
78 | cli_msg(-1018, "%-17s %4u %cB", dsc, (unsigned) val, px[i]); | |
79 | } | |
80 | ||
81 | extern pool *rt_table_pool; | |
82 | extern pool *rta_pool; | |
af582c48 | 83 | extern pool *roa_pool; |
acb60628 OZ |
84 | extern pool *proto_pool; |
85 | ||
86 | void | |
87 | cmd_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)); | |
af582c48 | 92 | print_size("ROA tables:", rmemsize(roa_pool)); |
acb60628 OZ |
93 | print_size("Protocols:", rmemsize(proto_pool)); |
94 | print_size("Total:", rmemsize(&root_pool)); | |
95 | cli_msg(0, ""); | |
96 | } | |
508d9360 | 97 | |
508d9360 OZ |
98 | void |
99 | cmd_eval(struct f_inst *expr) | |
100 | { | |
101 | struct f_val v = f_eval(expr, this_cli->parser_pool); | |
508d9360 OZ |
102 | |
103 | if (v.type == T_RETURN) | |
104 | { | |
105 | cli_msg(8008, "runtime error"); | |
106 | return; | |
107 | } | |
108 | ||
0e175f9f OZ |
109 | buffer buf; |
110 | LOG_BUFFER_INIT(buf); | |
111 | val_format(v, &buf); | |
112 | cli_msg(23, "%s", buf.start); | |
508d9360 | 113 | } |