From 4e502fd624e56922e8951acd1d71e662ffefb1e9 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Mon, 8 May 2017 10:41:03 +0000 Subject: [PATCH] - Set SO_REUSEADDR on outgoing tcp connections to fix the bind before connect limited tcp connections. With the option tcp connections can share the same source port (for different destinations). git-svn-id: file:///svn/unbound/trunk@4151 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 3 +++ services/outside_network.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/doc/Changelog b/doc/Changelog index bf78e5189..f22d39e3e 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,8 @@ 8 May 2017: Wouter - Fix tcp-mss failure printout text. + - Set SO_REUSEADDR on outgoing tcp connections to fix the bind before + connect limited tcp connections. With the option tcp connections + can share the same source port (for different destinations). 2 May 2017: Ralph - Added mesh_add_sub to add detached mesh entries. diff --git a/services/outside_network.c b/services/outside_network.c index 525ae2e5e..89518ce19 100644 --- a/services/outside_network.c +++ b/services/outside_network.c @@ -204,6 +204,9 @@ outnet_tcp_take_into_use(struct waiting_tcp* w, uint8_t* pkt, size_t pkt_len) { struct pending_tcp* pend = w->outnet->tcp_free; int s; +#ifdef SO_REUSEADDR + int on = 1; +#endif log_assert(pend); log_assert(pkt); log_assert(w->addrlen > 0); @@ -225,6 +228,13 @@ outnet_tcp_take_into_use(struct waiting_tcp* w, uint8_t* pkt, size_t pkt_len) return 0; } +#ifdef SO_REUSEADDR + if(setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&on, + (socklen_t)sizeof(on)) < 0) { + verbose(VERB_ALGO, "outgoing tcp:" + " setsockopt(.. SO_REUSEADDR ..) failed"); + } +#endif if (w->outnet->tcp_mss > 0) { #if defined(IPPROTO_TCP) && defined(TCP_MAXSEG) if(setsockopt(s, IPPROTO_TCP, TCP_MAXSEG,