Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: net: customize dnsConfig #49096

Closed
nkeonkeo opened this issue Oct 21, 2021 · 9 comments
Closed

proposal: net: customize dnsConfig #49096

nkeonkeo opened this issue Oct 21, 2021 · 9 comments

Comments

@nkeonkeo
Copy link

dnsConfig currently reflects the contents of /etc/resolv.conf, and reread regularly.

I hope can customize dnsConfig , and only once.

It should be helpful. Thanks very much!

@cherrymui
Copy link
Member

Could you provide some detail about what you want to customize and how? A code example would be good. Thanks.

@cherrymui cherrymui added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 21, 2021
@nkeonkeo
Copy link
Author

net/lookup.go:119

add dnsConfig

type Resolver struct {
	// PreferGo controls whether Go's built-in DNS resolver is preferred
	// on platforms where it's available. It is equivalent to setting
	// GODEBUG=netdns=go, but scoped to just this resolver.
	PreferGo bool

	// StrictErrors controls the behavior of temporary errors
	// (including timeout, socket errors, and SERVFAIL) when using
	// Go's built-in resolver. For a query composed of multiple
	// sub-queries (such as an A+AAAA address lookup, or walking the
	// DNS search list), this option causes such errors to abort the
	// whole query instead of returning a partial result. This is
	// not enabled by default because it may affect compatibility
	// with resolvers that process AAAA queries incorrectly.
	StrictErrors bool

	// Dial optionally specifies an alternate dialer for use by
	// Go's built-in DNS resolver to make TCP and UDP connections
	// to DNS services. The host in the address parameter will
	// always be a literal IP address and not a host name, and the
	// port in the address parameter will be a literal port number
	// and not a service name.
	// If the Conn returned is also a PacketConn, sent and received DNS
	// messages must adhere to RFC 1035 section 4.2.1, "UDP usage".
	// Otherwise, DNS messages transmitted over Conn must adhere
	// to RFC 7766 section 5, "Transport Protocol Selection".
	// If nil, the default dialer is used.
	Dial func(ctx context.Context, network, address string) (Conn, error)

	// lookupGroup merges LookupIPAddr calls together for lookups for the same
	// host. The lookupGroup key is the LookupIPAddr.host argument.
	// The return values are ([]IPAddr, error).
	lookupGroup singleflight.Group

	// TODO(bradfitz): optional interface impl override hook
	// TODO(bradfitz): Timeout time.Duration?
	
	
	// add dnsConfig	
	DnsConfig *dnsConfig
}

net/dnsclient_unix.go:567

try to read dnsConfig of the resolver

func (r *Resolver) goLookupIPCNAMEOrder(ctx context.Context, network, name string, order hostLookupOrder) (addrs []IPAddr, cname dnsmessage.Name, err error) {
	if order == hostLookupFilesDNS || order == hostLookupFiles {
		addrs = goLookupIPFiles(name)
		if len(addrs) > 0 || order == hostLookupFiles {
			return addrs, dnsmessage.Name{}, nil
		}
	}
	if !isDomainName(name) {
		// See comment in func lookup above about use of errNoSuchHost.
		return nil, dnsmessage.Name{}, &DNSError{Err: errNoSuchHost.Error(), Name: name, IsNotFound: true}
	}
	
	// try to read dnsConfig of the resolver
	var conf *dnsConfig
	if r.DnsConfig != nil {
		conf = r.DnsConfig
	} else {
		resolvConf.tryUpdate("/etc/resolv.conf")
		resolvConf.mu.RLock()
		conf = resolvConf.dnsConfig
		resolvConf.mu.RUnlock()
	}
	...
}

@cherrymui cherrymui removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 25, 2021
@cherrymui cherrymui changed the title net: customize dnsConfig proposal: net: customize dnsConfig Oct 25, 2021
@cherrymui
Copy link
Member

I guess you also need some API to set up the DnsConfig (as the type is unexported)?

Changing to a proposal as this adds new API.

@gopherbot gopherbot added this to the Proposal milestone Oct 25, 2021
@nkeonkeo
Copy link
Author

I guess you also need some API to set up the DnsConfig (as the type is unexported)?

Changing to a proposal as this adds new API.

Yes! Thank you very much!

@ianlancetaylor
Copy link
Contributor

ianlancetaylor commented Oct 25, 2021

Note that the dnsConfig type only exists on Unix, it does not exist on Windows or Plan 9.

I think that in order to understand this proposal we need a complete description of all the API change involved. Simply adding a DNSConfig field to Resolver won't help at all. So what do we need?

@ianlancetaylor ianlancetaylor added this to Incoming in Proposals (old) Oct 25, 2021
@rsc
Copy link
Contributor

rsc commented Nov 3, 2021

We clearly can't add a new exported field of an unexported, os-specific type.
What would you use the DNS config for?

It seems like maybe using https://github.com/miekg/dns would be more appropriate in this case?

@rsc rsc moved this from Incoming to Active in Proposals (old) Nov 3, 2021
@rsc
Copy link
Contributor

rsc commented Nov 3, 2021

This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group

@rsc rsc moved this from Active to Likely Decline in Proposals (old) Nov 10, 2021
@rsc
Copy link
Contributor

rsc commented Nov 10, 2021

Based on the discussion above, this proposal seems like a likely decline.
— rsc for the proposal review group

@rsc rsc moved this from Likely Decline to Declined in Proposals (old) Dec 1, 2021
@rsc
Copy link
Contributor

rsc commented Dec 1, 2021

No change in consensus, so declined.
— rsc for the proposal review group

@rsc rsc closed this as completed Dec 1, 2021
@golang golang locked and limited conversation to collaborators Dec 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

No branches or pull requests

5 participants