Files
sdns-proxy/cmd/resolver/main.go

95 lines
2.3 KiB
Go

package main
import (
"log"
"github.com/afonsofrancof/sdns-perf/internal/protocols/do53"
"github.com/afonsofrancof/sdns-perf/internal/protocols/doh"
"github.com/afonsofrancof/sdns-perf/internal/protocols/doq"
"github.com/afonsofrancof/sdns-perf/internal/protocols/dot"
"github.com/alecthomas/kong"
)
type CommonFlags struct {
DomainName string `help:"Domain name to resolve" arg:"" required:""`
QueryType string `help:"Query type" enum:"A,AAAA,MX,TXT,NS,CNAME,SOA,PTR" default:"A"`
Server string `help:"DNS server to use" required:""`
DNSSEC bool `help:"Enable DNSSEC validation"`
}
type DoHCmd struct {
CommonFlags `embed:""`
HTTP3 bool `help:"Use HTTP/3" name:"http3"`
Path string `help:"The HTTP path for the POST request" name:"path" required:""`
Proxy string `help:"The Proxy to use with ODoH"`
}
type DoTCmd struct {
CommonFlags
}
type DoQCmd struct {
CommonFlags
}
type Do53Cmd struct {
CommonFlags
}
var cli struct {
Verbose bool `help:"Enable verbose logging" short:"v"`
DoH DoHCmd `cmd:"doh" help:"Query using DNS-over-HTTPS" name:"doh"`
DoT DoTCmd `cmd:"dot" help:"Query using DNS-over-TLS" name:"dot"`
DoQ DoQCmd `cmd:"doq" help:"Query using DNS-over-QUIC" name:"doq"`
Do53 Do53Cmd `cmd:"doq" help:"Query using plain DNS over UDP" name:"do53"`
}
func (c *Do53Cmd) Run() error {
do53client, err := do53.New(c.Server)
if err != nil {
return err
}
return do53client.Query(c.DomainName, c.QueryType, c.Server, c.DNSSEC)
}
func (c *DoHCmd) Run() error {
dohclient, err := doh.New(c.Server, c.Path, c.Proxy)
if err != nil {
return err
}
return dohclient.Query(c.DomainName, c.QueryType, c.DNSSEC)
}
func (c *DoTCmd) Run() error {
dotclient, err := dot.New(c.Server)
if err != nil {
return err
}
return dotclient.Query(c.DomainName, c.QueryType, c.Server, c.DNSSEC)
}
func (c *DoQCmd) Run() error {
doqclient, err := doq.New(c.Server)
if err != nil {
return err
}
return doqclient.Query(c.DomainName, c.QueryType, c.DNSSEC)
}
func main() {
ctx := kong.Parse(&cli,
kong.Name("dns-go"),
kong.Description("A DNS resolver supporting DoH, DoT, and DoQ protocols"),
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
Compact: true,
Summary: true,
}))
err := ctx.Run()
if err != nil {
log.Fatalf("Error: %v", err)
}
}