Commit graph

52 commits

Author SHA1 Message Date
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
Miek Gieben
23526aec1d core: drop invalid packets (#1123)
We can still be on the receiving end of invalid packet. Drop them
here.
2017-09-29 22:27:40 +01:00
Miek Gieben
d8714e64e4 Remove the word middleware (#1067)
* 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
2017-09-14 09:36:06 +01:00
Miek Gieben
5eccfa2d1e core: harden request.Request (#1009)
Check for a nil message and if we have a question section. Request is
usually called with an external Msg that already saw validation checks,
but we may also call it from message we create of our own, that may or
may not adhire to this. Just be more robust in this case.

This PR reverts a previous commit that was applied to master.
2017-08-31 16:24:11 +02:00
Miek Gieben
c72084187c core: add nil check (#1005)
Check if msg is nil in DefaultErrorFunc. If this is the case log this
and short cut the function.

Hoping to get more insight in #925
2017-08-31 08:20:13 +02:00
Miek Gieben
55dafe6f59 core: block CH queries earlier (#973)
block chaos queries, unless the chaos or proxy middleware is loaded. We
respond with REFUSED.

This removes the need for each middleware to do this class != ClassINET
if-then.

Also make config.Registry non-public.
2017-08-25 08:55:53 +01:00
Miek Gieben
8931ede142 core: hide registerHandler (#964)
* core: hide registerHandler

Remove RegisterHandler and just make it implicit when we look at the
handler compilation step.

* Rename GetHandler to just Handler

Update callers and make auto check Hander in OnStartup.

* Up test coverage in erratic

* up test coverage
2017-08-22 14:21:42 +01:00
Miek Gieben
468d5b57de core: export ClientWrite (#849)
Make ClientWrite available for middleware to use.
2017-08-07 07:39:57 -07:00
Miek Gieben
bcb2eb1ecc all: gometalinter (#843)
* kubernetes/reverse: remove deadcode
* deadcode in errors and kubernetes removed
* unnecessary conversion
* constants
* proxy: time.Since()
* simplications
* static check
* Disable test/external_test
2017-08-06 05:54:24 -07:00
Miek Gieben
8e86fa6f23 middleware/debug: add (#735)
* middleware/debug: add

Add a debug "middleware" that disables the recover() and just lets
CoreDNS crash; very useful for testing.

Fixes ##563

* fix test

* Feedback: check the value of Debug
2017-06-13 16:47:17 -06:00
Yong Tang
37050dc217 Some golint cleanup (#674)
This commit fixes some golint issues in `core/dnsserver`
and `middleware/kubernetes`.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2017-05-25 20:08:34 +01:00
John Belamaric
5a60090933 Tracing for gRPC Server (#619)
* Implements tracing in the native gRPC server

* Undo some unnecessary changes

* Properly revert trace/setup.go this time

* Some very very basic tests

* Remove warning for non-Trace middleware
2017-04-18 11:10:49 -04:00
Miek Gieben
bfaf9e0aec core: add more transports (#574)
* core: add listening for other protocols

Allow CoreDNS to listen for TLS request coming over port 853. This can
be enabled with `tls://` in the config file.

Implement listening for grps:// as well.

a Corefile like:

~~~
. tls://.:1853 {
    whoami
    tls
}
~~~

Means we listen on 1853 for tls requests, the `tls` config item allows
configuration for TLS parameters. We *might* be tempted to use Caddy's
Let's Encrypt implementation here.

* Refactor coredns/grpc into CoreDNS

This makes gRPC a first class citizen in CoreDNS. Add defines as being
just another server.

* some cleanups

* unexport the servers

* Move protobuf dir

* Hook up TLS properly

* Fix test

* listen for TLS as well. README updates

* disable test, fix package

* fix test

* Fix tests

* Fix remaining test

* Some tests

* Make the test work

* Add grpc test from #580

* fix crash

* Fix tests

* Close conn

* README cleanups

* README

* link RFC
2017-03-13 20:24:37 +00:00
Miek Gieben
05dee778bd core: remove dns.ServeMux (#576)
We don't need to use the muxer in Go DNS s we only have one entry point
per server - and mux ourselves in ServeDNS. Also make ServeDNS take a
context, and make that the canonical way to call all middleware.
2017-03-09 09:11:59 +00:00
John Belamaric
72bc7e6278 Export ServeDNSWithContext for use by gRPC server middleware (#577) 2017-03-08 21:28:26 +00:00
Yong Tang
1e4ba588dc Enforce go lint check and fix several lint issues (#570)
This fix updates the Makefile to add the `go lint` check
for the build. This fix also fixes several go lint issues.

NOTE: This fix does not enforce `go lint` (suggestion only).
This fix also ignores the `go lint` error:
```
middleware/middleware.go:72:1: context.Context should be the first parameter of a function
```
as it requires too many changes in API.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2017-03-05 14:17:05 -08:00
John Belamaric
9ea8cde36e Grpc tracing (#544)
* checkpoint

* Pass context through ServeDNS, enable gRPC tracing

* Fix types and make tracer available to proxy. go fmt

* Fix imports

* Use the DoNotStartTrace option

* Change to SpanFilter from DoNotStartTrace

* Use new name (IncludeSpan)

* Final names

* Add tests; fix possible client/conn leaks in grpc

* go fmt
2017-03-01 10:41:54 -05:00
Yong Tang
81af74aad0 Fix import path github.com/miekg/coredns -> github.com/coredns/coredns (#547)
This fix fixes import path from
`github.com/miekg/coredns`
->
`github.com/coredns/coredns`
2017-02-22 06:51:47 +00:00
Miek Gieben
bcd9c8b0fb server: fix data race (#536)
* server: fix data race

This fixes the detected race.

Fixes #534

* Remove the listener and packetconn from Server

There does not seem a need to store the listener and packetconn again
in the Server structure. The dns.Servers already has access to them
and can also shutdown the handlers.
2017-02-19 20:34:09 +00:00
Miek Gieben
5f6c7682be core: make coredns.Server a caddy.GracefulServer (#520)
* core: make coredns.Server a caddy.GracefulServer

We needed to also implement the Address() method.

Fixes: #519

* Add compile time check if we implement caddy.GracefulServer

* Check if we should shutdown
2017-02-10 19:50:31 +00:00
John Belamaric
3a04d2a306 Changes needed to support external gRPC server middleware (#498)
The gRPC server middleware[1] needs access to the Server object
in order to push the unpacked Msg through the normal middleware
pipeline. These are the changes to core needed to make that
possible.

[1] https://github.com/infobloxopen/coredns-grpc
2017-01-31 22:21:55 +00:00
Miek Gieben
219bfd0493 middleware/metrics: cleanup (#355)
* middleware/metrics: add more metrics

middleware/cache:
Add metrics for number of elements in the cache. Also export the total
size. Update README to detail the new metrics.

middleware/metrics

Move metrics into subpackage called "vars". This breaks the import
cycle and is cleaner. This allows vars.Report to be used in the
the dnsserver to log refused queries.

middleware/metrics: tests

Add tests to the metrics framework. The metrics/test subpackage allows
scraping of the local server. Do a few test scrape of the metrics that
are defined in the metrics middleware.

This also allows metrics integration tests to check if the caching and
dnssec middleware export their metrics correctly.

* update README

* typos

* fix tests
2016-10-26 10:01:52 +01:00
Miek Gieben
4f36e63a05 middleware/file: fix DS handling (#344)
The DS record is handled specially in the server ServeDNS mux, but there
was no code that actually called the correct middleware handler chain
when encountering a DS.

This PR fixes that behavoir, additonal bugs has been files to look into
how we are handling delegation (secure and non-secure ones).
2016-10-19 17:46:03 +01:00
Miek Gieben
aa7744dc86 cleanups: go vet/golint (#331)
Go vet and golint the new code once again.

Drop Name from NameTemplate - it's cleaner: nametemplate.Template.
2016-10-12 12:46:35 +01:00
Miek Gieben
9b5c9df321 Don't register quiet flag in register.go (#299)
This clashes to Caddy, which also has its own quiet flag. Move stuff
around a bit, also to prevent cyclic imports.
2016-09-25 18:42:08 +01:00
Miek Gieben
de0fa53379 Doc: add package docs (#296)
* Doc: add package docs

Add short package level docs to make godoc looks nicer.
Add some badges to the README.

* correct url
2016-09-25 08:39:20 +01:00
Miek Gieben
8555716046 Cleanups and tests (#272)
For some reasons there was a dnsserver/middleware.go that defined
the middleware handlers. This code was a repeat from
middleware/middleware.go. Removed dnsserver/middleware.go and replaced
all uses of dnsserver.Middleware with middleware.Middleware.

Added dnsserver/address_test.go to test the zone normalization (and to
improve the test coverage). The deleted file will also improve the test
coverage :)
2016-09-19 11:26:00 +01:00
Miek Gieben
31851c6acd coredns: default Corefile (#265)
When no Corefile is given, default to loading the whoami middleware on
the default port (2053).  Also add back the -port flag that allows you
to override the default port.

Further cleanup the startup messages and use caddy's OnStartupComplete()
to blurp out which zones and ports we have.  These can be suppressed
with the -quiet flag.

Normal startup:

miek.nl.:1053
miek.nl2.:1053
example.org.:1054
2016/09/17 20:41:19 [INFO] CoreDNS-001 starting
CoreDNS-001 starting

with the -quiet flag:

2016/09/17 20:41:34 [INFO] CoreDNS-001 starting
2016-09-17 21:24:39 +01:00
Miek Gieben
d1f17fa7e0 Cleanup: put middleware helper functions in pkgs (#245)
Move all (almost all) Go files in middleware into their
own packages. This makes for better naming and discoverability.

Lot of changes elsewhere to make this change.

The middleware.State was renamed to request.Request which is better,
but still does not cover all use-cases. It was also moved out middleware
because it is used by `dnsserver` as well.

A pkg/dnsutil packages was added for shared, handy, dns util functions.

All normalize functions are now put in normalize.go
2016-09-07 11:10:16 +01:00