Allow rewriting of the the name of the query as well. And improve
the docs a little.
This commit is contained in:
parent
41d5d40a31
commit
e954332b9f
3 changed files with 24 additions and 7 deletions
|
@ -1,6 +1,10 @@
|
||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
)
|
||||||
|
|
||||||
// Name represents a domain name.
|
// Name represents a domain name.
|
||||||
type Name string
|
type Name string
|
||||||
|
@ -13,3 +17,8 @@ type Name string
|
||||||
func (n Name) Matches(other string) bool {
|
func (n Name) Matches(other string) bool {
|
||||||
return strings.HasSuffix(string(n), other)
|
return strings.HasSuffix(string(n), other)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normalize lowercases and makes n fully qualified.
|
||||||
|
func (n Name) Normalize() string {
|
||||||
|
return strings.ToLower(dns.Fqdn(string(n)))
|
||||||
|
}
|
||||||
|
|
|
@ -69,27 +69,31 @@ func NewSimpleRule(from, to string) SimpleRule {
|
||||||
// It's only a type if uppercase is used.
|
// It's only a type if uppercase is used.
|
||||||
if from != strings.ToUpper(from) {
|
if from != strings.ToUpper(from) {
|
||||||
tpf = 0
|
tpf = 0
|
||||||
|
from = middleware.Name(from).Normalize()
|
||||||
}
|
}
|
||||||
if to != strings.ToUpper(to) {
|
if to != strings.ToUpper(to) {
|
||||||
tpt = 0
|
tpt = 0
|
||||||
|
to = middleware.Name(to).Normalize()
|
||||||
}
|
}
|
||||||
|
|
||||||
// lowercase and fully qualify the others here? TODO(miek)
|
|
||||||
return SimpleRule{From: from, To: to, fromType: tpf, toType: tpt}
|
return SimpleRule{From: from, To: to, fromType: tpf, toType: tpt}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rewrite rewrites the the current request.
|
// Rewrite rewrites the the current request.
|
||||||
func (s SimpleRule) Rewrite(r *dns.Msg) Result {
|
func (s SimpleRule) Rewrite(r *dns.Msg) Result {
|
||||||
|
// type rewrite
|
||||||
if s.fromType > 0 && s.toType > 0 {
|
if s.fromType > 0 && s.toType > 0 {
|
||||||
if r.Question[0].Qtype == s.fromType {
|
if r.Question[0].Qtype == s.fromType {
|
||||||
r.Question[0].Qtype = s.toType
|
r.Question[0].Qtype = s.toType
|
||||||
return RewriteDone
|
return RewriteDone
|
||||||
}
|
}
|
||||||
|
return RewriteIgnored
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the question name matches the full name, or subset rewrite that
|
// name rewite
|
||||||
// s.Question[0].Name
|
if s.From == r.Question[0].Name {
|
||||||
|
r.Question[0].Name = s.To
|
||||||
|
return RewriteDone
|
||||||
|
}
|
||||||
return RewriteIgnored
|
return RewriteIgnored
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,13 @@ rewrite from to
|
||||||
If from *and* to look like a DNS type (`A`, `MX`, etc.) the type of the message will be rewriten,
|
If from *and* to look like a DNS type (`A`, `MX`, etc.) the type of the message will be rewriten,
|
||||||
i.e. to rewrite ANY queries to HINFO, use `rewrite ANY HINFO`.
|
i.e. to rewrite ANY queries to HINFO, use `rewrite ANY HINFO`.
|
||||||
|
|
||||||
If it does not look like a type a name is assumed and the qname in the message is rewritten.
|
If it does not look like a type a name is assumed and the qname in the message is rewritten, this
|
||||||
|
needs to be a full match of the name `rewrite miek.nl example.org`.
|
||||||
|
|
||||||
Advanced users may open a block and make a complex rewrite rule:
|
Advanced users may open a block and make a complex rewrite rule:
|
||||||
|
TODO(miek): this has not yet been implemented.
|
||||||
|
|
||||||
|
> Everything below this line has not been implemented, yet.
|
||||||
|
|
||||||
~~~
|
~~~
|
||||||
rewrite [basename] {
|
rewrite [basename] {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue