mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-21 22:06:33 +00:00
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:
parent
786d31cbb7
commit
abd7441d0a
11
dns/dns.go
11
dns/dns.go
@ -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)
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user