]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Format moved files
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 10 Sep 2024 14:07:05 +0000 (16:07 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 10 Sep 2024 14:07:05 +0000 (16:07 +0200)
.not-formatted
pdns/dnsdistdist/bpf-filter.cc
pdns/dnsdistdist/bpf-filter.hh
pdns/dnsdistdist/delaypipe.cc
pdns/dnsdistdist/delaypipe.hh
pdns/dnsdistdist/doh.hh

index 4d48f339e646d8214170fa2fb630a22b9a3797f8..d539c7d15470e8a1dbd38f44b91a89e2ec471be7 100644 (file)
@@ -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
index 4a12d9d94e615cecbae56729f1cee5fe88e7f54c..fc398b867e74e85c76de3af333327d767a674b50 100644 (file)
@@ -33,9 +33,9 @@
 
 #include "misc.hh"
 
-static __u64 ptr_to_u64(const void *ptr)
+static __u64 ptr_to_u64(const voidptr)
 {
-  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, voidkey)
 {
   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_insninsns, size_t prog_len,
+                         const charlicense, 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<int>(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<std::string, MapConfiguration>& 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<std::pair<ComboAddress, uint64_t> > BPFFilter::getAddrStats()
+std::vector<std::pair<ComboAddress, uint64_t>> BPFFilter::getAddrStats()
 {
-  std::vector<std::pair<ComboAddress, uint64_t> > result;
+  std::vector<std::pair<ComboAddress, uint64_t>> result;
   {
     auto maps = d_maps.lock();
     result.reserve(maps->d_v4.d_count + maps->d_v6.d_count);
@@ -744,8 +743,8 @@ std::vector<std::pair<ComboAddress, uint64_t> > 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<std::pair<Netmask, CounterAndActionValue>> BPFFilter::getRangeRule()
   return result;
 }
 
-std::vector<std::tuple<DNSName, uint16_t, uint64_t> > BPFFilter::getQNameStats()
+std::vector<std::tuple<DNSName, uint16_t, uint64_t>> BPFFilter::getQNameStats()
 {
-  std::vector<std::tuple<DNSName, uint16_t, uint64_t> > result;
+  std::vector<std::tuple<DNSName, uint16_t, uint64_t>> 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<std::tuple<DNSName, uint16_t, uint64_t> > 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<const char*>(nextKey.qname), sizeof(nextKey.qname), 0, false), value.qtype, value.counter);
       }
 
@@ -853,7 +852,7 @@ std::vector<std::tuple<DNSName, uint16_t, uint64_t> > 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<const char*>(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<std::pair<Netmask, CounterAndActionValue>> BPFFilter::getRangeRule(){
+std::vector<std::pair<Netmask, CounterAndActionValue>> BPFFilter::getRangeRule()
+{
   std::vector<std::pair<Netmask, CounterAndActionValue>> result;
   return result;
 }
-std::vector<std::pair<ComboAddress, uint64_t> > BPFFilter::getAddrStats()
+std::vector<std::pair<ComboAddress, uint64_t>> BPFFilter::getAddrStats()
 {
-  std::vector<std::pair<ComboAddress, uint64_t> > result;
+  std::vector<std::pair<ComboAddress, uint64_t>> result;
   return result;
 }
 
-std::vector<std::tuple<DNSName, uint16_t, uint64_t> > BPFFilter::getQNameStats()
+std::vector<std::tuple<DNSName, uint16_t, uint64_t>> BPFFilter::getQNameStats()
 {
-  std::vector<std::tuple<DNSName, uint16_t, uint64_t> > result;
+  std::vector<std::tuple<DNSName, uint16_t, uint64_t>> result;
   return result;
 }
 
index 2ab3aa561b7e4f2efbdbc86105ef99a589c8800f..b4f4ea1da412d0396465e27c7c86084515606b33 100644 (file)
@@ -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<std::string, MapConfiguration>& 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<std::pair<ComboAddress, uint64_t> > getAddrStats();
+  std::vector<std::pair<ComboAddress, uint64_t>> getAddrStats();
   std::vector<std::pair<Netmask, CounterAndActionValue>> getRangeRule();
-  std::vector<std::tuple<DNSName, uint16_t, uint64_t> > getQNameStats();
+  std::vector<std::tuple<DNSName, uint16_t, uint64_t>> getQNameStats();
 
   uint64_t getHits(const ComboAddress& requestor);
 
index ada096c1a27fa65ac1f918d0b7303c0de14c6960..fdd828862cc55f9ce4889e2348769537480f2019 100644 (file)
@@ -25,7 +25,7 @@
 #include <thread>
 #include "threadname.hh"
 
-template<class T>
+template <class T>
 ObjectPipe<T>::ObjectPipe()
 {
   auto [sender, receiver] = pdns::channel::createObjectQueue<T>(pdns::channel::SenderBlockingMode::SenderBlocking, pdns::channel::ReceiverBlockingMode::ReceiverNonBlocking, 0, false);
@@ -33,13 +33,13 @@ ObjectPipe<T>::ObjectPipe()
   d_receiver = std::move(receiver);
 }
 
-template<class T>
+template <class T>
 void ObjectPipe<T>::close()
 {
   d_sender.close();
 }
 
-template<class T>
+template <class T>
 void ObjectPipe<T>::write(T& t)
 {
   auto ptr = std::make_unique<T>(t);
@@ -48,11 +48,11 @@ void ObjectPipe<T>::write(T& t)
   }
 }
 
-template<class T>
+template <class T>
 int ObjectPipe<T>::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<T>::readTimeout(T* t, double msec)
   }
 }
 
-
-template<class T>
-DelayPipe<T>::DelayPipe() : d_thread(&DelayPipe<T>::worker, this)
+template <class T>
+DelayPipe<T>::DelayPipe() :
+  d_thread(&DelayPipe<T>::worker, this)
 {
 }
 
-template<class T>
+template <class T>
 void DelayPipe<T>::gettime(struct timespec* ts)
 {
   ::gettime(ts);
 }
 
-
-template<class T>
+template <class T>
 void DelayPipe<T>::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<class T>
+template <class T>
 DelayPipe<T>::~DelayPipe()
 {
   d_pipe.close();
   d_thread.join();
 }
 
-
-
-template<class T>
+template <class T>
 void DelayPipe<T>::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<T>::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;
       }
     }
   }
index b12fd50eac1bb0d6fe49ad6164d6d377d7a84c9b..ebbe1888f0d7dfec353d0dcc2c524ecce261b30f 100644 (file)
 
 /**
    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<class T>
+template <class T>
 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<T> d_sender;
   pdns::channel::Receiver<T> d_receiver;
 };
 
-template<class T>
+template <class T>
 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<Combo> 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);
index 58a26f16918f6e33da6ecd2ed728800c25e324c3..04fe358ec5110aa6e111738b822ef864686dfcf1 100644 (file)
@@ -40,7 +40,6 @@ std::unique_ptr<CrossProtocolQuery> getDoHCrossProtocolQueryFromDQ(DNSQuestion&
 struct H2ODOHFrontend : public DOHFrontend
 {
 public:
-
   void setup() override;
   void reloadCertificates() override;