Cleanup docs and the chaos middleware

Make the CH middleware actually work. Needs a bit of a hack to route

the fake version.bind and friends zone to the correct handler. Fiddle

with the order in directive.go so that CH queries get logged as well.



Secondly add class rewriting to the rewrite middleware handler and also

log the class by default.
This commit is contained in:
Miek Gieben
2016-04-04 15:45:17 +01:00
parent 45ac2dd0c0
commit 6445a3f2f0
10 changed files with 60 additions and 20 deletions

View File

@@ -58,24 +58,29 @@ type Rule interface {
// the type of the request is rewritten, otherwise the name is.
// Note: TSIG signed requests will be invalid.
type SimpleRule struct {
From, To string
fromType, toType uint16
From, To string
fromType, toType uint16
fromClass, toClass uint16
}
// NewSimpleRule creates a new Simple Rule
func NewSimpleRule(from, to string) SimpleRule {
tpf := dns.StringToType[from]
tpt := dns.StringToType[to]
// It's only a type if uppercase is used.
clf := dns.StringToClass[from]
clt := dns.StringToClass[to]
// It's only a type/class if uppercase is used.
if from != strings.ToUpper(from) {
tpf = 0
clf = 0
from = middleware.Name(from).Normalize()
}
if to != strings.ToUpper(to) {
tpt = 0
clt = 0
to = middleware.Name(to).Normalize()
}
return SimpleRule{From: from, To: to, fromType: tpf, toType: tpt}
return SimpleRule{From: from, To: to, fromType: tpf, toType: tpt, fromClass: clf, toClass: clt}
}
// Rewrite rewrites the the current request.
@@ -89,6 +94,15 @@ func (s SimpleRule) Rewrite(r *dns.Msg) Result {
return RewriteIgnored
}
// class rewrite
if s.fromClass > 0 && s.toClass > 0 {
if r.Question[0].Qclass == s.fromClass {
r.Question[0].Qclass = s.toClass
return RewriteDone
}
return RewriteIgnored
}
// name rewite
if s.From == r.Question[0].Name {
r.Question[0].Name = s.To