From b94710c8152a592ad295adb772d0010938920ee4 Mon Sep 17 00:00:00 2001 From: florian Date: Wed, 31 May 2017 09:39:03 +0000 Subject: [PATCH] Deleting a default route proposal is a bit of work and the code got copied around (not always correctly). Introduce free_dfr_proposal() to have this in one place. --- usr.sbin/slaacd/engine.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/usr.sbin/slaacd/engine.c b/usr.sbin/slaacd/engine.c index c43bfc4c708..4debc8b3562 100644 --- a/usr.sbin/slaacd/engine.c +++ b/usr.sbin/slaacd/engine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: engine.c,v 1.37 2017/05/31 07:30:32 florian Exp $ */ +/* $OpenBSD: engine.c,v 1.38 2017/05/31 09:39:03 florian Exp $ */ /* * Copyright (c) 2017 Florian Obser @@ -233,6 +233,7 @@ void in6_prefixlen2mask(struct in6_addr *, int len); void gen_dfr_proposal(struct slaacd_iface *, struct radv *); void configure_dfr(struct dfr_proposal *); +void free_dfr_proposal(struct dfr_proposal *); void withdraw_dfr(struct dfr_proposal *); void debug_log_ra(struct imsg_ra *); char *parse_dnssl(char *, int); @@ -868,8 +869,7 @@ remove_slaacd_iface(uint32_t if_index) while(!LIST_EMPTY(&iface->dfr_proposals)) { dfr_proposal = LIST_FIRST(&iface->dfr_proposals); - LIST_REMOVE(dfr_proposal, entries); - free(dfr_proposal); + free_dfr_proposal(dfr_proposal); } free(iface); break; @@ -1480,10 +1480,7 @@ void update_iface_ra(struct slaacd_iface *iface, struct radv *ra) if (memcmp(&dfr_proposal->addr, &ra->from, sizeof(struct sockaddr_in6)) == 0) { - LIST_REMOVE(dfr_proposal, entries); - evtimer_del(&dfr_proposal->timer); - withdraw_dfr(dfr_proposal); - free(dfr_proposal); + free_dfr_proposal(dfr_proposal); } } } else { @@ -1808,6 +1805,23 @@ withdraw_dfr(struct dfr_proposal *dfr_proposal) engine_imsg_compose_main(IMSG_WITHDRAW_DFR, 0, &dfr, sizeof(dfr)); } +void +free_dfr_proposal(struct dfr_proposal *dfr_proposal) +{ + + LIST_REMOVE(dfr_proposal, entries); + evtimer_del(&dfr_proposal->timer); + switch (dfr_proposal->state) { + case PROPOSAL_CONFIGURED: + case PROPOSAL_NEARLY_EXPIRED: + withdraw_dfr(dfr_proposal); + break; + default: + break; + } + free(dfr_proposal); +} + void send_proposal(struct imsg_proposal *proposal) { @@ -1990,9 +2004,7 @@ dfr_proposal_timeout(int fd, short events, void *arg) } else { log_debug("%s: giving up, no response to proposal", __func__); - LIST_REMOVE(dfr_proposal, entries); - evtimer_del(&dfr_proposal->timer); - free(dfr_proposal); + free_dfr_proposal(dfr_proposal); } break; case PROPOSAL_CONFIGURED: @@ -2011,10 +2023,7 @@ dfr_proposal_timeout(int fd, short events, void *arg) case PROPOSAL_NEARLY_EXPIRED: if (real_lifetime(&dfr_proposal->uptime, dfr_proposal->router_lifetime) == 0) { - evtimer_del(&dfr_proposal->timer); - LIST_REMOVE(dfr_proposal, entries); - withdraw_dfr(dfr_proposal); - free(dfr_proposal); + free_dfr_proposal(dfr_proposal); log_debug("%s: removing dfr proposal", __func__); break; } -- 2.20.1