]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add a RE2Rule based on Google RE2 regex library. Note that if we detect it, we compil...
authorbert hubert <bert.hubert@netherlabs.nl>
Sun, 14 Feb 2016 10:16:56 +0000 (11:16 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Sun, 14 Feb 2016 10:16:56 +0000 (11:16 +0100)
configure.ac
m4/pdns_check_re2.m4 [new file with mode: 0644]
pdns/Makefile.am
pdns/dnsdist-lua.cc
pdns/dnsdistdist/Makefile.am
pdns/dnsdistdist/configure.ac
pdns/dnsdistdist/m4/pdns_check_re2.m4 [new symlink]
pdns/dnsrulactions.hh

index d1afd89d4204333b1df41fbecbc36d982917ef24..5a2a1f32df73ddb3ae5a07b12629d6f63f71ba70 100644 (file)
@@ -254,6 +254,8 @@ AM_CONDITIONAL([LDAP],[test "x$needldap" = "xyes"])
 PDNS_CHECK_SQLITE3
 AM_CONDITIONAL([SQLITE3], [test "x$needsqlite3" = "xyes"])
 
+PDNS_CHECK_RE2
+
 for a in $modules; do
   AC_MSG_CHECKING([whether we can build module "${a}"])
   if [[ -d "$srcdir/modules/${a}backend" ]]; then
diff --git a/m4/pdns_check_re2.m4 b/m4/pdns_check_re2.m4
new file mode 100644 (file)
index 0000000..538b7ff
--- /dev/null
@@ -0,0 +1,6 @@
+AC_DEFUN([PDNS_CHECK_RE2], [
+    PKG_CHECK_MODULES([RE2], [re2], [HAVE_RE2=1], [HAVE_RE2=0])
+    AM_CONDITIONAL([HAVE_RE2], [test "$HAVE_RE2" -eq 1])
+    AS_IF([test "$HAVE_RE2" -eq 1], [AC_DEFINE([HAVE_RE2], [1], [Define if using RE2.])])
+    
+])
index 93cb28226d64032e1096a114434284f6adfcd9d9..e43ea20740a72180da970212fbdcc7e4450f8dc9 100644 (file)
@@ -29,6 +29,10 @@ if SQLITE3
 AM_CPPFLAGS += $(SQLITE3_CFLAGS)
 endif
 
+if HAVE_RE2
+AM_CPPFLAGS += $(RE2_CFLAGS)
+endif
+
 if LUA
 AM_CPPFLAGS +=$(LUA_CFLAGS)
 endif
@@ -1215,6 +1219,10 @@ dnsdist_LDADD = \
        $(LIBSODIUM_LIBS) \
        $(OPENSSL_LIBS)
 
+if HAVE_RE2
+dnsdist_LDADD += $(RE2_LIBS)
+endif
+
 htmlfiles.h: $(srcdir)/dnsdistdist/html/*
        $(srcdir)/dnsdistdist/incfiles $(srcdir)/dnsdistdist > $@
 endif
index 9df0b5b6702c06218b9a04277037992d44cbf8f6..fb88a56141775d95e541fb9eb39817f7c18884e4 100644 (file)
@@ -644,6 +644,12 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
       return std::shared_ptr<DNSRule>(new RegexRule(str));
     });
 
+#ifdef HAVE_RE2
+  g_lua.writeFunction("RE2Rule", [](const std::string& str) {
+      return std::shared_ptr<DNSRule>(new RE2Rule(str));
+    });
+#endif
+
   g_lua.writeFunction("SuffixMatchNodeRule", [](const SuffixMatchNode& smn) {
       return std::shared_ptr<DNSRule>(new SuffixMatchNodeRule(smn));
     });
index f71fb7fbe909c6bfeb4ea0e01ba53873e031d776..7c33865238284400d55941fb8bb82046e9d9d5ac 100644 (file)
@@ -20,6 +20,11 @@ html/js/%.min.js: src_js/%.js
 
 min_js: $(MIN_JS_FILES)
 
+if HAVE_RE2
+AM_CPPFLAGS += $(RE2_CFLAGS)
+endif
+
+
 EXTRA_DIST=dnslabeltext.rl \
           dnsdistconf.lua \
           README.md \
@@ -88,6 +93,10 @@ dnsdist_LDADD = \
        $(LIBSODIUM_LIBS) \
        $(SANITIZER_FLAGS)
 
+if HAVE_RE2
+dnsdist_LDADD += $(RE2_LIBS)
+endif
+
 
 testrunner_SOURCES = \
        base64.hh \
index 805eab41b5c7000de1cb7c49b5eca7d70809b831..3325bd6e02577f8b2e460332115fd310555ea4f4 100644 (file)
@@ -13,6 +13,7 @@ PDNS_CHECK_CLOCK_GETTIME
 BOOST_REQUIRE([1.35])
 BOOST_FOREACH
 PDNS_ENABLE_UNIT_TESTS
+PDNS_CHECK_RE2
 DNSDIST_ENABLE_DNSCRYPT
 
 AC_SUBST([YAHTTP_CFLAGS], ['-I$(top_srcdir)/ext/yahttp'])
diff --git a/pdns/dnsdistdist/m4/pdns_check_re2.m4 b/pdns/dnsdistdist/m4/pdns_check_re2.m4
new file mode 120000 (symlink)
index 0000000..60ec5f9
--- /dev/null
@@ -0,0 +1 @@
+../../../m4/pdns_check_re2.m4
\ No newline at end of file
index 86dc1a57c19ac210600a72f959096d3cb13b08c5..749aec2a95719ea89b796e21c61779e19e3c7bd9 100644 (file)
@@ -202,13 +202,37 @@ public:
 
   string toString() const override
   {
-    return "Regex qname: "+d_visual;
+    return "Regex: "+d_visual;
   }
 private:
   Regex d_regex;
   string d_visual;
 };
 
+#ifdef HAVE_RE2
+#include <re2/re2.h>
+class RE2Rule : public DNSRule
+{
+public:
+  RE2Rule(const std::string& re2) : d_re2(re2, RE2::Latin1), d_visual(re2)
+  {
+    
+  }
+  bool matches(const DNSQuestion* dq) const override
+  {
+    return RE2::FullMatch(dq->qname->toStringNoDot(), d_re2);
+  }
+
+  string toString() const override
+  {
+    return "RE2 match: "+d_visual;
+  }
+private:
+  RE2 d_re2;
+  string d_visual;
+};
+#endif
+
 
 class SuffixMatchNodeRule : public DNSRule
 {