In total there are 6 rt_timer_queues in our kernel. 3 IPv4 and 3 IPv6.
That number may be increased to 8 if arp and nd would use these timers as
well. Because of this allocation the queue heads via pool(9) is overkill.
Switch rt_timer_queue_create to rt_timer_queue_init which just sets up the
struct and links it to the rt_timer_queue.
--
:wq Claudio
Index: net/route.c
===================================================================
RCS file: /cvs/src/sys/net/route.c,v
retrieving revision 1.409
diff -u -p -r1.409 route.c
--- net/route.c 4 May 2022 16:52:10 -0000 1.409
+++ net/route.c 5 May 2022 12:38:16 -0000
@@ -150,7 +150,6 @@ int ifatrash; /* ifas not in ifp list
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
mtx_enter(&rttimer_mtx);
LIST_INSERT_HEAD(&rttimer_queue_head, rtq, rtq_link);
mtx_leave(&rttimer_mtx);
-
- return (rtq);
}
void
Index: net/route.h
===================================================================
RCS file: /cvs/src/sys/net/route.h,v
retrieving revision 1.193
diff -u -p -r1.193 route.h
--- net/route.h 4 May 2022 16:52:10 -0000 1.193
+++ net/route.h 5 May 2022 12:39:15 -0000
@@ -457,16 +457,16 @@ void rtm_proposal(struct ifnet *, struc
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 *);
Index: netinet/ip_icmp.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_icmp.c,v
retrieving revision 1.190
diff -u -p -r1.190 ip_icmp.c
--- netinet/ip_icmp.c 4 May 2022 16:52:10 -0000 1.190
+++ netinet/ip_icmp.c 5 May 2022 12:49:51 -0000
@@ -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
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, vo
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
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;
Index: netinet/ip_input.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_input.c,v
retrieving revision 1.370
diff -u -p -r1.370 ip_input.c
--- netinet/ip_input.c 4 May 2022 16:52:10 -0000 1.370
+++ netinet/ip_input.c 5 May 2022 12:49:55 -0000
@@ -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
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);
Index: netinet/ip_mroute.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_mroute.c,v
retrieving revision 1.134
diff -u -p -r1.134 ip_mroute.c
--- netinet/ip_mroute.c 4 May 2022 16:52:10 -0000 1.134
+++ netinet/ip_mroute.c 5 May 2022 12:51:07 -0000
@@ -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_i
/* 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
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;
Index: netinet/ip_mroute.h
===================================================================
RCS file: /cvs/src/sys/netinet/ip_mroute.h,v
retrieving revision 1.30
diff -u -p -r1.30 ip_mroute.h
--- netinet/ip_mroute.h 4 May 2022 16:52:10 -0000 1.30
+++ netinet/ip_mroute.h 5 May 2022 12:43:40 -0000
@@ -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;
Index: netinet/ip_var.h
===================================================================
RCS file: /cvs/src/sys/netinet/ip_var.h,v
retrieving revision 1.92
diff -u -p -r1.92 ip_var.h
--- netinet/ip_var.h 28 Apr 2022 16:56:39 -0000 1.92
+++ netinet/ip_var.h 5 May 2022 12:50:18 -0000
@@ -217,7 +217,7 @@ extern int ipmforwarding; /* enable mul
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;
Index: netinet6/icmp6.c
===================================================================
RCS file: /cvs/src/sys/netinet6/icmp6.c,v
retrieving revision 1.241
diff -u -p -r1.241 icmp6.c
--- netinet6/icmp6.c 4 May 2022 16:52:10 -0000 1.241
+++ netinet6/icmp6.c 5 May 2022 12:48:54 -0000
@@ -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
* 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
* 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
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
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, v
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;
Index: netinet6/ip6_input.c
===================================================================
RCS file: /cvs/src/sys/netinet6/ip6_input.c,v
retrieving revision 1.244
diff -u -p -r1.244 ip6_input.c
--- netinet6/ip6_input.c 4 May 2022 16:52:10 -0000 1.244
+++ netinet6/ip6_input.c 5 May 2022 12:49:16 -0000
@@ -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, voi
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);
Index: netinet6/ip6_mroute.c
===================================================================
RCS file: /cvs/src/sys/netinet6/ip6_mroute.c,v
retrieving revision 1.130
diff -u -p -r1.130 ip6_mroute.c
--- netinet6/ip6_mroute.c 4 May 2022 16:52:10 -0000 1.130
+++ netinet6/ip6_mroute.c 5 May 2022 12:46:00 -0000
@@ -130,7 +130,7 @@ void phyint_send6(struct ifnet *, struct
* 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
}
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_
if (mf6c->mf6c_expire == 0) {
mf6c->mf6c_expire = 1;
- rt_timer_add(rt, ip6_mrouterq, rtableid);
+ rt_timer_add(rt, &ip6_mrouterq, rtableid);
return;
}
Index: netinet6/ip6_mroute.h
===================================================================
RCS file: /cvs/src/sys/netinet6/ip6_mroute.h,v
retrieving revision 1.22
diff -u -p -r1.22 ip6_mroute.h
--- netinet6/ip6_mroute.h 4 May 2022 16:52:10 -0000 1.22
+++ netinet6/ip6_mroute.h 5 May 2022 12:46:29 -0000
@@ -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);
/*
Index: netinet6/ip6_var.h
===================================================================
RCS file: /cvs/src/sys/netinet6/ip6_var.h,v
retrieving revision 1.91
diff -u -p -r1.91 ip6_var.h
--- netinet6/ip6_var.h 25 Feb 2022 23:51:04 -0000 1.91
+++ netinet6/ip6_var.h 5 May 2022 12:48:09 -0000
@@ -268,7 +268,7 @@ ip6stat_add(enum ip6stat_counters c, uin
#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 */