Index: net/if_loop.c =================================================================== RCS file: /cvs/src/sys/net/if_loop.c,v diff -u -p -r1.98 if_loop.c --- net/if_loop.c 29 Dec 2023 11:43:04 -0000 1.98 +++ net/if_loop.c 25 Jul 2024 04:24:51 -0000 @@ -261,12 +261,6 @@ looutput(struct ifnet *ifp, struct mbuf if ((m->m_flags & M_PKTHDR) == 0) panic("%s: no header mbuf", __func__); - if (rt && rt->rt_flags & (RTF_REJECT|RTF_BLACKHOLE)) { - m_freem(m); - return (rt->rt_flags & RTF_BLACKHOLE ? 0 : - rt->rt_flags & RTF_HOST ? EHOSTUNREACH : ENETUNREACH); - } - /* * Do not call if_input_local() directly. Queue the packet to avoid * stack overflow and make TCP handshake over loopback work. Index: netinet/ip_output.c =================================================================== RCS file: /cvs/src/sys/netinet/ip_output.c,v diff -u -p -r1.400 ip_output.c --- netinet/ip_output.c 7 Jun 2024 18:24:16 -0000 1.400 +++ netinet/ip_output.c 25 Jul 2024 04:24:51 -0000 @@ -184,22 +184,33 @@ reroute: } } else { struct in_ifaddr *ia; + struct rtentry *rt; if (ro->ro_rt == NULL) ro->ro_rt = rtalloc_mpath(&ro->ro_dstsa, &ip->ip_src.s_addr, ro->ro_tableid); - if (ro->ro_rt == NULL) { + rt = ro->ro_rt; + if (rt == NULL) { ipstat_inc(ips_noroute); error = EHOSTUNREACH; goto bad; } + if (ISSET(rt->rt_flags, RTF_REJECT)) { + error = ISSET(rt->rt_flags, RTF_HOST) ? + EHOSTUNREACH : ENETUNREACH; + goto bad; + } + if (ISSET(rt->rt_flags, RTF_BLACKHOLE)) { + error = 0; + goto bad; + } - ia = ifatoia(ro->ro_rt->rt_ifa); - if (ISSET(ro->ro_rt->rt_flags, RTF_LOCAL)) + ia = ifatoia(rt->rt_ifa); + if (ISSET(rt->rt_flags, RTF_LOCAL)) ifp = if_get(rtable_loindex(m->m_pkthdr.ph_rtableid)); else - ifp = if_get(ro->ro_rt->rt_ifidx); + ifp = if_get(rt->rt_ifidx); /* * We aren't using rtisvalid() here because the UP/DOWN state * machine is broken with some Ethernet drivers like em(4). @@ -211,11 +222,11 @@ reroute: error = EHOSTUNREACH; goto bad; } - if ((mtu = ro->ro_rt->rt_mtu) == 0) + if ((mtu = rt->rt_mtu) == 0) mtu = ifp->if_mtu; - if (ro->ro_rt->rt_flags & RTF_GATEWAY) - dst = satosin(ro->ro_rt->rt_gateway); + if (ISSET(rt->rt_flags, RTF_GATEWAY)) + dst = satosin(rt->rt_gateway); /* Set the source IP address */ if (ip->ip_src.s_addr == INADDR_ANY && ia) Index: netinet6/ip6_output.c =================================================================== RCS file: /cvs/src/sys/netinet6/ip6_output.c,v diff -u -p -r1.291 ip6_output.c --- netinet6/ip6_output.c 17 Apr 2024 20:48:51 -0000 1.291 +++ netinet6/ip6_output.c 25 Jul 2024 04:24:51 -0000 @@ -483,9 +483,20 @@ reroute: route6_cache(ro, &ip6->ip6_dst, NULL, m->m_pkthdr.ph_rtableid); } - if (rt && (rt->rt_flags & RTF_GATEWAY) && - !IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) - dst = satosin6(rt->rt_gateway); + if (rt != NULL) { + if (ISSET(rt->rt_flags, RTF_REJECT)) { + error = ISSET(rt->rt_flags, RTF_HOST) ? + EHOSTUNREACH : ENETUNREACH; + goto bad; + } + if (ISSET(rt->rt_flags, RTF_BLACKHOLE)) { + error = 0; + goto bad; + } + if (ISSET(rt->rt_flags, RTF_GATEWAY) && + !IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) + dst = satosin6(rt->rt_gateway); + } if (!IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { /* Unicast */