feat: DNS. Add the ability to disable version 6 address resolution (#240)

Co-authored-by: Andrey Semenov <semenov.ao@greendatasoft.ru>
This commit is contained in:
LiquidTheDangerous 2024-09-08 18:45:24 +05:00 committed by GitHub
parent 786d31cbb7
commit abd7441d0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 2 deletions

View File

@ -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,
}
}
@ -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)

View File

@ -13,6 +13,7 @@ type Args struct {
Port uint16
DnsAddr string
DnsPort uint16
DnsIPv4Only bool
EnableDoh bool
Debug bool
Silent bool
@ -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()

View File

@ -13,6 +13,7 @@ type Config struct {
Port int
DnsAddr string
DnsPort int
DnsIPv4Only bool
EnableDoh bool
Debug bool
Silent bool
@ -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