diff options
author | Michele Marchetto <michele@cvs.openbsd.org> | 2006-11-10 11:09:57 +0000 |
---|---|---|
committer | Michele Marchetto <michele@cvs.openbsd.org> | 2006-11-10 11:09:57 +0000 |
commit | dc7048abf3b3cb3c0cf88d43b1d2855c32ef1fe1 (patch) | |
tree | 5e7aaef1f848dbda3051ec796d9e4161b9b4e7e5 | |
parent | b6f99c47962964adb3daf4bfc772965ac50f901e (diff) |
introduce reference count for struct route_report so it can be shared and
freed correctly.
OK norby@ henning@
-rw-r--r-- | usr.sbin/dvmrpd/dvmrpe.h | 3 | ||||
-rw-r--r-- | usr.sbin/dvmrpd/neighbor.c | 5 | ||||
-rw-r--r-- | usr.sbin/dvmrpd/report.c | 17 |
3 files changed, 16 insertions, 9 deletions
diff --git a/usr.sbin/dvmrpd/dvmrpe.h b/usr.sbin/dvmrpd/dvmrpe.h index f4fead67baa..d85833a4148 100644 --- a/usr.sbin/dvmrpd/dvmrpe.h +++ b/usr.sbin/dvmrpd/dvmrpe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dvmrpe.h,v 1.1 2006/06/01 14:12:20 norby Exp $ */ +/* $OpenBSD: dvmrpe.h,v 1.2 2006/11/10 11:09:56 michele Exp $ */ /* * Copyright (c) 2004, 2005, 2006 Esben Norby <norby@openbsd.org> @@ -75,6 +75,7 @@ struct route_report { struct in_addr mask; struct in_addr nexthop; struct in_addr adv_rtr; + int refcount; u_short ifindex; u_int8_t metric; diff --git a/usr.sbin/dvmrpd/neighbor.c b/usr.sbin/dvmrpd/neighbor.c index 074544f61e7..3f27c507a1b 100644 --- a/usr.sbin/dvmrpd/neighbor.c +++ b/usr.sbin/dvmrpd/neighbor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: neighbor.c,v 1.2 2006/06/01 18:18:25 norby Exp $ */ +/* $OpenBSD: neighbor.c,v 1.3 2006/11/10 11:09:56 michele Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -382,8 +382,7 @@ int nbr_act_clear_lists(struct nbr *nbr) { log_debug("nbr_act_clear_lists: neighbor ID %s", inet_ntoa(nbr->id)); - - /* XXX clear lists */ + rr_list_clr(&nbr->rr_list); return (0); } diff --git a/usr.sbin/dvmrpd/report.c b/usr.sbin/dvmrpd/report.c index 9aef66217f9..14b6618c502 100644 --- a/usr.sbin/dvmrpd/report.c +++ b/usr.sbin/dvmrpd/report.c @@ -1,4 +1,4 @@ -/* $OpenBSD: report.c,v 1.3 2006/06/17 16:53:33 norby Exp $ */ +/* $OpenBSD: report.c,v 1.4 2006/11/10 11:09:56 michele Exp $ */ /* * Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org> @@ -34,7 +34,7 @@ extern struct dvmrpd_conf *deconf; -void rr_list_remove(struct rr_head *, struct route_report *); +void rr_list_remove(struct route_report *); /* DVMRP report packet handling */ int @@ -201,16 +201,24 @@ rr_list_add(struct rr_head *rr_list, struct route_report *rr) TAILQ_INSERT_TAIL(rr_list, le, entry); le->re = rr; + rr->refcount++; } void +rr_list_remove(struct route_report *rr) +{ + if (--rr->refcount == 0) + free(rr); +} + +void rr_list_clr(struct rr_head *rr_list) { struct rr_entry *le; while ((le = TAILQ_FIRST(rr_list)) != NULL) { TAILQ_REMOVE(rr_list, le, entry); - free(le->re); + rr_list_remove(le->re); free(le); } } @@ -279,9 +287,8 @@ rr_list_send(struct rr_head *rr_list, struct iface *xiface, struct nbr *nbr) buf_add(buf, &metric, sizeof(metric)); - /* XXX rr_list_remove */ TAILQ_REMOVE(rr_list, le, entry); - /* XXX free(le->re); */ + rr_list_remove(le->re); free(le); } send_report(iface, addr, buf->buf, buf->wpos); |