Commit graph

80 commits

Author SHA1 Message Date
Ondřej Benkovský
c2dbb7141a
add golangci-lint linter (#5499) 2022-07-10 11:06:33 -07:00
coredns[bot]
f8ef1dc652 auto go fmt
Signed-off-by: coredns[bot] <bot@bot.coredns.io>
2022-07-04 10:29:59 +00:00
Chris O'Haver
68e141eff2
plugin/tsig: new plugin TSIG (#4957)
* expose tsig secrets via dnsserver.Config
* add tsig plugin

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2022-06-27 15:48:34 -04:00
Radim Hatlapatka
91bcbc2e3a
recover from panic log including stacktrace to help finding the origin (#5392) 2022-05-24 14:36:36 +02:00
Ondřej Benkovský
a9adfd56ad
Log panic cause for better debugging (#5091) 2022-01-13 12:41:32 -08:00
Miek Gieben
6953ab2b4f
Metrics: expand coredns_dns_responses_total with plugin label (#4914)
* Metrics: expand coredns_dns_responses_total with plugin label

This adds (somewhat hacky?) code to add a plugin label to the
coredns_dns_responses_total metric. It's completely obvlious to the
plugin as we just check who called the *recorder.WriteMsg method. We use
runtime.Caller( 1 2 3) to get multiple levels of callers, this should be
deep enough, but it depends on the dns.ResponseWriter wrapping that's
occuring.

README.md of metrics updates and test added in test/metrics_test.go to
check for the label being set.

I went through the plugin to see what metrics could be removed, but
actually didn't find any, the plugin push out metrics that make sense.

Due to the path fiddling to figure out the plugin name I doubt this
works (out-of-the-box) for external plugins, but I haven't tested that.

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

* better comment

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

* Metrics: expand coredns_dns_responses_total with plugin label

This adds (somewhat hacky?) code to add a plugin label to the
coredns_dns_responses_total metric. It's completely obvlious to the
plugin as we just check who called the *recorder.WriteMsg method. We use
runtime.Caller( 1 2 3) to get multiple levels of callers, this should be
deep enough, but it depends on the dns.ResponseWriter wrapping that's
occuring.

README.md of metrics updates and test added in test/metrics_test.go to
check for the label being set.

I went through the plugin to see what metrics could be removed, but
actually didn't find any, the plugin push out metrics that make sense.

Due to the path fiddling to figure out the plugin name I doubt this
works (out-of-the-box) for external plugins, but I haven't tested that.

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

* Update core/dnsserver/server.go

Co-authored-by: dilyevsky <ilyevsky@gmail.com>

* Use [3]string

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

* imports

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

* remove dnstest changes

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

* revert

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

* Add some sleeps to make it less flaky

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

* Revert "Add some sleeps to make it less flaky"

This reverts commit b5c6655196.

* Remove forward when not needed

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

* remove newline

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

Co-authored-by: dilyevsky <ilyevsky@gmail.com>
2021-11-12 16:07:05 +00:00
Miek Gieben
e42614edc5
reverse zones (#4538)
* core: fix v4 non-octet reverse zones

This fixes the reverse zones handling. Add expanstion of the reverse
notation to all octet boundary subnets and add those to the config - just as if
they were directly typed in the config.

This takes inspiration from #4501, but that (even with DCO!!) seems to
be just using https://github.com/apparentlymart/go-cidr/ so use that
instead - I think a minor function is still needed that one is copied
from #4501.

Also sort the zones we are listing on startup - caught in this PR
because of the expanded zones being not listed next to each other.

This also removes the need for FilterFunc from the config, so this is
now gone as well, making the whole thing slightly more efficient.

Add couple of reverse unit tests and a e2e test that queries for the
correct (and incorrect) reverse zones and checks the reply.

Closes: #4501
Fixes: #2779

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

* Add more test cases

Add test from origin bug report: #2779

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

* Rebase and fix conflicts

Signed-off-by: Miek Gieben <miek@miek.nl>
2021-05-11 09:50:18 +02:00
Miek Gieben
342eae9b4b
plugin/file: guard against cname loops (#4387)
Automatically submitted.
2021-01-15 18:26:04 +00:00
Miek Gieben
04e532b257
core: fix crash with no plugins (#4184)
* core: fix crash with no plugins

A Corefile that defines a zone without plugins crashes coredns with the
stack trace below. Change this to return a refused.

~~~ corefile
 example.org {
    whoami
    log
    cache
    debug
}

example.net {
}
~~~

Asking for anyhing in example.net does this. Add test that tests this.

~~~
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xa5e6a4]

goroutine 55 [running]:
github.com/coredns/coredns/core/dnsserver.(*Server).ServeDNS(0xc000438f60, 0x2059420, 0xc0005a4030, 0x206c0e0, 0xc000522140, 0xc0005ae000)
	/home/miek/src/github.com/coredns/coredns/core/dnsserver/server.go:247 +0x884
github.com/coredns/coredns/core/dnsserver.(*Server).ServePacket.func1(0x206dd00, 0xc00009e180, 0xc0005ae000)
	/home/miek/src/github.com/coredns/coredns/core/dnsserver/server.go:126 +0xaf
github.com/miekg/dns.HandlerFunc.ServeDNS(0xc000529270, 0x206dd00, 0xc00009e180, 0xc0005ae000)
	/home/miek/go/pkg/mod/github.com/miekg/dns@v1.1.31/server.go:37 +0x44
github.com/miekg/dns.(*Server).serveDNS(0xc000286c60, 0xc000282400, 0x34, 0x200, 0xc00009e180)
	/home/miek/go/pkg/mod/github.com/miekg/dns@v1.1.31/server.go:609 +0x2f7
github.com/miekg/dns.(*Server).serveUDPPacket(0xc000286c60, 0xc0003b03b4, 0xc000282400, 0x34, 0x200, 0xc00000e320, 0xc000522080)
	/home/miek/go/pkg/mod/github.com/miekg/dns@v1.1.31/server.go:549 +0xb2
created by github.com/miekg/dns.(*Server).serveUDP
	/home/miek/go/pkg/mod/github.com/miekg/dns@v1.1.31/server.go:479 +0x292
~~~

Also fix single typo in chaos_test.go

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

* Fix naming

Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-07 15:58:14 +02:00
Miek Gieben
b003d06003
For caddy v1 in our org (#4018)
* For caddy v1 in our org

This RP changes all imports for caddyserver/caddy to coredns/caddy. This
is the v1 code of caddy.

For the coredns/caddy repo the following changes have been made:

* anything not needed by us is deleted
* all `telemetry` stuff is deleted
* all its import paths are also changed to point to coredns/caddy
* the v1 branch has been moved to the master branch
* a v1.1.0 tag has been added to signal the latest release

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

* Fix imports

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

* Group coredns/caddy with out plugins

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

* remove this file

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

* Relax import ordering

github.com/coredns is now also a coredns dep, this makes
github.com/coredns/caddy fit more natural in the list.

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

* Fix final import

Signed-off-by: Miek Gieben <miek@miek.nl>
2020-09-24 18:14:41 +02:00
Yong Tang
7b78170041
Fix trailing whitespace (#4103)
The latest commit (e233f59) on master branch introduced a trailing
whitespace and is causing Travis CI build to fail:
https://travis-ci.org/github/coredns/coredns/builds/722988413

This PR fixes the failing test.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2020-09-06 20:57:56 -04:00
Hu Shuai
e233f59ee8
Fix some typos in comments. (#4100)
Signed-off-by: Hu Shuai <hus.fnst@cn.fujitsu.com>
2020-09-01 09:10:45 +02:00
Olivier Lemasle
f36715e889
Enable debug globally if enabled in any server config (#4007)
* Enable debug globally if enabled in any server config

It was currently enabled only if the plugin debug
was enabled in the last server config of the Corefile.

Signed-off-by: Olivier Lemasle <o.lemasle@gmail.com>

* Add test and update debug's README

Signed-off-by: Olivier Lemasle <o.lemasle@gmail.com>
2020-08-24 09:12:00 +02:00
Zou Nengren
a74a209129
validate object implements the corresponding interface (#3724)
Signed-off-by: zouyee <zounengren@cmss.chinamobile.com>
2020-03-06 09:25:07 +01:00
Miek Gieben
e14e053d3d create pkg/reuseport (#3455)
* create pkg/reuseport

Move the core server listening functions to a new package so plugins can
use them.

Also make *all* servers use the functions here; as only the udp/tcp
listeners where using SO_REUSEPORT (if available). This is the only
actual change in this PR; in it's core it's just a move of 2 files.

This can also be used to cleanup the dance we're doing now for
re-acquiring the sockets in e.g. the metrics plugins and the ready
plugin.

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

* Also push a small doc update

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-11-16 18:02:46 -08:00
Miek Gieben
5f114d38ca
pkg/log: add Clear to stop debug logging (#3372)
When reloading we need to disable debug output when the debug plugin is
removed from the config file. Add a `Clear` function to pkg/log and use
it in the server server.

Add test case in pkg/log, for actuall check I manually checked the
output by sprinkling some debug statements in the startup and checking
with sending SIGUSR1.

Also clear up the comments in pkg/log to remove the text about time
stamping.

Fixes: #3035

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-10-17 15:53:11 +01:00
Miek Gieben
27e22b0696 Use strings.ToLower in server (#3304)
Automatically submitted.
2019-09-25 17:18:54 +00:00
Guangming Wang
081e45afa3 cleanup: remove redundant return statement (#3297)
Signed-off-by: Guangming Wang <guangming.wang@daocloud.io>
2019-09-23 14:40:14 +01:00
Chris O'Haver
3f47fc8ba4
typo fixes (#3169)
* spelling fixes

* its/it's
2019-08-21 16:08:55 -04:00
Miek Gieben
cd5dcebe93
core: log panics (#3072)
These are too hidden now. They increase the issue-load, because people
don't see them.

Add log.Errorf in the core/dnsserver recover routine.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-07-31 18:18:49 +00:00
Miek Gieben
a84413bd07
pkg/log: fix data race on d (#2698)
* pkg/log: fix data race on d

Wrap d in a mutex to prevent data race. This makes is slower, but this
is a debugging aid anyway. It's not used normally.

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

* Fix tests compilation

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

* Fix test compile

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-05-23 21:02:30 +01:00
Miek Gieben
58c703f5ef
Run gofmt -w -s on codebase (#2773)
This formats and simplifies all code by running gofmt -w -s on all Go
files.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-04-08 11:13:46 +01:00
Miek Gieben
db34c10589
server: small cleanups (#2740)
Rename connTimeout to graceTimeout to be more instructive on it's use,
some whitespace for imports lines.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-03-31 08:32:55 +01:00
Miek Gieben
b75478e73b
server: remove if registry != nil code (#2735)
I can't find what's this code should be doing and it looks like it's
not doing anything.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-03-30 11:50:19 +00:00
Miek Gieben
93f635023a
Don't double report metrics on error (#2719)
* Don't double report metrics on error

When there is an error use a different function to report the metrics,
in case the plugin chain handled the request the metrics are already
reported.

Fixes: #2717

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

* Compile again

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-03-25 19:04:03 +00:00
Miek Gieben
9a8c301a42 Remove server addr from the context (#2722)
* more

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

* Remove server addr from the context

This was added twice, just leave the server which also holds the
address.

Conflicts with #2719 but should be easy to fix.

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

* doesn't need server context

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-03-25 10:46:44 -07:00
Miek Gieben
45624a0c0a plugin/log: remove ErrorFunc (#2716)
The server handles this case no need to also do it in the log plugin.

Means DefaultErrorFunc can be private to the dnsserver and is now
renamed to just errorFunc

Fixes: #2715

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-03-25 11:36:46 +08:00
Miek Gieben
2b7e84a076
Remove internal loop detection (#2647)
* Remove internal loop detection

I can't actually think of a situation where we can create an internal
loop. Sure externally triggered cycles can happen, but this is where the
*loop* plugin comes in that detects those.

Fixes #2602

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

* Remove test

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-03-07 20:23:00 +00:00
Miek Gieben
2743c8eab1
Upgrade caddy to 0.11.X (#2541)
* Upgrade caddy to 0.11.2

Redo of #2505 (cherry-picked commit)

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

* .4 has been released

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-02-17 15:11:19 +00:00
Miek Gieben
9abbf4a4a0 map bool -> map struct{} (#2386)
This clear out the remaining map[x]bool usage and moves the bool to an
empty struct.

Two note worthy other changes:

* EnableChaos in the server is now also exported to make it show up in
  the documentation.
* The auto plugin is left as is, because there the boolean is
  explicitaly set to false to signal 'to-be-deleted' and the key is left
  as-is.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-12-10 02:17:15 -08:00
Miek Gieben
fb971ffff3 Core: Support REUSE_PORT (#2149)
Automatically submitted.
2018-10-01 17:05:24 +00:00
Miek Gieben
c349446a23
Cleanup ParseHostOrFile (#2100)
Create plugin/pkg/transport that holds the transport related functions.
This needed to be a new pkg to prevent cyclic import errors.

This cleans up a bunch of duplicated code in core/dnsserver that also
tried to parse a transport (now all done in transport.Parse).

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-09-19 07:29:37 +01:00
Miek Gieben
ba1efee4f1
Default to scrubbing replies in the server (#2012)
Every plugin needs to deal with EDNS0 and should call Scrub to make a
message fit the client's buffer. Move this functionality into the server
and wrapping the ResponseWriter into a ScrubWriter that handles these
bits for us. Result:

Less code and faster, because multiple chained plugins could all be
calling scrub and SizeAndDo - now there is just one place.

Most tests in file/* and dnssec/* needed adjusting because in those unit
tests you don't see OPT RRs anymore. The DNSSEC signer was also looking
at the returned OPT RR to see if it needed to sign - as those are now
added by the server (and thus later), this needed to change slightly.

Scrub itself still exist (for backward compat reasons), but has been
made a noop. Scrub has been renamed to scrub as it should not be used by
external plugins.

Fixes: #2010

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-08-29 12:26:22 +01:00
Miek Gieben
7c27577707
plugin/metrics: add panic counter (#1778)
Count and export number of panics we see.

Fixes #1294
2018-05-05 19:47:41 +02:00
Miek Gieben
8722336fff
global: move to context (#1699)
* global: move to context

Move from golang.org/x/net/context to std lib's context.

Change done with:

for i in $(grep -l '/context' **/*.go); do sed -e 's|golang.org/x/net/context|context|' -i $i; echo $i; done
for i in **/*.go; do goimports -w $i; done

* drop from dns.pb.go as well
2018-04-20 11:01:06 +01:00
Miek Gieben
b4b65fbc18
pkg/log: ability for debug logs (#1689)
* pkg/log: ability for debug logs

When the debug plugin is enabled all log.Debug calls will print to
standard; if not there are a noop (almost).

The log package wraps some standard log functions as well, so just
replacing "log" with "plugin/pkg/log" should be enough to use this
package.

* docs

* Add docs

* lint

* Test fallthrough to log pkg as well

* simple package - up test coverage

* add other log levels as well

* update docs
2018-04-18 21:02:01 +01:00
Miek Gieben
08443a9f00
plugin/metrics: add 'server' label (#1682)
* plugin/metrics: add 'server' label

This uses the new WithServer(ctx) to get the current server from the
context.

First in a larger refactor to make all plugins do this.

* compile

* compile

* lala test

* compile and test

* typos

* Dont duplicate the code
2018-04-18 09:42:20 +01:00
Miek Gieben
4df416ca1d
Metrics (#1579)
* plugin/metrics: set server address in context

Allow cross server block metrics to co-exist; for this we should label
each metric with the server label. Put this information in the context
and provide a helper function to get it out.

Abstracting with entirely away with difficult as the release client_go
(0.8.0) doesn't have the CurryWith functions yet. So current use is like
so:

define metric, with server label:

	RcodeCount = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: "forward",
		Name:      "response_rcode_count_total",
		Help:      "Counter of requests made per upstream.",
	}, []string{"server", "rcode", "to"})

And report ith with the helper function metrics.WithServer:

	RcodeCount.WithLabelValues(metrics.WithServer(ctx), rc, p.addr).Add(1)
2018-04-01 13:57:03 +01:00
Uladzimir Trehubenka
0e0a641f16 Fixed NewServer() init logic (#1637) 2018-03-27 16:32:21 +01:00
Miek Gieben
182235458f
Fix start mesg for all protocol (#1617)
Recent bind refactoring missed this:

    grpc://example.com.:1055
    example.com.:1053 on 127.0.0.1

now becomes

    grpc://example.com.:1055 on 127.0.0.1
    example.com.:1053 on 127.0.0.1

If you're using *bind* directive.
2018-03-17 19:04:01 +00:00
Miek Gieben
7b93ce2ec1
server: drop logging (#1581)
* server: drop logging

Drop this log line; you have no control over it; it doesn't add that
much and can be used to easily ddos you.

* compile
2018-03-01 17:59:07 -08:00
Miek Gieben
36e86231ad
Fix zone printing (#1578)
Dont return here, but continue
2018-03-01 13:56:19 -08:00
Francois Tur
9047bdf3a0 Allow overlapping Zones if binding addresses are different (#1530)
* add OverlapChecker, move the test of overlap AFTER the directive setup process, change key of configs to allow multiple same key

* glitch when rebase. init of Config should include the default host

* add tests for the registering of configuration
rename multicast in 'unbound'.
add comments on the validator

* - merged zoneAddr and addrKey that are very similar
- move maps of Validator to zoneAddr, avoinding need to have string representation of zoneaddr
- moving key build for saving Config at Config side instead of dnsContext

* - UT on saving config is now useless.

* - cannot cleanup access to Configs after setup. Deferred function to Start, use it

* - cleanup register unit tests. remove useless function

* - address comments of review. name of validator, comments, simplify registerAndCheck

* - fixes after review. renaming a function and a comment
2018-02-23 16:54:42 +00:00
Chris O'Haver
71ee323651 plugin/kubernetes: Add upstream @self and loop count (#1484)
* add upstream @self and loop count

* 1st round of feedback

* allow argless upstream

* update test

* readmes

* feedback
2018-02-14 21:11:26 +01:00
Francois Tur
76455c6a0d Plugin/BIND - extend the syntax to allow multiple addresses (#1512)
* Extend bind to allow multiple addresses. UTs added. Changes the log for server starting, adding address when available

* update readme for bind

* fixes after review

* minor fix on readme

* accept multiple BIND directives in blocserver, consolidate the addresses

* fixes after review - format logging server address, variable names
2018-02-14 20:19:32 +01:00
Miek Gieben
74a9d28f1b
core: unblock CH class for forward as well (#1498)
Retweak this a little to make it slightly easier to *not* forget this,
but it is hardly perfect. Should probably make it an interface a plugin
can implement and then unblock if we see that interface.
2018-02-08 12:59:30 +00:00
Miek Gieben
c655589fa3
core: Fix no handler crash (#1328)
If you have no handlers for any zone CoreDNS would crash, this is very
*uncommon*, because it makes your server a bit unusable. Example config:
~~~
. {
    #forward . tls://9.9.9.9 8.8.8.8 {
    #    health_check 5s
    #    tls_servername dns.quad9.net
    #}
    pprof
    debug
}
~~~
It this does nothing and doesn't setup you plugin chain because pprof and
debug don't handle queries
2017-12-22 08:55:35 +00:00
Miek Gieben
4443b4a096
server: update comment (#1213)
Because we have our own mux we can't depend on the dns.Mux to do the
Question section checking for us. Clarify this in the comment.
2017-11-10 11:19:49 +00:00
Miek Gieben
fcd0342e42 CIDR query routing (#1159)
* core: allow all CIDR ranges in zone specifications

Allow (e.g.) a v4 reverse on a /17. If a zone is specified in such a
way a FilterFunc is set in the config. This filter is checked against
incoming queries.

For all other queries this adds a 'x != nil' check which will not impact
performace too much. Benchmark function is added as well to check for
this as wel.

Add multiple tests in tests/server_reverse_test.go.

Benchmark shows in the non-reverse case this hardly impact the speed:

~~~
classless:
pkg: github.com/coredns/coredns/core/dnsserver
BenchmarkCoreServeDNS-4   	 1000000	      1431 ns/op	      16 B/op	       1 allocs/op

pkg: github.com/coredns/coredns/core/dnsserver
BenchmarkCoreServeDNS-4   	 1000000	      1429 ns/op	      16 B/op	       1 allocs/op

master:
pkg: github.com/coredns/coredns/core/dnsserver
BenchmarkCoreServeDNS-4   	 1000000	      1412 ns/op	      16 B/op	       1 allocs/op

pkg: github.com/coredns/coredns/core/dnsserver
BenchmarkCoreServeDNS-4   	 1000000	      1429 ns/op	      16 B/op	       1 allocs/op
~~~

* README.md updates
2017-10-24 10:16:03 +01:00
Miek Gieben
0af3fbab4f core: add ServeDNS benchmark (#1158)
* core: add ServeDNS benchmark

Add benchmark function so we can perf test future additions to the
servers' ServeDNS function.

* naming
2017-10-21 09:30:59 +01:00