Skip to content
1 change: 1 addition & 0 deletions plugin/enabled_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
_ "github.com/IrineSistiana/mosdns/v5/plugin/executable/debug_print"
_ "github.com/IrineSistiana/mosdns/v5/plugin/executable/drop_resp"
_ "github.com/IrineSistiana/mosdns/v5/plugin/executable/dual_selector"
_ "github.com/IrineSistiana/mosdns/v5/plugin/executable/ech"
_ "github.com/IrineSistiana/mosdns/v5/plugin/executable/ecs_handler"
_ "github.com/IrineSistiana/mosdns/v5/plugin/executable/forward"
_ "github.com/IrineSistiana/mosdns/v5/plugin/executable/forward_edns0opt"
Expand Down
41 changes: 41 additions & 0 deletions plugin/executable/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"errors"
"fmt"
"io"
"net"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -186,6 +187,46 @@ func (c *Cache) RegMetricsTo(r prometheus.Registerer) error {
return nil
}

func (c *Cache) GetIPByQName(qn string) []net.IP {
var ips []net.IP

m := dns.Msg{}
m.Opcode = dns.OpcodeQuery
m.Question = make([]dns.Question, 1)
m.Question[0].Qclass = dns.ClassINET

m.Question[0].Name = qn

for _, qt := range []uint16{dns.TypeA, dns.TypeAAAA} {
m.Question[0].Qtype = qt
for _, ad := range []bool{false, true} {
m.AuthenticatedData = ad
for _, cd := range []bool{false, true} {
m.CheckingDisabled = cd

msgKey := getMsgKey(&m)
if len(msgKey) == 0 {
continue
}
cr, _ := getRespFromCache(msgKey, c.backend, true, 0)
if cr == nil {
continue
}
for _, rr := range cr.Answer {
switch rr := rr.(type) {
case *dns.A:
ips = append(ips, rr.A)
case *dns.AAAA:
ips = append(ips, rr.AAAA)
}
}
}
}
}

return ips
}

func (c *Cache) Exec(ctx context.Context, qCtx *query_context.Context, next sequence.ChainWalker) error {
c.queryTotal.Inc()
q := qCtx.Q()
Expand Down
Loading