Commit graph

658 commits

Author SHA1 Message Date
Miek Gieben
92a636df53 plugin/file: z.Expired needs be read under a rlock (#3056)
Read lock before reading the Expired field of a zone.

Fixes: #3053

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-07-27 08:06:50 -07:00
Miek Gieben
7a3371d740
plugin/file: allow README.md testing (#3052)
* Fix corefile usage

* plugin/file: allow README.md testing

Allow readme testing for the file plugin and fix bugs that where found:

* the reader wasn't reset when re-reading the same io.reader for a
  different origin.

Signed-off-by: Miek Gieben <miek@miek.nl>

* Update test/example_test.go

Co-Authored-By: Michael Grosser <development@stp-ip.net>
2019-07-27 11:47:55 +00:00
Miek Gieben
89fa9bc61e plugin/host: don't append the names when reparsing hosts file (#3045)
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>
2019-07-25 11:53:07 -07:00
Erfan Besharat
048987fca5 plugin/file: Add SOA serial to axfr log (#3042) 2019-07-24 17:39:07 +00:00
Miek Gieben
eba020e6a1
plugin/file: simplify locking (#3024)
* plugin/file: simplify locking

Simplify the locking, remove the reloadMu and just piggyback on the
other lock for accessing content, which assumes things can be move
underneath.

Copy the Apex and Zone to new vars to make sure the pointer isn't
updated from under us.

The releadMu isn't need at all, the time.Ticker firing while we're
reading means we will just miss that tick and get it on the next go.

Add rrutil subpackage and put some more generic functions in there, that
are now used from file and the tree package. This removes some
duplication.

Rename additionalProcessing that didn't actually do that to
externalLookup, because that's what being done at some point.

Signed-off-by: Miek Gieben <miek@miek.nl>

* Update plugin/file/lookup.go

Co-Authored-By: Michael Grosser <development@stp-ip.net>
2019-07-23 18:32:44 +00:00
Mat Lowery
dae6aea292 Fix response_rcode_count_total metric (#3029) 2019-07-23 06:23:16 +00:00
Miek Gieben
01e13c622e plugin/file: New zone should have zero records (#3025)
After calling NewZone the number of records should be zero, but due to
how zone.All() was implemented so empty RRs would be added. This then
fails the == 0 check in xfr.go and put nil in the slice, this then
subsequently panics on the Len().

Fix this making All() smarter when adding records. Added little test to
enfore this.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-07-20 11:13:43 -07:00
Charlie Vieth
031dfede90 pkg/cache: fix race in Add() and Evict() (#3013)
* pkg/cache: fix race in Add() and Evict()

This fixes a race in Add() when the shard is at max capacity and the key
being added is already stored.  Previously, the shard would evict a
random value - when all it needed to do was replace an existing value.
There was a race in how Evict() picked which key to remove, which would
cause concurrent calls to Evict() to remove the same key.

Additionally, this commit removes a lot of the lock contention and a
race around Add() and Evict() by changing them to immediately hold the
write lock.  Previously, they would check conditions with the read lock
held and not re-check those conditions once the write lock was acquired
(this is a race).

* pkg/cache: code review comments

* pkg/cache: simplify Add() logic
2019-07-19 09:19:03 +00:00
Christian Muehlhaeuser
c928dbd754 Added comment why ominous assignment is required (#3021) 2019-07-19 06:31:29 +00:00
Miek Gieben
1d5095cf67
plugin/file: Rename do to walk and cleanup and document (#2987)
* plugin/file: Rename do to walk, cleanup and document

* This renames Do to Walk to be more inline with Go standards. Also make
  it return an error instead of a bool.
  Also give give walk access to rrs. Alternatively e.m could be
  exported, but just access the map of rrs should work as well. Another
  alternative would be adding a whole bunch of helper functions, but
  those need grab and return the data. Just having access to the rrs
  should be easiest for most Walks.
* It adds Type and TypeForWildcard to show the different functions
* *Removes* the identical RR check when inserting; this was only done
  for A, AAAA and MX and not finished; removed under the mantra garbage
  in garbage out.
* Reuses Types to return all the types in an *tree.Elem

Signed-off-by: Miek Gieben <miek@miek.nl>

* better comments

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-07-18 17:44:47 +00:00
Miek Gieben
6c9a599761
plugin/file: fix setting ReloadInterval (#3017)
* plugin/file: fix setting ReloadInterval

The reload interval was only correctly set if there was an extra
block for the file. Move this down to set up.

Add test case that fails before, but now works.

Signed-off-by: Miek Gieben <miek@miek.nl>

* layout and use Errorf

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-07-18 14:56:59 +00:00
Miek Gieben
eefe49dd3e plugin/route53: small doc cleanups (#3016)
Adjust style to rest fo the plugins.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-07-17 13:40:15 -07:00
Charlie Vieth
a2af651ecb replacer: evaluate format once and improve perf by ~3x (#3002)
* replacer: evaluate format once and improve perf by ~3x

This improves the performance of logging by almost 3x and reduces memory
usage by ~8x.

Benchmark results:

benchmark                                old ns/op     new ns/op     delta
BenchmarkReplacer-12                     644           324           -49.69%
BenchmarkReplacer_CommonLogFormat-12     4228          1471          -65.21%

benchmark                                old allocs     new allocs     delta
BenchmarkReplacer-12                     8              2              -75.00%
BenchmarkReplacer_CommonLogFormat-12     51             17             -66.67%

benchmark                                old bytes     new bytes     delta
BenchmarkReplacer-12                     240           48            -80.00%
BenchmarkReplacer_CommonLogFormat-12     3723          446           -88.02%

* replacer: code review comments

* bufPool: document why we use a pointer to a slice
* parseFormat: fix confusing comment
* TestParseFormat_Nodes: rename to TestParseFormatNodes

* replacer: use a value for bufPool instead of a pointer

* replacer: remove comment

* replacer: replace labels with knownLabels

The previous slice of label names is no longer needed.
2019-07-17 06:57:46 +00:00
Charlie Vieth
21e9c6047b Fix log plugin benchmark and slightly improve performance (#3004)
* log: use ioutil.Discard as write buffer in benchmark

Using a buffer gives unrealistic stats and consumes a large amount of
memory.

* log: lazily check if a msg should be logged

* log: improve variable name

Change 'ok' to the more descriptive 'shouldLog'.

* log: code comments: don't reuse variable
2019-07-16 19:00:22 +00:00
Anshul Sharma
0674325efb plugin/route53: fix IAM credential file (#2983)
- Fix the ability for CoreDNS to fetch credentials via IAM
2019-07-15 05:56:28 +00:00
Jintao Zhang
2874c963c1 doc:remove duplicate word (#3005)
Signed-off-by: Jintao Zhang <zhangjintao9020@gmail.com>
2019-07-15 05:51:08 +00:00
Charlie Vieth
db417f97af rewrite: remove condition file (#3003)
Nothing it declares is used by CoreDNS and it does not appear to be used
by any third-party packages (according to godoc.org).
2019-07-14 08:44:00 +00:00
Ruslan Drozhdzh
69a2397bf5 plugin/rewrite: fix domain length validation (#2995)
* unit test

* fix domain length validation

* code optimization

* remove unit test
2019-07-12 12:22:45 +00:00
Yong Tang
f4a6bea4b4 gofmt fix for No newline at end of file (#2973)
This fix fixes the `\ No newline at end of file`
in plugin/chaos/zowners.go, by adding `"\n"`
to the end of owners_generate.go.

Also fixes a gofmt issue in plugin/etcd/setup.go

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2019-07-04 07:50:49 +01:00
Miek Gieben
18304ce9b7 plugin/file: make non-existent file non-fatal (#2955)
* plugin/file: make non-existent file non-fatal

If the zone file being loaded doesn't exist *and* reload is enabled,
just wait the file to pop up in the normal Reload routine.

If reload is set to 0s; we keep this a fatal error on startup. Aslo fix
the ticker in z.Reload(): remove the per second ticks and just use the
reload interval for the ticker.

Brush up the documentation a bit as well.

Fixes: #2951

Signed-off-by: Miek Gieben <miek@miek.nl>

* Stickler and test compile

Signed-off-by: Miek Gieben <miek@miek.nl>

* Remove there too

Signed-off-by: Miek Gieben <miek@miek.nl>

* Cant README test these because zone files dont exist

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-07-04 13:56:37 +08:00
Anshul Sharma
f9fb9db171 ISSUE-2911 (#2923)
- Remove resyncperiod from Kubernetes plugin
2019-07-03 20:39:12 +01:00
Anshul Sharma
2bd77d0823 Fix multiple credentials in route53 (#2859) 2019-07-03 20:14:31 +01:00
John Belamaric
7cf73cc01d
plugin/template: support metadata (#2958)
* Enable use of metadata in templates

* Update README

* Don't stash away ctx, instead use a new func
2019-07-03 16:10:56 +01:00
Miek Gieben
3e5fd21e68
file: close correctlty after AXFR (#2943)
* file: close correctlty after AXFR

Don't hijack, but wait for the writes to be done and then savely close
the connection.

Fixes: #2929

Signed-off-by: Miek Gieben <miek@miek.nl>

* Update comment

Signed-off-by: Miek Gieben <miek@miek.nl>

* file: close correctlty after AXFR (#2943)

apply

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-07-03 07:01:57 +01:00
Yong Tang
f8bba51f84
Update Caddy to 1.0.1, and update import path (#2961)
* Update Caddy to 1.0.1, and update import path

This fix updates caddy to 1.0.1 and also
updates the import path to github.com/caddyserver/caddy

This fix fixes 2959

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Also update plugin.cfg

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Update and bump zplugin.go

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2019-07-03 09:04:47 +08:00
Miek Gieben
22c6e3e179
plugins: set upstream unconditionally (#2956)
`upstream` is not needed as a setting; just set if unconditionally and
remove all documentation and tests for it.

At some point we want remove the hanlding for `upstream` as well and
error out on seeing it.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-07-02 16:23:47 +01:00
Miek Gieben
3a0c7c6153 plugin/file: load secondary zones lazily on startup (#2944)
This fixes a long standing bug:
fixes: #1609

Load secondary zones in a go-routine; this required another mutex to
protect some fields; I think those were needded anyway because a
transfer can also happen when we're running; we just didn't have a test
for that situation.

The test had to be changed to wait for the transfer to happen at this is
async now.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-06-30 05:22:34 +08:00
bcebere
6e7a5f5677 TLS hardening (#2938)
Automatically submitted.
2019-06-28 11:03:34 +00:00
Timoses
41661b0848 Provide example to utilize k8s_external plugin (#2936)
* Provide example to utilize k8s_external plugin

The example provides a specific use case of k8s_external and may help others to grasp `k8s_external`'s capabilities.

* Update plugin/k8s_external/README.md

Co-Authored-By: Chris O'Haver <cohaver@infoblox.com>

* Update plugin/k8s_external/README.md

Co-Authored-By: Chris O'Haver <cohaver@infoblox.com>
2019-06-27 20:02:08 +01:00
Anshul Sharma
ad352cee88 plugin/reload: Add metrics (#2922)
* Issue 2920
- Add failed reload counter metrics

* typo fix

* Requested Changes
2019-06-26 07:38:46 +01:00
Miek Gieben
cd176f859b Run gofmt -s and golint on the codebase (#2918)
* Run gofmt -s and golint on the codebase

Run golint and fix everythign it flagged (except the context arg
ordering), mostly edits in the rewrite plugin.

Signed-off-by: Miek Gieben <miek@miek.nl>

* ... and ofcourse the test as well

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-06-25 15:00:33 +08:00
Chris O'Haver
b94c85a0db Update README.md (#2896) 2019-06-17 20:46:02 +01:00
Chris O'Haver
1cb44f0bfd Update plugin.go (#2894) 2019-06-17 20:01:06 +01:00
Miek Gieben
8848792e40
plugin/file: document using an explicit origin (#2893)
* plugin/file: document using an explicit origin

See #2880

Signed-off-by: Miek Gieben <miek@miek.nl>

* Code review comments

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-06-17 19:47:07 +01:00
An Xiao
c432f894b2 Rename bind_test.go to setup_test.go (#2891)
Signed-off-by: Xiao An <hac@zju.edu.cn>
2019-06-17 13:20:33 +01:00
An Xiao
c1d7c2e69b Raise error if regexp and template are not specified together (#2884)
Signed-off-by: Xiao An <hac@zju.edu.cn>
2019-06-13 12:07:41 +01:00
Miek Gieben
481dea50ad
plugin/cache: remove item.Autoritative (#2885)
* plugin/cache: remove item.Autoritative

Confuses clients if not set; remove it.

Signed-off-by: Miek Gieben <miek@miek.nl>

* Add extra comments on why we do this

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-06-13 10:36:47 +01:00
An Xiao
27ca097df4 Fix a typo in the document of plugin file (#2882) 2019-06-11 16:11:42 -04:00
Yong Tang
f13482f4d1 Follow up on PR 2868 (#2877)
This fix is a follow up on comment https://github.com/coredns/coredns/pull/2868#discussion_r291609761

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2019-06-10 10:02:02 +01:00
Yong Tang
60f483e98b Fix lowercase presummit (#2876)
While running make encountered the following error:
```
$ docker run -i -t --rm -v $PWD:/v --net=host -w /v golang:1.12 make
...
...
** presubmit/test-lowercase
plugin/kubernetes/metadata_test.go:			t.Errorf("case %d expected metadata %v and got %v", i, tc.Md, md)
** presubmit/test-lowercase: please start with an upper case letter when using t.Error*()
Makefile:62: recipe for target 'presubmit' failed
make: *** [presubmit] Error 1
```

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2019-06-10 07:35:07 +01:00
Anshul Sharma
74303a985c Fix Datadog tracer (#2868)
- Fixes #2862
2019-06-09 13:44:19 -07:00
John Belamaric
ffcd2f61cf Publish metadata from kubernetes plugin (#2829)
* Publish metadata from kubernetes plugin

* stickler fix

* Add a couple tests

* Add metadata section to README

* Update plugin/kubernetes/README.md

Co-Authored-By: Chris O'Haver <cohaver@infoblox.com>

* Address nit
2019-06-09 08:10:57 +01:00
Miek Gieben
a1c97f82a6
plugin/ready: fix starts and restarts (#2814)
Add OnRestartFailed to the ready plugin and some various cleanups.

Document slightly better how things are supposed to work with multiple
`ready`'s in the multiple Server Blocks.

All manually tested with this Corefile:
~~~
. {
    log
    ready
}

example.org {
    log
    chaos
    ready
}
~~~
And then `kill -SIGUSR1` and curling the ready endpoint. This works
well, the FailedReload is triggered by adding a syntax error in the
Corefile.

See #2659

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-06-09 08:10:15 +01:00
Chris O'Haver
bd83f74deb remove unused functions (#2873) 2019-06-09 08:09:55 +01:00
Miek Gieben
458e778113
Revert "be sure to close connection after completion of xfr out. (#2866)" (#2872)
This reverts commit a657e1f661.
2019-06-07 15:29:42 +01:00
JINMEI Tatuya
a657e1f661 be sure to close connection after completion of xfr out. (#2866)
otherwise the connection and associated socket stay in the CLOSE_WAIT
state unless/until golang runtime performs GC.
2019-06-05 07:21:59 +01:00
Francois Tur
d3e2ef73b8 stepdown from CoreDNS maintainer (#2861) 2019-06-03 16:21:05 -04:00
Chris O'Haver
e1d0b63e3f allow an empty response (#2855) 2019-06-01 08:40:12 +01:00
Miek Gieben
3b3fb6f583
plugin/kubernetes: skip deleting pods (#2853)
Don't add pods to our internal cache that are being deleted. This saves
a field in the struct as well.

Add (extra) comments about adding fields to the
object/{Pod,Service,Endpoint} structs.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-06-01 08:39:52 +01:00
Cricket Liu
adc021d6ff Update README.md (#2856)
General syntactic cleanup.
2019-05-31 15:42:47 -07:00