Switch ip_output/icmp_reflect rt lookup calls with fib4_lookup.

fib4_lookup_nh_ represents pre-epoch generation of fib api,
providing less guarantees over pointer validness and requiring
on-stack data copying.

Conversion is straight-forwarded, as the only 2 differences are
requirement of running in network epoch and the need to handle
RTF_GATEWAY case in the caller code.

Reviewed by:	ae
Differential Revision:	https://reviews.freebsd.org/D24976
This commit is contained in:
Alexander V. Chernikov 2020-05-28 07:31:53 +00:00
parent 1483c1c508
commit 3553b3007f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=361574
2 changed files with 14 additions and 13 deletions

View File

@ -764,7 +764,7 @@ icmp_reflect(struct mbuf *m)
struct ifnet *ifp;
struct in_ifaddr *ia;
struct in_addr t;
struct nhop4_extended nh_ext;
struct nhop_object *nh;
struct mbuf *opts = NULL;
int optlen = (ip->ip_hl << 2) - sizeof(struct ip);
@ -851,12 +851,13 @@ icmp_reflect(struct mbuf *m)
* When we don't have a route back to the packet source, stop here
* and drop the packet.
*/
if (fib4_lookup_nh_ext(M_GETFIB(m), ip->ip_dst, 0, 0, &nh_ext) != 0) {
nh = fib4_lookup(M_GETFIB(m), ip->ip_dst, 0, NHR_NONE, 0);
if (nh == NULL) {
m_freem(m);
ICMPSTAT_INC(icps_noroute);
goto done;
}
t = nh_ext.nh_src;
t = IA_SIN(ifatoia(nh->nh_ifa))->sin_addr;
match:
#ifdef MAC
mac_netinet_icmp_replyinplace(m);

View File

@ -512,11 +512,10 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
mtu = ifp->if_mtu;
src = IA_SIN(ia)->sin_addr;
} else {
struct nhop4_extended nh;
struct nhop_object *nh;
bzero(&nh, sizeof(nh));
if (fib4_lookup_nh_ext(M_GETFIB(m), ip->ip_dst, 0, 0, &nh) !=
0) {
nh = fib4_lookup(M_GETFIB(m), ip->ip_dst, 0, NHR_NONE, 0);
if (nh == NULL) {
#if defined(IPSEC) || defined(IPSEC_SUPPORT)
/*
* There is no route for this packet, but it is
@ -530,8 +529,8 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
error = EHOSTUNREACH;
goto bad;
}
ifp = nh.nh_ifp;
mtu = nh.nh_mtu;
ifp = nh->nh_ifp;
mtu = nh->nh_mtu;
/*
* We are rewriting here dst to be gw actually, contradicting
* comment at the beginning of the function. However, in this
@ -540,10 +539,11 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
* function, the dst would be rewritten by ip_output_pfil().
*/
MPASS(dst == &sin);
dst->sin_addr = nh.nh_addr;
ia = nh.nh_ia;
src = nh.nh_src;
isbroadcast = (((nh.nh_flags & (NHF_HOST | NHF_BROADCAST)) ==
if (nh->nh_flags & NHF_GATEWAY)
dst->sin_addr = nh->gw4_sa.sin_addr;
ia = ifatoia(nh->nh_ifa);
src = IA_SIN(ia)->sin_addr;
isbroadcast = (((nh->nh_flags & (NHF_HOST | NHF_BROADCAST)) ==
(NHF_HOST | NHF_BROADCAST)) ||
((ifp->if_flags & IFF_BROADCAST) &&
in_ifaddr_broadcast(dst->sin_addr, ia)));