middleware/proxy: fix except keyword (#505)

Fix the except keyword usage - the config would allow it, but it was
not enforced in the code.
Turns out that **FROM** was also not enforced, fix both, by (basically)
copying the code from Caddy.

Update the README and tests.

Locally test as well, shows that this works:

~~~
.:1053 {
    proxy miek.nl 8.8.8.8:53 {
        except a.miek.nl
    }
    proxy a.miek.nl 8.8.4.4:53

    errors stdout
    log stdout
}
~~~

And gives the desired results, not having a proxy line for `a.miek.nl`
results in a SERVFAIL (as expected).

Fixes #502
This commit is contained in:
Miek Gieben
2017-02-07 18:01:16 +00:00
committed by GitHub
parent e8ebcd3cfd
commit dbe1b2510d
5 changed files with 43 additions and 16 deletions

View File

@@ -16,7 +16,7 @@ func NewLookup(hosts []string) Proxy {
p := Proxy{Next: nil}
upstream := &staticUpstream{
from: "",
from: ".",
Hosts: make([]*UpstreamHost, len(hosts)),
Policy: &Random{},
Spray: nil,
@@ -71,7 +71,11 @@ func (p Proxy) Forward(state request.Request) (*dns.Msg, error) {
}
func (p Proxy) lookup(state request.Request) (*dns.Msg, error) {
for _, upstream := range *p.Upstreams {
upstream := p.match(state)
if upstream == nil {
return nil, errInvalidDomain
}
for {
start := time.Now()
// Since Select() should give us "up" hosts, keep retrying
@@ -106,5 +110,4 @@ func (p Proxy) lookup(state request.Request) (*dns.Msg, error) {
}
return nil, errUnreachable
}
return nil, errUnreachable
}