All users use the same callback per queue so that makes sense.
Also replace rt_timer_queue_destroy() with rt_timer_queue_flush().
OK bluhm@
-/* $OpenBSD: route.c,v 1.408 2022/04/30 07:20:35 claudio Exp $ */
+/* $OpenBSD: route.c,v 1.409 2022/05/04 16:52:10 claudio Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
LIST_HEAD(, rttimer_queue) rttimer_queue_head; /* [T] */
#define RTTIMER_CALLOUT(r) { \
- if (r->rtt_func != NULL) { \
- (*r->rtt_func)(r->rtt_rt, r->rtt_tableid); \
+ if (r->rtt_queue->rtq_func != NULL) { \
+ (*r->rtt_queue->rtq_func)(r->rtt_rt, r->rtt_tableid); \
} else { \
struct ifnet *ifp; \
\
}
struct rttimer_queue *
-rt_timer_queue_create(int timeout)
+rt_timer_queue_create(int timeout, void (*func)(struct rtentry *, u_int))
{
struct rttimer_queue *rtq;
rtq->rtq_timeout = timeout;
rtq->rtq_count = 0;
+ rtq->rtq_func = func;
TAILQ_INIT(&rtq->rtq_head);
mtx_enter(&rttimer_mtx);
}
void
-rt_timer_queue_destroy(struct rttimer_queue *rtq)
+rt_timer_queue_flush(struct rttimer_queue *rtq)
{
struct rttimer *r;
TAILQ_HEAD(, rttimer) rttlist;
KASSERT(rtq->rtq_count > 0);
rtq->rtq_count--;
}
- LIST_REMOVE(rtq, rtq_link);
mtx_leave(&rttimer_mtx);
while ((r = TAILQ_FIRST(&rttlist)) != NULL) {
RTTIMER_CALLOUT(r);
pool_put(&rttimer_pool, r);
}
- pool_put(&rttimer_queue_pool, rtq);
}
unsigned long
}
int
-rt_timer_add(struct rtentry *rt, void (*func)(struct rtentry *, u_int),
- struct rttimer_queue *queue, u_int rtableid)
+rt_timer_add(struct rtentry *rt, struct rttimer_queue *queue, u_int rtableid)
{
struct rttimer *r, *rnew;
time_t current_time;
rnew->rtt_rt = rt;
rnew->rtt_time = current_time;
- rnew->rtt_func = func;
rnew->rtt_queue = queue;
rnew->rtt_tableid = rtableid;
* we add a new one.
*/
LIST_FOREACH(r, &rt->rt_timer, rtt_link) {
- if (r->rtt_func == func) {
+ if (r->rtt_queue == queue) {
LIST_REMOVE(r, rtt_link);
TAILQ_REMOVE(&r->rtt_queue->rtq_head, r, rtt_next);
KASSERT(r->rtt_queue->rtq_count > 0);
-/* $OpenBSD: route.h,v 1.192 2022/04/30 07:20:35 claudio Exp $ */
+/* $OpenBSD: route.h,v 1.193 2022/05/04 16:52:10 claudio Exp $ */
/* $NetBSD: route.h,v 1.9 1996/02/13 22:00:49 christos Exp $ */
/*
LIST_ENTRY(rttimer) rtt_link; /* [T] timers per rtentry */
struct rttimer_queue *rtt_queue; /* [T] back pointer to queue */
struct rtentry *rtt_rt; /* [I] back pointer to route */
- void (*rtt_func) /* [I] callback */
- (struct rtentry *, u_int);
time_t rtt_time; /* [I] when timer registered */
u_int rtt_tableid; /* [I] rtable id of rtt_rt */
};
struct rttimer_queue {
TAILQ_HEAD(, rttimer) rtq_head; /* [T] */
LIST_ENTRY(rttimer_queue) rtq_link; /* [T] */
+ void (*rtq_func) /* [I] callback */
+ (struct rtentry *, u_int);
unsigned long rtq_count; /* [T] */
int rtq_timeout; /* [T] */
};
void rt_timer_init(void);
int rt_timer_add(struct rtentry *,
- void(*)(struct rtentry *, u_int),
struct rttimer_queue *, u_int);
void rt_timer_remove_all(struct rtentry *);
-struct rttimer_queue *rt_timer_queue_create(int);
+struct rttimer_queue *rt_timer_queue_create(int,
+ void(*)(struct rtentry *, u_int));
void rt_timer_queue_change(struct rttimer_queue *, int);
-void rt_timer_queue_destroy(struct rttimer_queue *);
+void rt_timer_queue_flush(struct rttimer_queue *);
unsigned long rt_timer_queue_count(struct rttimer_queue *);
void rt_timer_timer(void *);
-/* $OpenBSD: ip_icmp.c,v 1.189 2022/04/30 07:20:35 claudio Exp $ */
+/* $OpenBSD: ip_icmp.c,v 1.190 2022/05/04 16:52:10 claudio Exp $ */
/* $NetBSD: ip_icmp.c,v 1.19 1996/02/13 23:42:22 christos Exp $ */
/*
static int icmperrpps_count = 0;
static struct timeval icmperrppslim_last;
+struct rttimer_queue *ip_mtudisc_timeout_q;
struct rttimer_queue *icmp_redirect_timeout_q;
struct cpumem *icmpcounters;
void
icmp_init(void)
{
- icmp_redirect_timeout_q = rt_timer_queue_create(icmp_redirtimeout);
+ ip_mtudisc_timeout_q = rt_timer_queue_create(ip_mtudisc_timeout,
+ &icmp_mtudisc_timeout);
+ icmp_redirect_timeout_q = rt_timer_queue_create(icmp_redirtimeout,
+ NULL);
icmpcounters = counters_alloc(icps_ncounters);
}
rtredirect(sintosa(&sdst), sintosa(&sgw),
sintosa(&ssrc), &newrt, m->m_pkthdr.ph_rtableid);
if (newrt != NULL && icmp_redirtimeout > 0) {
- rt_timer_add(newrt, NULL, icmp_redirect_timeout_q,
+ rt_timer_add(newrt, icmp_redirect_timeout_q,
m->m_pkthdr.ph_rtableid);
}
rtfree(newrt);
rt = nrt;
rtm_send(rt, RTM_ADD, 0, rtableid);
}
- error = rt_timer_add(rt, icmp_mtudisc_timeout, ip_mtudisc_timeout_q,
- rtableid);
+ error = rt_timer_add(rt, ip_mtudisc_timeout_q, rtableid);
if (error)
goto bad;
-/* $OpenBSD: ip_input.c,v 1.369 2022/04/28 17:27:14 claudio Exp $ */
+/* $OpenBSD: ip_input.c,v 1.370 2022/05/04 16:52:10 claudio Exp $ */
/* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */
/*
int ip_mtudisc_timeout = IPMTUDISCTIMEOUT;
int ip_directedbcast = 0;
-struct rttimer_queue *ip_mtudisc_timeout_q;
-
/* Protects `ipq' and `ip_frags'. */
struct mutex ipq_mutex = MUTEX_INITIALIZER(IPL_SOFTNET);
pr->pr_protocol < IPPROTO_MAX)
ip_protox[pr->pr_protocol] = pr - inetsw;
LIST_INIT(&ipq);
- ip_mtudisc_timeout_q = rt_timer_queue_create(ip_mtudisc_timeout);
/* Fill in list of ports not to allocate dynamically. */
memset(&baddynamicports, 0, sizeof(baddynamicports));
ipsec_init();
#endif
#ifdef MROUTING
- ip_mrouterq = rt_timer_queue_create(MCAST_EXPIRE_FREQUENCY);
+ ip_mrouterq = rt_timer_queue_create(MCAST_EXPIRE_FREQUENCY,
+ &mfc_expire_route);
#endif
}
case IPCTL_MTUDISC:
NET_LOCK();
error = sysctl_int(oldp, oldlenp, newp, newlen, &ip_mtudisc);
- if (ip_mtudisc == 0) {
- rt_timer_queue_destroy(ip_mtudisc_timeout_q);
- ip_mtudisc_timeout_q =
- rt_timer_queue_create(ip_mtudisc_timeout);
- }
+ if (ip_mtudisc == 0)
+ rt_timer_queue_flush(ip_mtudisc_timeout_q);
NET_UNLOCK();
return error;
case IPCTL_MTUDISCTIMEOUT:
-/* $OpenBSD: ip_mroute.c,v 1.133 2022/04/30 07:20:35 claudio Exp $ */
+/* $OpenBSD: ip_mroute.c,v 1.134 2022/05/04 16:52:10 claudio Exp $ */
/* $NetBSD: ip_mroute.c,v 1.85 2004/04/26 01:31:57 matt Exp $ */
/*
int add_vif(struct socket *, struct mbuf *);
int del_vif(struct socket *, struct mbuf *);
void update_mfc_params(struct mfcctl2 *, int, unsigned int);
-void mfc_expire_route(struct rtentry *, u_int);
int mfc_add(struct mfcctl2 *, struct in_addr *, struct in_addr *,
int, unsigned int, int);
int add_mfc(struct socket *, struct mbuf *);
/* Not expired, add it back to the queue. */
if (mfc->mfc_expire == 0) {
mfc->mfc_expire = 1;
- rt_timer_add(rt, mfc_expire_route, ip_mrouterq, rtableid);
+ rt_timer_add(rt, ip_mrouterq, rtableid);
return;
}
rt->rt_llinfo = (caddr_t)mfc;
- rt_timer_add(rt, mfc_expire_route, ip_mrouterq, rtableid);
+ rt_timer_add(rt, ip_mrouterq, rtableid);
mfc->mfc_parent = mfccp->mfcc_parent;
mfc->mfc_pkt_cnt = 0;
-/* $OpenBSD: ip_mroute.h,v 1.29 2022/04/28 17:27:14 claudio Exp $ */
+/* $OpenBSD: ip_mroute.h,v 1.30 2022/05/04 16:52:10 claudio Exp $ */
/* $NetBSD: ip_mroute.h,v 1.23 2004/04/21 17:49:46 itojun Exp $ */
#ifndef _NETINET_IP_MROUTE_H_
#define MCAST_EXPIRE_FREQUENCY 30
extern struct rttimer_queue *ip_mrouterq;
+void mfc_expire_route(struct rtentry *, u_int);
+
extern int ip_mrtproto;
/*
-/* $OpenBSD: icmp6.c,v 1.240 2022/04/30 07:20:35 claudio Exp $ */
+/* $OpenBSD: icmp6.c,v 1.241 2022/05/04 16:52:10 claudio Exp $ */
/* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */
/*
icmp6_init(void)
{
mld6_init();
- icmp6_mtudisc_timeout_q = rt_timer_queue_create(ip6_mtudisc_timeout);
- icmp6_redirect_timeout_q = rt_timer_queue_create(icmp6_redirtimeout);
+ icmp6_mtudisc_timeout_q = rt_timer_queue_create(ip6_mtudisc_timeout,
+ &icmp6_mtudisc_timeout);
+ icmp6_redirect_timeout_q = rt_timer_queue_create(icmp6_redirtimeout,
+ NULL);
icmp6counters = counters_alloc(icp6s_ncounters);
}
rtredirect(sin6tosa(&sdst), sin6tosa(&sgw), sin6tosa(&ssrc),
&newrt, m->m_pkthdr.ph_rtableid);
if (newrt != NULL && icmp6_redirtimeout > 0) {
- rt_timer_add(newrt, NULL, icmp6_redirect_timeout_q,
+ rt_timer_add(newrt, icmp6_redirect_timeout_q,
m->m_pkthdr.ph_rtableid);
}
rtfree(newrt);
rt = nrt;
rtm_send(rt, RTM_ADD, 0, rtableid);
}
- error = rt_timer_add(rt, icmp6_mtudisc_timeout, icmp6_mtudisc_timeout_q,
- rtableid);
+ error = rt_timer_add(rt, icmp6_mtudisc_timeout_q, rtableid);
if (error)
goto bad;
-/* $OpenBSD: ip6_input.c,v 1.243 2022/04/28 17:27:14 claudio Exp $ */
+/* $OpenBSD: ip6_input.c,v 1.244 2022/05/04 16:52:10 claudio Exp $ */
/* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */
/*
ip6counters = counters_alloc(ip6s_ncounters);
#ifdef MROUTING
- ip6_mrouterq = rt_timer_queue_create(MCAST_EXPIRE_TIMEOUT);
+ ip6_mrouterq = rt_timer_queue_create(MCAST_EXPIRE_TIMEOUT,
+ &mf6c_expire_route);
#endif
}
-/* $OpenBSD: ip6_mroute.c,v 1.129 2022/04/30 07:20:35 claudio Exp $ */
+/* $OpenBSD: ip6_mroute.c,v 1.130 2022/05/04 16:52:10 claudio Exp $ */
/* $NetBSD: ip6_mroute.c,v 1.59 2003/12/10 09:28:38 itojun Exp $ */
/* $KAME: ip6_mroute.c,v 1.45 2001/03/25 08:38:51 itojun Exp $ */
struct rtentry *mrt6_mcast_add(struct ifnet *, struct sockaddr *,
struct sockaddr *);
void mrt6_mcast_del(struct rtentry *, unsigned int);
-void mf6c_expire_route(struct rtentry *, u_int);
/*
* Handle MRT setsockopt commands to modify the multicast routing tables.
}
rt->rt_llinfo = (caddr_t)mf6c;
- rt_timer_add(rt, mf6c_expire_route, ip6_mrouterq, rtableid);
+ rt_timer_add(rt, ip6_mrouterq, rtableid);
mf6c->mf6c_parent = mf6cc->mf6cc_parent;
rtfree(rt);
if (mf6c->mf6c_expire == 0) {
mf6c->mf6c_expire = 1;
- rt_timer_add(rt, mf6c_expire_route, ip6_mrouterq, rtableid);
+ rt_timer_add(rt, ip6_mrouterq, rtableid);
return;
}
-/* $OpenBSD: ip6_mroute.h,v 1.21 2022/04/28 17:27:14 claudio Exp $ */
+/* $OpenBSD: ip6_mroute.h,v 1.22 2022/05/04 16:52:10 claudio Exp $ */
/* $KAME: ip6_mroute.h,v 1.17 2001/02/10 02:05:52 itojun Exp $ */
/*
#define MCAST_EXPIRE_TIMEOUT 30
extern struct rttimer_queue *ip6_mrouterq;
+void mf6c_expire_route(struct rtentry *, u_int);
/*
* The kernel's multicast-interface structure.