diff options
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 16 | ||||
-rw-r--r-- | usr.sbin/bgpd/control.c | 3 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde.c | 7 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde.h | 4 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_attr.c | 19 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_prefix.c | 14 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_rib.c | 13 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.c | 3 |
8 files changed, 69 insertions, 10 deletions
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 931bec7d860..197612631e2 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.182 2006/01/03 22:19:59 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.183 2006/01/03 22:49:17 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -315,6 +315,7 @@ enum imsg_type { IMSG_CTL_SHOW_RIB_PREFIX, IMSG_CTL_SHOW_NETWORK, IMSG_CTL_SHOW_NETWORK6, + IMSG_CTL_SHOW_RIB_MEM, IMSG_REFRESH, IMSG_IFINFO }; @@ -629,6 +630,19 @@ struct rrefresh { u_int8_t safi; }; +struct rde_memstats { + int64_t path_cnt; + int64_t prefix_cnt; + int64_t pt4_cnt; + int64_t pt6_cnt; + int64_t nexthop_cnt; + int64_t aspath_cnt; + int64_t aspath_size; + int64_t aspath_refs; + int64_t attr_cnt; + int64_t attr_data; +}; + /* Address Family Numbers as per rfc1700 */ #define AFI_IPv4 1 #define AFI_IPv6 2 diff --git a/usr.sbin/bgpd/control.c b/usr.sbin/bgpd/control.c index 18f63aa8dc8..b2cb2418c67 100644 --- a/usr.sbin/bgpd/control.c +++ b/usr.sbin/bgpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.45 2005/10/19 12:32:16 henning Exp $ */ +/* $OpenBSD: control.c,v 1.46 2006/01/03 22:49:17 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -288,6 +288,7 @@ control_dispatch_msg(struct pollfd *pfd, u_int *ctl_cnt) case IMSG_CTL_SHOW_RIB: case IMSG_CTL_SHOW_RIB_AS: case IMSG_CTL_SHOW_RIB_PREFIX: + case IMSG_CTL_SHOW_RIB_MEM: case IMSG_CTL_SHOW_NETWORK: c->ibuf.pid = imsg.hdr.pid; imsg_compose_rde(imsg.hdr.type, imsg.hdr.pid, diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 99ade4ff685..1a971277e2f 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.187 2006/01/03 15:48:39 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.188 2006/01/03 22:49:17 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -97,6 +97,7 @@ struct filter_head *rules_l, *newrules; struct imsgbuf *ibuf_se; struct imsgbuf *ibuf_main; struct mrt *mrt; +struct rde_memstats rdemem; void rde_sighdlr(int sig) @@ -435,6 +436,10 @@ rde_dispatch_imsg_session(struct imsgbuf *ibuf) imsg_compose(ibuf_se, IMSG_CTL_END, 0, imsg.hdr.pid, -1, NULL, 0); break; + case IMSG_CTL_SHOW_RIB_MEM: + imsg_compose(ibuf_se, IMSG_CTL_SHOW_RIB_MEM, 0, + imsg.hdr.pid, -1, &rdemem, sizeof(rdemem)); + break; default: break; } diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index 2dd90e7e40f..0ad9c60550c 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.78 2006/01/03 22:19:59 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.79 2006/01/03 22:49:17 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and @@ -236,6 +236,8 @@ struct prefix { u_int32_t flags; }; +extern struct rde_memstats rdemem; + /* prototypes */ /* rde.c */ void rde_send_kroute(struct prefix *, struct prefix *); diff --git a/usr.sbin/bgpd/rde_attr.c b/usr.sbin/bgpd/rde_attr.c index f7cd6a86638..9a303cc3d8c 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.53 2006/01/03 22:19:59 claudio Exp $ */ +/* $OpenBSD: rde_attr.c,v 1.54 2006/01/03 22:49:17 claudio Exp $ */ /* * Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org> @@ -74,6 +74,7 @@ attr_optadd(struct rde_aspath *asp, u_int8_t flags, u_int8_t type, a = calloc(1, sizeof(struct attr)); if (a == NULL) fatal("attr_optadd"); + rdemem.attr_cnt++; a->flags = flags; a->type = type; @@ -83,6 +84,7 @@ attr_optadd(struct rde_aspath *asp, u_int8_t flags, u_int8_t type, if (a->data == NULL) fatal("attr_optadd"); + rdemem.attr_data += len; memcpy(a->data, data, len); } else a->data = NULL; @@ -91,6 +93,8 @@ attr_optadd(struct rde_aspath *asp, u_int8_t flags, u_int8_t type, TAILQ_FOREACH_REVERSE(p, &asp->others, attr_list, entry) { if (type == p->type) { /* attribute allowed only once */ + rdemem.attr_data -= len; + rdemem.attr_cnt--; free(a->data); free(a); return (-1); @@ -135,6 +139,8 @@ attr_optfree(struct rde_aspath *asp) while ((a = TAILQ_FIRST(&asp->others)) != NULL) { TAILQ_REMOVE(&asp->others, a, entry); + rdemem.attr_data -= a->len; + rdemem.attr_cnt--; free(a->data); free(a); } @@ -226,6 +232,9 @@ aspath_get(void *data, u_int16_t len) if (aspath == NULL) fatal("aspath_get"); + rdemem.aspath_cnt++; + rdemem.aspath_size += ASPATH_HEADER_SIZE + len; + aspath->refcnt = 0; aspath->len = len; aspath->ascnt = aspath_count(data, len); @@ -237,6 +246,7 @@ aspath_get(void *data, u_int16_t len) LIST_INSERT_HEAD(head, aspath, entry); } aspath->refcnt++; + rdemem.aspath_refs++; return (aspath); } @@ -247,13 +257,17 @@ aspath_put(struct aspath *aspath) if (aspath == NULL) return; - if (--aspath->refcnt > 0) + rdemem.aspath_refs--; + if (--aspath->refcnt > 0) { /* somebody still holds a reference */ return; + } /* unlink */ LIST_REMOVE(aspath, entry); + rdemem.aspath_cnt--; + rdemem.aspath_size -= ASPATH_HEADER_SIZE + aspath->len; free(aspath); } @@ -395,6 +409,7 @@ aspath_prepend(struct aspath *asp, u_int16_t as, int quantum) if (quantum == 0) { /* no change needed but increase refcnt as we return a copy */ asp->refcnt++; + rdemem.aspath_refs++; return (asp); } else if (type == AS_SET || size + quantum > 255) { /* need to attach a new AS_SEQUENCE */ diff --git a/usr.sbin/bgpd/rde_prefix.c b/usr.sbin/bgpd/rde_prefix.c index f161fb3610e..52e61bb031e 100644 --- a/usr.sbin/bgpd/rde_prefix.c +++ b/usr.sbin/bgpd/rde_prefix.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_prefix.c,v 1.21 2004/11/11 16:53:01 claudio Exp $ */ +/* $OpenBSD: rde_prefix.c,v 1.22 2006/01/03 22:49:17 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -289,6 +289,7 @@ pt_alloc4(void) p = calloc(1, sizeof(*p)); if (p == NULL) fatal("pt_alloc"); + rdemem.pt4_cnt++; return (p); } @@ -300,12 +301,23 @@ pt_alloc6(void) p = calloc(1, sizeof(*p)); if (p == NULL) fatal("pt_alloc"); + rdemem.pt6_cnt++; return (p); } static void pt_free(struct pt_entry *pte) { + switch (pte->af) { + case AF_INET: + rdemem.pt4_cnt--; + break; + case AF_INET6: + rdemem.pt6_cnt--; + break; + default: + break; + } free(pte); } diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c index bb51d1514fc..bef5b9c4f2b 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.71 2005/12/30 14:07:40 claudio Exp $ */ +/* $OpenBSD: rde_rib.c,v 1.72 2006/01/03 22:49:17 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -272,8 +272,10 @@ path_copy(struct rde_aspath *asp) nasp = path_get(); nasp->aspath = asp->aspath; - if (nasp->aspath != NULL) + if (nasp->aspath != NULL) { nasp->aspath->refcnt++; + rdemem.aspath_refs++; + } nasp->nexthop = asp->nexthop; nasp->med = asp->med; nasp->lpref = asp->lpref; @@ -299,6 +301,8 @@ path_get(void) asp = calloc(1, sizeof(*asp)); if (asp == NULL) fatal("path_alloc"); + rdemem.path_cnt++; + LIST_INIT(&asp->prefix_h); TAILQ_INIT(&asp->others); asp->origin = ORIGIN_INCOMPLETE; @@ -320,6 +324,7 @@ path_put(struct rde_aspath *asp) rtlabel_unref(asp->rtlabelid); aspath_put(asp->aspath); attr_optfree(asp); + rdemem.path_cnt--; free(asp); } @@ -663,6 +668,7 @@ prefix_alloc(void) p = calloc(1, sizeof(*p)); if (p == NULL) fatal("prefix_alloc"); + rdemem.prefix_cnt++; return p; } @@ -672,6 +678,7 @@ prefix_free(struct prefix *pref) { ENSURE(pref->aspath == NULL && pref->prefix == NULL); + rdemem.prefix_cnt--; free(pref); } @@ -833,6 +840,7 @@ nexthop_unlink(struct rde_aspath *asp) LIST_REMOVE(nh, nexthop_l); rde_send_nexthop(&nh->exit_nexthop, 0); + rdemem.nexthop_cnt--; free(nh); } } @@ -847,6 +855,7 @@ nexthop_get(struct bgpd_addr *nexthop) nh = calloc(1, sizeof(*nh)); if (nh == NULL) fatal("nexthop_alloc"); + rdemem.nexthop_cnt++; LIST_INIT(&nh->path_h); nh->state = NEXTHOP_LOOKUP; diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index b05aa7f98b2..15e8622e408 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.240 2006/01/03 16:49:24 claudio Exp $ */ +/* $OpenBSD: session.c,v 1.241 2006/01/03 22:49:17 claudio Exp $ */ /* * Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org> @@ -2304,6 +2304,7 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx, u_int *listener_cnt) break; case IMSG_CTL_SHOW_RIB: case IMSG_CTL_SHOW_RIB_PREFIX: + case IMSG_CTL_SHOW_RIB_MEM: case IMSG_CTL_SHOW_NETWORK: case IMSG_CTL_SHOW_NETWORK6: case IMSG_CTL_SHOW_NEIGHBOR: |