LookupStaticHostV4/V6 dereferenced h.hmap and h.inline as call arguments,
which are evaluated before lookupStaticHostFamily takes the read lock. The
reload path (readHosts) swaps h.hmap under h.Lock() on every reload, so the
field read raced the swap for every A/AAAA lookup. This was introduced when
wildcard support (#8185) refactored these methods to pass the maps as
parameters; LookupStaticAddr still reads the fields inside the lock and was
unaffected.
Read h.hmap/h.inline inside the RLock by selecting the address family with a
bool instead of passing pre-dereferenced maps.
Also read h.mtime under the existing RLock in readHosts: it was read without a
lock while the reload writes it under h.Lock(), and readHosts runs from both
the OnStartup handler and the reload ticker goroutine.
Both races are confirmed by go test -race.
Signed-off-by: Pavel Lazureykis <pavel@lazureykis.dev>
The host plugin kept on adding entries instead of overwriting. Split the
inline cache off from the /etc/hosts file cache and clear /etc/hosts
file cache and re-parsing.
A bunch of other cleanup as well. Use functions defined in the plugin
package, don't re-parse strings if you don't have to and use To4() to
check the family for IP addresses. Fix all test cases a carried entries
are always fqdn-ed. Various smaller cleanup in unnessacry constants.
Fixes: #3014
Signed-off-by: Miek Gieben <miek@miek.nl>
* plugin/hosts provide more configuration flexibility
This patch adds few features to the host plugin
* no-reverse (both as first argument on the plugin line and inline)
disable the automatic generation of reserve entries for hosts
* ttl <duration> (inline only atm)
allows to change the default ttl (default 5 minutes)
* reload <duration> (inline only atm)
allows to change the reloading interval (default 5s)
* plugin/hosts remove superfluous parameters to parse
* plugin/host: parse file without holding lock
Parse first and then swap the maps *while* holding the lock.
Signed-off-by: Miek Gieben <miek@miek.nl>
* add back in the parse function, but now purely for testing
Signed-off-by: Miek Gieben <miek@miek.nl>
This fix add inline support for middleware/hosts so that
it is possible to specify hosts file insides the Corefile:
```
hosts inline example.org {
10.0.0.1 example.org
fallthrough
}
```
This fix fixes 999.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
* Rename middleware to plugin
first pass; mostly used 'sed', few spots where I manually changed
text.
This still builds a coredns binary.
* fmt error
* Rename AddMiddleware to AddPlugin
* Readd AddMiddleware to remain backwards compat