Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jan 2018 03:15:39 +0000 (UTC)
From:      Ryan Stone <rstone@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r328271 - in head/sys: net netinet
Message-ID:  <201801230315.w0N3FdWE006958@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rstone
Date: Tue Jan 23 03:15:39 2018
New Revision: 328271
URL: https://svnweb.freebsd.org/changeset/base/328271

Log:
  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

Modified:
  head/sys/net/route.h
  head/sys/netinet/in_pcb.c
  head/sys/netinet/ip_output.c

Modified: head/sys/net/route.h
==============================================================================
--- head/sys/net/route.h	Tue Jan 23 03:15:35 2018	(r328270)
+++ head/sys/net/route.h	Tue Jan 23 03:15:39 2018	(r328271)
@@ -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)

Modified: head/sys/netinet/in_pcb.c
==============================================================================
--- head/sys/netinet/in_pcb.c	Tue Jan 23 03:15:35 2018	(r328270)
+++ head/sys/netinet/in_pcb.c	Tue Jan 23 03:15:39 2018	(r328271)
@@ -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;
 }
 

Modified: head/sys/netinet/ip_output.c
==============================================================================
--- head/sys/netinet/ip_output.c	Tue Jan 23 03:15:35 2018	(r328270)
+++ head/sys/netinet/ip_output.c	Tue Jan 23 03:15:39 2018	(r328271)
@@ -302,11 +302,8 @@ again:
 		    !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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801230315.w0N3FdWE006958>