From 94e3db7eed0ecc330ffe4ce26fd8ac1500f56c40 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 23 Jan 2024 13:03:35 +0100 Subject: [PATCH] dnsdist: Fix more clang-tidy warnings --- pdns/bpf-filter.cc | 5 +++-- pdns/dnsdist-tcp.cc | 2 +- pdns/dnsdist.cc | 8 ++++---- pdns/dnsdistdist/doh.cc | 2 +- pdns/dnsdistdist/doh3.cc | 2 +- pdns/dnsdistdist/doq.cc | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pdns/bpf-filter.cc b/pdns/bpf-filter.cc index 225432cc1c4a..32f6986d9763 100644 --- a/pdns/bpf-filter.cc +++ b/pdns/bpf-filter.cc @@ -83,6 +83,7 @@ static void bpf_check_map_sizes(int descriptor, uint32_t expectedKeySize, uint32 } } +// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) static int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size, int max_entries, int map_flags) { @@ -137,7 +138,7 @@ static int bpf_get_next_key(int descriptor, void *key, void *next_key) } static int bpf_prog_load(enum bpf_prog_type prog_type, - const struct bpf_insn *insns, int prog_len, + const struct bpf_insn *insns, size_t prog_len, const char *license, int kern_version) { char log_buf[65535]; @@ -145,7 +146,7 @@ static int bpf_prog_load(enum bpf_prog_type prog_type, memset(&attr, 0, sizeof(attr)); attr.prog_type = prog_type; attr.insns = ptr_to_u64((void *) insns); - attr.insn_cnt = prog_len / sizeof(struct bpf_insn); + attr.insn_cnt = static_cast(prog_len / sizeof(struct bpf_insn)); attr.license = ptr_to_u64((void *) license); attr.log_buf = ptr_to_u64(log_buf); attr.log_size = sizeof(log_buf); diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 9d8edaf572ff..e3eb68e1152c 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -674,7 +674,7 @@ IncomingTCPConnectionState::QueryProcessingResult IncomingTCPConnectionState::ha { /* this pointer will be invalidated the second the buffer is resized, don't hold onto it! */ const dnsheader_aligned dnsHeader(query.data()); - if (!checkQueryHeaders(*dnsHeader.get(), *d_ci.cs)) { + if (!checkQueryHeaders(*dnsHeader, *d_ci.cs)) { return QueryProcessingResult::InvalidHeaders; } diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 204db07f1413..c78fb5a650c4 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1705,9 +1705,9 @@ bool assignOutgoingUDPQueryToBackend(std::shared_ptr& downstrea } try { - int fd = downstream->pickSocketForSending(); + int descriptor = downstream->pickSocketForSending(); if (actuallySend) { - dnsQuestion.ids.backendFD = fd; + dnsQuestion.ids.backendFD = descriptor; } dnsQuestion.ids.origID = queryID; dnsQuestion.ids.forwardedOverUDP = true; @@ -1726,7 +1726,7 @@ bool assignOutgoingUDPQueryToBackend(std::shared_ptr& downstrea /* you can't touch ids or du after this line, unless the call returned a non-negative value, because it might already have been freed */ - ssize_t ret = udpClientSendRequestToBackend(downstream, fd, query); + ssize_t ret = udpClientSendRequestToBackend(downstream, descriptor, query); if (ret < 0) { failed = true; @@ -1799,7 +1799,7 @@ static void processUDPQuery(ClientState& cs, LocalHolders& holders, const struct const dnsheader_aligned dnsHeader(query.data()); queryId = ntohs(dnsHeader->id); - if (!checkQueryHeaders(*dnsHeader.get(), cs)) { + if (!checkQueryHeaders(*dnsHeader, cs)) { return; } diff --git a/pdns/dnsdistdist/doh.cc b/pdns/dnsdistdist/doh.cc index f40923d385b1..5ecdd00f6fd6 100644 --- a/pdns/dnsdistdist/doh.cc +++ b/pdns/dnsdistdist/doh.cc @@ -719,7 +719,7 @@ static void processDOHQuery(DOHUnitUniquePtr&& unit, bool inMainThread = false) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) const dnsheader_aligned dnsHeader(unit->query.data()); - if (!checkQueryHeaders(*dnsHeader.get(), clientState)) { + if (!checkQueryHeaders(*dnsHeader, clientState)) { unit->status_code = 400; handleImmediateResponse(std::move(unit), "DoH invalid headers"); return; diff --git a/pdns/dnsdistdist/doh3.cc b/pdns/dnsdistdist/doh3.cc index 66081eb08a6d..4c0823ab621e 100644 --- a/pdns/dnsdistdist/doh3.cc +++ b/pdns/dnsdistdist/doh3.cc @@ -513,7 +513,7 @@ static void processDOH3Query(DOH3UnitUniquePtr&& doh3Unit) /* don't keep that pointer around, it will be invalidated if the buffer is ever resized */ dnsheader_aligned dnsHeader(unit->query.data()); - if (!checkQueryHeaders(*dnsHeader.get(), clientState)) { + if (!checkQueryHeaders(*dnsHeader, clientState)) { dnsdist::PacketMangling::editDNSHeaderFromPacket(unit->query, [](dnsheader& header) { header.rcode = RCode::ServFail; header.qr = true; diff --git a/pdns/dnsdistdist/doq.cc b/pdns/dnsdistdist/doq.cc index 3f52d33dc962..277a8c5985ac 100644 --- a/pdns/dnsdistdist/doq.cc +++ b/pdns/dnsdistdist/doq.cc @@ -425,7 +425,7 @@ static void processDOQQuery(DOQUnitUniquePtr&& doqUnit) /* don't keep that pointer around, it will be invalidated if the buffer is ever resized */ dnsheader_aligned dnsHeader(unit->query.data()); - if (!checkQueryHeaders(*dnsHeader.get(), clientState)) { + if (!checkQueryHeaders(*dnsHeader, clientState)) { dnsdist::PacketMangling::editDNSHeaderFromPacket(unit->query, [](dnsheader& header) { header.rcode = RCode::ServFail; header.qr = true;