From owner-freebsd-hackers@freebsd.org Tue Dec 20 16:49:47 2016 Return-Path: Delivered-To: freebsd-hackers@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 98D1FC89ED6 for ; Tue, 20 Dec 2016 16:49:47 +0000 (UTC) (envelope-from wjw@digiware.nl) Received: from smtp.digiware.nl (smtp.digiware.nl [IPv6:2001:4cb8:90:ffff::3]) (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 63B0115F9 for ; Tue, 20 Dec 2016 16:49:47 +0000 (UTC) (envelope-from wjw@digiware.nl) Received: from router.digiware.nl (localhost.digiware.nl [127.0.0.1]) by smtp.digiware.nl (Postfix) with ESMTP id 4D3813392F; Tue, 20 Dec 2016 17:49:44 +0100 (CET) X-Virus-Scanned: amavisd-new at digiware.com Received: from smtp.digiware.nl ([127.0.0.1]) by router.digiware.nl (router.digiware.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5LvM782EHLKw; Tue, 20 Dec 2016 17:49:43 +0100 (CET) Received: from [192.168.10.67] (opteron [192.168.10.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.digiware.nl (Postfix) with ESMTPSA id 5E6B43392E; Tue, 20 Dec 2016 17:49:43 +0100 (CET) Subject: Re: binding by different process on the same port To: Jan Knepper , "freebsd-hackers@freebsd.org" References: <896832c9-7d63-cd9a-b0e9-7ad32e90568a@digiware.nl> <4CD224CB-1114-4361-B46D-5A3E7455DA0B@digitaldaemon.com> <357e648a-d136-c251-bcdd-35eae31527d5@digiware.nl> From: Willem Jan Withagen Message-ID: <65e3c99d-1267-c719-5da4-49ae88336086@digiware.nl> Date: Tue, 20 Dec 2016 17:49:40 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <357e648a-d136-c251-bcdd-35eae31527d5@digiware.nl> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Dec 2016 16:49:47 -0000 On 18-12-2016 20:21, Willem Jan Withagen wrote: > On 18-12-2016 16:50, Jan Knepper wrote: >> I would guess >> >>> wjw ceph-osd-0 93336 43 tcp4 127.0.0.1:6804 *:* >> >> was started first. Claiming a specific port on a specific IP address... > > Well I've been trying to recreate the situation with a fake server > programs, one binds on localhost:port and the other on 0.0.0.0:port. And > the order does not matter, but I have not (yet) been able to actually > register on a port for the second time. > > So it needs a bit more than just: > socket, bind, listen, accept 'mmmm, There is SO_REUSEPORT, which explains the exact behaviour of what is going on: SO_REUSEPORT allows completely duplicate bindings by multiple processes if they all set SO_REUSEPORT before binding the port. This option permits multiple instances of a program to each receive UDP/IP i multicast or broadcast datagrams destined for the bound port. But the flag is not explicitly set in the code. But there is a LOT of info on the net about Linux <> FreeBSD on SO_REUSE{ADRR,PORT}. So i guess that I have enough things to read over X-mas. --WjW