cloak plugin: return multiple the entire set of IPv4 or IPv6 addresses

Fixes #1547
This commit is contained in:
Frank Denis 2020-12-17 09:47:44 +01:00
parent a8a0677ea9
commit c4d9860577
1 changed files with 15 additions and 23 deletions

View File

@ -147,33 +147,25 @@ func (plugin *PluginCloak) Eval(pluginsState *PluginsState, msg *dns.Msg) error
plugin.Unlock() plugin.Unlock()
plugin.RLock() plugin.RLock()
} }
var ip *net.IP
if question.Qtype == dns.TypeA {
ipLen := len(cloakedName.ipv4)
if ipLen > 0 {
ip = &cloakedName.ipv4[rand.Intn(ipLen)]
}
} else {
ipLen := len(cloakedName.ipv6)
if ipLen > 0 {
ip = &cloakedName.ipv6[rand.Intn(ipLen)]
}
}
plugin.RUnlock() plugin.RUnlock()
synth := EmptyResponseFromMessage(msg) synth := EmptyResponseFromMessage(msg)
if ip == nil { synth.Answer = []dns.RR{}
synth.Answer = []dns.RR{} if question.Qtype == dns.TypeA {
} else if question.Qtype == dns.TypeA { for _, ip := range cloakedName.ipv4 {
rr := new(dns.A) rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: ttl} rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: ttl}
rr.A = *ip rr.A = ip
synth.Answer = []dns.RR{rr} synth.Answer = append(synth.Answer, rr)
}
} else { } else {
rr := new(dns.AAAA) for _, ip := range cloakedName.ipv6 {
rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: ttl} rr := new(dns.AAAA)
rr.AAAA = *ip rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: ttl}
synth.Answer = []dns.RR{rr} rr.AAAA = ip
synth.Answer = append(synth.Answer, rr)
}
} }
rand.Shuffle(len(synth.Answer), func(i, j int) { synth.Answer[i], synth.Answer[j] = synth.Answer[j], synth.Answer[i] })
pluginsState.synthResponse = synth pluginsState.synthResponse = synth
pluginsState.action = PluginsActionSynth pluginsState.action = PluginsActionSynth
pluginsState.returnCode = PluginsReturnCodeCloak pluginsState.returnCode = PluginsReturnCodeCloak