forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdns.go
More file actions
58 lines (50 loc) · 1.7 KB
/
dns.go
File metadata and controls
58 lines (50 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package vpn
import "tailscale.com/net/dns"
func NewDNSConfigurator(t *Tunnel) dns.OSConfigurator {
return &dnsManager{tunnel: t}
}
type dnsManager struct {
tunnel *Tunnel
}
func (v *dnsManager) SetDNS(cfg dns.OSConfig) error {
settings := convertDNSConfig(cfg)
return v.tunnel.ApplyNetworkSettings(v.tunnel.ctx, &NetworkSettingsRequest{
DnsSettings: settings,
})
}
func (*dnsManager) GetBaseConfig() (dns.OSConfig, error) {
// Tailscale calls this function to blend the OS's DNS configuration with
// it's own, so this is only called if `SupportsSplitDNS` returns false.
return dns.OSConfig{}, dns.ErrGetBaseConfigNotSupported
}
func (*dnsManager) SupportsSplitDNS() bool {
// macOS & Windows 10+ support split DNS, so we'll assume all CoderVPN
// clients do too.
return true
}
// Close implements dns.OSConfigurator.
func (*dnsManager) Close() error {
// There's no cleanup that we need to initiate from within the dylib.
return nil
}
func convertDNSConfig(cfg dns.OSConfig) *NetworkSettingsRequest_DNSSettings {
servers := make([]string, 0, len(cfg.Nameservers))
for _, ns := range cfg.Nameservers {
servers = append(servers, ns.String())
}
searchDomains := make([]string, 0, len(cfg.SearchDomains))
for _, domain := range cfg.SearchDomains {
searchDomains = append(searchDomains, domain.WithoutTrailingDot())
}
matchDomains := make([]string, 0, len(cfg.MatchDomains))
for _, domain := range cfg.MatchDomains {
matchDomains = append(matchDomains, domain.WithoutTrailingDot())
}
return &NetworkSettingsRequest_DNSSettings{
Servers: servers,
SearchDomains: searchDomains,
DomainName: "coder",
MatchDomains: matchDomains,
MatchDomainsNoSearch: false,
}
}