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) } 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 * Validate a cached route based on a supplied cookie. If there is an
* out-of-date cache, simply free it. Update the generation number * 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 { \ #define RT_VALIDATE(ro, cookiep, fibnum) do { \
rt_gen_t cookie = RT_GEN(fibnum, (ro)->ro_dst.sa_family); \ rt_gen_t cookie = RT_GEN(fibnum, (ro)->ro_dst.sa_family); \
if (*(cookiep) != cookie) { \ if (*(cookiep) != cookie) { \
if ((ro)->ro_rt != NULL) { \ RO_INVALIDATE_CACHE(ro); \
RTFREE((ro)->ro_rt); \
(ro)->ro_rt = NULL; \
} \
if ((ro)->ro_lle != NULL) { \
LLE_FREE((ro)->ro_lle); \
(ro)->ro_lle = NULL; \
} \
*(cookiep) = cookie; \ *(cookiep) = cookie; \
} \ } \
} while (0) } while (0)

View File

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

View File

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