Skip to content

Commit

Permalink
Add disableDNS option
Browse files Browse the repository at this point in the history
  • Loading branch information
kayrus committed Jul 15, 2020
1 parent 402dd58 commit 6f5bb7b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ ipv6: false
driver: wireguard
# When pppd driver is used, you can specify a list of extra pppd arguments
PPPdArgs: []
# disableDNS allows to completely disable DNS handling,
# i.e. don't alter the /etc/resolv.conf file at all
disableDNS: false
# a list of DNS zones to be resolved by VPN DNS servers
# when empty, every DNS query will be resolved by VPN DNS servers
dns:
Expand Down
10 changes: 6 additions & 4 deletions pkg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,12 @@ func readConfig() (*Config, error) {
return nil, fmt.Errorf("%q driver is unsupported, supported drivers are: %q", config.Driver, supportedDrivers)
}

// read current resolv.conf
config.resolvConf, err = ioutil.ReadFile(resolvPath)
if err != nil {
return nil, fmt.Errorf("cannot read %s: %s", resolvPath, err)
if !config.DisableDNS {
// read current resolv.conf
config.resolvConf, err = ioutil.ReadFile(resolvPath)
if err != nil {
return nil, fmt.Errorf("cannot read %s: %s", resolvPath, err)
}
}

if len(config.DNSServers) == 0 {
Expand Down
20 changes: 12 additions & 8 deletions pkg/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,16 @@ func (l *vpnLink) waitAndConfig(config *Config) {
l.Lock()
defer l.Unlock()

// define DNS servers, provided by F5
log.Printf("Setting %s", resolvPath)
if err = configureDNS(config); err != nil {
l.errChan <- err
}
if !config.DisableDNS {
// define DNS servers, provided by F5
log.Printf("Setting %s", resolvPath)
if err = configureDNS(config); err != nil {
l.errChan <- err
}

if len(config.DNS) > 0 {
startDNS(l, config)
if len(config.DNS) > 0 {
startDNS(l, config)
}
}

// set routes
Expand Down Expand Up @@ -321,7 +323,9 @@ func (l *vpnLink) restoreConfig(config *Config) {
}
}()

restoreDNS(config)
if !config.DisableDNS {
restoreDNS(config)
}

if l.serverRoutesReady {
// remove F5 gateway route
Expand Down
2 changes: 2 additions & 0 deletions pkg/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ type Config struct {
InsecureTLS bool `yaml:"insecureTLS"`
DTLS bool `yaml:"dtls"`
IPv6 bool `yaml:"ipv6"`
// completely disable DNS servers handling
DisableDNS bool `yaml:"disableDNS"`
// list of DNS local servers
// when list is empty, parsed from /etc/resolv.conf
DNSServers []net.IP `yaml:"-"`
Expand Down

0 comments on commit 6f5bb7b

Please sign in to comment.