diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2006-01-03 22:51:15 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2006-01-03 22:51:15 +0000 |
commit | 5c8a42afadc988c6eb549ec4826d92f7db1ab41d (patch) | |
tree | c9ac796cf1b917764affc02518acb9e273459988 | |
parent | b7edfa3948e4771e4f64dfa20a7d3416b0b86f2c (diff) |
Show RIB statistics via "bgpctl show rib mem".
-rw-r--r-- | usr.sbin/bgpctl/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/bgpctl/bgpctl.c | 69 | ||||
-rw-r--r-- | usr.sbin/bgpctl/parser.c | 3 | ||||
-rw-r--r-- | usr.sbin/bgpctl/parser.h | 3 |
4 files changed, 73 insertions, 5 deletions
diff --git a/usr.sbin/bgpctl/Makefile b/usr.sbin/bgpctl/Makefile index 38e2c973d9a..8ec9355eb68 100644 --- a/usr.sbin/bgpctl/Makefile +++ b/usr.sbin/bgpctl/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.4 2006/01/03 22:20:59 claudio Exp $ +# $OpenBSD: Makefile,v 1.5 2006/01/03 22:51:13 claudio Exp $ .PATH: ${.CURDIR}/../bgpd @@ -11,5 +11,6 @@ CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual CFLAGS+= -Wsign-compare CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../bgpd MAN= bgpctl.8 +LDADD= -lutil .include <bsd.prog.mk> diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c index c79a0d8fe78..3b356c9605e 100644 --- a/usr.sbin/bgpctl/bgpctl.c +++ b/usr.sbin/bgpctl/bgpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpctl.c,v 1.95 2006/01/03 22:20:59 claudio Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.96 2006/01/03 22:51:14 claudio Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -29,6 +29,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <util.h> #include "bgpd.h" #include "session.h" @@ -69,6 +70,8 @@ void show_rib_summary_head(void); void print_prefix(struct bgpd_addr *, u_int8_t, u_int8_t); const char * print_origin(u_int8_t, int); int show_rib_summary_msg(struct imsg *); +char *fmt_mem(int64_t); +int show_rib_memory_msg(struct imsg *); void send_filterset(struct imsgbuf *, struct filter_set_head *); static const char *get_errstr(u_int8_t, u_int8_t); int show_result(struct imsg *); @@ -201,6 +204,9 @@ main(int argc, char *argv[]) &res->af, sizeof(res->af)); show_rib_summary_head(); break; + case SHOW_RIB_MEM: + imsg_compose(ibuf, IMSG_CTL_SHOW_RIB_MEM, 0, 0, -1, NULL, 0); + break; case RELOAD: imsg_compose(ibuf, IMSG_CTL_RELOAD, 0, 0, -1, NULL, 0); printf("reload request sent.\n"); @@ -302,6 +308,9 @@ main(int argc, char *argv[]) case SHOW_RIB: done = show_rib_summary_msg(&imsg); break; + case SHOW_RIB_MEM: + done = show_rib_memory_msg(&imsg); + break; case NETWORK_SHOW: done = show_fib_msg(&imsg); break; @@ -948,7 +957,6 @@ print_origin(u_int8_t origin, int sum) } } - int show_rib_summary_msg(struct imsg *imsg) { @@ -984,6 +992,63 @@ show_rib_summary_msg(struct imsg *imsg) return (0); } +char * +fmt_mem(int64_t num) +{ + static char buf[16]; + + if (fmt_scaled(num, buf) == -1) + snprintf(buf, sizeof(buf), "%lldB", num); + + return (buf); +} + +int +show_rib_memory_msg(struct imsg *imsg) +{ + struct rde_memstats stats; + + switch (imsg->hdr.type) { + case IMSG_CTL_SHOW_RIB_MEM: + memcpy(&stats, imsg->data, sizeof(stats)); + printf("RDE memory statistics\n"); + printf("%10lld IPv4 network entries using %s of memory\n", + stats.pt4_cnt, fmt_mem(stats.pt4_cnt * + sizeof(struct pt_entry4))); + if (stats.pt6_cnt != 0) + printf("%10lld IPv6 network entries using " + "%s of memory\n", stats.pt6_cnt, + fmt_mem(stats.pt6_cnt * sizeof(struct pt_entry6))); + printf("%10lld prefix entries using %s of memory\n", + stats.prefix_cnt, fmt_mem(stats.prefix_cnt * + sizeof(struct prefix))); + printf("%10lld BGP path attribute entries using %s of memory\n", + stats.path_cnt, fmt_mem(stats.path_cnt * + sizeof(struct rde_aspath))); + printf("%10lld BGP AS-PATH attribute entries using " + "%s of memory,\n\t and holding %lld references\n", + stats.aspath_cnt, fmt_mem(stats.aspath_size), + stats.aspath_refs); + printf("%10lld BGP attributes entries using %s of memory\n", + stats.attr_cnt, fmt_mem(stats.attr_cnt * + sizeof(struct attr))); + printf("%10lld BGP attributes using %s of memory\n", + stats.attr_cnt, fmt_mem(stats.attr_data)); + printf("RIB using %s of memory\n", fmt_mem( + stats.pt4_cnt * sizeof(struct pt_entry4) + + stats.pt6_cnt * sizeof(struct pt_entry6) + + stats.prefix_cnt * sizeof(struct prefix) + + stats.path_cnt * sizeof(struct rde_aspath) + + stats.aspath_size + stats.attr_cnt * sizeof(struct attr) + + stats.attr_data)); + break; + default: + break; + } + + return (1); +} + void send_filterset(struct imsgbuf *i, struct filter_set_head *set) { diff --git a/usr.sbin/bgpctl/parser.c b/usr.sbin/bgpctl/parser.c index 17632a9d098..8a848c5a922 100644 --- a/usr.sbin/bgpctl/parser.c +++ b/usr.sbin/bgpctl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.25 2006/01/03 22:05:13 claudio Exp $ */ +/* $OpenBSD: parser.c,v 1.26 2006/01/03 22:51:14 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -123,6 +123,7 @@ static const struct token t_show_rib[] = { { ASTYPE, "transit-as", AS_TRANSIT, t_show_as}, { ASTYPE, "empty-as", AS_EMPTY, NULL}, { KEYWORD, "summary", SHOW_SUMMARY, NULL}, + { KEYWORD, "memory", SHOW_RIB_MEM, NULL}, { FAMILY, "", NONE, NULL}, { ENDTOKEN, "", NONE, NULL} }; diff --git a/usr.sbin/bgpctl/parser.h b/usr.sbin/bgpctl/parser.h index 043eebea9a1..289e036da80 100644 --- a/usr.sbin/bgpctl/parser.h +++ b/usr.sbin/bgpctl/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.9 2005/06/06 17:13:56 henning Exp $ */ +/* $OpenBSD: parser.h,v 1.10 2006/01/03 22:51:14 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -28,6 +28,7 @@ enum actions { SHOW_NEIGHBOR_TIMERS, SHOW_FIB, SHOW_RIB, + SHOW_RIB_MEM, SHOW_NEXTHOP, SHOW_INTERFACE, RELOAD, |