From c0a00acd14357fefa37b619ecc478f4f93a7d3b3 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 1 Jun 2018 12:07:11 +0200 Subject: [PATCH] rec: Resize the incoming query buffer to 512 after each query --- pdns/pdns_recursor.cc | 176 +++++++++++++++++++++++------------------- 1 file changed, 95 insertions(+), 81 deletions(-) diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index f3f71e5b5..3c6a9b189 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -2019,107 +2019,121 @@ static void handleNewUDPQuestion(int fd, FDMultiplexer::funcparam_t& var) char cbuf[256]; bool firstQuery = true; - data.resize(maxIncomingQuerySize); - fromaddr.sin6.sin6_family=AF_INET6; // this makes sure fromaddr is big enough - fillMSGHdr(&msgh, &iov, cbuf, sizeof(cbuf), &data[0], data.size(), &fromaddr); + for(size_t queriesCounter = 0; queriesCounter < s_maxUDPQueriesPerRound; queriesCounter++) { + data.resize(maxIncomingQuerySize); + fromaddr.sin6.sin6_family=AF_INET6; // this makes sure fromaddr is big enough + fillMSGHdr(&msgh, &iov, cbuf, sizeof(cbuf), &data[0], data.size(), &fromaddr); - for(size_t queriesCounter = 0; queriesCounter < s_maxUDPQueriesPerRound; queriesCounter++) - if((len=recvmsg(fd, &msgh, 0)) >= 0) { + if((len=recvmsg(fd, &msgh, 0)) >= 0) { - firstQuery = false; + firstQuery = false; - if (static_cast(len) < sizeof(dnsheader)) { - g_stats.ignoredCount++; - if (!g_quiet) { - g_log<(len) < sizeof(dnsheader)) { + g_stats.ignoredCount++; + if (!g_quiet) { + g_log<push_back(fromaddr); - if(t_allowFrom && !t_allowFrom->match(&fromaddr)) { - if(!g_quiet) - g_log<getTid()<<"] dropping UDP query from "<getTid()<<"] dropping UDP query from "<push_back(fromaddr); + } - g_stats.clientParseError++; // not quite the best place to put it, but needs to go somewhere - return; - } - try { - data.resize(static_cast(len)); - dnsheader* dh=(dnsheader*)&data[0]; + if(t_allowFrom && !t_allowFrom->match(&fromaddr)) { + if(!g_quiet) { + g_log<getTid()<<"] dropping UDP query from "<qr) { - g_stats.ignoredCount++; - if(g_logCommonErrors) - g_log<opcode) { - g_stats.ignoredCount++; - if(g_logCommonErrors) - g_log<opcode<<" from "<getTid()<<"] dropping UDP query from "<sin4.sin_port; + + try { + data.resize(static_cast(len)); + dnsheader* dh=(dnsheader*)&data[0]; + + if(dh->qr) { + g_stats.ignoredCount++; + if(g_logCommonErrors) { + g_log<opcode) { + g_stats.ignoredCount++; + if(g_logCommonErrors) { + g_log<opcode<<" from "<sin4.sin_port; + } } else { - dest.sin4.sin_family = fromaddr.sin4.sin_family; - socklen_t slen = dest.getSocklen(); - getsockname(fd, (sockaddr*)&dest, &slen); // if this fails, we're ok with it + if(loc) { + dest = *loc; + } + else { + dest.sin4.sin_family = fromaddr.sin4.sin_family; + socklen_t slen = dest.getSocklen(); + getsockname(fd, (sockaddr*)&dest, &slen); // if this fails, we're ok with it + } + } + + if(g_weDistributeQueries) { + distributeAsyncFunction(data, boost::bind(doProcessUDPQuestion, data, fromaddr, dest, tv, fd)); + } + else { + doProcessUDPQuestion(data, fromaddr, dest, tv, fd); } } - if(g_weDistributeQueries) - distributeAsyncFunction(data, boost::bind(doProcessUDPQuestion, data, fromaddr, dest, tv, fd)); - else - doProcessUDPQuestion(data, fromaddr, dest, tv, fd); + } + catch(const MOADNSException& mde) { + g_stats.clientParseError++; + if(g_logCommonErrors) { + g_log<