Skip to content

Commit

Permalink
Fix warnings with GCC and older clang
Browse files Browse the repository at this point in the history
  • Loading branch information
fredmorcos committed Dec 13, 2023
1 parent f8a7f19 commit d65e98f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 44 deletions.
62 changes: 32 additions & 30 deletions pdns/dnsbulktest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#endif
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#if __clang_major__ >= 15
#pragma GCC diagnostic ignored "-Wdeprecated-copy-with-user-provided-copy"
#endif
#include <boost/accumulators/accumulators.hpp>
#include <boost/array.hpp>
#include <boost/accumulators/statistics.hpp>
Expand Down Expand Up @@ -77,7 +79,7 @@ struct SendReceive
using Answer = DNSResult; // ip
Socket d_socket;
std::deque<uint16_t> d_idqueue;

using acc_t = accumulator_set<
double
, stats<boost::accumulators::tag::extended_p_square,
Expand All @@ -96,7 +98,7 @@ struct SendReceive
unsigned int d_received{0};
unsigned int d_receiveerrors{0};
unsigned int d_senderrors{0};

SendReceive(const std::string& remoteAddr, uint16_t port) :
d_socket(AF_INET, SOCK_DGRAM),
d_acc(make_unique<acc_t>(acc_t(boost::accumulators::tag::extended_p_square::probabilities=s_probs)))
Expand All @@ -108,57 +110,57 @@ struct SendReceive
d_idqueue.push_back(id);
}
}

Identifier send(TypedQuery& domain)
{
//cerr<<"Sending query for '"<<domain<<"'"<<endl;

// send it, copy code from 'sdig'
vector<uint8_t> packet;

DNSPacketWriter pw(packet, domain.name, domain.type);

if (d_idqueue.empty()) {
cerr<<"Exhausted ids!"<<endl;
exit(1);
}
}
pw.getHeader()->id = d_idqueue.front();
d_idqueue.pop_front();
pw.getHeader()->rd = 1;
pw.getHeader()->qr = 0;

if (::send(d_socket.getHandle(), &*packet.begin(), packet.size(), 0) < 0) {
d_senderrors++;
}

if (!g_quiet) {
cout<<"Sent out query for '"<<domain.name<<"' with id "<<pw.getHeader()->id<<endl;
}
return pw.getHeader()->id;
}

bool receive(Identifier& id, DNSResult& dr)
{
if (waitForData(d_socket.getHandle(), 0, 500000) > 0) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init): no need to initialize the buffer
std::array<char, 512> buf;

auto len = recv(d_socket.getHandle(), buf.data(), buf.size(), 0);
if (len < 0) {
d_receiveerrors++;
return false;
}
d_received++;
// parse packet, set 'id', fill out 'ip'
// parse packet, set 'id', fill out 'ip'

MOADNSParser mdp(false, string(buf.data(), static_cast<size_t>(len)));
if(!g_quiet) {
cout<<"Reply to question for qname='"<<mdp.d_qname<<"', qtype="<<DNSRecordContent::NumberToType(mdp.d_qtype)<<endl;
cout<<"Rcode: "<<mdp.d_header.rcode<<", RD: "<<mdp.d_header.rd<<", QR: "<<mdp.d_header.qr;
cout<<", TC: "<<mdp.d_header.tc<<", AA: "<<mdp.d_header.aa<<", opcode: "<<mdp.d_header.opcode<<endl;
}
dr.rcode = mdp.d_header.rcode;
for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) {
for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) {

Check warning on line 163 in pdns/dnsbulktest.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

use auto when declaring iterators (modernize-use-auto - Level=Warning)
if(i->first.d_place == 1 && i->first.d_type == mdp.d_qtype)
dr.ips.push_back(ComboAddress(i->first.getContent()->getZoneRepresentation()));
if(i->first.d_place == 2 && i->first.d_type == QType::SOA) {
Expand All @@ -170,23 +172,23 @@ struct SendReceive
cout<<"\t"<<i->first.d_ttl<<"\t"<< i->first.getContent()->getZoneRepresentation()<<"\n";
}
}

id = mdp.d_header.id;
d_idqueue.push_back(id);

return true;
}
return false;
}

void deliverTimeout(const Identifier& id)
{
if(!g_quiet) {
cout<<"Timeout for id "<<id<<endl;
}
d_idqueue.push_back(id);
}

