From: bert hubert Date: Sun, 14 Feb 2016 10:16:56 +0000 (+0100) Subject: add a RE2Rule based on Google RE2 regex library. Note that if we detect it, we compil... X-Git-Tag: auth-4.0.0-alpha2~56^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ed8dfeb6c791622165a42c82796ccb6962b8831;p=thirdparty%2Fpdns.git add a RE2Rule based on Google RE2 regex library. Note that if we detect it, we compile it in unconditionally which sucks as it is a dynamic link. We should make this something you turn on. --- diff --git a/configure.ac b/configure.ac index d1afd89d42..5a2a1f32df 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 0000000000..538b7ffff6 --- /dev/null +++ b/m4/pdns_check_re2.m4 @@ -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.])]) + +]) diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 93cb28226d..e43ea20740 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -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 diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 9df0b5b670..fb88a56141 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -644,6 +644,12 @@ vector> setupLua(bool client, const std::string& confi return std::shared_ptr(new RegexRule(str)); }); +#ifdef HAVE_RE2 + g_lua.writeFunction("RE2Rule", [](const std::string& str) { + return std::shared_ptr(new RE2Rule(str)); + }); +#endif + g_lua.writeFunction("SuffixMatchNodeRule", [](const SuffixMatchNode& smn) { return std::shared_ptr(new SuffixMatchNodeRule(smn)); }); diff --git a/pdns/dnsdistdist/Makefile.am b/pdns/dnsdistdist/Makefile.am index f71fb7fbe9..7c33865238 100644 --- a/pdns/dnsdistdist/Makefile.am +++ b/pdns/dnsdistdist/Makefile.am @@ -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 \ diff --git a/pdns/dnsdistdist/configure.ac b/pdns/dnsdistdist/configure.ac index 805eab41b5..3325bd6e02 100644 --- a/pdns/dnsdistdist/configure.ac +++ b/pdns/dnsdistdist/configure.ac @@ -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 index 0000000000..60ec5f937e --- /dev/null +++ b/pdns/dnsdistdist/m4/pdns_check_re2.m4 @@ -0,0 +1 @@ +../../../m4/pdns_check_re2.m4 \ No newline at end of file diff --git a/pdns/dnsrulactions.hh b/pdns/dnsrulactions.hh index 86dc1a57c1..749aec2a95 100644 --- a/pdns/dnsrulactions.hh +++ b/pdns/dnsrulactions.hh @@ -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 +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 {