diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2011-03-24 08:36:01 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2011-03-24 08:36:01 +0000 |
commit | fa66820cd20f3b54ca989719ec9244a84aa4878f (patch) | |
tree | 53765e1f9c56682a8880f71be8aff544717bb225 /usr.sbin/ospfd | |
parent | 563791e39b7b5faf4456db0f90f172c20542eec4 (diff) |
Fix some memory leaks. Mainly better cleanup on shutdown but the v_nexthop
leak is a runtime one.
OK bluhm@
Diffstat (limited to 'usr.sbin/ospfd')
-rw-r--r-- | usr.sbin/ospfd/neighbor.c | 5 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfd.c | 9 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfe.c | 4 | ||||
-rw-r--r-- | usr.sbin/ospfd/rde.c | 31 | ||||
-rw-r--r-- | usr.sbin/ospfd/rde.h | 5 | ||||
-rw-r--r-- | usr.sbin/ospfd/rde_lsdb.c | 32 | ||||
-rw-r--r-- | usr.sbin/ospfd/rde_spf.c | 61 |
7 files changed, 90 insertions, 57 deletions
diff --git a/usr.sbin/ospfd/neighbor.c b/usr.sbin/ospfd/neighbor.c index ad86602461b..6ff76c2b1f6 100644 --- a/usr.sbin/ospfd/neighbor.c +++ b/usr.sbin/ospfd/neighbor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: neighbor.c,v 1.41 2010/05/07 22:32:34 sthen Exp $ */ +/* $OpenBSD: neighbor.c,v 1.42 2011/03/24 08:35:59 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -342,7 +342,8 @@ nbr_del(struct nbr *nbr) db_sum_list_clr(nbr); ls_req_list_clr(nbr); - LIST_REMOVE(nbr, entry); + if (nbr->peerid != NBR_IDSELF) + LIST_REMOVE(nbr, entry); LIST_REMOVE(nbr, hash); free(nbr); diff --git a/usr.sbin/ospfd/ospfd.c b/usr.sbin/ospfd/ospfd.c index aabe7611e4f..de63f6ad88c 100644 --- a/usr.sbin/ospfd/ospfd.c +++ b/usr.sbin/ospfd/ospfd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.c,v 1.75 2010/09/02 14:03:22 sobrado Exp $ */ +/* $OpenBSD: ospfd.c,v 1.76 2011/03/24 08:35:59 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -309,7 +309,8 @@ main(int argc, char *argv[]) void ospfd_shutdown(void) { - pid_t pid; + pid_t pid; + struct redistribute *r; if (ospfe_pid) kill(ospfe_pid, SIGTERM); @@ -318,6 +319,10 @@ ospfd_shutdown(void) kill(rde_pid, SIGTERM); control_cleanup(ospfd_conf->csock); + while ((r = SIMPLEQ_FIRST(&ospfd_conf->redist_list)) != NULL) { + SIMPLEQ_REMOVE_HEAD(&ospfd_conf->redist_list, entry); + free(r); + } kr_shutdown(); carp_demote_shutdown(); diff --git a/usr.sbin/ospfd/ospfe.c b/usr.sbin/ospfd/ospfe.c index 01917c10ede..f0fa84887bc 100644 --- a/usr.sbin/ospfd/ospfe.c +++ b/usr.sbin/ospfd/ospfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.c,v 1.78 2011/03/08 10:56:02 claudio Exp $ */ +/* $OpenBSD: ospfe.c,v 1.79 2011/03/24 08:35:59 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -223,6 +223,8 @@ ospfe_shutdown(void) area_del(area); } + nbr_del(nbr_find_peerid(NBR_IDSELF)); + kr_shutdown(); close(oeconf->ospf_socket); /* clean up */ diff --git a/usr.sbin/ospfd/rde.c b/usr.sbin/ospfd/rde.c index fe8c05bc566..a262162cd7b 100644 --- a/usr.sbin/ospfd/rde.c +++ b/usr.sbin/ospfd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.91 2011/01/18 20:46:06 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.92 2011/03/24 08:35:59 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org> @@ -59,6 +59,7 @@ void rde_req_list_free(struct rde_nbr *); struct iface *rde_asext_lookup(u_int32_t, int); void rde_asext_get(struct kroute *); void rde_asext_put(struct kroute *); +void rde_asext_free(void); struct lsa *orig_asext_lsa(struct kroute *, u_int32_t, u_int16_t); struct lsa *orig_sum_lsa(struct rt_node *, struct area *, u_int8_t, int); @@ -194,6 +195,7 @@ void rde_shutdown(void) { struct area *a; + struct vertex *v, *nv; stop_spf_timer(rdeconf); cand_list_clr(); @@ -203,7 +205,13 @@ rde_shutdown(void) LIST_REMOVE(a, entry); area_del(a); } + for (v = RB_MIN(lsa_tree, &asext_tree); v != NULL; v = nv) { + nv = RB_NEXT(lsa_tree, &asext_tree, v); + vertex_free(v); + } + rde_asext_free(); rde_nbr_free(); + kr_shutdown(); msgbuf_clear(&iev_ospfe->ibuf.w); free(iev_ospfe); @@ -366,8 +374,11 @@ rde_dispatch_imsg(int fd, short event, void *bula) if ((v = lsa_find(nbr->area, ntohl(req_hdr.type), req_hdr.ls_id, req_hdr.adv_rtr)) == NULL) { - imsg_compose_event(iev_ospfe, IMSG_LS_BADREQ, - imsg.hdr.peerid, 0, -1, NULL, 0); + log_debug("rde_dispatch_imsg: " + "requested LSA not found"); + imsg_compose_event(iev_ospfe, + IMSG_LS_BADREQ, imsg.hdr.peerid, + 0, -1, NULL, 0); continue; } imsg_compose_event(iev_ospfe, IMSG_LS_UPD, @@ -396,7 +407,7 @@ rde_dispatch_imsg(int fd, short event, void *bula) } v = lsa_find(nbr->area, lsa->hdr.type, lsa->hdr.ls_id, - lsa->hdr.adv_rtr); + lsa->hdr.adv_rtr); if (v == NULL) db_hdr = NULL; else @@ -1200,6 +1211,18 @@ rde_asext_put(struct kroute *rr) free(an); } +void +rde_asext_free(void) +{ + struct asext_node *an, *nan; + + for (an = RB_MIN(asext_tree, &ast); an != NULL; an = nan) { + nan = RB_NEXT(asext_tree, &ast, an); + RB_REMOVE(asext_tree, &ast, an); + free(an); + } +} + struct lsa * orig_asext_lsa(struct kroute *rr, u_int32_t ls_id, u_int16_t age) { diff --git a/usr.sbin/ospfd/rde.h b/usr.sbin/ospfd/rde.h index c0baebc2049..fb32bae829e 100644 --- a/usr.sbin/ospfd/rde.h +++ b/usr.sbin/ospfd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.35 2009/01/07 21:16:36 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.36 2011/03/24 08:36:00 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -124,6 +124,9 @@ struct lsa *orig_sum_lsa(struct rt_node *, struct area *, u_int8_t, int); void lsa_init(struct lsa_tree *); int lsa_compare(struct vertex *, struct vertex *); void vertex_free(struct vertex *); +void vertex_nexthop_clear(struct vertex *); +void vertex_nexthop_add(struct vertex *, struct vertex *, + u_int32_t); int lsa_newer(struct lsa_hdr *, struct lsa_hdr *); int lsa_check(struct rde_nbr *, struct lsa *, u_int16_t); int lsa_self(struct rde_nbr *, struct lsa *, struct vertex *); diff --git a/usr.sbin/ospfd/rde_lsdb.c b/usr.sbin/ospfd/rde_lsdb.c index 650235b91cc..f90f0d3d305 100644 --- a/usr.sbin/ospfd/rde_lsdb.c +++ b/usr.sbin/ospfd/rde_lsdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_lsdb.c,v 1.44 2010/07/19 09:11:08 claudio Exp $ */ +/* $OpenBSD: rde_lsdb.c,v 1.45 2011/03/24 08:36:00 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org> @@ -98,10 +98,40 @@ vertex_free(struct vertex *v) RB_REMOVE(lsa_tree, &v->area->lsa_tree, v); (void)evtimer_del(&v->ev); + vertex_nexthop_clear(v); free(v->lsa); free(v); } +void +vertex_nexthop_clear(struct vertex *v) +{ + struct v_nexthop *vn; + + while ((vn = TAILQ_FIRST(&v->nexthop))) { + TAILQ_REMOVE(&v->nexthop, vn, entry); + free(vn); + } +} + +void +vertex_nexthop_add(struct vertex *dst, struct vertex *parent, u_int32_t nexthop) +{ + struct v_nexthop *vn; + + if (nexthop == 0) + /* invalid nexthop, skip it */ + return; + + if ((vn = calloc(1, sizeof(*vn))) == NULL) + fatal("vertex_nexthop_add"); + + vn->prev = parent; + vn->nexthop.s_addr = nexthop; + + TAILQ_INSERT_TAIL(&dst->nexthop, vn, entry); +} + /* returns -1 if a is older, 1 if newer and 0 if equal to b */ int lsa_newer(struct lsa_hdr *a, struct lsa_hdr *b) diff --git a/usr.sbin/ospfd/rde_spf.c b/usr.sbin/ospfd/rde_spf.c index fb285880252..91418381ba7 100644 --- a/usr.sbin/ospfd/rde_spf.c +++ b/usr.sbin/ospfd/rde_spf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_spf.c,v 1.69 2010/02/16 08:22:42 dlg Exp $ */ +/* $OpenBSD: rde_spf.c,v 1.70 2011/03/24 08:36:00 claudio Exp $ */ /* * Copyright (c) 2005 Esben Norby <norby@openbsd.org> @@ -35,8 +35,6 @@ RB_PROTOTYPE(rt_tree, rt_node, entry, rt_compare) RB_GENERATE(rt_tree, rt_node, entry, rt_compare) struct vertex *spf_root = NULL; -void calc_nexthop_clear(struct vertex *); -void calc_nexthop_add(struct vertex *, struct vertex *, u_int32_t); void calc_nexthop(struct vertex *, struct vertex *, struct area *, struct lsa_rtr_link *); void rt_nexthop_clear(struct rt_node *); @@ -133,7 +131,7 @@ spf_calc(struct area *area) continue; if (d < w->cost) { w->cost = d; - calc_nexthop_clear(w); + vertex_nexthop_clear(w); calc_nexthop(w, v, area, rtr_link); /* * need to readd to candidate list @@ -147,7 +145,7 @@ spf_calc(struct area *area) } else if (w->cost == LS_INFINITY && d < LS_INFINITY) { w->cost = d; - calc_nexthop_clear(w); + vertex_nexthop_clear(w); calc_nexthop(w, v, area, rtr_link); cand_list_add(w); } @@ -237,9 +235,9 @@ rt_calc(struct vertex *v, struct area *area, struct ospfd_conf *conf) return; /* copy nexthops */ - calc_nexthop_clear(v); /* XXX needed ??? */ + vertex_nexthop_clear(v); /* XXX needed ??? */ TAILQ_FOREACH(vn, &w->nexthop, entry) - calc_nexthop_add(v, w, vn->nexthop.s_addr); + vertex_nexthop_add(v, w, vn->nexthop.s_addr); v->cost = w->cost + (ntohl(v->lsa->data.sum.metric) & LSA_METRIC_MASK); @@ -317,20 +315,20 @@ asext_calc(struct vertex *v) adv_rtr.s_addr = htonl(v->adv_rtr); addr.s_addr = htonl(v->ls_id) & v->lsa->data.asext.mask; - calc_nexthop_clear(v); + vertex_nexthop_clear(v); TAILQ_FOREACH(rn, &r->nexthop, entry) { if (rn->invalid) continue; if (rn->connected && r->d_type == DT_NET) { if (v->lsa->data.asext.fw_addr != 0) - calc_nexthop_add(v, NULL, + vertex_nexthop_add(v, NULL, v->lsa->data.asext.fw_addr); else - calc_nexthop_add(v, NULL, + vertex_nexthop_add(v, NULL, htonl(v->adv_rtr)); } else - calc_nexthop_add(v, NULL, rn->nexthop.s_addr); + vertex_nexthop_add(v, NULL, rn->nexthop.s_addr); } rt_update(addr, mask2prefixlen(v->lsa->data.asext.mask), @@ -350,40 +348,11 @@ spf_tree_clr(struct area *area) RB_FOREACH(v, lsa_tree, tree) { v->cost = LS_INFINITY; - calc_nexthop_clear(v); + vertex_nexthop_clear(v); } } void -calc_nexthop_clear(struct vertex *v) -{ - struct v_nexthop *vn; - - while ((vn = TAILQ_FIRST(&v->nexthop))) { - TAILQ_REMOVE(&v->nexthop, vn, entry); - free(vn); - } -} - -void -calc_nexthop_add(struct vertex *dst, struct vertex *parent, u_int32_t nexthop) -{ - struct v_nexthop *vn; - - if (nexthop == 0) - /* invalid nexthop, skip it */ - return; - - if ((vn = calloc(1, sizeof(*vn))) == NULL) - fatal("calc_nexthop_add"); - - vn->prev = parent; - vn->nexthop.s_addr = nexthop; - - TAILQ_INSERT_TAIL(&dst->nexthop, vn, entry); -} - -void calc_nexthop(struct vertex *dst, struct vertex *parent, struct area *area, struct lsa_rtr_link *rtr_link) { @@ -399,7 +368,7 @@ calc_nexthop(struct vertex *dst, struct vertex *parent, fatalx("inconsistent SPF tree"); LIST_FOREACH(iface, &area->iface_list, entry) { if (rtr_link->data == iface->addr.s_addr) { - calc_nexthop_add(dst, parent, + vertex_nexthop_add(dst, parent, iface->dst.s_addr); return; } @@ -416,7 +385,7 @@ calc_nexthop(struct vertex *dst, struct vertex *parent, dst->lsa->data.net.mask) == (rtr_link->data & dst->lsa->data.net.mask)) { - calc_nexthop_add(dst, parent, + vertex_nexthop_add(dst, parent, rtr_link->data); } break; @@ -443,11 +412,11 @@ calc_nexthop(struct vertex *dst, struct vertex *parent, parent->lsa->data.net.mask) == (htonl(parent->ls_id) & parent->lsa->data.net.mask)) - calc_nexthop_add(dst, parent, + vertex_nexthop_add(dst, parent, rtr_link->data); } } else { - calc_nexthop_add(dst, parent, + vertex_nexthop_add(dst, parent, vn->nexthop.s_addr); } } @@ -456,7 +425,7 @@ calc_nexthop(struct vertex *dst, struct vertex *parent, /* case 3 */ TAILQ_FOREACH(vn, &parent->nexthop, entry) - calc_nexthop_add(dst, parent, vn->nexthop.s_addr); + vertex_nexthop_add(dst, parent, vn->nexthop.s_addr); } /* candidate list */ |