feat: Add support for extra protocol tweaks

Adds support to set protocol tweaks like aa,ad,cd flags to be
set when preparing a dns.Message
cli
Karan Sharma 2022-07-03 11:31:33 +05:30
parent 18078cdb7c
commit 6c3b17ba0d
5 changed files with 31 additions and 8 deletions

View File

@ -48,6 +48,7 @@ func main() {
f.String("strategy", "all", "Strategy to query nameservers in resolv.conf file (`all`, `random`, `first`)")
f.String("tls-hostname", "", "Provide a hostname for doing verification of the certificate if the provided DoT nameserver is an IP")
f.Bool("skip-hostname-verification", false, "Skip TLS Hostname Verification")
f.StringSliceP("tweaks", "Z", []string{}, "Specify protocol tweaks. Set flags like aa,ad,cd")
// Output Options
f.BoolP("json", "J", false, "Set the output format as JSON")
@ -112,8 +113,7 @@ func main() {
app.Logger.WithError(err).Fatal("error loading nameservers")
}
// Load Resolvers.
rslvrs, err := resolvers.LoadResolvers(resolvers.Options{
ropts := resolvers.Options{
Nameservers: app.Nameservers,
UseIPv4: app.QueryFlags.UseIPv4,
UseIPv6: app.QueryFlags.UseIPv6,
@ -124,7 +124,19 @@ func main() {
Strategy: app.QueryFlags.Strategy,
InsecureSkipVerify: app.QueryFlags.InsecureSkipVerify,
TLSHostname: app.QueryFlags.TLSHostname,
})
}
if contains(app.QueryFlags.Tweaks, "aa") {
ropts.Authoritative = true
}
if contains(app.QueryFlags.Tweaks, "ad") {
ropts.AuthenticatedData = true
}
if contains(app.QueryFlags.Tweaks, "cd") {
ropts.CheckingDisabled = true
}
// Load Resolvers.
rslvrs, err := resolvers.LoadResolvers(ropts)
if err != nil {
app.Logger.WithError(err).Fatal("error loading resolver")
}

View File

@ -19,10 +19,10 @@ var appHelpTextTemplate = `{{ "NAME" | color "" "heading" }}:
{{.Version | color "red" "" }}
{{ "EXAMPLES" | color "" "heading" }}:
{{ .Name | color "green" "bold" }} {{ "mrkaran.dev" | color "cyan" "" }} Query a domain using defaults.
{{ .Name | color "green" "bold" }} {{ "mrkaran.dev CNAME" | color "cyan" "" }} Looks up for a CNAME record.
{{ .Name | color "green" "bold" }} {{ "mrkaran.dev MX @9.9.9.9" | color "cyan" "" }} Uses a custom DNS resolver.
{{ .Name | color "green" "bold" }} {{"-q mrkaran.dev -t MX -n 1.1.1.1" | color "yellow" ""}} Using named arguments.
{{ .Name | color "green" "bold" }} {{ "mrkaran.dev" | color "cyan" "" }} {{"\t"}} Query a domain using defaults.
{{ .Name | color "green" "bold" }} {{ "mrkaran.dev CNAME" | color "cyan" "" }} {{"\t"}} Looks up for a CNAME record.
{{ .Name | color "green" "bold" }} {{ "mrkaran.dev MX @9.9.9.9" | color "cyan" "" }} {{"\t"}} Uses a custom DNS resolver.
{{ .Name | color "green" "bold" }} {{"-q mrkaran.dev -t MX -n 1.1.1.1" | color "yellow" ""}} {{"\t"}} Using named arguments.
{{ "Free Form Arguments" | color "" "heading" }}:
Supply hostnames, query types, classes without any flag. For eg:

View File

@ -33,3 +33,13 @@ func loadUnparsedArgs(args []string) ([]string, []string, []string, []string) {
}
return ns, qt, qc, qn
}
// contains is a helper method to check if a paritcular element exists in the slice.
func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}

View File

@ -40,6 +40,7 @@ type QueryFlags struct {
InsecureSkipVerify bool `koanf:"skip-hostname-verification" skip-hostname-verification:"-"`
TLSHostname string `koanf:"tls-hostname" tls-hostname:"-"`
RetryCount int `koanf:"retry" retry:"-"`
Tweaks []string `koanf:"tweaks" json:"-"`
}
// Nameserver represents the type of Nameserver

View File

@ -24,7 +24,7 @@ func prepareMessages(q dns.Question, opts Options) []dns.Msg {
Authoritative: opts.Authoritative,
AuthenticatedData: opts.AuthenticatedData,
CheckingDisabled: opts.CheckingDisabled,
RecursionDesired: opts.RecursionDesired,
RecursionDesired: true,
},
}
// It's recommended to only send 1 question for 1 DNS message.