refactor of query.go #27
3 changed files with 39 additions and 1 deletions
35
query.go
35
query.go
|
@ -20,6 +20,7 @@ func doQuery(c *cli.Context) error {
|
|||
var (
|
||||
err error
|
||||
)
|
||||
// load cli flags into options struct
|
||||
Options := query.Options{
|
||||
Logger: util.InitLogger(c.Bool("debug")),
|
||||
Port: c.Int("port"),
|
||||
|
@ -60,6 +61,40 @@ func doQuery(c *cli.Context) error {
|
|||
Options.Port = 53
|
||||
}
|
||||
}
|
||||
Options.Logger.Debug("setting any message flags")
|
||||
// Make this authoritative (does this do anything?)
|
||||
if Options.AA {
|
||||
Options.Logger.Debug("making message authorative")
|
||||
msg.Authoritative = true
|
||||
}
|
||||
// Set truncated flag (why)
|
||||
if Options.TC {
|
||||
msg.Truncated = true
|
||||
}
|
||||
// Set the zero flag if requested (does nothing)
|
||||
if Options.Z {
|
||||
Options.Logger.Debug("setting to zero")
|
||||
msg.Zero = true
|
||||
}
|
||||
// Disable DNSSEC validation
|
||||
if Options.CD {
|
||||
Options.Logger.Debug("disabling DNSSEC validation")
|
||||
msg.CheckingDisabled = true
|
||||
}
|
||||
// Disable wanting recursion
|
||||
if Options.NoRD {
|
||||
Options.Logger.Debug("disabling recursion")
|
||||
msg.RecursionDesired = false
|
||||
}
|
||||
// Disable recursion being available (I don't think this does anything)
|
||||
if Options.NoRA {
|
||||
msg.RecursionAvailable = false
|
||||
}
|
||||
// Set DNSSEC if requested
|
||||
if Options.DNSSEC {
|
||||
Options.Logger.Debug("using DNSSEC")
|
||||
msg.SetEdns0(1232, true)
|
||||
}
|
||||
|
||||
resolver, err := query.LoadResolver(Options.Answers.Server, Options)
|
||||
if err != nil {
|
||||
|
|
|
@ -21,7 +21,7 @@ func (r *QUICResolver) LookUp(msg *dns.Msg) (*dns.Msg, time.Duration, error) {
|
|||
tls := &tls.Config{
|
||||
NextProtos: []string{"doq"},
|
||||
}
|
||||
|
||||
r.opts.Logger.Debug("making DoQ request")
|
||||
connection, err := quic.DialAddr(r.server, tls, nil)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
|
@ -60,6 +60,7 @@ func (r *QUICResolver) LookUp(msg *dns.Msg) (*dns.Msg, time.Duration, error) {
|
|||
}
|
||||
|
||||
resp.DNS = dns.Msg{}
|
||||
r.opts.Logger.Debug("unpacking DoQ response")
|
||||
err = resp.DNS.Unpack(fullRes)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
|
|
|
@ -55,6 +55,7 @@ type Resolver interface {
|
|||
|
||||
func LoadResolver(server string, opts Options) (Resolver, error) {
|
||||
if opts.HTTPS {
|
||||
opts.Logger.Debug("loading DoH resolver")
|
||||
if !strings.HasPrefix(server, "https://") {
|
||||
server = "https://" + server
|
||||
}
|
||||
|
@ -63,6 +64,7 @@ func LoadResolver(server string, opts Options) (Resolver, error) {
|
|||
opts: opts,
|
||||
}, nil
|
||||
} else if opts.QUIC {
|
||||
opts.Logger.Debug("loading DoQ resolver")
|
||||
server = net.JoinHostPort(opts.Answers.Server, strconv.Itoa(opts.Port))
|
||||
return &QUICResolver{
|
||||
server: server,
|
||||
|
|
Loading…
Reference in a new issue