From: Otto Date: Tue, 19 Jan 2021 15:48:43 +0000 (+0100) Subject: Start supporting fastopen for outgoing TCP connections. X-Git-Tag: rec-4.5.0-beta1^2~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2bc7ddac81944ebde8f103d1dcf1b6131d0b586f;p=thirdparty%2Fpdns.git Start supporting fastopen for outgoing TCP connections. --- diff --git a/pdns/lwres.cc b/pdns/lwres.cc index 9b09b4dafd..4ff3809f11 100644 --- a/pdns/lwres.cc +++ b/pdns/lwres.cc @@ -328,11 +328,14 @@ LWResult::Result asyncresolve(const ComboAddress& ip, const DNSName& domain, int s.setNonBlocking(); ComboAddress local = pdns::getQueryLocalAddress(ip.sin4.sin_family, 0); + if (SyncRes::s_tcp_fast_open > 0) { + s.setFastOpen(SyncRes::s_tcp_fast_open); + } s.bind(local); - + s.connect(ip); - + uint16_t tlen=htons(vpacket.size()); char *lenP=(char*)&tlen; const char *msgP=(const char*)&*vpacket.begin(); @@ -341,7 +344,7 @@ LWResult::Result asyncresolve(const ComboAddress& ip, const DNSName& domain, int if (ret != LWResult::Result::Success) { return ret; } - + packet.clear(); ret = arecvtcp(packet, 2, &s, false); if (ret != LWResult::Result::Success) { diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index d293c73d30..d9ec1ad229 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -3290,10 +3290,9 @@ static void makeTCPServerSockets(deferredAdd_t& deferredAdds, std::set& tcp #endif } - if (::arg().asNum("tcp-fast-open") > 0) { + if (SyncRes::s_tcp_fast_open > 0) { #ifdef TCP_FASTOPEN - int fastOpenQueueSize = ::arg().asNum("tcp-fast-open"); - if (setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN, &fastOpenQueueSize, sizeof fastOpenQueueSize) < 0) { + if (setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN, &SyncRes::tcp_fast_open, sizeof SyncRes::tcp_fast_open) < 0) { int err = errno; g_log<(&var); - ssize_t ret=send(fd, pid->outMSG.c_str() + pid->outPos, pid->outMSG.size() - pid->outPos,0); - if(ret > 0) { - pid->outPos+=(ssize_t)ret; - if(pid->outPos==pid->outMSG.size()) { + PacketID* pid = boost::any_cast(&var); + ssize_t ret = send(fd, pid->outMSG.c_str() + pid->outPos, pid->outMSG.size() - pid->outPos,0); + if (ret > 0) { + pid->outPos += (ssize_t)ret; + if (pid->outPos == pid->outMSG.size()) { PacketID tmp=*pid; t_fdm->removeWriteFD(fd); MT->sendEvent(tmp, &tmp.outMSG); // send back what we sent to convey everything is ok @@ -4671,6 +4670,7 @@ static int serviceMain(int argc, char*argv[]) SyncRes::s_maxdepth=::arg().asNum("max-recursion-depth"); SyncRes::s_rootNXTrust = ::arg().mustDo( "root-nx-trust"); SyncRes::s_refresh_ttlperc = ::arg().asNum("refresh-on-ttl-perc"); + SyncRes::s_tcp_fast_open = ::arg().asNum("tcp-fast-open"); RecursorPacketCache::s_refresh_ttlperc = SyncRes::s_refresh_ttlperc; if(SyncRes::s_serverID.empty()) { diff --git a/pdns/sstuff.hh b/pdns/sstuff.hh index 38d57c85e7..548e0d0729 100644 --- a/pdns/sstuff.hh +++ b/pdns/sstuff.hh @@ -127,6 +127,13 @@ public: } } + void setFastOpen(int fastOpenQueueSize) + { +#ifdef TCP_FASTOPEN_CONNECT + setsockopt(d_socket, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, &fastOpenQueueSize, sizeof fastOpenQueueSize); +#endif + } + //! Bind the socket to a specified endpoint void bind(const ComboAddress &local, bool reuseaddr=true) { diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 71bb60ff5c..08619eed24 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -98,6 +98,7 @@ bool SyncRes::s_noEDNS; bool SyncRes::s_qnameminimization; SyncRes::HardenNXD SyncRes::s_hardenNXD; unsigned int SyncRes::s_refresh_ttlperc; +int SyncRes::s_tcp_fast_open; #define LOG(x) if(d_lm == Log) { g_log < d_discardedPolicies; DNSFilterEngine::Policy d_appliedPolicy;