Skip to content

Commit

Permalink
feat: DNS. Add the ability to disable version 6 address resolution (#240
Browse files Browse the repository at this point in the history
)

Co-authored-by: Andrey Semenov <[email protected]>
  • Loading branch information
LiquidTheDangerous and Andrey Semenov authored Sep 8, 2024
1 parent 786d31c commit abd7441
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,25 @@ type Dns struct {
systemClient Resolver
generalClient Resolver
dohClient Resolver
qTypes []uint16
}

func NewDns(config *util.Config) *Dns {
addr := config.DnsAddr
port := strconv.Itoa(config.DnsPort)

var qTypes []uint16
if config.DnsIPv4Only {
qTypes = []uint16{dns.TypeA}
} else {
qTypes = []uint16{dns.TypeAAAA, dns.TypeA}
}
return &Dns{
host: config.DnsAddr,
port: port,
systemClient: resolver.NewSystemResolver(),
generalClient: resolver.NewGeneralResolver(net.JoinHostPort(addr, port)),
dohClient: resolver.NewDOHResolver(addr),
qTypes: qTypes,
}
}

Expand All @@ -57,7 +64,7 @@ func (d *Dns) ResolveHost(ctx context.Context, host string, enableDoh bool, useS

t := time.Now()

addrs, err := clt.Resolve(ctx, host, []uint16{dns.TypeAAAA, dns.TypeA})
addrs, err := clt.Resolve(ctx, host, d.qTypes)
// addrs, err := clt.Resolve(ctx, host, []uint16{dns.TypeAAAA})
if err != nil {
return "", fmt.Errorf("%s: %w", clt, err)
Expand Down
2 changes: 2 additions & 0 deletions util/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Args struct {
Port uint16
DnsAddr string
DnsPort uint16
DnsIPv4Only bool
EnableDoh bool
Debug bool
Silent bool
Expand Down Expand Up @@ -57,6 +58,7 @@ fragmentation for the first data packet and the rest
"pattern",
"bypass DPI only on packets matching this regex pattern; can be given multiple times",
)
flag.BoolVar(&args.DnsIPv4Only, "dns-ipv4-only", false, "resolve only version 4 addresses")

flag.Parse()

Expand Down
2 changes: 2 additions & 0 deletions util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Config struct {
Port int
DnsAddr string
DnsPort int
DnsIPv4Only bool
EnableDoh bool
Debug bool
Silent bool
Expand All @@ -36,6 +37,7 @@ func (c *Config) Load(args *Args) {
c.Port = int(args.Port)
c.DnsAddr = args.DnsAddr
c.DnsPort = int(args.DnsPort)
c.DnsIPv4Only = args.DnsIPv4Only
c.Debug = args.Debug
c.EnableDoh = args.EnableDoh
c.Silent = args.Silent
Expand Down

0 comments on commit abd7441

Please sign in to comment.