From 4670f09df3f86b76b6603b22b005127adb0eb216 Mon Sep 17 00:00:00 2001 From: claudio Date: Wed, 11 Jul 2018 16:34:36 +0000 Subject: [PATCH] On IMSG_CTL_SHOW_RIB_MEM also send back information of some of the hash structures used in the RDE. Makes it fairly obvious that more is needed in that area. OK phessler@ benno@ --- usr.sbin/bgpd/bgpd.h | 12 +++++++++- usr.sbin/bgpd/rde.c | 14 ++++++++++- usr.sbin/bgpd/rde.h | 5 +++- usr.sbin/bgpd/rde_attr.c | 52 +++++++++++++++++++++++++++++++++++++++- usr.sbin/bgpd/rde_rib.c | 28 +++++++++++++++++++++- usr.sbin/bgpd/session.c | 3 ++- 6 files changed, 108 insertions(+), 6 deletions(-) diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 9c9902ba4ad..c5a00e7b83f 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.323 2018/07/11 14:08:46 benno Exp $ */ +/* $OpenBSD: bgpd.h,v 1.324 2018/07/11 16:34:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -391,6 +391,7 @@ enum imsg_type { IMSG_CTL_SHOW_RIB_LARGECOMMUNITY, IMSG_CTL_SHOW_NETWORK, IMSG_CTL_SHOW_RIB_MEM, + IMSG_CTL_SHOW_RIB_HASH, IMSG_CTL_SHOW_TERSE, IMSG_CTL_SHOW_TIMER, IMSG_CTL_LOG_VERBOSE, @@ -998,6 +999,15 @@ struct rde_memstats { int64_t attr_dcnt; }; +struct rde_hashstats { + char name[16]; + int64_t num; + int64_t min; + int64_t max; + int64_t sum; + int64_t sumq; +}; + #define MRT_FILE_LEN 512 #define MRT2MC(x) ((struct mrt_config *)(x)) #define MRT_MAX_TIMEOUT 7200 diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index bd20edaff5b..66555ff04a8 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.390 2018/07/10 15:13:35 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.391 2018/07/11 16:34:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -376,6 +376,7 @@ rde_dispatch_imsg_session(struct imsgbuf *ibuf) struct ctl_show_rib_request req; struct rde_peer *peer; struct rde_aspath *asp; + struct rde_hashstats rdehash; struct filter_set *s; u_int8_t *asdata; ssize_t n; @@ -620,6 +621,17 @@ badnet: case IMSG_CTL_SHOW_RIB_MEM: imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_RIB_MEM, 0, imsg.hdr.pid, -1, &rdemem, sizeof(rdemem)); + path_hash_stats(&rdehash); + imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_RIB_HASH, 0, + imsg.hdr.pid, -1, &rdehash, sizeof(rdehash)); + aspath_hash_stats(&rdehash); + imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_RIB_HASH, 0, + imsg.hdr.pid, -1, &rdehash, sizeof(rdehash)); + attr_hash_stats(&rdehash); + imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_RIB_HASH, 0, + imsg.hdr.pid, -1, &rdehash, sizeof(rdehash)); + imsg_compose(ibuf_se_ctl, IMSG_CTL_END, 0, imsg.hdr.pid, + -1, NULL, 0); break; case IMSG_CTL_LOG_VERBOSE: /* already checked by SE */ diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index 06a3e0fb24e..80dd6005336 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.176 2018/07/09 14:08:48 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.177 2018/07/11 16:34:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker and @@ -352,6 +352,7 @@ int attr_writebuf(struct ibuf *, u_int8_t, u_int8_t, void *, u_int16_t); void attr_init(u_int32_t); void attr_shutdown(void); +void attr_hash_stats(struct rde_hashstats *); int attr_optadd(struct rde_aspath *, u_int8_t, u_int8_t, void *, u_int16_t); struct attr *attr_optget(const struct rde_aspath *, u_int8_t); @@ -369,6 +370,7 @@ int aspath_verify(void *, u_int16_t, int); #define AS_ERR_SOFT -4 void aspath_init(u_int32_t); void aspath_shutdown(void); +void aspath_hash_stats(struct rde_hashstats *); struct aspath *aspath_get(void *, u_int16_t); void aspath_put(struct aspath *); u_char *aspath_inflate(void *, u_int16_t, u_int16_t *); @@ -472,6 +474,7 @@ re_rib(struct rib_entry *re) void path_init(u_int32_t); void path_init(u_int32_t); void path_shutdown(void); +void path_hash_stats(struct rde_hashstats *); int path_update(struct rib *, struct rde_peer *, struct rde_aspath *, struct bgpd_addr *, int, int); int path_compare(struct rde_aspath *, struct rde_aspath *); diff --git a/usr.sbin/bgpd/rde_attr.c b/usr.sbin/bgpd/rde_attr.c index 424aac1d8a4..a806ce83537 100644 --- a/usr.sbin/bgpd/rde_attr.c +++ b/usr.sbin/bgpd/rde_attr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_attr.c,v 1.102 2018/06/29 11:45:50 claudio Exp $ */ +/* $OpenBSD: rde_attr.c,v 1.103 2018/07/11 16:34:36 claudio Exp $ */ /* * Copyright (c) 2004 Claudio Jeker @@ -137,6 +137,31 @@ attr_shutdown(void) free(attrtable.hashtbl); } +void +attr_hash_stats(struct rde_hashstats *hs) +{ + struct attr *a; + u_int32_t i; + int64_t n; + + memset(hs, 0, sizeof(*hs)); + strlcpy(hs->name, "attr hash", sizeof(hs->name)); + hs->min = LLONG_MAX; + hs->num = attrtable.hashmask + 1; + + for (i = 0; i <= attrtable.hashmask; i++) { + n = 0; + LIST_FOREACH(a, &attrtable.hashtbl[i], entry) + n++; + if (n < hs->min) + hs->min = n; + if (n > hs->max) + hs->max = n; + hs->sum += n; + hs->sumq += n * n; + } +} + int attr_optadd(struct rde_aspath *asp, u_int8_t flags, u_int8_t type, void *data, u_int16_t len) @@ -508,6 +533,31 @@ aspath_shutdown(void) free(astable.hashtbl); } +void +aspath_hash_stats(struct rde_hashstats *hs) +{ + struct aspath *a; + u_int32_t i; + int64_t n; + + memset(hs, 0, sizeof(*hs)); + strlcpy(hs->name, "aspath hash", sizeof(hs->name)); + hs->min = LLONG_MAX; + hs->num = astable.hashmask + 1; + + for (i = 0; i <= astable.hashmask; i++) { + n = 0; + LIST_FOREACH(a, &astable.hashtbl[i], entry) + n++; + if (n < hs->min) + hs->min = n; + if (n > hs->max) + hs->max = n; + hs->sum += n; + hs->sumq += n * n; + } +} + struct aspath * aspath_get(void *data, u_int16_t len) { diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c index 707d35b802e..54c6fcc029b 100644 --- a/usr.sbin/bgpd/rde_rib.c +++ b/usr.sbin/bgpd/rde_rib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_rib.c,v 1.168 2018/07/10 07:58:13 benno Exp $ */ +/* $OpenBSD: rde_rib.c,v 1.169 2018/07/11 16:34:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -389,6 +390,31 @@ path_shutdown(void) free(pathtable.path_hashtbl); } +void +path_hash_stats(struct rde_hashstats *hs) +{ + struct rde_aspath *a; + u_int32_t i; + int64_t n; + + memset(hs, 0, sizeof(*hs)); + strlcpy(hs->name, "path hash", sizeof(hs->name)); + hs->min = LLONG_MAX; + hs->num = pathtable.path_hashmask + 1; + + for (i = 0; i <= pathtable.path_hashmask; i++) { + n = 0; + LIST_FOREACH(a, &pathtable.path_hashtbl[i], path_l) + n++; + if (n < hs->min) + hs->min = n; + if (n > hs->max) + hs->max = n; + hs->sum += n; + hs->sumq += n * n; + } +} + int path_update(struct rib *rib, struct rde_peer *peer, struct rde_aspath *nasp, struct bgpd_addr *prefix, int prefixlen, int flag) diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index 61cd8dc7e7d..1cd90aa3d2c 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.364 2017/05/29 14:22:51 benno Exp $ */ +/* $OpenBSD: session.c,v 1.365 2018/07/11 16:34:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004, 2005 Henning Brauer @@ -2877,6 +2877,7 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx, u_int *listener_cnt) case IMSG_CTL_SHOW_RIB_PREFIX: case IMSG_CTL_SHOW_RIB_ATTR: case IMSG_CTL_SHOW_RIB_MEM: + case IMSG_CTL_SHOW_RIB_HASH: case IMSG_CTL_SHOW_NETWORK: case IMSG_CTL_SHOW_NEIGHBOR: if (idx != PFD_PIPE_ROUTE_CTL) -- 2.20.1