]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Apply suggestions from code review on the new eBPF map type
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 15 Nov 2021 17:11:02 +0000 (18:11 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 16 Nov 2021 08:02:48 +0000 (09:02 +0100)
pdns/bpf-filter.cc
pdns/dnsdist-lua-bindings.cc
pdns/dnsdistdist/docs/reference/ebpf.rst

index 2b5df7a07f4bdc5e678114787e88893c1c08cc0b..29bd6fe313491b3e476591b994dfbad98d2bd1cf 100644 (file)
@@ -89,7 +89,6 @@ void bpf_check_map_sizes(int fd, uint32_t expectedKeySize, uint32_t expectedValu
   if (info.value_size != expectedValueSize) {
     throw std::runtime_error("Error checking the size of eBPF map: value size mismatch (" + std::to_string(info.value_size) + " VS " + std::to_string(expectedValueSize) + ")");
   }
-
 }
 
 int bpf_update_elem(int fd, void *key, void *value, unsigned long long flags)
@@ -133,8 +132,8 @@ int bpf_get_next_key(int fd, void *key, void *next_key)
 }
 
 int bpf_prog_load(enum bpf_prog_type prog_type,
-                 const struct bpf_insn *insns, int prog_len,
-                 const char *license, int kern_version)
+                  const struct bpf_insn *insns, int prog_len,
+                  const char *license, int kern_version)
 {
   char log_buf[65535];
   union bpf_attr attr;
@@ -254,38 +253,30 @@ BPFFilter::Map::Map(const BPFFilter::MapConfiguration& config, BPFFilter::MapFor
 
         if (d_config.d_type == MapType::IPv4) {
           uint32_t key = 0;
-          int res = bpf_get_next_key(d_fd.getHandle(), &key, &key);
-          while (res == 0) {
+          while (bpf_get_next_key(d_fd.getHandle(), &key, &key) == 0) {
             ++d_count;
-            res = bpf_get_next_key(d_fd.getHandle(), &key, &key);
           }
         }
         else if (d_config.d_type == MapType::IPv6) {
           KeyV6 key;
           memset(&key, 0, sizeof(key));
-          int res = bpf_get_next_key(d_fd.getHandle(), &key, &key);
-          while (res == 0) {
+          while (bpf_get_next_key(d_fd.getHandle(), &key, &key) == 0) {
             ++d_count;
-            res = bpf_get_next_key(d_fd.getHandle(), &key, &key);
           }
         }
         else if (d_config.d_type == MapType::QNames) {
           if (format == MapFormat::Legacy) {
             QNameKey key;
             memset(&key, 0, sizeof(key));
-            int res = bpf_get_next_key(d_fd.getHandle(), &key, &key);
-            while (res == 0) {
+            while (bpf_get_next_key(d_fd.getHandle(), &key, &key) == 0) {
               ++d_count;
-              res = bpf_get_next_key(d_fd.getHandle(), &key, &key);
             }
           }
           else {
             QNameAndQTypeKey key;
             memset(&key, 0, sizeof(key));
-            int res = bpf_get_next_key(d_fd.getHandle(), &key, &key);
-            while (res == 0) {
+            while (bpf_get_next_key(d_fd.getHandle(), &key, &key) == 0) {
               ++d_count;
-              res = bpf_get_next_key(d_fd.getHandle(), &key, &key);
             }
           }
         }
index 43c3d0412271552cc42a57ac14cd3408e62acf37..ae44c7b63123621128d547c6100bce1d5d2b39c9 100644 (file)
@@ -478,7 +478,7 @@ void setupLuaBindings(LuaContext& luaCtx, bool client)
             match = BPFFilter::MatchAction::Truncate;
             break;
           default:
-            throw std::runtime_error("Unsupported action for BPFFilter::block");
+            throw std::runtime_error("Unsupported action for BPFFilter::blockQName");
           }
           return bpf->block(qname, match, qtype.value_or(255));
         }
index f723c1b51c30599ac672c903a4803e40ef110553..5fc3da9f0e4ae348ef59b82fc8c772c86e07dfc0 100644 (file)
@@ -20,7 +20,7 @@ These are all the functions, objects and methods related to the :doc:`../advance
     This function now supports a table for each parameters, and the ability to use pinned eBPF maps.
 
   Return a new eBPF socket filter with a maximum of maxV4 IPv4, maxV6 IPv6 and maxQNames qname entries in the block tables.
-  Maps can be pinned to a filesystem path, which makes their content persistent across restarts and allows external programs to read their content and to add new entries. dnsdist will try to load maps that are pinned to a filesystem path on startups, inheriting any existing entries, and fall back to creating them if they do not exist yet. Note that the user dnsdist is running under must have the right privileges to read and write to the given file, and to go through all the directories in the path leading to that file.
+  Maps can be pinned to a filesystem path, which makes their content persistent across restarts and allows external programs to read their content and to add new entries. dnsdist will try to load maps that are pinned to a filesystem path on startups, inheriting any existing entries, and fall back to creating them if they do not exist yet. Note that the user dnsdist is running under must have the right privileges to read and write to the given file, and to go through all the directories in the path leading to that file. The pinned path must be on a filesystem of type ``BPF``, usually below ``/sys/fs/bpf/``.
 
   :param int maxV4: Maximum number of IPv4 entries in this filter
   :param int maxV6: Maximum number of IPv6 entries in this filter
@@ -33,7 +33,7 @@ These are all the functions, objects and methods related to the :doc:`../advance
   Options:
 
   * ``maxItems``: int - The maximum number of entries in a given map. Default is 0 which will not allow any entry at all.
-  * ``pinnedPaths``: str - The filesystem path this map should be pinned to.
+  * ``pinnedPath``: str - The filesystem path this map should be pinned to.
 
 .. function:: newDynBPFFilter(bpf) -> DynBPFFilter