Date: Mon, 5 Sep 2011 17:11:46 +0200 From: Daniel Hartmeier <daniel@benzedrine.cx> To: petz@nisshoko.net Cc: freebsd-hackers@freebsd.org Subject: Re: TIME_WAIT Assassination in FreeBSD??? Message-ID: <20110905151146.GA10185@insomnia.benzedrine.cx> In-Reply-To: <001e01cc6a9d$8e62c870$ab285950$@internode.on.net> References: <007301cc6979$a690f9a0$f3b2ece0$@internode.on.net> <4E616D6E.4030903@FreeBSD.org> <001701cc69d3$aea9a0b0$0bfce210$@internode.on.net> <4E61BA37.2060204@FreeBSD.org> <20110903134634.GA55652@owl.midgard.homeip.net> <4E62B99C.6020707@FreeBSD.org> <001e01cc6a9d$8e62c870$ab285950$@internode.on.net>
next in thread | previous in thread | raw e-mail | index | archive | help
In FreeBSD, the ftp client allocates the port for an active-mode data connection by calling bind(2) with so_port set to 0, which means it lets the kernel pick a port, see http://www.freebsd.org/cgi/cvsweb.cgi/src/contrib/lukemftp/src/Attic/ftp.c?rev=1.1.1.8;content-type=text%2Fplain;hideattic=0 The kernel code where the port is picked is in function in_pcb_lport(), see http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/netinet/in_pcb.c?rev=1.281;content-type=text%2Fplain Basically, there is a range of ports (49152-65535, adjustable with sysctl), and the algorithm picks a random port within that range: if (dorandom) *lastport = first + (arc4random() % (last - first)); It checks whether that port is available. If not, it increments it by one, and tries again, etc. in a loop, until it finds one. So, for your case, it is unlikely that two subsequent bind() calls from the ftp client would result in the same port being picked randomly, unless a large part of the port range is unavailable. You can get port re-use that is quick enough to confuse pf, for instance, by opening new connections (to the same destination address and port) at a high rate, e.g. when running the Apache web server benchmark tool. But if you're simply running the ftp client on an otherwise idle host, and two subsequent bind() calls get assigned the same 'random' port, I'd say the port randomization is not working properly :) HTH, Daniel
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110905151146.GA10185>