void deliverAnswer(TypedQuery& domain, const DNSResult& dr, unsigned int usec)
{
(*d_acc)(usec/1000.0);
Expand All @@ -205,7 +207,7 @@ struct SendReceive
else if(dr.rcode) {
d_errors++;
}
else if(dr.ips.empty() && dr.seenauthsoa)
else if(dr.ips.empty() && dr.seenauthsoa)

Check warning on line 210 in pdns/dnsbulktest.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

statement should be inside braces (readability-braces-around-statements - Level=Warning)
d_nodatas++;
else if(!dr.ips.empty())
d_oks++;
Expand Down Expand Up @@ -284,15 +286,15 @@ try

SendReceive sr(g_vm["ip-address"].as<string>(), g_vm["portnumber"].as<uint16_t>());
unsigned int limit = g_vm["limit"].as<unsigned int>();

vector<TypedQuery> domains;

Inflighter<vector<TypedQuery>, SendReceive> inflighter(domains, sr);
inflighter.d_maxInFlight = 1000;
inflighter.d_timeoutSeconds = 3;
inflighter.d_burst = 100;
string line;

pair<string, string> split;
string::size_type pos;
while(stringfgets(stdin, line)) {
Expand Down Expand Up @@ -337,25 +339,25 @@ try
cerr<< datafmt % " Queued " % domains.size() % " Received" % sr.d_received;
cerr<< datafmt % " Error -/-" % sr.d_senderrors % " Timeouts" % inflighter.getTimeouts();
cerr<< datafmt % " " % "" % " Unexpected" % inflighter.getUnexpecteds();

cerr<< datafmt % " Sent" % (domains.size() - sr.d_senderrors) % " Total" % (sr.d_received + inflighter.getTimeouts() + inflighter.getUnexpecteds());
cerr<<endl;

cerr<<endl;
cerr<< datafmt % "DNS Status" % "" % "" % "";
cerr<< datafmt % " OK" % sr.d_oks % "" % "";
cerr<< datafmt % " Error" % sr.d_errors % "" % "";
cerr<< datafmt % " No Data" % sr.d_nodatas % "" % "";
cerr<< datafmt % " Error" % sr.d_errors % "" % "";
cerr<< datafmt % " No Data" % sr.d_nodatas % "" % "";
cerr<< datafmt % " NXDOMAIN" % sr.d_nxdomains % "" % "";
cerr<< datafmt % " Unknowns" % sr.d_unknowns % "" % "";
cerr<< datafmt % " Unknowns" % sr.d_unknowns % "" % "";
cerr<< datafmt % "Answers" % (sr.d_oks + sr.d_errors + sr.d_nodatas + sr.d_nxdomains + sr.d_unknowns) % "" % "";
cerr<< datafmt % " Timeouts " % (inflighter.getTimeouts()) % "" % "";
cerr<< datafmt % "Total " % (sr.d_oks + sr.d_errors + sr.d_nodatas + sr.d_nxdomains + sr.d_unknowns + inflighter.getTimeouts()) % "" % "";

cerr<<"\n";
cerr<< "Mean response time: "<<mean(*sr.d_acc) << " ms"<<", median: "<<median(*sr.d_acc)<< " ms\n";

boost::format statfmt("Time < %6.03f ms %|30t|%6.03f%% cumulative\n");

for (unsigned int i = 0; i < SendReceive::s_probs.size(); ++i) {
cerr << statfmt % extended_p_square(*sr.d_acc)[i] % (100*SendReceive::s_probs.at(i));
}
Expand Down
30 changes: 16 additions & 14 deletions pdns/dnstcpbench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#endif
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#if __clang_major__ >= 15
#pragma GCC diagnostic ignored "-Wdeprecated-copy-with-user-provided-copy"
#endif
#include <boost/accumulators/statistics/median.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/accumulators.hpp>
Expand Down Expand Up @@ -61,7 +63,7 @@ static unsigned int makeUsec(const struct timeval& tv)
return 1000000*tv.tv_sec + tv.tv_usec;
}

/* On Linux, run echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
/* On Linux, run echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
to prevent running out of free TCP ports */

struct BenchQuery
Expand All @@ -87,7 +89,7 @@ try

if(!g_onlyTCP) {
Socket udpsock(g_dest.sin4.sin_family, SOCK_DGRAM);

udpsock.sendTo(string(packet.begin(), packet.end()), g_dest);
ComboAddress origin;
res = waitForData(udpsock.getHandle(), 0, 1000 * g_timeoutMsec);
Expand All @@ -112,10 +114,10 @@ try

Socket sock(g_dest.sin4.sin_family, SOCK_STREAM);
int tmp=1;
if(setsockopt(sock.getHandle(),SOL_SOCKET,SO_REUSEADDR,(char*)&tmp,sizeof tmp)<0)
if(setsockopt(sock.getHandle(),SOL_SOCKET,SO_REUSEADDR,(char*)&tmp,sizeof tmp)<0)

Check warning on line 117 in pdns/dnstcpbench.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

do not use C-style cast to convert between unrelated types (cppcoreguidelines-pro-type-cstyle-cast - Level=Warning)

Check warning on line 117 in pdns/dnstcpbench.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

statement should be inside braces (readability-braces-around-statements - Level=Warning)
throw runtime_error("Unable to set socket reuse: "+stringerror());
if(g_tcpNoDelay && setsockopt(sock.getHandle(), IPPROTO_TCP, TCP_NODELAY,(char*)&tmp,sizeof tmp)<0)

if(g_tcpNoDelay && setsockopt(sock.getHandle(), IPPROTO_TCP, TCP_NODELAY,(char*)&tmp,sizeof tmp)<0)

Check warning on line 120 in pdns/dnstcpbench.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

do not use C-style cast to convert between unrelated types (cppcoreguidelines-pro-type-cstyle-cast - Level=Warning)

Check warning on line 120 in pdns/dnstcpbench.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

statement should be inside braces (readability-braces-around-statements - Level=Warning)
throw runtime_error("Unable to set socket no delay: "+stringerror());

sock.connect(g_dest);
Expand All @@ -132,10 +134,10 @@ try
g_timeOuts++;
return;
}

if(sock.read((char *) &len, 2) != 2)
throw PDNSException("tcp read failed");

len=ntohs(len);
auto creply = std::make_unique<char[]>(len);
int n=0;
Expand All @@ -146,9 +148,9 @@ try
throw PDNSException("tcp read failed");
n+=numread;
}

