From owner-freebsd-net@freebsd.org Fri May 20 13:02:52 2016 Return-Path: Delivered-To: freebsd-net@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 0C834B43010 for ; Fri, 20 May 2016 13:02:52 +0000 (UTC) (envelope-from aler@playground.ru) Received: from mail.playground.ru (mail.playground.ru [212.42.43.194]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C2F111102 for ; Fri, 20 May 2016 13:02:51 +0000 (UTC) (envelope-from aler@playground.ru) Received: from [213.141.155.134] (helo=[10.0.2.15]) by mail.playground.ru with esmtpa (Exim 4.80.1 (FreeBSD)) (envelope-from ) id 1b3jlW-0001Se-K1 for freebsd-net@freebsd.org; Fri, 20 May 2016 16:42:54 +0400 To: freebsd-net@freebsd.org From: aler Subject: connect() EADDRINUSE Message-ID: <1a502a88-29df-fc93-d3f1-b8d2f0da15cc@playground.ru> Date: Fri, 20 May 2016 15:40:05 +0400 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 May 2016 13:02:52 -0000 Port autoselection on connect() without bind() (or with bind() with zero sin_port) sometimes works wronly and gives already busy local port number that will lead to EADDRINUSE on connection attempt. This all happens when jails used. How to fix: src/sys/netinet/in_pcb.c, in_pcb_lport() function calls to in_pcblookup_local() should have last argument NULL, not cred that's because here we are not about getting some access but about avoiding port number conflicts, so all inpcb's should be taken in account This all applies to FreeBSD 10.x