From 38f7d33d7bd206332a3a6138cfafaf66154ed6c1 Mon Sep 17 00:00:00 2001 From: claudio Date: Wed, 4 May 2022 16:52:10 +0000 Subject: [PATCH] Move rttimer callback function from the rttimer itself to rttimer_queue. 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@ --- sys/net/route.c | 19 ++++++++----------- sys/net/route.h | 12 ++++++------ sys/netinet/ip_icmp.c | 13 ++++++++----- sys/netinet/ip_input.c | 15 +++++---------- sys/netinet/ip_mroute.c | 7 +++---- sys/netinet/ip_mroute.h | 4 +++- sys/netinet6/icmp6.c | 13 +++++++------ sys/netinet6/ip6_input.c | 5 +++-- sys/netinet6/ip6_mroute.c | 7 +++---- sys/netinet6/ip6_mroute.h | 3 ++- 10 files changed, 48 insertions(+), 50 deletions(-) diff --git a/sys/net/route.c b/sys/net/route.c index b10dde62c5c..8afc2a04238 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -1365,8 +1365,8 @@ struct mutex rttimer_mtx; 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; \ \ @@ -1403,7 +1403,7 @@ rt_timer_init(void) } 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; @@ -1411,6 +1411,7 @@ rt_timer_queue_create(int timeout) rtq->rtq_timeout = timeout; rtq->rtq_count = 0; + rtq->rtq_func = func; TAILQ_INIT(&rtq->rtq_head); mtx_enter(&rttimer_mtx); @@ -1429,7 +1430,7 @@ rt_timer_queue_change(struct rttimer_queue *rtq, int timeout) } void -rt_timer_queue_destroy(struct rttimer_queue *rtq) +rt_timer_queue_flush(struct rttimer_queue *rtq) { struct rttimer *r; TAILQ_HEAD(, rttimer) rttlist; @@ -1445,7 +1446,6 @@ rt_timer_queue_destroy(struct rttimer_queue *rtq) KASSERT(rtq->rtq_count > 0); rtq->rtq_count--; } - LIST_REMOVE(rtq, rtq_link); mtx_leave(&rttimer_mtx); while ((r = TAILQ_FIRST(&rttlist)) != NULL) { @@ -1453,7 +1453,6 @@ rt_timer_queue_destroy(struct rttimer_queue *rtq) RTTIMER_CALLOUT(r); pool_put(&rttimer_pool, r); } - pool_put(&rttimer_queue_pool, rtq); } unsigned long @@ -1486,8 +1485,7 @@ rt_timer_remove_all(struct rtentry *rt) } 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; @@ -1500,7 +1498,6 @@ rt_timer_add(struct rtentry *rt, void (*func)(struct rtentry *, u_int), rnew->rtt_rt = rt; rnew->rtt_time = current_time; - rnew->rtt_func = func; rnew->rtt_queue = queue; rnew->rtt_tableid = rtableid; @@ -1511,7 +1508,7 @@ rt_timer_add(struct rtentry *rt, void (*func)(struct rtentry *, u_int), * 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); diff --git a/sys/net/route.h b/sys/net/route.h index 833592340a0..6d4fe60a741 100644 --- a/sys/net/route.h +++ b/sys/net/route.h @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -410,8 +410,6 @@ struct rttimer { 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 */ }; @@ -419,6 +417,8 @@ struct rttimer { 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] */ }; @@ -459,12 +459,12 @@ struct rtentry *rt_getll(struct rtentry *); 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 *); diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 9316bb35e4c..d1d3466e90a 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -120,6 +120,7 @@ int icmp_redirtimeout = 10 * 60; 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; @@ -140,7 +141,10 @@ int icmp_sysctl_icmpstat(void *, size_t *, void *); 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); } @@ -633,7 +637,7 @@ reflect: 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); @@ -974,8 +978,7 @@ icmp_mtudisc_clone(struct in_addr dst, u_int rtableid, int ipsec) 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; diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index d741ae339c3..eba9bbe9b55 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -94,8 +94,6 @@ int ip_mtudisc = 1; 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); @@ -200,7 +198,6 @@ ip_init(void) 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)); @@ -224,7 +221,8 @@ ip_init(void) 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 } @@ -1656,11 +1654,8 @@ ip_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, 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: diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index 55acb800762..c3b1643c946 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -113,7 +113,6 @@ int get_version(struct mbuf *); 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 *); @@ -793,7 +792,7 @@ mfc_expire_route(struct rtentry *rt, u_int rtableid) /* 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; } @@ -827,7 +826,7 @@ mfc_add_route(struct ifnet *ifp, struct sockaddr *origin, 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; diff --git a/sys/netinet/ip_mroute.h b/sys/netinet/ip_mroute.h index 05e4b0f2602..40665862138 100644 --- a/sys/netinet/ip_mroute.h +++ b/sys/netinet/ip_mroute.h @@ -1,4 +1,4 @@ -/* $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_ @@ -176,6 +176,8 @@ struct mrtstat { #define MCAST_EXPIRE_FREQUENCY 30 extern struct rttimer_queue *ip_mrouterq; +void mfc_expire_route(struct rtentry *, u_int); + extern int ip_mrtproto; /* diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 7ea31f0b4de..30ea817a921 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -143,8 +143,10 @@ void 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); } @@ -1404,7 +1406,7 @@ icmp6_redirect_input(struct mbuf *m, int off) 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); @@ -1828,8 +1830,7 @@ icmp6_mtudisc_clone(struct sockaddr_in6 *dst, u_int rtableid, int ipsec) 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; diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 6230f03f895..937ef1a9c44 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -162,7 +162,8 @@ ip6_init(void) 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 } diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index 504b2082bb9..28c7c04cb8f 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -1,4 +1,4 @@ -/* $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 $ */ @@ -176,7 +176,6 @@ struct rtentry *mf6c_find(struct ifnet *, struct in6_addr *, 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. @@ -677,7 +676,7 @@ mf6c_add_route(struct ifnet *ifp, struct sockaddr *origin, } 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); @@ -1004,7 +1003,7 @@ mf6c_expire_route(struct rtentry *rt, u_int rtableid) 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; } diff --git a/sys/netinet6/ip6_mroute.h b/sys/netinet6/ip6_mroute.h index b63e968f370..f7d3e6cdcb7 100644 --- a/sys/netinet6/ip6_mroute.h +++ b/sys/netinet6/ip6_mroute.h @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -195,6 +195,7 @@ struct sioc_mif_req6 { #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. -- 2.20.1