Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Jan 2010 18:24:38 +0200
From:      Janne Huttunen <jahuttun@gmail.com>
To:        Patrick Mahan <mahan@mahan.org>
Cc:        freebsd-net@freebsd.org
Subject:   Re: Anon port selection
Message-ID:  <4cd8d14e1001120824s6e70e29fm60a71ebdac21e131@mail.gmail.com>
In-Reply-To: <4B474F89.9020108@mahan.org>
References:  <4cd8d14e1001080238yfc2ee4cx6f261aa94f79a246@mail.gmail.com> <4B474F89.9020108@mahan.org>

next in thread | previous in thread | raw e-mail | index | archive | help
> > 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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4cd8d14e1001120824s6e70e29fm60a71ebdac21e131>