| 
									
										
										
										
											2000-01-19 12:30:19 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *	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"
 | 
					
						
							| 
									
										
										
										
											2014-03-20 14:07:12 +01:00
										 |  |  | #include "nest/protocol.h"
 | 
					
						
							| 
									
										
										
										
											2022-03-31 19:09:38 +02:00
										 |  |  | #include "nest/rt.h"
 | 
					
						
							| 
									
										
										
										
											2000-01-19 12:30:19 +00:00
										 |  |  | #include "nest/cli.h"
 | 
					
						
							|  |  |  | #include "conf/conf.h"
 | 
					
						
							|  |  |  | #include "nest/cmds.h"
 | 
					
						
							|  |  |  | #include "lib/string.h"
 | 
					
						
							| 
									
										
										
										
											2010-06-02 22:20:40 +02:00
										 |  |  | #include "lib/resource.h"
 | 
					
						
							| 
									
										
										
										
											2013-07-25 13:15:32 +02:00
										 |  |  | #include "filter/filter.h"
 | 
					
						
							| 
									
										
										
										
											2000-01-19 12:30:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-26 12:40:48 +01:00
										 |  |  | extern int shutting_down; | 
					
						
							|  |  |  | extern int configuring; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-01-19 12:30:19 +00:00
										 |  |  | void | 
					
						
							|  |  |  | cmd_show_status(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-03-12 22:44:54 +00:00
										 |  |  |   byte tim[TM_DATETIME_BUFFER_SIZE]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   cli_msg(-1000, "BIRD " BIRD_VERSION); | 
					
						
							| 
									
										
										
										
											2017-06-06 16:47:30 +02:00
										 |  |  |   tm_format_time(tim, &config->tf_base, current_time()); | 
					
						
							| 
									
										
										
										
											2009-07-23 16:06:25 +02:00
										 |  |  |   cli_msg(-1011, "Router ID is %R", config->router_id); | 
					
						
							| 
									
										
										
										
											2021-02-10 16:53:57 +01:00
										 |  |  |   cli_msg(-1011, "Hostname is %s", config->hostname); | 
					
						
							| 
									
										
										
										
											2000-03-12 22:44:54 +00:00
										 |  |  |   cli_msg(-1011, "Current server time is %s", tim); | 
					
						
							| 
									
										
										
										
											2017-06-06 16:47:30 +02:00
										 |  |  |   tm_format_time(tim, &config->tf_base, boot_time); | 
					
						
							| 
									
										
										
										
											2000-03-12 22:44:54 +00:00
										 |  |  |   cli_msg(-1011, "Last reboot on %s", tim); | 
					
						
							| 
									
										
										
										
											2017-06-06 16:47:30 +02:00
										 |  |  |   tm_format_time(tim, &config->tf_base, config->load_time); | 
					
						
							| 
									
										
										
										
											2000-03-12 22:44:54 +00:00
										 |  |  |   cli_msg(-1011, "Last reconfiguration on %s", tim); | 
					
						
							| 
									
										
										
										
											2012-12-26 12:40:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-20 14:07:12 +01:00
										 |  |  |   graceful_restart_show_status(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-03-12 22:44:54 +00:00
										 |  |  |   if (shutting_down) | 
					
						
							|  |  |  |     cli_msg(13, "Shutdown in progress"); | 
					
						
							| 
									
										
										
										
											2012-12-26 12:40:48 +01:00
										 |  |  |   else if (configuring) | 
					
						
							| 
									
										
										
										
											2000-03-12 22:44:54 +00:00
										 |  |  |     cli_msg(13, "Reconfiguration in progress"); | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     cli_msg(13, "Daemon is up and running"); | 
					
						
							| 
									
										
										
										
											2000-01-19 12:30:19 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							| 
									
										
										
										
											2012-03-16 12:47:12 +01:00
										 |  |  | cmd_show_symbols(struct sym_show_data *sd) | 
					
						
							| 
									
										
										
										
											2000-01-19 12:30:19 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-25 23:30:39 +02:00
										 |  |  |   if (sd->sym) | 
					
						
							|  |  |  |     cli_msg(1010, "%-8s\t%s", sd->sym->name, cf_symbol_class_name(sd->sym)); | 
					
						
							| 
									
										
										
										
											2000-01-19 12:30:19 +00:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2017-05-25 23:30:39 +02:00
										 |  |  |   { | 
					
						
							| 
									
										
										
										
											2022-05-02 20:29:03 +02:00
										 |  |  |     for (const struct sym_scope *scope = config->root_scope; scope; scope = scope->next) | 
					
						
							|  |  |  |       HASH_WALK(scope->hash, next, sym) | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  | 	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)); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       HASH_WALK_END; | 
					
						
							| 
									
										
										
										
											2017-05-25 23:30:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     cli_msg(0, ""); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2000-01-19 12:30:19 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-06-02 22:20:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-27 00:21:12 +01:00
										 |  |  | #define SIZE_SUFFIX	" kMGT"
 | 
					
						
							|  |  |  | #define SIZE_FORMAT	"% 4u.%1u % 1cB"
 | 
					
						
							|  |  |  | #define SIZE_ARGS(a)	(a).val, (a).decimal, SIZE_SUFFIX[(a).magnitude]
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct size_args { | 
					
						
							|  |  |  |   u64 val:48; | 
					
						
							|  |  |  |   u64 decimal:8; | 
					
						
							|  |  |  |   u64 magnitude:8; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct size_args | 
					
						
							|  |  |  | get_size_args(u64 val) | 
					
						
							| 
									
										
										
										
											2010-06-02 22:20:40 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-11-27 00:21:12 +01:00
										 |  |  | #define VALDEC	10 /* One decimal place */
 | 
					
						
							|  |  |  |   val *= VALDEC; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   uint i = 0; | 
					
						
							|  |  |  |   while ((val >= 10000 * VALDEC) && (i < 4)) | 
					
						
							| 
									
										
										
										
											2010-06-02 22:20:40 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |       val = (val + 512) / 1024; | 
					
						
							|  |  |  |       i++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-27 00:21:12 +01:00
										 |  |  |   return (struct size_args) { | 
					
						
							|  |  |  |     .val = (val / VALDEC), | 
					
						
							|  |  |  |     .decimal = (val % VALDEC), | 
					
						
							|  |  |  |     .magnitude = i, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | print_size(char *dsc, struct resmem vals) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   struct size_args effective = get_size_args(vals.effective); | 
					
						
							|  |  |  |   struct size_args overhead = get_size_args(vals.overhead); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   cli_msg(-1018, "%-17s " SIZE_FORMAT "   " SIZE_FORMAT, dsc, SIZE_ARGS(effective), SIZE_ARGS(overhead)); | 
					
						
							| 
									
										
										
										
											2010-06-02 22:20:40 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extern pool *rt_table_pool; | 
					
						
							|  |  |  | extern pool *rta_pool; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | cmd_show_memory(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   cli_msg(-1018, "BIRD memory usage"); | 
					
						
							| 
									
										
										
										
											2021-11-27 00:21:12 +01:00
										 |  |  |   cli_msg(-1018, "%-17s Effective    Overhead", ""); | 
					
						
							| 
									
										
										
										
											2010-06-02 22:20:40 +02:00
										 |  |  |   print_size("Routing tables:", rmemsize(rt_table_pool)); | 
					
						
							|  |  |  |   print_size("Route attributes:", rmemsize(rta_pool)); | 
					
						
							|  |  |  |   print_size("Protocols:", rmemsize(proto_pool)); | 
					
						
							| 
									
										
										
										
											2022-11-01 08:56:26 +01:00
										 |  |  |   print_size("Current config:", rmemsize(config_pool)); | 
					
						
							| 
									
										
										
										
											2021-11-27 00:21:12 +01:00
										 |  |  |   struct resmem total = rmemsize(&root_pool); | 
					
						
							| 
									
										
										
										
											2021-11-24 17:30:13 +01:00
										 |  |  | #ifdef HAVE_MMAP
 | 
					
						
							| 
									
										
										
										
											2022-09-21 11:49:35 +02:00
										 |  |  |   int pk  = atomic_load_explicit(&pages_kept, memory_order_relaxed) | 
					
						
							|  |  |  | 	  + atomic_load_explicit(&pages_kept_locally, memory_order_relaxed); | 
					
						
							| 
									
										
										
										
											2022-09-20 14:57:43 +02:00
										 |  |  |   print_size("Standby memory:", (struct resmem) { .overhead = page_size * pk }); | 
					
						
							|  |  |  |   total.overhead += page_size * pk; | 
					
						
							| 
									
										
										
										
											2021-11-24 17:30:13 +01:00
										 |  |  | #endif
 | 
					
						
							|  |  |  |   print_size("Total:", total); | 
					
						
							| 
									
										
										
										
											2010-06-02 22:20:40 +02:00
										 |  |  |   cli_msg(0, ""); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-07-25 13:15:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							| 
									
										
										
										
											2018-12-27 14:26:11 +01:00
										 |  |  | cmd_eval(const struct f_line *expr) | 
					
						
							| 
									
										
										
										
											2013-07-25 13:15:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-11 17:12:48 +01:00
										 |  |  |   buffer buf; | 
					
						
							|  |  |  |   LOG_BUFFER_INIT(buf); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-10 18:55:15 +02:00
										 |  |  |   if (f_eval_buf(expr, &buf) > F_RETURN) | 
					
						
							| 
									
										
										
										
											2013-07-25 13:15:32 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |       cli_msg(8008, "runtime error"); | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-05 20:12:28 +02:00
										 |  |  |   cli_msg(23, "%s", buf.start); | 
					
						
							| 
									
										
										
										
											2013-07-25 13:15:32 +02:00
										 |  |  | } |