From: Remi Gacogne Date: Tue, 10 Sep 2024 14:07:05 +0000 (+0200) Subject: dnsdist: Format moved files X-Git-Tag: rec-5.2.0-alpha1~86^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85246232546d23a8932968f5a70ea35aeab9e296;p=thirdparty%2Fpdns.git dnsdist: Format moved files --- diff --git a/.not-formatted b/.not-formatted index 4d48f339e6..d539c7d154 100644 --- a/.not-formatted +++ b/.not-formatted @@ -19,8 +19,6 @@ ./pdns/base64.cc ./pdns/base64.hh ./pdns/bindparserclasses.hh -./pdns/bpf-filter.cc -./pdns/bpf-filter.hh ./pdns/calidns.cc ./pdns/capabilities.cc ./pdns/cdb.cc @@ -28,8 +26,6 @@ ./pdns/comfun.cc ./pdns/comment.hh ./pdns/dbdnsseckeeper.cc -./pdns/delaypipe.cc -./pdns/delaypipe.hh ./pdns/distributor.hh ./pdns/dns.cc ./pdns/dns.hh @@ -88,7 +84,6 @@ ./pdns/dnswasher.cc ./pdns/dnswriter.cc ./pdns/dnswriter.hh -./pdns/doh.hh ./pdns/dumresp.cc ./pdns/dynhandler.cc ./pdns/dynhandler.hh diff --git a/pdns/dnsdistdist/bpf-filter.cc b/pdns/dnsdistdist/bpf-filter.cc index 4a12d9d94e..fc398b867e 100644 --- a/pdns/dnsdistdist/bpf-filter.cc +++ b/pdns/dnsdistdist/bpf-filter.cc @@ -33,9 +33,9 @@ #include "misc.hh" -static __u64 ptr_to_u64(const void *ptr) +static __u64 ptr_to_u64(const void* ptr) { - return (__u64) (unsigned long) ptr; + return (__u64)(unsigned long)ptr; } /* these can be static as they are not declared in libbpf.h: */ @@ -97,7 +97,7 @@ static int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_si return syscall(SYS_bpf, BPF_MAP_CREATE, &attr, sizeof(attr)); } -static int bpf_update_elem(int descriptor, void *key, void *value, unsigned long long flags) +static int bpf_update_elem(int descriptor, void* key, void* value, unsigned long long flags) { union bpf_attr attr; memset(&attr, 0, sizeof(attr)); @@ -108,7 +108,7 @@ static int bpf_update_elem(int descriptor, void *key, void *value, unsigned long return syscall(SYS_bpf, BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); } -static int bpf_lookup_elem(int descriptor, void *key, void *value) +static int bpf_lookup_elem(int descriptor, void* key, void* value) { union bpf_attr attr; memset(&attr, 0, sizeof(attr)); @@ -118,7 +118,7 @@ static int bpf_lookup_elem(int descriptor, void *key, void *value) return syscall(SYS_bpf, BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr)); } -static int bpf_delete_elem(int descriptor, void *key) +static int bpf_delete_elem(int descriptor, void* key) { union bpf_attr attr; memset(&attr, 0, sizeof(attr)); @@ -127,7 +127,7 @@ static int bpf_delete_elem(int descriptor, void *key) return syscall(SYS_bpf, BPF_MAP_DELETE_ELEM, &attr, sizeof(attr)); } -static int bpf_get_next_key(int descriptor, void *key, void *next_key) +static int bpf_get_next_key(int descriptor, void* key, void* next_key) { union bpf_attr attr; memset(&attr, 0, sizeof(attr)); @@ -138,16 +138,16 @@ 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, size_t prog_len, - const char *license, int kern_version) + const struct bpf_insn* insns, size_t prog_len, + const char* license, int kern_version) { char log_buf[65535]; union bpf_attr attr; memset(&attr, 0, sizeof(attr)); attr.prog_type = prog_type; - attr.insns = ptr_to_u64((void *) insns); + attr.insns = ptr_to_u64((void*)insns); attr.insn_cnt = static_cast(prog_len / sizeof(struct bpf_insn)); - attr.license = ptr_to_u64((void *) license); + attr.license = ptr_to_u64((void*)license); attr.log_buf = ptr_to_u64(log_buf); attr.log_size = sizeof(log_buf); attr.log_level = 1; @@ -195,8 +195,8 @@ struct QNameValue uint16_t qtype{0}; }; - -BPFFilter::Map::Map(const BPFFilter::MapConfiguration& config, BPFFilter::MapFormat format): d_config(config) +BPFFilter::Map::Map(const BPFFilter::MapConfiguration& config, BPFFilter::MapFormat format) : + d_config(config) { if (d_config.d_type == BPFFilter::MapType::Filters) { /* special case, this is a map of eBPF programs */ @@ -349,7 +349,6 @@ static FDWrapper loadProgram(const struct bpf_insn* filter, size_t filterSize) return descriptor; } - BPFFilter::BPFFilter(std::unordered_map& configs, BPFFilter::MapFormat format, bool external) : d_mapFormat(format), d_external(external) { @@ -710,9 +709,9 @@ void BPFFilter::unblock(const DNSName& qname, uint16_t qtype) } } -std::vector > BPFFilter::getAddrStats() +std::vector> BPFFilter::getAddrStats() { - std::vector > result; + std::vector> result; { auto maps = d_maps.lock(); result.reserve(maps->d_v4.d_count + maps->d_v6.d_count); @@ -744,8 +743,8 @@ std::vector > BPFFilter::getAddrStats() while (res == 0) { v4Key = nextV4Key; if (bpf_lookup_elem(map.d_fd.getHandle(), &v4Key, &value) == 0) { - v4Addr.sin_addr.s_addr = ntohl(v4Key); - result.emplace_back(ComboAddress(&v4Addr), value.counter); + v4Addr.sin_addr.s_addr = ntohl(v4Key); + result.emplace_back(ComboAddress(&v4Addr), value.counter); } res = bpf_get_next_key(map.d_fd.getHandle(), &v4Key, &nextV4Key); @@ -816,13 +815,13 @@ std::vector> BPFFilter::getRangeRule() return result; } -std::vector > BPFFilter::getQNameStats() +std::vector> BPFFilter::getQNameStats() { - std::vector > result; + std::vector> result; if (d_mapFormat == MapFormat::Legacy) { - QNameKey key = { { 0 } }; - QNameKey nextKey = { { 0 } }; + QNameKey key = {{0}}; + QNameKey nextKey = {{0}}; QNameValue value; auto maps = d_maps.lock(); @@ -832,7 +831,7 @@ std::vector > BPFFilter::getQNameStats() while (res == 0) { if (bpf_lookup_elem(map.d_fd.getHandle(), &nextKey, &value) == 0) { - nextKey.qname[sizeof(nextKey.qname) - 1 ] = '\0'; + nextKey.qname[sizeof(nextKey.qname) - 1] = '\0'; result.emplace_back(DNSName(reinterpret_cast(nextKey.qname), sizeof(nextKey.qname), 0, false), value.qtype, value.counter); } @@ -853,7 +852,7 @@ std::vector > BPFFilter::getQNameStats() while (res == 0) { if (bpf_lookup_elem(map.d_fd.getHandle(), &nextKey, &value) == 0) { - nextKey.qname[sizeof(nextKey.qname) - 1 ] = '\0'; + nextKey.qname[sizeof(nextKey.qname) - 1] = '\0'; result.emplace_back(DNSName(reinterpret_cast(nextKey.qname), sizeof(nextKey.qname), 0, false), key.qtype, value.counter); } @@ -941,19 +940,20 @@ void BPFFilter::rmRangeRule(const Netmask&) throw std::runtime_error("eBPF support not enabled"); } -std::vector> BPFFilter::getRangeRule(){ +std::vector> BPFFilter::getRangeRule() +{ std::vector> result; return result; } -std::vector > BPFFilter::getAddrStats() +std::vector> BPFFilter::getAddrStats() { - std::vector > result; + std::vector> result; return result; } -std::vector > BPFFilter::getQNameStats() +std::vector> BPFFilter::getQNameStats() { - std::vector > result; + std::vector> result; return result; } diff --git a/pdns/dnsdistdist/bpf-filter.hh b/pdns/dnsdistdist/bpf-filter.hh index 2ab3aa561b..b4f4ea1da4 100644 --- a/pdns/dnsdistdist/bpf-filter.hh +++ b/pdns/dnsdistdist/bpf-filter.hh @@ -32,7 +32,8 @@ class BPFFilter { public: - enum class MapType : uint8_t { + enum class MapType : uint8_t + { IPv4, IPv6, QNames, @@ -41,12 +42,14 @@ public: CIDR6 }; - enum class MapFormat : uint8_t { + enum class MapFormat : uint8_t + { Legacy = 0, WithActions = 1 }; - enum class MatchAction : uint8_t { + enum class MatchAction : uint8_t + { Pass = 0, Drop = 1, Truncate = 2 @@ -76,7 +79,6 @@ public: uint64_t counter{0}; BPFFilter::MatchAction action{BPFFilter::MatchAction::Pass}; }; - BPFFilter(std::unordered_map& configs, BPFFilter::MapFormat format, bool external); BPFFilter(const BPFFilter&) = delete; @@ -88,14 +90,14 @@ public: void removeSocket(int sock); void block(const ComboAddress& addr, MatchAction action); void addRangeRule(const Netmask& address, bool force, BPFFilter::MatchAction action); - void block(const DNSName& qname, MatchAction action, uint16_t qtype=255); + void block(const DNSName& qname, MatchAction action, uint16_t qtype = 255); void unblock(const ComboAddress& addr); void rmRangeRule(const Netmask& address); - void unblock(const DNSName& qname, uint16_t qtype=255); + void unblock(const DNSName& qname, uint16_t qtype = 255); - std::vector > getAddrStats(); + std::vector> getAddrStats(); std::vector> getRangeRule(); - std::vector > getQNameStats(); + std::vector> getQNameStats(); uint64_t getHits(const ComboAddress& requestor); diff --git a/pdns/dnsdistdist/delaypipe.cc b/pdns/dnsdistdist/delaypipe.cc index ada096c1a2..fdd828862c 100644 --- a/pdns/dnsdistdist/delaypipe.cc +++ b/pdns/dnsdistdist/delaypipe.cc @@ -25,7 +25,7 @@ #include #include "threadname.hh" -template +template ObjectPipe::ObjectPipe() { auto [sender, receiver] = pdns::channel::createObjectQueue(pdns::channel::SenderBlockingMode::SenderBlocking, pdns::channel::ReceiverBlockingMode::ReceiverNonBlocking, 0, false); @@ -33,13 +33,13 @@ ObjectPipe::ObjectPipe() d_receiver = std::move(receiver); } -template +template void ObjectPipe::close() { d_sender.close(); } -template +template void ObjectPipe::write(T& t) { auto ptr = std::make_unique(t); @@ -48,11 +48,11 @@ void ObjectPipe::write(T& t) } } -template +template int ObjectPipe::readTimeout(T* t, double msec) { while (true) { - int ret = waitForData(d_receiver.getDescriptor(), 0, 1000*msec); + int ret = waitForData(d_receiver.getDescriptor(), 0, 1000 * msec); if (ret < 0) { if (errno == EINTR) { continue; @@ -81,48 +81,45 @@ int ObjectPipe::readTimeout(T* t, double msec) } } - -template -DelayPipe::DelayPipe() : d_thread(&DelayPipe::worker, this) +template +DelayPipe::DelayPipe() : + d_thread(&DelayPipe::worker, this) { } -template +template void DelayPipe::gettime(struct timespec* ts) { ::gettime(ts); } - -template +template void DelayPipe::submit(T& t, int msec) { struct timespec now; gettime(&now); - now.tv_nsec += msec*1e6; - while(now.tv_nsec > 1e9) { + now.tv_nsec += msec * 1e6; + while (now.tv_nsec > 1e9) { now.tv_sec++; - now.tv_nsec-=1e9; + now.tv_nsec -= 1e9; } Combo c{t, now}; d_pipe.write(c); } -template +template DelayPipe::~DelayPipe() { d_pipe.close(); d_thread.join(); } - - -template +template void DelayPipe::worker() { setThreadName("dnsdist/delayPi"); Combo c; - for(;;) { + for (;;) { /* this code is slightly too subtle, but I don't see how it could be any simpler. So we have a set of work to do, and we need to wait until the time arrives to do it. Simultaneously new work might come in. So we try to combine both of these things by @@ -133,39 +130,38 @@ void DelayPipe::worker() The other special case is that the first we have to do.. is in the past, so we need to do it immediately. */ - - double delay=-1; // infinite + double delay = -1; // infinite struct timespec now; - if(!d_work.empty()) { + if (!d_work.empty()) { gettime(&now); - delay=1000*tsdelta(d_work.begin()->first, now); - if(delay < 0) { - delay=0; // don't wait - we have work that is late already! + delay = 1000 * tsdelta(d_work.begin()->first, now); + if (delay < 0) { + delay = 0; // don't wait - we have work that is late already! } } - if(delay != 0 ) { + if (delay != 0) { int ret = d_pipe.readTimeout(&c, delay); - if(ret > 0) { // we got an object + if (ret > 0) { // we got an object d_work.emplace(c.when, c.what); } - else if(ret==0) { // EOF - break; + else if (ret == 0) { // EOF + break; } else { - ; + ; } gettime(&now); } tscomp cmp; - for(auto iter = d_work.begin() ; iter != d_work.end(); ) { // do the needful - if(cmp(iter->first, now)) { - iter->second(); - d_work.erase(iter++); + for (auto iter = d_work.begin(); iter != d_work.end();) { // do the needful + if (cmp(iter->first, now)) { + iter->second(); + d_work.erase(iter++); } else { - break; + break; } } } diff --git a/pdns/dnsdistdist/delaypipe.hh b/pdns/dnsdistdist/delaypipe.hh index b12fd50eac..ebbe1888f0 100644 --- a/pdns/dnsdistdist/delaypipe.hh +++ b/pdns/dnsdistdist/delaypipe.hh @@ -27,30 +27,30 @@ /** General idea: many threads submit work to this class, but only one executes it. The work should therefore be entirely trivial. - The implementation is that submitter threads create an object that represents the work, and it gets sent over a pipe + The implementation is that submitter threads create an object that represents the work, and it gets sent over a pipe to the worker thread. The worker thread meanwhile listens on this pipe (non-blocking), with a delay set to the next object that needs to be executed. If meanwhile new work comes in, all objects who's time has come are executed, a new sleep time is calculated. */ - /* ObjectPipe facilitates the type-safe passing of types over a pipe */ -template +template class ObjectPipe { public: ObjectPipe(); void write(T& t); int readTimeout(T* t, double msec); //!< -1 is timeout, 0 is no data, 1 is data. msec<0 waits infinitely long. msec==0 = undefined - void close(); + void close(); + private: pdns::channel::Sender d_sender; pdns::channel::Receiver d_receiver; }; -template +template class DelayPipe { public: @@ -68,11 +68,12 @@ private: double tsdelta(const struct timespec& a, const struct timespec& b) // read as a-b { - return 1.0*(a.tv_sec-b.tv_sec)+1.0*(a.tv_nsec-b.tv_nsec)/1000000000.0; + return 1.0 * (a.tv_sec - b.tv_sec) + 1.0 * (a.tv_nsec - b.tv_nsec) / 1000000000.0; } ObjectPipe d_pipe; - struct tscomp { + struct tscomp + { bool operator()(const struct timespec& a, const struct timespec& b) const { return std::tie(a.tv_sec, a.tv_nsec) < std::tie(b.tv_sec, b.tv_nsec); diff --git a/pdns/dnsdistdist/doh.hh b/pdns/dnsdistdist/doh.hh index 58a26f1691..04fe358ec5 100644 --- a/pdns/dnsdistdist/doh.hh +++ b/pdns/dnsdistdist/doh.hh @@ -40,7 +40,6 @@ std::unique_ptr getDoHCrossProtocolQueryFromDQ(DNSQuestion& struct H2ODOHFrontend : public DOHFrontend { public: - void setup() override; void reloadCertificates() override;