]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Move HTTP rules to dnsdist-rules.cc
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 24 Dec 2024 13:41:29 +0000 (14:41 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 16 Jan 2025 08:50:23 +0000 (09:50 +0100)
pdns/dnsdistdist/dnsdist-doh-common.cc
pdns/dnsdistdist/dnsdist-lua.hh
pdns/dnsdistdist/dnsdist-rules.cc
pdns/dnsdistdist/dnsdist-svc.cc
pdns/dnsdistdist/doh.cc

index df3c01d8a215599f65f3f396a1c793271f03bb24..c533cc7e8cd648fb5610cc66fc8ccaaf5ea64b4d 100644 (file)
  */
 #include "base64.hh"
 #include "dnsdist-doh-common.hh"
-#include "dnsdist-rules.hh"
+#include "dnsdist.hh"
 
 #ifdef HAVE_DNS_OVER_HTTPS
-
-HTTPHeaderRule::HTTPHeaderRule(const std::string& header, const std::string& regex) :
-  d_header(toLower(header)), d_regex(regex), d_visual("http[" + header + "] ~ " + regex)
-{
-}
-
-bool HTTPHeaderRule::matches(const DNSQuestion* dq) const
-{
-  if (dq->ids.du) {
-    const auto& headers = dq->ids.du->getHTTPHeaders();
-    for (const auto& header : headers) {
-      if (header.first == d_header) {
-        return d_regex.match(header.second);
-      }
-    }
-    return false;
-  }
-  if (dq->ids.doh3u) {
-    const auto& headers = dq->ids.doh3u->getHTTPHeaders();
-    for (const auto& header : headers) {
-      if (header.first == d_header) {
-        return d_regex.match(header.second);
-      }
-    }
-    return false;
-  }
-  return false;
-}
-
-string HTTPHeaderRule::toString() const
-{
-  return d_visual;
-}
-
-HTTPPathRule::HTTPPathRule(std::string path) :
-  d_path(std::move(path))
-{
-}
-
-bool HTTPPathRule::matches(const DNSQuestion* dq) const
-{
-  if (dq->ids.du) {
-    const auto path = dq->ids.du->getHTTPPath();
-    return d_path == path;
-  }
-  if (dq->ids.doh3u) {
-    return dq->ids.doh3u->getHTTPPath() == d_path;
-  }
-  return false;
-}
-
-string HTTPPathRule::toString() const
-{
-  return "url path == " + d_path;
-}
-
-HTTPPathRegexRule::HTTPPathRegexRule(const std::string& regex) :
-  d_regex(regex), d_visual("http path ~ " + regex)
-{
-}
-
-bool HTTPPathRegexRule::matches(const DNSQuestion* dq) const
-{
-  if (dq->ids.du) {
-    const auto path = dq->ids.du->getHTTPPath();
-    return d_regex.match(path);
-  }
-  if (dq->ids.doh3u) {
-    return d_regex.match(dq->ids.doh3u->getHTTPPath());
-  }
-  return false;
-}
-
-string HTTPPathRegexRule::toString() const
-{
-  return d_visual;
-}
-
 void DOHFrontend::rotateTicketsKey(time_t now)
 {
   return d_tlsContext.rotateTicketsKey(now);
index 572b8a692eb90b82b434a670a57c5862a0a64eb7..34d821f81dfd7382bce5388e20df009dacbd3c06 100644 (file)
  */
 #pragma once
 
-#include <random>
-
 #include "dolog.hh"
 #include "dnsdist.hh"
-#include "dnsdist-dnsparser.hh"
-#include "dnsparser.hh"
 
 #include "ext/luawrapper/include/LuaContext.hpp"
 
index 96666a21436eaf5338c7316419ef18a099b869f5..b2688b80ddb2ceb15e354a75b64cbe3dd1f7cfe6 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
-
 #include "dnsdist-rules.hh"
 
 std::atomic<uint64_t> LuaFFIPerThreadRule::s_functionsCounter = 0;
 thread_local std::map<uint64_t, LuaFFIPerThreadRule::PerThreadState> LuaFFIPerThreadRule::t_perThreadStates;
+
+HTTPHeaderRule::HTTPHeaderRule(const std::string& header, const std::string& regex) :
+  d_header(toLower(header)), d_regex(regex), d_visual("http[" + header + "] ~ " + regex)
+{
+#if !defined(HAVE_DNS_OVER_HTTPS) && !defined(HAVE_DNS_OVER_HTTP3)
+  throw std::runtime_error("Using HTTPHeaderRule while DoH support is not enabled");
+#endif /* HAVE_DNS_OVER_HTTPS || HAVE_DNS_OVER_HTTP3 */
+}
+
+bool HTTPHeaderRule::matches(const DNSQuestion* dnsQuestion) const
+{
+#if defined(HAVE_DNS_OVER_HTTPS)
+  if (dnsQuestion->ids.du) {
+    const auto& headers = dnsQuestion->ids.du->getHTTPHeaders();
+    for (const auto& header : headers) {
+      if (header.first == d_header) {
+        return d_regex.match(header.second);
+      }
+    }
+    return false;
+  }
+#endif /* HAVE_DNS_OVER_HTTPS */
+#if defined(HAVE_DNS_OVER_HTTP3)
+  if (dnsQuestion->ids.doh3u) {
+    const auto& headers = dnsQuestion->ids.doh3u->getHTTPHeaders();
+    for (const auto& header : headers) {
+      if (header.first == d_header) {
+        return d_regex.match(header.second);
+      }
+    }
+    return false;
+  }
+#endif /* defined(HAVE_DNS_OVER_HTTP3) */
+  return false;
+}
+
+string HTTPHeaderRule::toString() const
+{
+  return d_visual;
+}
+
+HTTPPathRule::HTTPPathRule(std::string path) :
+  d_path(std::move(path))
+{
+#if !defined(HAVE_DNS_OVER_HTTPS) && !defined(HAVE_DNS_OVER_HTTP3)
+  throw std::runtime_error("Using HTTPPathRule while DoH support is not enabled");
+#endif /* HAVE_DNS_OVER_HTTPS || HAVE_DNS_OVER_HTTP3 */
+}
+
+bool HTTPPathRule::matches(const DNSQuestion* dnsQuestion) const
+{
+#if defined(HAVE_DNS_OVER_HTTPS)
+  if (dnsQuestion->ids.du) {
+    const auto path = dnsQuestion->ids.du->getHTTPPath();
+    return d_path == path;
+  }
+#endif /* HAVE_DNS_OVER_HTTPS */
+#if defined(HAVE_DNS_OVER_HTTP3)
+  if (dnsQuestion->ids.doh3u) {
+    return dnsQuestion->ids.doh3u->getHTTPPath() == d_path;
+  }
+#endif /* defined(HAVE_DNS_OVER_HTTP3) */
+  return false;
+
+}
+
+string HTTPPathRule::toString() const
+{
+  return "url path == " + d_path;
+}
+
+HTTPPathRegexRule::HTTPPathRegexRule(const std::string& regex) :
+  d_regex(regex), d_visual("http path ~ " + regex)
+{
+#if !defined(HAVE_DNS_OVER_HTTPS) && !defined(HAVE_DNS_OVER_HTTP3)
+  throw std::runtime_error("Using HTTPRegexRule while DoH support is not enabled");
+#endif /* HAVE_DNS_OVER_HTTPS || HAVE_DNS_OVER_HTTP3 */
+}
+
+bool HTTPPathRegexRule::matches(const DNSQuestion* dnsQuestion) const
+{
+#if defined(HAVE_DNS_OVER_HTTPS)
+  if (dnsQuestion->ids.du) {
+    const auto path = dnsQuestion->ids.du->getHTTPPath();
+    return d_regex.match(path);
+  }
+#endif /* HAVE_DNS_OVER_HTTPS */
+#if defined(HAVE_DNS_OVER_HTTP3)
+  if (dnsQuestion->ids.doh3u) {
+    return d_regex.match(dnsQuestion->ids.doh3u->getHTTPPath());
+  }
+  return false;
+#endif /* HAVE_DNS_OVER_HTTP3 */
+  return false;
+}
+
+string HTTPPathRegexRule::toString() const
+{
+  return d_visual;
+}
index 574cc9eea1e3f52a4c193329077055df54b0dfd3..18ec3a62c3e1f4560030a806cc6c7e909fa05c3f 100644 (file)
@@ -21,6 +21,7 @@
  */
 #include "dnsdist-svc.hh"
 #include "dnsdist.hh"
+#include "dnsdist-dnsparser.hh"
 #include "dnsdist-ecs.hh"
 #include "dnsdist-lua.hh"
 #include "dnswriter.hh"
index 8b91a2bbe27f95fa58cd05e090bc91d0f0daeb6e..739684477b8277de8ac606ef936b8fa92000d899 100644 (file)
@@ -8,6 +8,7 @@
 #include <cerrno>
 #include <iostream>
 #include <thread>
+#include <string_view>
 
 #include <boost/algorithm/string.hpp>
 #include <h2o.h>
@@ -29,7 +30,6 @@
 #include "dnsdist-ecs.hh"
 #include "dnsdist-metrics.hh"
 #include "dnsdist-proxy-protocol.hh"
-#include "dnsdist-rules.hh"
 #include "libssl.hh"
 #include "threadname.hh"
 
@@ -56,7 +56,7 @@
 */
 
 /* 'Intermediate' compatibility from https://wiki.mozilla.org/Security/Server_Side_TLS#Intermediate_compatibility_.28default.29 */
-static constexpr string_view DOH_DEFAULT_CIPHERS = "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS";
+static constexpr std::string_view DOH_DEFAULT_CIPHERS = "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS";
 
 class DOHAcceptContext
 {