From owner-svn-src-stable-9@FreeBSD.ORG  Mon Jul 23 09:19:15 2012
Return-Path: <owner-svn-src-stable-9@FreeBSD.ORG>
Delivered-To: svn-src-stable-9@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 37AE5106566C;
	Mon, 23 Jul 2012 09:19:15 +0000 (UTC)
	(envelope-from glebius@FreeBSD.org)
Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c])
	by mx1.freebsd.org (Postfix) with ESMTP id 08C828FC14;
	Mon, 23 Jul 2012 09:19:15 +0000 (UTC)
Received: from svn.freebsd.org (localhost [127.0.0.1])
	by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q6N9JEmw087761;
	Mon, 23 Jul 2012 09:19:14 GMT (envelope-from glebius@svn.freebsd.org)
Received: (from glebius@localhost)
	by svn.freebsd.org (8.14.4/8.14.4/Submit) id q6N9JEj6087758;
	Mon, 23 Jul 2012 09:19:14 GMT (envelope-from glebius@svn.freebsd.org)
Message-Id: <201207230919.q6N9JEj6087758@svn.freebsd.org>
From: Gleb Smirnoff <glebius@FreeBSD.org>
Date: Mon, 23 Jul 2012 09:19:14 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
	svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
X-SVN-Group: stable-9
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Cc: 
Subject: svn commit: r238713 - stable/9/sys/netinet
X-BeenThere: svn-src-stable-9@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: SVN commit messages for only the 9-stable src tree
	<svn-src-stable-9.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-stable-9>, 
	<mailto:svn-src-stable-9-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-stable-9>
List-Post: <mailto:svn-src-stable-9@freebsd.org>
List-Help: <mailto:svn-src-stable-9-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-stable-9>, 
	<mailto:svn-src-stable-9-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Mon, 23 Jul 2012 09:19:15 -0000

Author: glebius
Date: Mon Jul 23 09:19:14 2012
New Revision: 238713
URL: http://svn.freebsd.org/changeset/base/238713

Log:
  Merge from head r238572, r238573:
    ------------------------------------------------------------------------
    r238572 | glebius | 2012-07-18 12:41:00 +0400 (ср, 18 июл 2012) | 3 lines
  
    When traversing global in_ifaddr list in the IFP_TO_IA() macro, we need
    to obtain IN_IFADDR_RLOCK().
  
    ------------------------------------------------------------------------
    r238573 | glebius | 2012-07-18 12:58:30 +0400 (ср, 18 июл 2012) | 5 lines
  
    Plug a reference leak: before doing 'goto again' we need to unref
    ia->ia_ifa if there is any.
  
    Submitted by:   Andrey Zonov <andrey zonov.org>
  
  Approved by:	re (kib)

Modified:
  stable/9/sys/netinet/in_var.h
  stable/9/sys/netinet/ip_output.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/netinet/in_var.h
==============================================================================
--- stable/9/sys/netinet/in_var.h	Mon Jul 23 04:48:58 2012	(r238712)
+++ stable/9/sys/netinet/in_var.h	Mon Jul 23 09:19:14 2012	(r238713)
@@ -159,14 +159,16 @@ do { \
 #define IFP_TO_IA(ifp, ia)						\
 	/* struct ifnet *ifp; */					\
 	/* struct in_ifaddr *ia; */					\
-{									\
+do {									\
+	IN_IFADDR_RLOCK();						\
 	for ((ia) = TAILQ_FIRST(&V_in_ifaddrhead);			\
 	    (ia) != NULL && (ia)->ia_ifp != (ifp);			\
 	    (ia) = TAILQ_NEXT((ia), ia_link))				\
 		continue;						\
 	if ((ia) != NULL)						\
 		ifa_ref(&(ia)->ia_ifa);					\
-}
+	IN_IFADDR_RUNLOCK();						\
+} while (0)
 #endif
 
 /*

Modified: stable/9/sys/netinet/ip_output.c
==============================================================================
--- stable/9/sys/netinet/ip_output.c	Mon Jul 23 04:48:58 2012	(r238712)
+++ stable/9/sys/netinet/ip_output.c	Mon Jul 23 09:19:14 2012	(r238713)
@@ -121,7 +121,7 @@ ip_output(struct mbuf *m, struct mbuf *o
 	int error = 0;
 	int nortfree = 0;
 	struct sockaddr_in *dst;
-	struct in_ifaddr *ia = NULL;
+	struct in_ifaddr *ia;
 	int isbroadcast, sw_csum;
 	struct route iproute;
 	struct rtentry *rte;	/* cache for ro->ro_rt */
@@ -196,6 +196,7 @@ ip_output(struct mbuf *m, struct mbuf *o
 
 	dst = (struct sockaddr_in *)&ro->ro_dst;
 again:
+	ia = NULL;
 	/*
 	 * If there is a cached route,
 	 * check that it is to the same destination
@@ -532,8 +533,11 @@ sendit:
 #endif
 			error = netisr_queue(NETISR_IP, m);
 			goto done;
-		} else
+		} else {
+			if (ia != NULL)
+				ifa_free(&ia->ia_ifa);
 			goto again;	/* Redo the routing table lookup. */
+		}
 	}
 
 #ifdef IPFIREWALL_FORWARD
@@ -563,6 +567,8 @@ sendit:
 		bcopy((fwd_tag+1), dst, sizeof(struct sockaddr_in));
 		m->m_flags |= M_SKIP_FIREWALL;
 		m_tag_delete(m, fwd_tag);
+		if (ia != NULL)
+			ifa_free(&ia->ia_ifa);
 		goto again;
 	}
 #endif /* IPFIREWALL_FORWARD */