net/dns: add GetBaseConfig to CallbackRouter.

Allow users of CallbackRouter to supply a GetBaseConfig
implementation. This is expected to be used on Android,
which currently lacks both a) platform support for
Split-DNS and b) a way to retrieve the current DNS
servers.

iOS/macOS also use the CallbackRouter but have platform
support for SplitDNS, so don't need getBaseConfig.

Updates https://github.com/tailscale/tailscale/issues/2116
Updates https://github.com/tailscale/tailscale/issues/988

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
This commit is contained in:
Denton Gentry
2021-10-09 12:17:59 -07:00
committed by Denton Gentry
parent a28d280b95
commit 878a20df29
4 changed files with 17 additions and 31 deletions

View File

@@ -18,6 +18,13 @@ type CallbackRouter struct {
SetBoth func(rcfg *Config, dcfg *dns.OSConfig) error
SplitDNS bool
// GetBaseConfigFunc optionally specifies a function to return the current DNS
// config in response to GetBaseConfig.
//
// If nil, reading the current config isn't supported and GetBaseConfig()
// will return ErrGetBaseConfigNotSupported.
GetBaseConfigFunc func() (dns.OSConfig, error)
mu sync.Mutex // protects all the following
rcfg *Config // last applied router config
dcfg *dns.OSConfig // last applied DNS config
@@ -50,7 +57,10 @@ func (r *CallbackRouter) SupportsSplitDNS() bool {
}
func (r *CallbackRouter) GetBaseConfig() (dns.OSConfig, error) {
return dns.OSConfig{}, dns.ErrGetBaseConfigNotSupported
if r.GetBaseConfigFunc == nil {
return dns.OSConfig{}, dns.ErrGetBaseConfigNotSupported
}
return r.GetBaseConfigFunc()
}
func (r *CallbackRouter) Close() error {