From 2028c273aac9cb855f4a8512da37f710917f3231 Mon Sep 17 00:00:00 2001 From: claudio Date: Thu, 5 May 2022 13:57:40 +0000 Subject: [PATCH] Use static objects for struct rttimer_queue instead of dynamically allocate them. Currently there are 6 rttimer_queues and not many more will follow. So change rt_timer_queue_create() to rt_timer_queue_init() which now takes a struct rttimer_queue * as argument which will be initialized. Since this changes the gloabl vars from pointer to struct adjust other callers as well. OK bluhm@ --- sys/net/route.c | 16 ++++------------ sys/net/route.h | 22 +++++++++++----------- sys/netinet/ip_icmp.c | 16 ++++++++-------- sys/netinet/ip_input.c | 8 ++++---- sys/netinet/ip_mroute.c | 8 ++++---- sys/netinet/ip_mroute.h | 4 ++-- sys/netinet/ip_var.h | 4 ++-- sys/netinet6/icmp6.c | 20 ++++++++++---------- sys/netinet6/ip6_input.c | 6 +++--- sys/netinet6/ip6_mroute.c | 8 ++++---- sys/netinet6/ip6_mroute.h | 4 ++-- sys/netinet6/ip6_var.h | 4 ++-- 12 files changed, 56 insertions(+), 64 deletions(-) diff --git a/sys/net/route.c b/sys/net/route.c index 8afc2a04238..56d927b9e7e 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.409 2022/05/04 16:52:10 claudio Exp $ */ +/* $OpenBSD: route.c,v 1.410 2022/05/05 13:57:40 claudio Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -150,7 +150,6 @@ int ifatrash; /* ifas not in ifp list but not free */ struct pool rtentry_pool; /* pool for rtentry structures */ struct pool rttimer_pool; /* pool for rttimer structures */ -struct pool rttimer_queue_pool; /* pool for rttimer_queue structures */ int rt_setgwroute(struct rtentry *, u_int); void rt_putgwroute(struct rtentry *); @@ -1393,8 +1392,6 @@ rt_timer_init(void) pool_init(&rttimer_pool, sizeof(struct rttimer), 0, IPL_MPFLOOR, 0, "rttmr", NULL); - pool_init(&rttimer_queue_pool, sizeof(struct rttimer_queue), 0, - IPL_MPFLOOR, 0, "rttmrq", NULL); mtx_init(&rttimer_mtx, IPL_MPFLOOR); LIST_INIT(&rttimer_queue_head); @@ -1402,13 +1399,10 @@ rt_timer_init(void) timeout_add_sec(&rt_timer_timeout, 1); } -struct rttimer_queue * -rt_timer_queue_create(int timeout, void (*func)(struct rtentry *, u_int)) +void +rt_timer_queue_init(struct rttimer_queue *rtq, int timeout, + void (*func)(struct rtentry *, u_int)) { - struct rttimer_queue *rtq; - - rtq = pool_get(&rttimer_queue_pool, PR_WAITOK | PR_ZERO); - rtq->rtq_timeout = timeout; rtq->rtq_count = 0; rtq->rtq_func = func; @@ -1417,8 +1411,6 @@ rt_timer_queue_create(int timeout, void (*func)(struct rtentry *, u_int)) mtx_enter(&rttimer_mtx); LIST_INSERT_HEAD(&rttimer_queue_head, rtq, rtq_link); mtx_leave(&rttimer_mtx); - - return (rtq); } void diff --git a/sys/net/route.h b/sys/net/route.h index 6d4fe60a741..0ad17bf7ec6 100644 --- a/sys/net/route.h +++ b/sys/net/route.h @@ -1,4 +1,4 @@ -/* $OpenBSD: route.h,v 1.193 2022/05/04 16:52:10 claudio Exp $ */ +/* $OpenBSD: route.h,v 1.194 2022/05/05 13:57:40 claudio Exp $ */ /* $NetBSD: route.h,v 1.9 1996/02/13 22:00:49 christos Exp $ */ /* @@ -457,16 +457,16 @@ void rtm_proposal(struct ifnet *, struct rt_addrinfo *, int, uint8_t); int rt_setgate(struct rtentry *, struct sockaddr *, u_int); struct rtentry *rt_getll(struct rtentry *); -void rt_timer_init(void); -int rt_timer_add(struct rtentry *, - struct rttimer_queue *, u_int); -void rt_timer_remove_all(struct rtentry *); -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_flush(struct rttimer_queue *); -unsigned long rt_timer_queue_count(struct rttimer_queue *); -void rt_timer_timer(void *); +void rt_timer_init(void); +int rt_timer_add(struct rtentry *, + struct rttimer_queue *, u_int); +void rt_timer_remove_all(struct rtentry *); +void rt_timer_queue_init(struct rttimer_queue *, int, + void(*)(struct rtentry *, u_int)); +void rt_timer_queue_change(struct rttimer_queue *, int); +void rt_timer_queue_flush(struct rttimer_queue *); +unsigned long rt_timer_queue_count(struct rttimer_queue *); +void rt_timer_timer(void *); int rt_mpls_set(struct rtentry *, struct sockaddr *, uint8_t); void rt_mpls_clear(struct rtentry *); diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index d1d3466e90a..44811886c26 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_icmp.c,v 1.190 2022/05/04 16:52:10 claudio Exp $ */ +/* $OpenBSD: ip_icmp.c,v 1.191 2022/05/05 13:57:40 claudio Exp $ */ /* $NetBSD: ip_icmp.c,v 1.19 1996/02/13 23:42:22 christos Exp $ */ /* @@ -120,8 +120,8 @@ 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 rttimer_queue ip_mtudisc_timeout_q; +struct rttimer_queue icmp_redirect_timeout_q; struct cpumem *icmpcounters; const struct sysctl_bounded_args icmpctl_vars[] = { @@ -141,9 +141,9 @@ int icmp_sysctl_icmpstat(void *, size_t *, void *); void icmp_init(void) { - ip_mtudisc_timeout_q = rt_timer_queue_create(ip_mtudisc_timeout, + rt_timer_queue_init(&ip_mtudisc_timeout_q, ip_mtudisc_timeout, &icmp_mtudisc_timeout); - icmp_redirect_timeout_q = rt_timer_queue_create(icmp_redirtimeout, + rt_timer_queue_init(&icmp_redirect_timeout_q, icmp_redirtimeout, NULL); icmpcounters = counters_alloc(icps_ncounters); } @@ -637,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, icmp_redirect_timeout_q, + rt_timer_add(newrt, &icmp_redirect_timeout_q, m->m_pkthdr.ph_rtableid); } rtfree(newrt); @@ -887,7 +887,7 @@ icmp_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, NET_LOCK(); error = sysctl_int_bounded(oldp, oldlenp, newp, newlen, &icmp_redirtimeout, 0, INT_MAX); - rt_timer_queue_change(icmp_redirect_timeout_q, + rt_timer_queue_change(&icmp_redirect_timeout_q, icmp_redirtimeout); NET_UNLOCK(); break; @@ -978,7 +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, 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 eba9bbe9b55..a0ef01bc55d 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_input.c,v 1.370 2022/05/04 16:52:10 claudio Exp $ */ +/* $OpenBSD: ip_input.c,v 1.371 2022/05/05 13:57:40 claudio Exp $ */ /* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */ /* @@ -221,7 +221,7 @@ ip_init(void) ipsec_init(); #endif #ifdef MROUTING - ip_mrouterq = rt_timer_queue_create(MCAST_EXPIRE_FREQUENCY, + rt_timer_queue_init(&ip_mrouterq, MCAST_EXPIRE_FREQUENCY, &mfc_expire_route); #endif } @@ -1655,14 +1655,14 @@ ip_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, NET_LOCK(); error = sysctl_int(oldp, oldlenp, newp, newlen, &ip_mtudisc); if (ip_mtudisc == 0) - rt_timer_queue_flush(ip_mtudisc_timeout_q); + rt_timer_queue_flush(&ip_mtudisc_timeout_q); NET_UNLOCK(); return error; case IPCTL_MTUDISCTIMEOUT: NET_LOCK(); error = sysctl_int_bounded(oldp, oldlenp, newp, newlen, &ip_mtudisc_timeout, 0, INT_MAX); - rt_timer_queue_change(ip_mtudisc_timeout_q, + rt_timer_queue_change(&ip_mtudisc_timeout_q, ip_mtudisc_timeout); NET_UNLOCK(); return (error); diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index c3b1643c946..124ded3c4c6 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_mroute.c,v 1.134 2022/05/04 16:52:10 claudio Exp $ */ +/* $OpenBSD: ip_mroute.c,v 1.135 2022/05/05 13:57:40 claudio Exp $ */ /* $NetBSD: ip_mroute.c,v 1.85 2004/04/26 01:31:57 matt Exp $ */ /* @@ -96,7 +96,7 @@ int mcast_debug = 1; * except for netstat or debugging purposes. */ struct socket *ip_mrouter[RT_TABLEID_MAX + 1]; -struct rttimer_queue *ip_mrouterq; +struct rttimer_queue ip_mrouterq; uint64_t mrt_count[RT_TABLEID_MAX + 1]; int ip_mrtproto = IGMP_DVMRP; /* for netstat only */ @@ -792,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, ip_mrouterq, rtableid); + rt_timer_add(rt, &ip_mrouterq, rtableid); return; } @@ -826,7 +826,7 @@ mfc_add_route(struct ifnet *ifp, struct sockaddr *origin, rt->rt_llinfo = (caddr_t)mfc; - rt_timer_add(rt, 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 40665862138..b389d63d598 100644 --- a/sys/netinet/ip_mroute.h +++ b/sys/netinet/ip_mroute.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_mroute.h,v 1.30 2022/05/04 16:52:10 claudio Exp $ */ +/* $OpenBSD: ip_mroute.h,v 1.31 2022/05/05 13:57:40 claudio Exp $ */ /* $NetBSD: ip_mroute.h,v 1.23 2004/04/21 17:49:46 itojun Exp $ */ #ifndef _NETINET_IP_MROUTE_H_ @@ -175,7 +175,7 @@ struct mrtstat { /* How frequent should we look for expired entries (in seconds). */ #define MCAST_EXPIRE_FREQUENCY 30 -extern struct rttimer_queue *ip_mrouterq; +extern struct rttimer_queue ip_mrouterq; void mfc_expire_route(struct rtentry *, u_int); extern int ip_mrtproto; diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index 8e41dd3bb69..3df8ffee7aa 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_var.h,v 1.92 2022/04/28 16:56:39 bluhm Exp $ */ +/* $OpenBSD: ip_var.h,v 1.93 2022/05/05 13:57:40 claudio Exp $ */ /* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */ /* @@ -217,7 +217,7 @@ extern int ipmforwarding; /* enable multicast forwarding */ extern int ipmultipath; /* enable multipath routing */ extern int la_hold_total; -extern struct rttimer_queue *ip_mtudisc_timeout_q; +extern struct rttimer_queue ip_mtudisc_timeout_q; extern struct pool ipqent_pool; struct route; struct inpcb; diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 30ea817a921..a9bf43e20b9 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: icmp6.c,v 1.241 2022/05/04 16:52:10 claudio Exp $ */ +/* $OpenBSD: icmp6.c,v 1.242 2022/05/05 13:57:40 claudio Exp $ */ /* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */ /* @@ -118,7 +118,7 @@ struct icmp6_mtudisc_callback { LIST_HEAD(, icmp6_mtudisc_callback) icmp6_mtudisc_callbacks = LIST_HEAD_INITIALIZER(icmp6_mtudisc_callbacks); -struct rttimer_queue *icmp6_mtudisc_timeout_q; +struct rttimer_queue icmp6_mtudisc_timeout_q; /* XXX do these values make any sense? */ static int icmp6_mtudisc_hiwat = 1280; @@ -127,7 +127,7 @@ static int icmp6_mtudisc_lowat = 256; /* * keep track of # of redirect routes. */ -struct rttimer_queue *icmp6_redirect_timeout_q; +struct rttimer_queue icmp6_redirect_timeout_q; /* XXX experimental, turned off */ static int icmp6_redirect_lowat = -1; @@ -143,9 +143,9 @@ void icmp6_init(void) { mld6_init(); - icmp6_mtudisc_timeout_q = rt_timer_queue_create(ip6_mtudisc_timeout, + rt_timer_queue_init(&icmp6_mtudisc_timeout_q, ip6_mtudisc_timeout, &icmp6_mtudisc_timeout); - icmp6_redirect_timeout_q = rt_timer_queue_create(icmp6_redirtimeout, + rt_timer_queue_init(&icmp6_redirect_timeout_q, icmp6_redirtimeout, NULL); icmp6counters = counters_alloc(icp6s_ncounters); } @@ -988,7 +988,7 @@ icmp6_mtudisc_update(struct ip6ctlparam *ip6cp, int validated) * allow non-validated cases if memory is plenty, to make traffic * from non-connected pcb happy. */ - rtcount = rt_timer_queue_count(icmp6_mtudisc_timeout_q); + rtcount = rt_timer_queue_count(&icmp6_mtudisc_timeout_q); if (validated) { if (0 <= icmp6_mtudisc_hiwat && rtcount > icmp6_mtudisc_hiwat) return; @@ -1384,7 +1384,7 @@ icmp6_redirect_input(struct mbuf *m, int off) * work just fine even if we do not install redirect route * (there will be additional hops, though). */ - rtcount = rt_timer_queue_count(icmp6_redirect_timeout_q); + rtcount = rt_timer_queue_count(&icmp6_redirect_timeout_q); if (0 <= ip6_maxdynroutes && rtcount >= ip6_maxdynroutes) goto freeit; else if (0 <= icmp6_redirect_lowat && @@ -1406,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, icmp6_redirect_timeout_q, + rt_timer_add(newrt, &icmp6_redirect_timeout_q, m->m_pkthdr.ph_rtableid); } rtfree(newrt); @@ -1830,7 +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_q, rtableid); + error = rt_timer_add(rt, &icmp6_mtudisc_timeout_q, rtableid); if (error) goto bad; @@ -1903,7 +1903,7 @@ icmp6_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, NET_LOCK(); error = sysctl_int_bounded(oldp, oldlenp, newp, newlen, &icmp6_redirtimeout, 0, INT_MAX); - rt_timer_queue_change(icmp6_redirect_timeout_q, + rt_timer_queue_change(&icmp6_redirect_timeout_q, icmp6_redirtimeout); NET_UNLOCK(); break; diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 937ef1a9c44..8dcab7d1f55 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_input.c,v 1.244 2022/05/04 16:52:10 claudio Exp $ */ +/* $OpenBSD: ip6_input.c,v 1.245 2022/05/05 13:57:40 claudio Exp $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -162,7 +162,7 @@ ip6_init(void) ip6counters = counters_alloc(ip6s_ncounters); #ifdef MROUTING - ip6_mrouterq = rt_timer_queue_create(MCAST_EXPIRE_TIMEOUT, + rt_timer_queue_init(&ip6_mrouterq, MCAST_EXPIRE_TIMEOUT, &mf6c_expire_route); #endif } @@ -1502,7 +1502,7 @@ ip6_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, NET_LOCK(); error = sysctl_int_bounded(oldp, oldlenp, newp, newlen, &ip6_mtudisc_timeout, 0, INT_MAX); - rt_timer_queue_change(icmp6_mtudisc_timeout_q, + rt_timer_queue_change(&icmp6_mtudisc_timeout_q, ip6_mtudisc_timeout); NET_UNLOCK(); return (error); diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index 28c7c04cb8f..006f6ad964a 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_mroute.c,v 1.130 2022/05/04 16:52:10 claudio Exp $ */ +/* $OpenBSD: ip6_mroute.c,v 1.131 2022/05/05 13:57:41 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 $ */ @@ -130,7 +130,7 @@ void phyint_send6(struct ifnet *, struct ip6_hdr *, struct mbuf *); * except for netstat or debugging purposes. */ struct socket *ip6_mrouter[RT_TABLEID_MAX + 1]; -struct rttimer_queue *ip6_mrouterq; +struct rttimer_queue ip6_mrouterq; int ip6_mrouter_ver = 0; int ip6_mrtproto; /* for netstat only */ struct mrt6stat mrt6stat; @@ -676,7 +676,7 @@ mf6c_add_route(struct ifnet *ifp, struct sockaddr *origin, } rt->rt_llinfo = (caddr_t)mf6c; - rt_timer_add(rt, ip6_mrouterq, rtableid); + rt_timer_add(rt, &ip6_mrouterq, rtableid); mf6c->mf6c_parent = mf6cc->mf6cc_parent; rtfree(rt); @@ -1003,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, 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 f7d3e6cdcb7..3edf0a7c29f 100644 --- a/sys/netinet6/ip6_mroute.h +++ b/sys/netinet6/ip6_mroute.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_mroute.h,v 1.22 2022/05/04 16:52:10 claudio Exp $ */ +/* $OpenBSD: ip6_mroute.h,v 1.23 2022/05/05 13:57:41 claudio Exp $ */ /* $KAME: ip6_mroute.h,v 1.17 2001/02/10 02:05:52 itojun Exp $ */ /* @@ -194,7 +194,7 @@ struct sioc_mif_req6 { /* How frequent should we look for expired entries (in seconds). */ #define MCAST_EXPIRE_TIMEOUT 30 -extern struct rttimer_queue *ip6_mrouterq; +extern struct rttimer_queue ip6_mrouterq; void mf6c_expire_route(struct rtentry *, u_int); /* diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h index 8460fbda64c..1fa3297b883 100644 --- a/sys/netinet6/ip6_var.h +++ b/sys/netinet6/ip6_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_var.h,v 1.91 2022/02/25 23:51:04 guenther Exp $ */ +/* $OpenBSD: ip6_var.h,v 1.92 2022/05/05 13:57:41 claudio Exp $ */ /* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */ /* @@ -268,7 +268,7 @@ ip6stat_add(enum ip6stat_counters c, uint64_t v) #define IPV6_MINMTU 0x04 /* use minimum MTU (IPV6_USE_MIN_MTU) */ extern int ip6_mtudisc_timeout; /* mtu discovery */ -extern struct rttimer_queue *icmp6_mtudisc_timeout_q; +extern struct rttimer_queue icmp6_mtudisc_timeout_q; extern int ip6_defhlim; /* default hop limit */ extern int ip6_defmcasthlim; /* default multicast hop limit */ -- 2.20.1