Fix: DNS query log

This commit is contained in:
JimhHan 2021-03-19 22:01:39 +08:00
parent 9b93b90fa9
commit 41d3f31447
No known key found for this signature in database
GPG key ID: 48D5D7CF95157AC5
5 changed files with 10 additions and 29 deletions

View file

@ -89,14 +89,10 @@ func (d *DefaultSystemDialer) lookupIP(domain string, strategy DomainStrategy, l
return d.dns.LookupIP(domain, option)
}
func (d *DefaultSystemDialer) canLookupIP(ctx context.Context, dst net.Destination, sockopt *SocketConfig) bool {
func (d *DefaultSystemDialer) doLookupIP(ctx context.Context, dst net.Destination, sockopt *SocketConfig) bool {
if sockopt == nil || dst.Address.Family().IsIP() || d.dns == nil {
return false
}
if dst.Address.Domain() == LookupDomainFromContext(ctx) {
newError("infinite loop detected").AtError().WriteToLog(session.ExportIDToError(ctx))
return false
}
return sockopt.DomainStrategy != DomainStrategy_AS_IS
}
@ -128,7 +124,7 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
}
}
if d.canLookupIP(ctx, dest, sockopt) {
if d.doLookupIP(ctx, dest, sockopt) {
ips, err := d.lookupIP(dest.Address.String(), sockopt.DomainStrategy, src)
if err == nil && len(ips) > 0 {
dest.Address = net.IPAddress(ips[dice.Roll(len(ips))])

View file

@ -1,18 +0,0 @@
package internet
import "context"
type systemDialer int
const systemDialerKey systemDialer = 0
func ContextWithLookupDomain(ctx context.Context, domain string) context.Context {
return context.WithValue(ctx, systemDialerKey, domain)
}
func LookupDomainFromContext(ctx context.Context) string {
if domain, ok := ctx.Value(systemDialerKey).(string); ok {
return domain
}
return ""
}