summaryrefslogtreecommitdiffstats
path: root/sys/netinet
diff options
context:
space:
mode:
authorkarels <karels@FreeBSD.org>2017-04-10 01:26:12 +0000
committerkarels <karels@FreeBSD.org>2017-04-10 01:26:12 +0000
commit0b219504060b9ed97df36d0816488603c7305d64 (patch)
tree73a20b3885f066bafcdd99ee33dd2315ccb1b8b4 /sys/netinet
parentaa70bf371240fb6aba8a23474d17509423657f10 (diff)
downloadFreeBSD-src-0b219504060b9ed97df36d0816488603c7305d64.zip
FreeBSD-src-0b219504060b9ed97df36d0816488603c7305d64.tar.gz
Fix reference count leak with L2 caching.
MFC r315956 ip_forward, TCP/IPv6, and probably SCTP leaked references to L2 cache entry because they used their own routes on the stack, not in_pcb routes. The original model for route caching was callers that provided a route structure to ip{,6}input() would keep the route, and this model was used for L2 caching as well. Instead, change L2 caching to be done by default only when using a route structure in the in_pcb; the pcb deallocation code frees L2 as well as L3 cacches. A separate change will add route caching to TCP/IPv6. Another suggestion was to have the transport protocols indicate willingness to use L2 caching, but this approach keeps the changes in the network level Reviewed by: ae gnn MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D10059
Diffstat (limited to 'sys/netinet')
-rw-r--r--sys/netinet/in_pcb.c6
-rw-r--r--sys/netinet/ip_output.c3
2 files changed, 7 insertions, 2 deletions
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
index 7eb48af..9526960 100644
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -326,6 +326,12 @@ in_pcballoc(struct socket *so, struct inpcbinfo *pcbinfo)
#endif
inp->inp_gencnt = ++pcbinfo->ipi_gencnt;
refcount_init(&inp->inp_refcount, 1); /* Reference from inpcbinfo */
+
+ /*
+ * Routes in inpcb's can cache L2 as well; they are guaranteed
+ * to be cleaned up.
+ */
+ inp->inp_route.ro_flags = RT_LLE_CACHE;
INP_LIST_WUNLOCK(pcbinfo);
#if defined(IPSEC) || defined(IPSEC_SUPPORT) || defined(MAC)
out:
diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c
index 7b59b72..da56300 100644
--- a/sys/netinet/ip_output.c
+++ b/sys/netinet/ip_output.c
@@ -241,8 +241,7 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
if (ro == NULL) {
ro = &iproute;
bzero(ro, sizeof (*ro));
- } else
- ro->ro_flags |= RT_LLE_CACHE;
+ }
#ifdef FLOWTABLE
if (ro->ro_rt == NULL)
OpenPOWER on IntegriCloud