On IMSG_CTL_SHOW_RIB_MEM also send back information of some of the
authorclaudio <claudio@openbsd.org>
Wed, 11 Jul 2018 16:34:36 +0000 (16:34 +0000)
committerclaudio <claudio@openbsd.org>
Wed, 11 Jul 2018 16:34:36 +0000 (16:34 +0000)
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
usr.sbin/bgpd/rde.c
usr.sbin/bgpd/rde.h
usr.sbin/bgpd/rde_attr.c
usr.sbin/bgpd/rde_rib.c
usr.sbin/bgpd/session.c

index 9c9902b..c5a00e7 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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
index bd20eda..66555ff 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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 */
index 06a3e0f..80dd600 100644 (file)
@@ -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 <claudio@openbsd.org> 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 *);
index 424aac1..a806ce8 100644 (file)
@@ -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 <claudio@openbsd.org>
@@ -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)
 {
index 707d35b..54c6fcc 100644 (file)
@@ -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 <claudio@openbsd.org>
@@ -19,6 +19,7 @@
 #include <sys/types.h>
 #include <sys/queue.h>
 
+#include <limits.h>
 #include <stdlib.h>
 #include <string.h>
 #include <siphash.h>
@@ -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)
index 61cd8dc..1cd90aa 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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)