2023-10-01 20:43:10 +00:00
|
|
|
package pancheri
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Resolver struct {
|
|
|
|
client *dns.Client
|
|
|
|
upstream string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewResolver(upstream string) *Resolver {
|
|
|
|
return &Resolver{
|
|
|
|
client: new(dns.Client),
|
|
|
|
upstream: upstream,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-03 01:59:37 +00:00
|
|
|
func (r *Resolver) Resolve(domain string, qtype uint16) (*dns.Msg, error) {
|
2023-10-01 20:43:10 +00:00
|
|
|
logrus.WithFields(logrus.Fields{
|
|
|
|
"domain": domain,
|
|
|
|
"qtype": qtype,
|
|
|
|
}).Trace("performing upstream resolution")
|
|
|
|
|
|
|
|
m := new(dns.Msg)
|
|
|
|
m.SetQuestion(dns.Fqdn(domain), qtype)
|
|
|
|
m.RecursionDesired = true
|
|
|
|
|
|
|
|
in, _, err := r.client.Exchange(m, r.upstream)
|
|
|
|
|
|
|
|
if err != nil {
|
2023-10-01 21:54:22 +00:00
|
|
|
return nil, err
|
2023-10-01 20:43:10 +00:00
|
|
|
}
|
|
|
|
|
2023-10-03 01:59:37 +00:00
|
|
|
return in, nil
|
2023-10-01 20:43:10 +00:00
|
|
|
}
|