Re: [boost] [asio] init acceptor to reuse_address?

Hi Chris.
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Christopher Kohlhoff Sent: Monday, October 03, 2005 3:01 PM To: boost@lists.boost.org Subject: Re: [boost] [asio] init acceptor to reuse_address?
Hi Dick,
--- BRIDGES Dick <Dick.Bridges@us.thalesgroup.com> wrote: [snip]
Mumbling something about defaulting modern socket libraries to SO_REUSEADDR,
Do you think I should change the default to set SO_REUSEADDR to true? At the moment I leave all options to default to whatever the OS provides. Is there a good reason why all OSes (that I know of) have it default to false I wonder? Or is it just historical?
No. SO_REUSEADDR does increase the attack surface. Not a lot and less now than in the past but IMHO there's no point in helping the bad guys even a little bit if it's not required. Besides, I doubt all that many people would find it useful. My mumbling was aimed more toward myself than anything else - I have written a fair amount of "server" code and should have developed better habits by now. ;) [snip]
asio::ipv4::tcp::endpoint endpoint(port); acceptor_.open(endpoint.protocol()); acceptor_.set_option(asio::socket_acceptor::reuse_address(true)); acceptor_.bind(endpoint); acceptor_.listen(); acceptor_.async_accept(new_connection_->socket(), boost::bind(&server::handle_accept, this, asio::placeholders::error));
(From the new http example I've written: http://cvs.sourceforge.net/viewcvs.py/asio/asio/src/examples/ http/server/server.cpp?rev=1.1&view=markup).
Hmmm. The copy of the library I downloaded on 14 September doesn't have socket_acceptor::reuse_address and linux.softpedia.com says the last update was 5 September. I used stream_socket::reuse_address instead and that worked. Is there a newer version of the library somewhere else? Other than that one substitution, this fixed the problem. I would like to see this initialization code pushed back down into the acceptor. Maybe something along the lines of an "option_policy", but I can't come up with anything to suggest that isn't more trouble than it's worth. Thanks - *AGAIN* - for the help. Regards, Dick

Hi Dick, --- BRIDGES Dick <Dick.Bridges@us.thalesgroup.com> wrote:
No. SO_REUSEADDR does increase the attack surface. Not a lot and less now than in the past but IMHO there's no point in helping the bad guys even a little bit if it's not required. Besides, I doubt all that many people would find it useful. My mumbling was aimed more toward myself than anything else - I have written a fair amount of "server" code and should have developed better habits by now. ;)
I just checked my copy of Unix Network Programming Vol. 1 and it does recommend always setting the SO_REUSEADDR option (even though it notes the security issue).
Hmmm. The copy of the library I downloaded on 14 September doesn't have socket_acceptor::reuse_address and linux.softpedia.com says the last update was 5 September. I used stream_socket::reuse_address instead and that worked. Is there a newer version of the library somewhere else?
There's the version I'm working on in sourceforge CVS, which is what I had based my answer on, sorry.
I would like to see this initialization code pushed back down into the acceptor. Maybe something along the lines of an "option_policy", but I can't come up with anything to suggest that isn't more trouble than it's worth.
Yeah, these sort of options might somehow be associated with the protocol, since I can see different protocols (e.g. UNIX domain sockets, Bluetooth RFCOMM, etc) needing different defaults. I might leave this until asio gets more use in other types of socket to see what can be made reusable. Cheers, Chris
participants (2)
-
BRIDGES Dick
-
Christopher Kohlhoff