From owner-freebsd-net@FreeBSD.ORG Tue Dec 2 00:09:33 2014 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1B500EB4 for ; Tue, 2 Dec 2014 00:09:33 +0000 (UTC) Received: from mail-wg0-x234.google.com (mail-wg0-x234.google.com [IPv6:2a00:1450:400c:c00::234]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9D7CADB3 for ; Tue, 2 Dec 2014 00:09:32 +0000 (UTC) Received: by mail-wg0-f52.google.com with SMTP id a1so15700505wgh.39 for ; Mon, 01 Dec 2014 16:09:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=p5mMDrpRm5GNF61GWmqDGU+ad7Kk/5I7y8CkPyAFKGA=; b=YeECxCbewNIBN1fujN7FeTlbMny1/5vmo20uO821Fk/oDzgHYbXLmrC3r/6KqtOPk9 vQx73+cWSW6oBpsdAs8xM+p0AMTdPvimqHJ0pOMzmh+y7ev9IB3T9dTSoMV/D6SMR/rA 5Aug6hfwLR3KXSLrPE4349IDHCQ/zomz3QQze8QkaaTYICn1tWaxAo4RLY+gg7qQSnrS x5EJnsIMMwS0Z9a2YdZkfdwF8S1n63opJDVYE/45UB1RFr/3/s/qSjfYiZVtn6FWY3B3 gRUC69/2SH/yjdFRAdGx7f69hreHDzh1s1775IfD164sYt4H6u5KkIBxETy+5Qh9GlvF 0pew== MIME-Version: 1.0 X-Received: by 10.180.240.201 with SMTP id wc9mr527739wic.59.1417478971135; Mon, 01 Dec 2014 16:09:31 -0800 (PST) Sender: adrian.chadd@gmail.com Received: by 10.216.106.195 with HTTP; Mon, 1 Dec 2014 16:09:31 -0800 (PST) In-Reply-To: <547C9F7A.5000803@rewt.org.uk> References: <547C5DD3.90604@rawbw.com> <20141201150225.GB64370@apollo.corbe.net> <547C88AD.40407@rawbw.com> <20141201153712.4304976.24709.1746@denninger.net> <547C9F7A.5000803@rewt.org.uk> Date: Mon, 1 Dec 2014 16:09:31 -0800 X-Google-Sender-Auth: uFpB4W7beVNnX3OcPNBEZ8lCoFM Message-ID: Subject: Re: Can multiple apps listen for TCP on the same port? From: Adrian Chadd To: Joe Holden Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: FreeBSD Net X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.18-1 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, 02 Dec 2014 00:09:33 -0000 On 1 December 2014 at 09:03, Joe Holden wrote: > Was there a specific reason why we couldn't just extend REUSEADDR/PORT to= do > this a la Linux? Just a simple round robin would make those useful perhap= s Because REUSEADDR/REUSEPORT have different meanings, doubly so if you're using multicast. I created a new socket option so we wouldn't have to try and untangle that mess of "what was it supposed to do in this context" which may have broken applications that rely on the existing behaviour. -adrian > > On 01/12/2014 16:21, Adrian Chadd wrote: >> >> Hi, >> >> I introduced a socket option in -HEAD that lets you bind multiple >> things to the same listen ports. >> >> They're only load balanced if you're using RSS and set up RSS socket >> options as well; otherwise only one gets the incoming requests. >> >> IP_BINDMULTI and IP6_BINDMULTI. >> >> >> -a >> >> >> On 1 December 2014 at 08:14, Someone Somewhere >> wrote: >>> >>> @Yuri , are you sure that the second instance of nc does not accept any >>> connection? >>> I did a simple test : -> >>> #: nc -l 12345 (shell 1) >>> #: nc localhost 12345 (shell2) >>> at this point netstat shows that there is no one listening on 12345. Th= is >>> means any process should not be able to bind over port 12345(over TCP). >>> # nc -l 12345 (shell 3, shell 1 , 2 still active) >>> this instance of nc starts listening which I could verify via netstat >>> cmd. >>> # nc localhost 12345 (shell 4) >>> this nc instance connected to the nc started in previous step over shel= l >>> 3. >>> >>> Test ran on Fedora 20. >>> [will try this on freeBSD VM if you confirm that this is what you are >>> trying] >>> >>> >>> Could you verify if your second nc(server) instance is listening on the >>> same socket number? >>> >>> >>> -Kunal. >>> >>> >>> >>> On 1 December 2014 at 21:07, Karl Denninger wrote: >>> >>>> The second bind() call does fail but if the application ignores the >>>> return >>>> code...=E2=80=8E. Are you sure all the associated system call return c= odes are >>>> being checked? >>>> >>>> The right way to do this Imho is to have a parent process that calls >>>> bind >>>> and listen, gets the notification of an incoming connection via select= () >>>> (allowing detection of exceptions as well) and then calls accept() and= , >>>> now >>>> having a connected file handle, fork()s and executes whatever is to >>>> handle >>>> the connection with the parent closing the handle so as to not orphan >>>> the >>>> handle when the child exits. >>>> =E2=80=8E >>>> -- Karl >>>> (On Passport PDA)=E2=80=8E >>>> >>>> >>>> Original Message >>>> From: Yuri=E2=80=8E >>>> Sent: Monday, December 1, 2014 10:26 >>>> To: Daniel Corbe >>>> Cc: freebsd-net@freebsd.org >>>> Subject: Re: Can multiple apps listen for TCP on the same port? >>>> >>>> On 12/01/2014 07:02, Daniel Corbe wrote: >>>>> >>>>> Generally the answer to your question is no. Two applications cannot >>>>> occupy the same port on the same protocol at the same time. >>>>> >>>>> To expand on this answer and to hopefully shed some light on why the >>>>> behavior you're observing with your application is absolutely correct= ; >>>>> the calling application (in this case, nc) has to explicitly call >>>>> bind(2) >>>>> before it can begin accepting connections. If that port is already in >>>>> use then the call to bind(2) will fail. And in your case I suspect nc >>>>> is simply choosing to silently fail. >>>> >>>> >>>> Here the question is what does it mean "occupy the port"? The first >>>> instance isn't listening any more. The listening socket was closed. Wh= y >>>> the presence of the socket that was accepted from (now closed) listeni= ng >>>> socket in the first instance is considered "occupying it"? >>>> >>>> Actually no system call in the second instance ever fails. >>>> >>>> Yuri >>>> _______________________________________________ >>>> freebsd-net@freebsd.org mailing list >>>> http://lists.freebsd.org/mailman/listinfo/freebsd-net >>>> To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" >>>> >>>> >>>> %SPAMBLOCK-SYS: Matched [@freebsd.org+], message ok >>>> >>>> >>>> _______________________________________________ >>>> freebsd-net@freebsd.org mailing list >>>> http://lists.freebsd.org/mailman/listinfo/freebsd-net >>>> To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" >>>> >>> _______________________________________________ >>> freebsd-net@freebsd.org mailing list >>> http://lists.freebsd.org/mailman/listinfo/freebsd-net >>> To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" >> >> _______________________________________________ >> freebsd-net@freebsd.org mailing list >> http://lists.freebsd.org/mailman/listinfo/freebsd-net >> To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" >> > _______________________________________________ > freebsd-net@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-net > To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org"