Reduce code duplication for inpcb route caching

Add a new macro to clear both the L3 and L2 route caches, to
hopefully prevent future instances where only the L3 cache was
cleared when both should have been.

MFC after:	1 week
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D13989
Reviewed by:	karels
This commit is contained in:
Ryan Stone 2018-01-23 03:15:39 +00:00
parent dbeab32f94
commit fc21c53f63
3 changed files with 13 additions and 19 deletions

View File

@ -416,6 +416,14 @@ struct rt_addrinfo {
} \
} while (0)
#define RO_INVALIDATE_CACHE(ro) do { \
RO_RTFREE(ro); \
if ((ro)->ro_lle != NULL) { \
LLE_FREE((ro)->ro_lle); \
(ro)->ro_lle = NULL; \
} \
} while (0)
/*
* Validate a cached route based on a supplied cookie. If there is an
* out-of-date cache, simply free it. Update the generation number
@ -424,14 +432,7 @@ struct rt_addrinfo {
#define RT_VALIDATE(ro, cookiep, fibnum) do { \
rt_gen_t cookie = RT_GEN(fibnum, (ro)->ro_dst.sa_family); \
if (*(cookiep) != cookie) { \
if ((ro)->ro_rt != NULL) { \
RTFREE((ro)->ro_rt); \
(ro)->ro_rt = NULL; \
} \
if ((ro)->ro_lle != NULL) { \
LLE_FREE((ro)->ro_lle); \
(ro)->ro_lle = NULL; \
} \
RO_INVALIDATE_CACHE(ro); \
*(cookiep) = cookie; \
} \
} while (0)

View File

@ -1319,9 +1319,7 @@ in_pcbfree(struct inpcb *inp)
if (inp->inp_moptions != NULL)
inp_freemoptions(inp->inp_moptions);
#endif
RO_RTFREE(&inp->inp_route);
if (inp->inp_route.ro_lle)
LLE_FREE(inp->inp_route.ro_lle); /* zeros ro_lle */
RO_INVALIDATE_CACHE(&inp->inp_route);
inp->inp_vflag = 0;
inp->inp_flags2 |= INP_FREED;
@ -2259,9 +2257,7 @@ void
in_losing(struct inpcb *inp)
{
RO_RTFREE(&inp->inp_route);
if (inp->inp_route.ro_lle)
LLE_FREE(inp->inp_route.ro_lle); /* zeros ro_lle */
RO_INVALIDATE_CACHE(&inp->inp_route);
return;
}

View File

@ -302,11 +302,8 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
!RT_LINK_IS_UP(rte->rt_ifp) ||
dst->sin_family != AF_INET ||
dst->sin_addr.s_addr != ip->ip_dst.s_addr)) {
RTFREE(rte);
rte = ro->ro_rt = (struct rtentry *)NULL;
if (ro->ro_lle)
LLE_FREE(ro->ro_lle); /* zeros ro_lle */
ro->ro_lle = (struct llentry *)NULL;
RO_INVALIDATE_CACHE(ro);
rte = NULL;
}
ia = NULL;
have_ia_ref = 0;