From owner-svn-src-all@freebsd.org Mon Apr 10 01:26:14 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5C26FD3559E; Mon, 10 Apr 2017 01:26:14 +0000 (UTC) (envelope-from karels@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1B551F92; Mon, 10 Apr 2017 01:26:14 +0000 (UTC) (envelope-from karels@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v3A1QDSJ045551; Mon, 10 Apr 2017 01:26:13 GMT (envelope-from karels@FreeBSD.org) Received: (from karels@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v3A1QCVu045548; Mon, 10 Apr 2017 01:26:12 GMT (envelope-from karels@FreeBSD.org) Message-Id: <201704100126.v3A1QCVu045548@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: karels set sender to karels@FreeBSD.org using -f From: Mike Karels Date: Mon, 10 Apr 2017 01:26:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r316668 - in stable/11/sys: netinet netinet6 X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Apr 2017 01:26:14 -0000 Author: karels Date: Mon Apr 10 01:26:12 2017 New Revision: 316668 URL: https://svnweb.freebsd.org/changeset/base/316668 Log: 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 Modified: stable/11/sys/netinet/in_pcb.c stable/11/sys/netinet/ip_output.c stable/11/sys/netinet6/ip6_output.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/netinet/in_pcb.c ============================================================================== --- stable/11/sys/netinet/in_pcb.c Sun Apr 9 21:50:21 2017 (r316667) +++ stable/11/sys/netinet/in_pcb.c Mon Apr 10 01:26:12 2017 (r316668) @@ -326,6 +326,12 @@ in_pcballoc(struct socket *so, struct in #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: Modified: stable/11/sys/netinet/ip_output.c ============================================================================== --- stable/11/sys/netinet/ip_output.c Sun Apr 9 21:50:21 2017 (r316667) +++ stable/11/sys/netinet/ip_output.c Mon Apr 10 01:26:12 2017 (r316668) @@ -241,8 +241,7 @@ ip_output(struct mbuf *m, struct mbuf *o if (ro == NULL) { ro = &iproute; bzero(ro, sizeof (*ro)); - } else - ro->ro_flags |= RT_LLE_CACHE; + } #ifdef FLOWTABLE if (ro->ro_rt == NULL) Modified: stable/11/sys/netinet6/ip6_output.c ============================================================================== --- stable/11/sys/netinet6/ip6_output.c Sun Apr 9 21:50:21 2017 (r316667) +++ stable/11/sys/netinet6/ip6_output.c Mon Apr 10 01:26:12 2017 (r316668) @@ -493,8 +493,7 @@ ip6_output(struct mbuf *m0, struct ip6_p if (ro == NULL) { ro = &ip6route; bzero((caddr_t)ro, sizeof(*ro)); - } else - ro->ro_flags |= RT_LLE_CACHE; + } ro_pmtu = ro; if (opt && opt->ip6po_rthdr) ro = &opt->ip6po_route;