reply=string(creply.get(), len);

gettimeofday(&now, 0);
q->tcpUsec = makeUsec(now - tv);
q->answerSecond = now.tv_sec;
Expand Down Expand Up @@ -181,7 +183,7 @@ static void worker()
{
setThreadName("dnstcpb/worker");
for(;;) {
unsigned int pos = g_pos++;
unsigned int pos = g_pos++;
if(pos >= g_queries.size())
break;

Expand Down Expand Up @@ -212,7 +214,7 @@ try
hidden.add_options()
("remote-host", po::value<string>(), "remote-host")
("remote-port", po::value<int>()->default_value(53), "remote-port");
alloptions.add(desc).add(hidden);
alloptions.add(desc).add(hidden);

po::positional_options_description p;
p.add("remote-host", 1);
Expand Down Expand Up @@ -246,7 +248,7 @@ try
g_dest = ComboAddress(g_vm["remote-host"].as<string>().c_str(), g_vm["remote-port"].as<int>());

unsigned int numworkers=g_vm["workers"].as<int>();

if(g_verbose) {
cout<<"Sending queries to: "<<g_dest.toStringWithPort()<<endl;
cout<<"Attempting UDP first: " << (g_onlyTCP ? "no" : "yes") <<endl;
Expand Down Expand Up @@ -283,7 +285,7 @@ try
for (auto& w : workers) {
w.join();
}

using namespace boost::accumulators;
typedef accumulator_set<
double
Expand All @@ -293,7 +295,7 @@ try
> acc_t;

acc_t udpspeeds, tcpspeeds, qps;

typedef map<time_t, uint32_t> counts_t;
counts_t counts;

Expand Down
2 changes: 2 additions & 0 deletions pdns/histog.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#pragma once
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#if __clang_major__ >= 15
#pragma GCC diagnostic ignored "-Wdeprecated-copy-with-user-provided-copy"
#endif
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics.hpp>
#pragma GCC diagnostic pop
Expand Down

0 comments on commit d65e98f

Please sign in to comment.