From ef8e83db3db18f07230f8ff6ab27b4231898b41c Mon Sep 17 00:00:00 2001 From: claudio Date: Thu, 28 Apr 2022 17:27:14 +0000 Subject: [PATCH] In the multicast router code don't allocate a rt timer queue for each rdomain. The rttimer API is rtable/rdomain aware and so there is no need to have so many queues. Also init the two queues (one for IPv4 and one for IPv6) early on. This will allow the rttable code to become simpler. OK bluhm@ --- sys/netinet/ip_input.c | 9 ++++----- sys/netinet/ip_mroute.c | 19 ++++++------------- sys/netinet/ip_mroute.h | 5 ++++- sys/netinet6/ip6_input.c | 5 ++++- sys/netinet6/ip6_mroute.c | 14 ++++---------- sys/netinet6/ip6_mroute.h | 7 ++++++- 6 files changed, 28 insertions(+), 31 deletions(-) diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 02a326c4481..d741ae339c3 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_input.c,v 1.368 2022/04/28 16:56:39 bluhm Exp $ */ +/* $OpenBSD: ip_input.c,v 1.369 2022/04/28 17:27:14 claudio Exp $ */ /* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */ /* @@ -106,10 +106,6 @@ LIST_HEAD(, ipq) ipq; int ip_maxqueue = 300; int ip_frags = 0; -#ifdef MROUTING -extern int ip_mrtproto; -#endif - const struct sysctl_bounded_args ipctl_vars[] = { #ifdef MROUTING { IPCTL_MRTPROTO, &ip_mrtproto, SYSCTL_INT_READONLY }, @@ -227,6 +223,9 @@ ip_init(void) #ifdef IPSEC ipsec_init(); #endif +#ifdef MROUTING + ip_mrouterq = rt_timer_queue_create(MCAST_EXPIRE_FREQUENCY); +#endif } /* diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index d6024e2a3c1..e9bc149b7d7 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_mroute.c,v 1.131 2021/12/15 17:21:08 deraadt Exp $ */ +/* $OpenBSD: ip_mroute.c,v 1.132 2022/04/28 17:27:14 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 *mrouterq[RT_TABLEID_MAX + 1]; +struct rttimer_queue *ip_mrouterq; uint64_t mrt_count[RT_TABLEID_MAX + 1]; int ip_mrtproto = IGMP_DVMRP; /* for netstat only */ @@ -515,12 +515,10 @@ ip_mrouter_init(struct socket *so, struct mbuf *m) if (*v != 1) return (EINVAL); - if (ip_mrouter[rtableid] != NULL || - mrouterq[rtableid] != NULL) + if (ip_mrouter[rtableid] != NULL) return (EADDRINUSE); ip_mrouter[rtableid] = so; - mrouterq[rtableid] = rt_timer_queue_create(MCAST_EXPIRE_FREQUENCY); return (0); } @@ -572,8 +570,6 @@ ip_mrouter_done(struct socket *so) mrt_api_config = 0; - rt_timer_queue_destroy(mrouterq[rtableid]); - mrouterq[rtableid] = NULL; ip_mrouter[rtableid] = NULL; mrt_count[rtableid] = 0; @@ -791,16 +787,14 @@ mfc_expire_route(struct rtentry *rt, struct rttimer *rtt) return; DPRINTF("Route domain %d origin %#08X group %#08x interface %d " - "expire %s", rtt->rtt_tableid, - satosin(rt->rt_gateway)->sin_addr.s_addr, + "expire %s", rtableid, satosin(rt->rt_gateway)->sin_addr.s_addr, satosin(rt_key(rt))->sin_addr.s_addr, rt->rt_ifidx, mfc->mfc_expire ? "yes" : "no"); /* Not expired, add it back to the queue. */ if (mfc->mfc_expire == 0) { mfc->mfc_expire = 1; - rt_timer_add(rt, mfc_expire_route, mrouterq[rtableid], - rtableid); + rt_timer_add(rt, mfc_expire_route, ip_mrouterq, rtableid); return; } @@ -834,8 +828,7 @@ mfc_add_route(struct ifnet *ifp, struct sockaddr *origin, rt->rt_llinfo = (caddr_t)mfc; - rt_timer_add(rt, mfc_expire_route, mrouterq[rtableid], - rtableid); + rt_timer_add(rt, mfc_expire_route, 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 ce4506b6b26..05e4b0f2602 100644 --- a/sys/netinet/ip_mroute.h +++ b/sys/netinet/ip_mroute.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_mroute.h,v 1.28 2017/02/01 20:59:47 dhill Exp $ */ +/* $OpenBSD: ip_mroute.h,v 1.29 2022/04/28 17:27:14 claudio Exp $ */ /* $NetBSD: ip_mroute.h,v 1.23 2004/04/21 17:49:46 itojun Exp $ */ #ifndef _NETINET_IP_MROUTE_H_ @@ -175,6 +175,9 @@ struct mrtstat { /* How frequent should we look for expired entries (in seconds). */ #define MCAST_EXPIRE_FREQUENCY 30 +extern struct rttimer_queue *ip_mrouterq; +extern int ip_mrtproto; + /* * The kernel's virtual-interface structure. */ diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 08dfec34b81..6230f03f895 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_input.c,v 1.242 2022/04/28 16:56:39 bluhm Exp $ */ +/* $OpenBSD: ip6_input.c,v 1.243 2022/04/28 17:27:14 claudio Exp $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -161,6 +161,9 @@ ip6_init(void) mq_init(&ip6send_mq, 64, IPL_SOFTNET); ip6counters = counters_alloc(ip6s_ncounters); +#ifdef MROUTING + ip6_mrouterq = rt_timer_queue_create(MCAST_EXPIRE_TIMEOUT); +#endif } /* diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index 80aa39b523a..2f6263637f6 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_mroute.c,v 1.127 2021/12/15 17:21:08 deraadt Exp $ */ +/* $OpenBSD: ip6_mroute.c,v 1.128 2022/04/28 17:27:14 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 *mrouter6q[RT_TABLEID_MAX + 1]; +struct rttimer_queue *ip6_mrouterq; int ip6_mrouter_ver = 0; int ip6_mrtproto; /* for netstat only */ struct mrt6stat mrt6stat; @@ -138,8 +138,6 @@ struct mrt6stat mrt6stat; #define NO_RTE_FOUND 0x1 #define RTE_FOUND 0x2 -#define MCAST_EXPIRE_TIMEOUT 30 /* seconds */ - /* * Macros to compute elapsed time efficiently * Borrowed from Van Jacobson's scheduling code @@ -494,7 +492,6 @@ ip6_mrouter_init(struct socket *so, int v, int cmd) ip6_mrouter[rtableid] = so; ip6_mrouter_ver = cmd; - mrouter6q[rtableid] = rt_timer_queue_create(MCAST_EXPIRE_TIMEOUT); return (0); } @@ -544,10 +541,8 @@ ip6_mrouter_done(struct socket *so) ip6_mrouter_detach(ifp); } - rt_timer_queue_destroy(mrouter6q[rtableid]); ip6_mrouter[inp->inp_rtableid] = NULL; ip6_mrouter_ver = 0; - mrouter6q[rtableid] = NULL; return 0; } @@ -682,7 +677,7 @@ mf6c_add_route(struct ifnet *ifp, struct sockaddr *origin, } rt->rt_llinfo = (caddr_t)mf6c; - rt_timer_add(rt, mf6c_expire_route, mrouter6q[rtableid], rtableid); + rt_timer_add(rt, mf6c_expire_route, ip6_mrouterq, rtableid); mf6c->mf6c_parent = mf6cc->mf6cc_parent; rtfree(rt); @@ -1010,8 +1005,7 @@ mf6c_expire_route(struct rtentry *rt, struct rttimer *rtt) if (mf6c->mf6c_expire == 0) { mf6c->mf6c_expire = 1; - rt_timer_add(rt, mf6c_expire_route, mrouter6q[rtableid], - rtableid); + rt_timer_add(rt, mf6c_expire_route, ip6_mrouterq, rtableid); return; } diff --git a/sys/netinet6/ip6_mroute.h b/sys/netinet6/ip6_mroute.h index 584ed869e9b..b63e968f370 100644 --- a/sys/netinet6/ip6_mroute.h +++ b/sys/netinet6/ip6_mroute.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_mroute.h,v 1.20 2017/05/16 08:50:18 rzalamena Exp $ */ +/* $OpenBSD: ip6_mroute.h,v 1.21 2022/04/28 17:27:14 claudio Exp $ */ /* $KAME: ip6_mroute.h,v 1.17 2001/02/10 02:05:52 itojun Exp $ */ /* @@ -191,6 +191,11 @@ struct sioc_mif_req6 { }; #if defined(_KERNEL) +/* How frequent should we look for expired entries (in seconds). */ +#define MCAST_EXPIRE_TIMEOUT 30 + +extern struct rttimer_queue *ip6_mrouterq; + /* * The kernel's multicast-interface structure. */ -- 2.20.1