From 38b1097925e222bce38f7098d843962168f8cf0a Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 16 Nov 2021 17:36:03 +0100 Subject: [PATCH] dnsdist: Fix compiler/static analyzer warnings --- pdns/bpf-filter.cc | 33 +++++++++++----------- pdns/dnsdistdist/dnsdist-tcp-downstream.cc | 2 ++ pdns/remote_logger.cc | 3 -- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/pdns/bpf-filter.cc b/pdns/bpf-filter.cc index 29bd6fe313..d0ec0f6172 100644 --- a/pdns/bpf-filter.cc +++ b/pdns/bpf-filter.cc @@ -35,19 +35,8 @@ static __u64 ptr_to_u64(void *ptr) return (__u64) (unsigned long) ptr; } -int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size, - int max_entries) -{ - union bpf_attr attr; - memset(&attr, 0, sizeof(attr)); - attr.map_type = map_type; - attr.key_size = key_size; - attr.value_size = value_size; - attr.max_entries = max_entries; - return syscall(SYS_bpf, BPF_MAP_CREATE, &attr, sizeof(attr)); -} - -int bpf_pin_map(int fd, const std::string& path) +/* these can be static as they are not declared in libbpf.h: */ +static int bpf_pin_map(int fd, const std::string& path) { union bpf_attr attr; memset(&attr, 0, sizeof(attr)); @@ -56,7 +45,7 @@ int bpf_pin_map(int fd, const std::string& path) return syscall(SYS_bpf, BPF_OBJ_PIN, &attr, sizeof(attr)); } -int bpf_load_pinned_map(const std::string& path) +static int bpf_load_pinned_map(const std::string& path) { union bpf_attr attr; memset(&attr, 0, sizeof(attr)); @@ -64,7 +53,7 @@ int bpf_load_pinned_map(const std::string& path) return syscall(SYS_bpf, BPF_OBJ_GET, &attr, sizeof(attr)); } -void bpf_check_map_sizes(int fd, uint32_t expectedKeySize, uint32_t expectedValueSize) +static void bpf_check_map_sizes(int fd, uint32_t expectedKeySize, uint32_t expectedValueSize) { struct bpf_map_info info; uint32_t info_len = sizeof(info); @@ -91,6 +80,18 @@ void bpf_check_map_sizes(int fd, uint32_t expectedKeySize, uint32_t expectedValu } } +int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size, + int max_entries) +{ + union bpf_attr attr; + memset(&attr, 0, sizeof(attr)); + attr.map_type = map_type; + attr.key_size = key_size; + attr.value_size = value_size; + attr.max_entries = max_entries; + return syscall(SYS_bpf, BPF_MAP_CREATE, &attr, sizeof(attr)); +} + int bpf_update_elem(int fd, void *key, void *value, unsigned long long flags) { union bpf_attr attr; @@ -475,13 +476,11 @@ void BPFFilter::block(const DNSName& qname, BPFFilter::MatchAction action, uint1 void* value = nullptr; if (d_external) { - memset(&cadvalue, 0, sizeof(cadvalue)); cadvalue.counter = 0; cadvalue.action = action; value = &cadvalue; } else { - memset(&qvalue, 0, sizeof(qvalue)); qvalue.counter = 0; qvalue.qtype = qtype; value = &qvalue; diff --git a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc index 7d3158cc21..9c636d227c 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc +++ b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc @@ -515,7 +515,9 @@ void TCPConnectionToBackend::notifyAllQueriesFailed(const struct timeval& now, F /* we might be terminated while notifying a query sender */ d_ds->outstanding -= d_pendingResponses.size(); auto pendingQueries = std::move(d_pendingQueries); + d_pendingQueries.clear(); auto pendingResponses = std::move(d_pendingResponses); + d_pendingResponses.clear(); auto increaseCounters = [reason](std::shared_ptr& sender) { if (reason == FailureReason::timeout) { diff --git a/pdns/remote_logger.cc b/pdns/remote_logger.cc index 6e41db647f..96e596888c 100644 --- a/pdns/remote_logger.cc +++ b/pdns/remote_logger.cc @@ -47,12 +47,10 @@ bool CircularWriteBuffer::flush(int fd) struct iovec iov[2]; int pos = 0; - size_t total = 0; for(const auto& arr : {arr1, arr2}) { if(arr.second) { iov[pos].iov_base = arr.first; iov[pos].iov_len = arr.second; - total += arr.second; ++pos; } } @@ -84,7 +82,6 @@ bool CircularWriteBuffer::flush(int fd) } while (res < 0); - // cout<<"Flushed "<(res) == d_buffer.size()) { d_buffer.clear(); } -- 2.47.2