From owner-freebsd-net@FreeBSD.ORG Wed Jul 17 21:23:43 2013 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id E2E5A723; Wed, 17 Jul 2013 21:23:42 +0000 (UTC) (envelope-from to.my.trociny@gmail.com) Received: from mail-la0-x236.google.com (mail-la0-x236.google.com [IPv6:2a00:1450:4010:c03::236]) by mx1.freebsd.org (Postfix) with ESMTP id 0C8B1C4B; Wed, 17 Jul 2013 21:23:41 +0000 (UTC) Received: by mail-la0-f54.google.com with SMTP id ec20so1933387lab.27 for ; Wed, 17 Jul 2013 14:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=7ijMOqhSiXP0ybvBOjuD7kiwU4wgW/YXXamP5x30TqI=; b=RL7NeGRtX+s26IH40qUlH7Mc4TpbBAtRBqzhO8U0tEw0G2rlQjyaDFY6UyPYwng1G8 2GfYqo3LXGH26ENz2DfPJQDDOmtOJp8DnyHRAO8RyDJFnqO9BNazfNTivCE1drBZhFJb 08uyx/nJN2rjMdHV5maClFekGk7axo3cTrtCRdqXqYAxhR3Byv7V8yfDjbH6e+KXcxWp RYyITBrvF+9SOU5o4veZRj66eYOYkIOC9XWeRyOpU80vi6a5wYL1JT2Oy+QpVmeznSrq vPGjxaJ+Dwcm3RyA/Akr1XWvxN9S4Vz0B7W6A9StdGgpXz/IxnP9LZidwCfry8Xq1AA1 ya+Q== X-Received: by 10.112.201.138 with SMTP id ka10mr3975791lbc.72.1374096220987; Wed, 17 Jul 2013 14:23:40 -0700 (PDT) Received: from localhost ([178.150.115.244]) by mx.google.com with ESMTPSA id 8sm3412368lbq.4.2013.07.17.14.23.38 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 17 Jul 2013 14:23:39 -0700 (PDT) Sender: Mikolaj Golub Date: Thu, 18 Jul 2013 00:23:37 +0300 From: Mikolaj Golub To: John Baldwin Subject: Re: bind error when using SO_REUSEPORT(implies SO_REUSEADDR) Message-ID: <20130717212336.GA35489@gmail.com> References: <1331855948.3317.17.camel@powernoodle-l7.corp.yahoo.com> <1331856466.3317.18.camel@powernoodle-l7.corp.yahoo.com> <201307161112.46116.jhb@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201307161112.46116.jhb@freebsd.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-net@freebsd.org X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Jul 2013 21:23:43 -0000 On Tue, Jul 16, 2013 at 11:12:46AM -0400, John Baldwin wrote: > On Thursday, March 15, 2012 8:07:46 pm Sean Bruno wrote: > > On Thu, 2012-03-15 at 16:59 -0700, Sean Bruno wrote: > > > Hey, I just found a bind bug ticket in my queue about bind. I noted > > > that on stable/6 stable/7 stable/9 & head the referenced code "fails". > > > > > > It seems that this is a problem, but I have no idea if its a real > > > problem or not. Our devs think it is. Anyway, here is a code snippet > > > to show the failure in bind. On linux/solaris this does not fail. > > > > > > http://people.freebsd.org/~sbruno/bind_test.c > > > > > > simple compile with gcc -o test test.c and run as normal user. > > > > > > Sean > > > > > > > this is bind() not bind ... :-) > > Did the recent commit to HEAD fix this btw? As for me, bind_test.c does not expose any bug in freebsd, it only shows different behavior for freebsd and linux. On freebsd the test output is: serversock addr is 127.0.0.1:27539 dup bind: Address already in use This error was expected, tried to bind to used addr/port BUG: binding duplicate socket to server port succeeded dup2sock addr is 0.0.0.0:27539 overlapping explicit bind to same port number succeeded without SO_REUSEPORT listen succeeded after explicitly overlapping port bind autosock addr is 0.0.0.0:27539 bug triggered, port number conflict on sockets without SO_REUSEPORT listen succeded after implicitly overlapping port bind So, the first socket (serversock) is bound to the loopback address, then it tries some combinations of binding the second socket to the same port but to the wildcard address. When SO_REUSEADDR socket option is set, binding to the wildcard address succeeds for freebsd (and fails for linux). They call this a bug in freebsd, but this is well known and expected behavior (see e.g. Stevens' TCP/IP Illustrated Vol1). Or I missed the test's point? -- Mikolaj Golub