From 80eefb13a29c30eeeba8c65975046a50822289a6 Mon Sep 17 00:00:00 2001 From: claudio Date: Sat, 30 Apr 2022 07:20:35 +0000 Subject: [PATCH] Convert the 2nd rttimer callback from struct rttimer to u_int rtableid. The callback only needs to know the rtableid all the other info from struct rtableid is not needed. Also change the default rttimer callback to only delete routes that are RTF_HOST and RTF_DYNAMIC. This way 2 of the ICMP handlers can use NULL as the callback. OK bluhm@ --- sys/net/route.c | 12 +++++++----- sys/net/route.h | 6 +++--- sys/netinet/ip_icmp.c | 33 +++++++-------------------------- sys/netinet/ip_mroute.c | 7 +++---- sys/netinet6/icmp6.c | 31 ++++++------------------------- sys/netinet6/ip6_mroute.c | 7 +++---- 6 files changed, 29 insertions(+), 67 deletions(-) diff --git a/sys/net/route.c b/sys/net/route.c index 3ac9717b4a3..b10dde62c5c 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.407 2022/04/28 17:47:41 bluhm Exp $ */ +/* $OpenBSD: route.c,v 1.408 2022/04/30 07:20:35 claudio Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -1366,12 +1366,14 @@ LIST_HEAD(, rttimer_queue) rttimer_queue_head; /* [T] */ #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; diff --git a/sys/net/route.h b/sys/net/route.h index 23d46bbbe64..833592340a0 100644 --- a/sys/net/route.h +++ b/sys/net/route.h @@ -1,4 +1,4 @@ -/* $OpenBSD: route.h,v 1.191 2022/04/28 17:47:41 bluhm Exp $ */ +/* $OpenBSD: route.h,v 1.192 2022/04/30 07:20:35 claudio Exp $ */ /* $NetBSD: route.h,v 1.9 1996/02/13 22:00:49 christos Exp $ */ /* @@ -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); diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 97b06361473..9316bb35e4c 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_icmp.c,v 1.188 2022/04/20 09:38:26 bluhm Exp $ */ +/* $OpenBSD: ip_icmp.c,v 1.189 2022/04/30 07:20:35 claudio Exp $ */ /* $NetBSD: ip_icmp.c,v 1.19 1996/02/13 23:42:22 christos Exp $ */ /* @@ -132,9 +132,8 @@ const struct sysctl_bounded_args icmpctl_vars[] = { }; -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 rtableid) } 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, struct rttimer *r) 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; @@ -1102,24 +1101,6 @@ icmp_ratelimit(const struct in_addr *dst, const int type, const int code) 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 icmp_do_exthdr(struct mbuf *m, u_int16_t class, u_int8_t ctype, void *buf, size_t len) diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index e9bc149b7d7..55acb800762 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_mroute.c,v 1.132 2022/04/28 17:27:14 claudio Exp $ */ +/* $OpenBSD: ip_mroute.c,v 1.133 2022/04/30 07:20:35 claudio Exp $ */ /* $NetBSD: ip_mroute.c,v 1.85 2004/04/26 01:31:57 matt Exp $ */ /* @@ -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) diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index ee1685ece95..7ea31f0b4de 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: icmp6.c,v 1.239 2022/04/20 09:38:26 bluhm Exp $ */ +/* $OpenBSD: icmp6.c,v 1.240 2022/04/30 07:20:35 claudio Exp $ */ /* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */ /* @@ -137,8 +137,7 @@ int icmp6_ratelimit(const struct in6_addr *, const int, const int); 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 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, - 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,7 +1851,7 @@ icmp6_mtudisc_timeout(struct rtentry *rt, struct rttimer *r) 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; @@ -1861,24 +1860,6 @@ icmp6_mtudisc_timeout(struct rtentry *rt, struct rttimer *r) 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); -} - const struct sysctl_bounded_args icmpv6ctl_vars[] = { { ICMPV6CTL_ND6_DELAY, &nd6_delay, 0, INT_MAX }, { ICMPV6CTL_ND6_UMAXTRIES, &nd6_umaxtries, 0, INT_MAX }, diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index 2f6263637f6..504b2082bb9 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_mroute.c,v 1.128 2022/04/28 17:27:14 claudio Exp $ */ +/* $OpenBSD: ip6_mroute.c,v 1.129 2022/04/30 07:20:35 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,7 @@ 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 *, 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 ifnet *ifp, struct mbuf *m) } 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 */ -- 2.20.1