Pull request: all: do not use dhcp clients when server is off

Closes #2934.

Squashed commit of the following:

commit 856ea4ec0c3ffb1da447b93260da90d37cd5d45d
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Apr 15 17:39:46 2021 +0300

    dnsforward: imp spacing

commit fa748e5a26cb6a38b5f87c5498287cb734ce7a59
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Apr 15 17:33:44 2021 +0300

    dnsforward: imp code

commit 771ba0de449faffff1cea523e8bbcc1039c992db
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Apr 15 17:06:03 2021 +0300

    all: do not use dhcp clients when server is off
This commit is contained in:
Ainar Garipov
2021-04-15 17:52:53 +03:00
parent b0013065a2
commit a1450c5595
8 changed files with 131 additions and 68 deletions

View File

@@ -43,6 +43,15 @@ var defaultBlockedHosts = []string{"version.bind", "id.server", "hostname.bind"}
var webRegistered bool
// hostToIPTable is an alias for the type of Server.tableHostToIP.
type hostToIPTable = map[string]net.IP
// ipToHostTable is an alias for the type of Server.tableIPToHost.
//
// TODO(a.garipov): Define an IPMap type in aghnet and use here and in other
// places?
type ipToHostTable = map[string]string
// Server is the main way to start a DNS server.
//
// Example:
@@ -69,11 +78,11 @@ type Server struct {
subnetDetector *aghnet.SubnetDetector
localResolvers *proxy.Proxy
tableHostToIP map[string]net.IP // "hostname -> IP" table for internal addresses (DHCP)
tableHostToIP hostToIPTable
tableHostToIPLock sync.Mutex
tablePTR map[string]string // "IP -> hostname" table for reverse lookup
tablePTRLock sync.Mutex
tableIPToHost ipToHostTable
tableIPToHostLock sync.Mutex
// DNS proxy instance for internal usage
// We don't Start() it and so no listen port is required.