From owner-freebsd-net@FreeBSD.ORG Tue Jan 12 16:24:48 2010 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B1068106566B for ; Tue, 12 Jan 2010 16:24:48 +0000 (UTC) (envelope-from jahuttun@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.153]) by mx1.freebsd.org (Postfix) with ESMTP id 53FE78FC19 for ; Tue, 12 Jan 2010 16:24:47 +0000 (UTC) Received: by fg-out-1718.google.com with SMTP id 22so23905fge.13 for ; Tue, 12 Jan 2010 08:24:38 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.85.132 with SMTP id u4mr674551wee.191.1263313478555; Tue, 12 Jan 2010 08:24:38 -0800 (PST) In-Reply-To: <4B474F89.9020108@mahan.org> References: <4cd8d14e1001080238yfc2ee4cx6f261aa94f79a246@mail.gmail.com> <4B474F89.9020108@mahan.org> Date: Tue, 12 Jan 2010 18:24:38 +0200 Message-ID: <4cd8d14e1001120824s6e70e29fm60a71ebdac21e131@mail.gmail.com> From: Janne Huttunen To: Patrick Mahan Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-net@freebsd.org Subject: Re: Anon port selection X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jan 2010 16:24:48 -0000 > > Then when the second process in in_pcbbind_setup() tries > > to check if the port is already in use, it won't match > > the INADDR_ANY and assigns the same port again. > > Well it has been almost 20 years since I first ran across > this issue and was told back then that it was "as designed". May be, but it sure feels unintuitive to me. Besides, as far as I can tell, NetBSD (5.0.1) doesn't do it, OpenBSD (4.6) doesn't do it, Linux (2.6.31) doesn't do it and FreeBSD with the attached patch doesn't do it. Whether or not this change breaks something else is another story. --- in_pcb.c.orig 2010-01-12 16:47:57.000000000 +0200 +++ in_pcb.c 2010-01-12 16:50:18.000000000 +0200 @@ -800,6 +800,12 @@ in_pcbconnect_setup(struct inpcb *inp, s faddr = sin->sin_addr; fport = sin->sin_port; + if (lport == 0) { + error = in_pcbbind_setup(inp, NULL, &laddr.s_addr, &lport, + cred); + if (error) + return (error); + } if (!TAILQ_EMPTY(&V_in_ifaddrhead)) { /* * If the destination address is INADDR_ANY, @@ -864,12 +870,6 @@ in_pcbconnect_setup(struct inpcb *inp, s *oinpp = oinp; return (EADDRINUSE); } - if (lport == 0) { - error = in_pcbbind_setup(inp, NULL, &laddr.s_addr, &lport, - cred); - if (error) - return (error); - } *laddrp = laddr.s_addr; *lportp = lport; *faddrp = faddr.s_addr;