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

Implement a runtime changeable rule that matches IP address for a certain time #5336

Merged
merged 3 commits into from Jun 21, 2017

Conversation

@ahupowerdns
Copy link
Member

@ahupowerdns ahupowerdns commented May 23, 2017

This effectively allows (for example) pool selection from Lua, but then cached.

Sample code:

newServer({address="192.168.1.20", pool=""})
newServer({address="8.8.8.8", pool="elgoog"})

tisrElGoog=TimedIPSetRule()
tisrRest=TimedIPSetRule()
addAction(tisrElGoog:slice(), PoolAction("elgoog"))
addAction(tisrRest:slice(), PoolAction(""))

elgoogPeople=newNMG()
elgoogPeople:addMask("192.168.1.0/28")

function pickPool(dq)
	if(elgoogPeople:match(dq.remoteaddr)) -- in real life, this would be external
	then
		print("Lua caught query for a googlePerson")
		tisrElGoog:add(dq.remoteaddr, 10)
		return DNSAction.Pool, "elgoog"
	else
		print("Lua caught query for restPerson")
		tisrRest:add(dq.remoteaddr, 60)
		return DNSAction.None, ""
	end
end

addLuaAction(AllRule(), pickPool)

Short description

A new DNSRule that can be manipulated from Lua

Checklist

I have:

  • read the CONTRIBUTING.md document
  • compiled and tested this code
  • included documentation (including possible behaviour changes)
  • documented the code
  • added or modified regression test(s)
  • added or modified unit test(s)
  • checked that this code was merged to master
@ahupowerdns ahupowerdns requested a review from rgacogne May 23, 2017
Copy link
Member

@rgacogne rgacogne left a comment

Looks good. How about adding a cleanup() method that walks the maps to remove expired entries? It would be nice to be able to call that from maintenance() from time to time when we care.

@rgacogne
Copy link
Member

@rgacogne rgacogne commented May 23, 2017

Could use a bit of documentation, console completion support and tests :-)

@rgacogne rgacogne added this to the dnsdist-1.2.0 milestone May 23, 2017
@rgacogne
Copy link
Member

@rgacogne rgacogne commented Jun 21, 2017

Looks very good but needs to be rebased!

@ahupowerdns
Copy link
Member Author

@ahupowerdns ahupowerdns commented Jun 21, 2017

How does this PR compare to your dynamic rule based work @rgacogne ? Complete overlap? Or not? Is this PR still worth it? I think so, but would like to be sure we are not merging this PR because ahu wrote it.

@rgacogne
Copy link
Member

@rgacogne rgacogne commented Jun 21, 2017

The recent dynamic block changes allow different actions than just dropping, but it's clearly a lot more limited than what can be achieved with this PR!

ahupowerdns added 3 commits May 22, 2017
…tain time.

This effectively allows (for example) pool selection from Lua, but then cached.

Sample code:

```
newServer({address="192.168.1.20", pool=""})
newServer({address="8.8.8.8", pool="elgoog"})

tisrElGoog=TimedIPSetRule()
tisrRest=TimedIPSetRule()
addAction(tisrElGoog:slice(), PoolAction("elgoog"))
addAction(tisrRest:slice(), PoolAction(""))

elgoogPeople=newNMG()
elgoogPeople:addMask("192.168.1.0/28")

function pickPool(dq)
	if(elgoogPeople:match(dq.remoteaddr)) -- in real life, this would be external
	then
		print("Lua caught query for a googlePerson")
		tisrElGoog:add(dq.remoteaddr, 10)
		return DNSAction.Pool, "elgoog"
	else
		print("Lua caught query for restPerson")
		tisrRest:add(dq.remoteaddr, 60)
		return DNSAction.None, ""
	end
end

addLuaAction(AllRule(), pickPool)
```
@ahupowerdns ahupowerdns force-pushed the ahupowerdns:tisr branch from 501514c to 1c1b722 Jun 21, 2017
@ahupowerdns ahupowerdns merged commit 984c4d4 into PowerDNS:master Jun 21, 2017
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.