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

Open
nkeonkeo opened this issue Oct 21, 2021 · 8 comments
Open

proposal: net: customize dnsConfig #49096

nkeonkeo opened this issue Oct 21, 2021 · 8 comments

Comments

@nkeonkeo
Copy link

@nkeonkeo nkeonkeo commented Oct 21, 2021

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
Contributor

@cherrymui cherrymui commented Oct 21, 2021

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

Loading

@nkeonkeo
Copy link
Author

@nkeonkeo nkeonkeo commented Oct 22, 2021

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()
	}
	...
}

Loading

@cherrymui cherrymui changed the title net: customize dnsConfig proposal: net: customize dnsConfig Oct 25, 2021
@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Oct 25, 2021

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.

Loading

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

@nkeonkeo nkeonkeo commented Oct 25, 2021

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!

Loading

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor 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?

Loading

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

@rsc 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?

Loading

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

@rsc 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

Loading

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

@rsc rsc commented Nov 10, 2021

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

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Proposals
Likely Decline
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants