On Fri, Apr 29, 2022 at 11:58:52AM +0200, Claudio Jeker wrote: > The callback currently uses struct rttimer as an argument but the code > only needs the rtt_tableid element from there. Change the callbacks to > be of the form void (*rtt_callback)(struct rtentry *r, u_int rtableid) > > Also change the default rttimer callback (in case the function is NULL) > to only handle routes with RTF_HOST and RTF_DYNAMIC set. By doing this > two rttimer queues can be switched to a NULL callback. The other option > would be to require always a callback. Right now nothing uses the default > so it should be removed or made useful. > > As a next step I plan to move the callback to struct rttimer_queue since > all rt_timer_add calls use the same callback.
OK bluhm@ > Index: net/route.c > =================================================================== > RCS file: /cvs/src/sys/net/route.c,v > retrieving revision 1.407 > diff -u -p -r1.407 route.c > --- net/route.c 28 Apr 2022 17:47:41 -0000 1.407 > +++ net/route.c 29 Apr 2022 09:42:09 -0000 > @@ -1366,12 +1366,14 @@ LIST_HEAD(, rttimer_queue) rttimer_queue > > #define RTTIMER_CALLOUT(r) { \ > if (r->rtt_func != NULL) { \ > - (*r->rtt_func)(r->rtt_rt, r); \ > + (*r->rtt_func)(r->rtt_rt, r->rtt_tableid); \ > } else { \ > struct ifnet *ifp; \ > \ > ifp = if_get(r->rtt_rt->rt_ifidx); \ > - if (ifp != NULL) \ > + if (ifp != NULL && \ > + (r->rtt_rt->rt_flags & (RTF_DYNAMIC|RTF_HOST)) == \ > + (RTF_DYNAMIC|RTF_HOST)) \ > rtdeletemsg(r->rtt_rt, ifp, r->rtt_tableid); \ > if_put(ifp); \ > } \ > @@ -1484,8 +1486,8 @@ rt_timer_remove_all(struct rtentry *rt) > } > > int > -rt_timer_add(struct rtentry *rt, void (*func)(struct rtentry *, > - struct rttimer *), struct rttimer_queue *queue, u_int rtableid) > +rt_timer_add(struct rtentry *rt, void (*func)(struct rtentry *, u_int), > + struct rttimer_queue *queue, u_int rtableid) > { > struct rttimer *r, *rnew; > time_t current_time; > Index: net/route.h > =================================================================== > RCS file: /cvs/src/sys/net/route.h,v > retrieving revision 1.191 > diff -u -p -r1.191 route.h > --- net/route.h 28 Apr 2022 17:47:41 -0000 1.191 > +++ net/route.h 29 Apr 2022 09:30:27 -0000 > @@ -411,7 +411,7 @@ struct rttimer { > 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 *, struct rttimer *); > + (struct rtentry *, u_int); > time_t rtt_time; /* [I] when timer registered */ > u_int rtt_tableid; /* [I] rtable id of rtt_rt */ > }; > @@ -459,7 +459,7 @@ struct rtentry *rt_getll(struct rtentry > > void rt_timer_init(void); > int rt_timer_add(struct rtentry *, > - void(*)(struct rtentry *, struct rttimer *), > + 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); > Index: netinet/ip_icmp.c > =================================================================== > RCS file: /cvs/src/sys/netinet/ip_icmp.c,v > retrieving revision 1.188 > diff -u -p -r1.188 ip_icmp.c > --- netinet/ip_icmp.c 20 Apr 2022 09:38:26 -0000 1.188 > +++ netinet/ip_icmp.c 29 Apr 2022 09:41:25 -0000 > @@ -132,9 +132,8 @@ const struct sysctl_bounded_args icmpctl > }; > > > -void icmp_mtudisc_timeout(struct rtentry *, struct rttimer *); > +void icmp_mtudisc_timeout(struct rtentry *, u_int); > int icmp_ratelimit(const struct in_addr *, const int, const int); > -void icmp_redirect_timeout(struct rtentry *, struct rttimer *); > int icmp_input_if(struct ifnet *, struct mbuf **, int *, int, int); > int icmp_sysctl_icmpstat(void *, size_t *, void *); > > @@ -634,8 +633,8 @@ 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, > - icmp_redirect_timeout_q, m->m_pkthdr.ph_rtableid); > + rt_timer_add(newrt, NULL, icmp_redirect_timeout_q, > + m->m_pkthdr.ph_rtableid); > } > rtfree(newrt); > pfctlinput(PRC_REDIRECT_HOST, sintosa(&sdst)); > @@ -1053,7 +1052,7 @@ icmp_mtudisc(struct icmp *icp, u_int rta > } > > void > -icmp_mtudisc_timeout(struct rtentry *rt, struct rttimer *r) > +icmp_mtudisc_timeout(struct rtentry *rt, u_int rtableid) > { > struct ifnet *ifp; > > @@ -1069,13 +1068,13 @@ icmp_mtudisc_timeout(struct rtentry *rt, > > sin = *satosin(rt_key(rt)); > > - rtdeletemsg(rt, ifp, r->rtt_tableid); > + rtdeletemsg(rt, ifp, rtableid); > > /* Notify TCP layer of increased Path MTU estimate */ > ctlfunc = inetsw[ip_protox[IPPROTO_TCP]].pr_ctlinput; > if (ctlfunc) > (*ctlfunc)(PRC_MTUINC, sintosa(&sin), > - r->rtt_tableid, NULL); > + rtableid, NULL); > } else { > if ((rt->rt_locks & RTV_MTU) == 0) > rt->rt_mtu = 0; > @@ -1100,24 +1099,6 @@ icmp_ratelimit(const struct in_addr *dst > icmperrppslim)) > return 1; /* The packet is subject to rate limit */ > return 0; /* okay to send */ > -} > - > -void > -icmp_redirect_timeout(struct rtentry *rt, struct rttimer *r) > -{ > - struct ifnet *ifp; > - > - NET_ASSERT_LOCKED(); > - > - ifp = if_get(rt->rt_ifidx); > - if (ifp == NULL) > - return; > - > - if ((rt->rt_flags & (RTF_DYNAMIC|RTF_HOST)) == (RTF_DYNAMIC|RTF_HOST)) { > - rtdeletemsg(rt, ifp, r->rtt_tableid); > - } > - > - if_put(ifp); > } > > int > Index: netinet/ip_mroute.c > =================================================================== > RCS file: /cvs/src/sys/netinet/ip_mroute.c,v > retrieving revision 1.132 > diff -u -p -r1.132 ip_mroute.c > --- netinet/ip_mroute.c 28 Apr 2022 17:27:14 -0000 1.132 > +++ netinet/ip_mroute.c 29 Apr 2022 09:35:45 -0000 > @@ -113,7 +113,7 @@ 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 *, struct rttimer *); > +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 *); > @@ -777,10 +777,9 @@ vif_delete(struct ifnet *ifp) > } > > void > -mfc_expire_route(struct rtentry *rt, struct rttimer *rtt) > +mfc_expire_route(struct rtentry *rt, u_int rtableid) > { > struct mfc *mfc = (struct mfc *)rt->rt_llinfo; > - unsigned int rtableid = rtt->rtt_tableid; > > /* Skip entry being deleted. */ > if (mfc == NULL) > Index: netinet6/icmp6.c > =================================================================== > RCS file: /cvs/src/sys/netinet6/icmp6.c,v > retrieving revision 1.239 > diff -u -p -r1.239 icmp6.c > --- netinet6/icmp6.c 20 Apr 2022 09:38:26 -0000 1.239 > +++ netinet6/icmp6.c 29 Apr 2022 09:43:28 -0000 > @@ -137,8 +137,7 @@ int icmp6_ratelimit(const struct in6_add > const char *icmp6_redirect_diag(struct in6_addr *, struct in6_addr *, > struct in6_addr *); > int icmp6_notify_error(struct mbuf *, int, int, int); > -void icmp6_mtudisc_timeout(struct rtentry *, struct rttimer *); > -void icmp6_redirect_timeout(struct rtentry *, struct rttimer *); > +void icmp6_mtudisc_timeout(struct rtentry *, u_int); > > void > icmp6_init(void) > @@ -1405,8 +1404,8 @@ 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, > - icmp6_redirect_timeout_q, m->m_pkthdr.ph_rtableid); > + rt_timer_add(newrt, NULL, icmp6_redirect_timeout_q, > + m->m_pkthdr.ph_rtableid); > } > rtfree(newrt); > } > @@ -1841,7 +1840,7 @@ bad: > } > > void > -icmp6_mtudisc_timeout(struct rtentry *rt, struct rttimer *r) > +icmp6_mtudisc_timeout(struct rtentry *rt, u_int rtableid) > { > struct ifnet *ifp; > > @@ -1852,28 +1851,10 @@ icmp6_mtudisc_timeout(struct rtentry *rt > return; > > if ((rt->rt_flags & (RTF_DYNAMIC|RTF_HOST)) == (RTF_DYNAMIC|RTF_HOST)) { > - rtdeletemsg(rt, ifp, r->rtt_tableid); > + rtdeletemsg(rt, ifp, rtableid); > } else { > if (!(rt->rt_locks & RTV_MTU)) > rt->rt_mtu = 0; > - } > - > - if_put(ifp); > -} > - > -void > -icmp6_redirect_timeout(struct rtentry *rt, struct rttimer *r) > -{ > - struct ifnet *ifp; > - > - NET_ASSERT_LOCKED(); > - > - ifp = if_get(rt->rt_ifidx); > - if (ifp == NULL) > - return; > - > - if ((rt->rt_flags & (RTF_DYNAMIC|RTF_HOST)) == (RTF_DYNAMIC|RTF_HOST)) { > - rtdeletemsg(rt, ifp, r->rtt_tableid); > } > > if_put(ifp); > Index: netinet6/ip6_mroute.c > =================================================================== > RCS file: /cvs/src/sys/netinet6/ip6_mroute.c,v > retrieving revision 1.128 > diff -u -p -r1.128 ip6_mroute.c > --- netinet6/ip6_mroute.c 28 Apr 2022 17:27:14 -0000 1.128 > +++ netinet6/ip6_mroute.c 29 Apr 2022 09:32:56 -0000 > @@ -176,7 +176,7 @@ struct rtentry *mf6c_find(struct ifnet * > 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 *, struct rttimer *); > +void mf6c_expire_route(struct rtentry *, u_int); > > /* > * Handle MRT setsockopt commands to modify the multicast routing tables. > @@ -984,10 +984,9 @@ ip6_mforward(struct ip6_hdr *ip6, struct > } > > void > -mf6c_expire_route(struct rtentry *rt, struct rttimer *rtt) > +mf6c_expire_route(struct rtentry *rt, u_int rtableid) > { > struct mf6c *mf6c = (struct mf6c *)rt->rt_llinfo; > - unsigned int rtableid = rtt->rtt_tableid; > #ifdef MCAST_DEBUG > char bsrc[INET6_ADDRSTRLEN], bdst[INET6_ADDRSTRLEN]; > #endif /* MCAST_DEBUG */