Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SuffixMatchNode:add: Accept more types #7985

Merged
merged 1 commit into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion pdns/dnsdist-lua-bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,32 @@ void setupLuaBindings(bool client)
g_lua.registerFunction("empty",(bool (DNSNameSet::*)()) &DNSNameSet::empty);

/* SuffixMatchNode */
g_lua.registerFunction("add",(void (SuffixMatchNode::*)(const DNSName&)) &SuffixMatchNode::add);
g_lua.registerFunction<void (SuffixMatchNode::*)(const boost::variant<DNSName, string, vector<pair<int, DNSName>>, vector<pair<int, string>>> &name)>("add", [](SuffixMatchNode &smn, const boost::variant<DNSName, string, vector<pair<int, DNSName>>, vector<pair<int, string>>> &name) {
if (name.type() == typeid(DNSName)) {
auto n = boost::get<DNSName>(name);
smn.add(n);
return;
}
if (name.type() == typeid(string)) {
auto n = boost::get<string>(name);
smn.add(n);
rgacogne marked this conversation as resolved.
Show resolved Hide resolved
return;
}
if (name.type() == typeid(vector<pair<int, DNSName>>)) {
auto names = boost::get<vector<pair<int, DNSName>>>(name);
for (auto const n : names) {
smn.add(n.second);
}
return;
}
if (name.type() == typeid(vector<pair<int, string>>)) {
auto names = boost::get<vector<pair<int, string>>>(name);
for (auto const n : names) {
smn.add(n.second);
rgacogne marked this conversation as resolved.
Show resolved Hide resolved
}
return;
}
});
g_lua.registerFunction("check",(bool (SuffixMatchNode::*)(const DNSName&) const) &SuffixMatchNode::check);

/* NetmaskGroup */
Expand Down
4 changes: 4 additions & 0 deletions pdns/dnsdistdist/docs/reference/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1072,10 +1072,14 @@ If you are looking for exact name matching, your might want to consider using a
Represent a set of DNS suffixes for quick matching.

.. method:: SuffixMatchNode:add(name)
.. versionchanged:: 1.4.0
This method now accepts strings, lists of DNSNames and lists of strings.

Add a suffix to the current set.

:param DNSName name: The suffix to add to the set.
:param string name: The suffix to add to the set.
:param table name: The suffixes to add to the set. Elements of the table should be of the same type, either DNSName or string.

.. method:: SuffixMatchNode:check(name) -> bool

Expand Down
5 changes: 5 additions & 0 deletions pdns/dnsname.hh
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ struct SuffixMatchNode
d_nodes.insert(dnsname);
}

void add(const std::string& name)
{
add(DNSName(name));
}

void add(std::vector<std::string> labels)
{
d_tree.add(labels, true);
Expand Down
4 changes: 4 additions & 0 deletions regression-tests.dnsdist/test_CheckConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def testWorkingConfig(self):
addAction(RegexRule("evil[0-9]{4,}\\\\.regex\\\\.tests\\\\.powerdns\\\\.com$"), RCodeAction(DNSRCode.REFUSED))
mySMN = newSuffixMatchNode()
mySMN:add(newDNSName("nameAndQtype.tests.powerdns.com."))
mySMN:add("string.smn.tests.powerdns.com.")
mySMN:add("string-no-dot.smn.tests.powerdns.com")
mySMN:add({"string-one.smn.tests.powerdns.com", "string-two.smn.tests.powerdns.com"})
mySMN:add({newDNSName("dnsname-one.smn.tests.powerdns.com"), newDNSName("dnsname-two.smn.tests.powerdns.com")})
addAction(AndRule{SuffixMatchNodeRule(mySMN), QTypeRule("TXT")}, RCodeAction(DNSRCode.NOTIMP))
addAction(makeRule("drop.test.powerdns.com."), DropAction())
"""
Expand Down