- clients: fix incorrect info for clients from /etc/hosts
Close #1786 Squashed commit of the following: commit fc662252be38f20c9afda46fcb578efa50c9baf2 Author: Simon Zolin <s.zolin@adguard.com> Date: Thu Jun 11 10:57:26 2020 +0300 - clients: fix incorrect info for clients from /etc/hosts
This commit is contained in:
parent
cf087fb8ff
commit
1356ac2633
|
@ -612,15 +612,13 @@ func (clients *clientsContainer) addFromHostsFile() {
|
||||||
_ = clients.rmHosts(ClientSourceHostsFile)
|
_ = clients.rmHosts(ClientSourceHostsFile)
|
||||||
|
|
||||||
n := 0
|
n := 0
|
||||||
for ip, names := range hosts {
|
for ip, name := range hosts {
|
||||||
for _, name := range names {
|
ok, err := clients.addHost(ip, name, ClientSourceHostsFile)
|
||||||
ok, err := clients.addHost(ip, name.String(), ClientSourceHostsFile)
|
if err != nil {
|
||||||
if err != nil {
|
log.Debug("Clients: %s", err)
|
||||||
log.Debug("Clients: %s", err)
|
}
|
||||||
}
|
if ok {
|
||||||
if ok {
|
n++
|
||||||
n++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -371,11 +371,11 @@ func (a *AutoHosts) ProcessReverse(addr string, qtype uint16) string {
|
||||||
return host
|
return host
|
||||||
}
|
}
|
||||||
|
|
||||||
// List - get the hosts table. Thread-safe.
|
// List - get "IP -> hostname" table. Thread-safe.
|
||||||
func (a *AutoHosts) List() map[string][]net.IP {
|
func (a *AutoHosts) List() map[string]string {
|
||||||
table := make(map[string][]net.IP)
|
table := make(map[string]string)
|
||||||
a.lock.Lock()
|
a.lock.Lock()
|
||||||
for k, v := range a.table {
|
for k, v := range a.tableReverse {
|
||||||
table[k] = v
|
table[k] = v
|
||||||
}
|
}
|
||||||
a.lock.Unlock()
|
a.lock.Unlock()
|
||||||
|
|
|
@ -49,10 +49,9 @@ func TestAutoHostsResolution(t *testing.T) {
|
||||||
|
|
||||||
// Test hosts file
|
// Test hosts file
|
||||||
table := ah.List()
|
table := ah.List()
|
||||||
ips, _ = table["host"]
|
name, ok := table["127.0.0.1"]
|
||||||
assert.NotNil(t, ips)
|
assert.True(t, ok)
|
||||||
assert.Equal(t, 1, len(ips))
|
assert.Equal(t, "host", name)
|
||||||
assert.Equal(t, "127.0.0.1", ips[0].String())
|
|
||||||
|
|
||||||
// Test PTR
|
// Test PTR
|
||||||
a, _ := dns.ReverseAddr("127.0.0.1")
|
a, _ := dns.ReverseAddr("127.0.0.1")
|
||||||
|
|
Loading…
Reference in New Issue