Index: netinet/ip_icmp.c =================================================================== RCS file: /cvs/src/sys/netinet/ip_icmp.c,v diff -u -p -r1.202 ip_icmp.c --- netinet/ip_icmp.c 2 Jul 2025 05:44:46 -0000 1.202 +++ netinet/ip_icmp.c 2 Jul 2025 05:55:25 -0000 @@ -768,9 +768,27 @@ icmp_reflect(struct mbuf *m, struct mbuf } /* - * If the above didn't find an ip_src, ip_output() will try - * and fill it in for us. + * If the above didn't find an ip_src, get the IP of the + * interface the original packet was received on. If all this + * comes up with nothing, ip_output() will try and fill it + * in for us. */ + if (ip_src.s_addr == INADDR_ANY) { + struct ifnet *ifp; + struct ifaddr *ifa; + + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp != NULL) { + TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) { + if (ifa->ifa_addr->sa_family != AF_INET) + continue; + + ip_src = satosin(ifa->ifa_addr)->sin_addr; + break; + } + } + if_put(ifp); + } pfflags = m->m_pkthdr.pf.flags; Index: net/pf.c =================================================================== RCS file: /cvs/src/sys/net/pf.c,v diff -u -p -r1.1217 pf.c --- net/pf.c 30 Jun 2025 12:43:22 -0000 1.1217 +++ net/pf.c 2 Jul 2025 05:55:25 -0000 @@ -6672,11 +6672,6 @@ pf_route(struct pf_pdesc *pd, struct pf_ if (ifp == NULL) goto bad; - /* A locally generated packet may have invalid source address. */ - if ((ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET && - (ifp->if_flags & IFF_LOOPBACK) == 0) - ip->ip_src = ifatoia(rt->rt_ifa)->ia_addr.sin_addr; - if (st->rt != PF_DUPTO && pd->dir == PF_IN) { if (pf_test(AF_INET, PF_OUT, ifp, &m0) != PF_PASS) goto bad; @@ -6791,11 +6786,6 @@ pf_route6(struct pf_pdesc *pd, struct pf ifp = if_get(rt->rt_ifidx); if (ifp == NULL) goto bad; - - /* A locally generated packet may have invalid source address. */ - if (IN6_IS_ADDR_LOOPBACK(&ip6->ip6_src) && - (ifp->if_flags & IFF_LOOPBACK) == 0) - ip6->ip6_src = ifatoia6(rt->rt_ifa)->ia_addr.sin6_addr; if (st->rt != PF_DUPTO && pd->dir == PF_IN) { if (pf_test(AF_INET6, PF_OUT, ifp, &m0) != PF_PASS)