Make rt_refcnt take into account rt_timer

This commit is contained in:
ozaki-r 2015-08-31 06:25:15 +00:00
parent 4e97073b73
commit 3aedc74443
4 changed files with 31 additions and 11 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: route.c,v 1.149 2015/08/24 22:21:26 pooka Exp $ */
/* $NetBSD: route.c,v 1.150 2015/08/31 06:25:15 ozaki-r Exp $ */
/*-
* Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@ -96,7 +96,7 @@
#endif
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.149 2015/08/24 22:21:26 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.150 2015/08/31 06:25:15 ozaki-r Exp $");
#include <sys/param.h>
#ifdef RTFLUSH_DEBUG
@ -1270,6 +1270,7 @@ rt_timer_queue_remove_all(struct rttimer_queue *rtq, int destroy)
TAILQ_REMOVE(&rtq->rtq_head, r, rtt_next);
if (destroy)
RTTIMER_CALLOUT(r);
rtfree(r->rtt_rt);
/* we are already at splsoftnet */
pool_put(&rttimer_pool, r);
if (rtq->rtq_count > 0)
@ -1313,6 +1314,7 @@ rt_timer_remove_all(struct rtentry *rt, int destroy)
r->rtt_queue->rtq_count--;
else
printf("rt_timer_remove_all: rtq_count reached 0\n");
rtfree(r->rtt_rt);
/* we are already at splsoftnet */
pool_put(&rttimer_pool, r);
}
@ -1341,6 +1343,7 @@ rt_timer_add(struct rtentry *rt,
r->rtt_queue->rtq_count--;
else
printf("rt_timer_add: rtq_count reached 0\n");
rtfree(r->rtt_rt);
} else {
s = splsoftnet();
r = pool_get(&rttimer_pool, PR_NOWAIT);
@ -1351,6 +1354,7 @@ rt_timer_add(struct rtentry *rt,
memset(r, 0, sizeof(*r));
rt->rt_refcnt++;
r->rtt_rt = rt;
r->rtt_time = time_uptime;
r->rtt_func = func;
@ -1377,6 +1381,7 @@ rt_timer_timer(void *arg)
LIST_REMOVE(r, rtt_link);
TAILQ_REMOVE(&rtq->rtq_head, r, rtt_next);
RTTIMER_CALLOUT(r);
rtfree(r->rtt_rt);
pool_put(&rttimer_pool, r);
if (rtq->rtq_count > 0)
rtq->rtq_count--;

View File

@ -1,4 +1,4 @@
/* $NetBSD: route.h,v 1.93 2015/08/24 04:44:54 ozaki-r Exp $ */
/* $NetBSD: route.h,v 1.94 2015/08/31 06:25:15 ozaki-r Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -412,6 +412,13 @@ rt_get_gwroute(struct rtentry *rt)
return rt->rt_gwroute;
}
static inline void
rt_assert_referenced(const struct rtentry *rt)
{
KASSERT(rt->rt_refcnt > 0);
}
void rtcache_copy(struct route *, const struct route *);
void rtcache_free(struct route *);
struct rtentry *

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_icmp.c,v 1.141 2015/08/24 22:21:26 pooka Exp $ */
/* $NetBSD: ip_icmp.c,v 1.142 2015/08/31 06:25:15 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -94,7 +94,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.141 2015/08/24 22:21:26 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.142 2015/08/31 06:25:15 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_ipsec.h"
@ -1214,7 +1214,9 @@ ip_next_mtu(u_int mtu, int dir) /* XXX */
static void
icmp_mtudisc_timeout(struct rtentry *rt, struct rttimer *r)
{
KASSERT(rt != NULL);
rt_assert_referenced(rt);
if ((rt->rt_flags & (RTF_DYNAMIC | RTF_HOST)) ==
(RTF_DYNAMIC | RTF_HOST)) {
@ -1230,7 +1232,9 @@ icmp_mtudisc_timeout(struct rtentry *rt, struct rttimer *r)
static void
icmp_redirect_timeout(struct rtentry *rt, struct rttimer *r)
{
KASSERT(rt != NULL);
rt_assert_referenced(rt);
if ((rt->rt_flags & (RTF_DYNAMIC | RTF_HOST)) ==
(RTF_DYNAMIC | RTF_HOST)) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: icmp6.c,v 1.175 2015/08/24 22:21:27 pooka Exp $ */
/* $NetBSD: icmp6.c,v 1.176 2015/08/31 06:25:15 ozaki-r Exp $ */
/* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */
/*
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.175 2015/08/24 22:21:27 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.176 2015/08/31 06:25:15 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -2714,8 +2714,10 @@ icmp6_mtudisc_clone(struct sockaddr *dst)
static void
icmp6_mtudisc_timeout(struct rtentry *rt, struct rttimer *r)
{
if (rt == NULL)
panic("icmp6_mtudisc_timeout: bad route to timeout");
KASSERT(rt != NULL);
rt_assert_referenced(rt);
if ((rt->rt_flags & (RTF_DYNAMIC | RTF_HOST)) ==
(RTF_DYNAMIC | RTF_HOST)) {
rtrequest((int) RTM_DELETE, rt_getkey(rt),
@ -2729,8 +2731,10 @@ icmp6_mtudisc_timeout(struct rtentry *rt, struct rttimer *r)
static void
icmp6_redirect_timeout(struct rtentry *rt, struct rttimer *r)
{
if (rt == NULL)
panic("icmp6_redirect_timeout: bad route to timeout");
KASSERT(rt != NULL);
rt_assert_referenced(rt);
if ((rt->rt_flags & (RTF_GATEWAY | RTF_DYNAMIC | RTF_HOST)) ==
(RTF_GATEWAY | RTF_DYNAMIC | RTF_HOST)) {
rtrequest((int) RTM_DELETE, rt_getkey(rt),