Commit graph

46 commits

Author SHA1 Message Date
Ondřej Benkovský
c2dbb7141a
add golangci-lint linter (#5499) 2022-07-10 11:06:33 -07:00
chantra
8ecde0f37b
[request] Also clear do and size (#4465)
Those 2 attriburtes were not cleared as part of `Clear()` call.

Signed-off-by: chantra <chantr4@gmail.com>
2021-02-17 20:42:37 +01:00
Miek Gieben
acf9a0fa19
cache: default to DNSSEC (#4085)
* cache: default to DNSSEC

This change does away with the DNS/DNSSEC distinction the cache
currently makes. Cache will always make coredns perform a DNSSEC query
and store that result. If a client just needs plain DNS, the DNSSEC
records are stripped from the response.

It should also be more memory efficient, because we store a reply once
and not one DNS and another for DNSSEC.

Fixes: #3836

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

* Change OPT RR when one is present in the msg.

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

* Fix comment for isDNSSEC

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

* Update plugin/cache/handler.go

Co-authored-by: Chris O'Haver <cohaver@infoblox.com>

* Update plugin/cache/item.go

Co-authored-by: Chris O'Haver <cohaver@infoblox.com>

* Code review; fix comment for isDNSSEC

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

* Update doc and set AD to false

Set Authenticated Data to false when DNSSEC was not wanted. Also update
the readme with the new behavior.

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

* Update plugin/cache/handler.go

Co-authored-by: Chris O'Haver <cohaver@infoblox.com>

Co-authored-by: Chris O'Haver <cohaver@infoblox.com>
2020-09-17 07:28:43 -07:00
Zou Nengren
45c43554a8 make Prot to method (#3500)
Signed-off-by: zouyee <zounengren@cmss.chinamobile.com>
2019-12-06 11:21:34 +00:00
Miek Gieben
03ea2ae955
Make request.Request smaller (#3351)
* Make request.Request smaller

This makes the request struct smaller and removes the pointer to the do
boolean (tri-bool) as size == 0 will indicate if we have cached it.

Family can be a int8 because it only carries 3 values, Size itself is
just a uint16 under the covers.

This is a more comprehensive fix than #3292

Closes #3292

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

* cache: fix test

this now needs a valid response writter

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-10-04 09:44:58 +01:00
Guangming Wang
8af4685587 cleanup code by lint (#3312)
Signed-off-by: Guangming Wang <guangming.wang@daocloud.io>
2019-09-27 11:10:34 +01:00
AllenZMC
55160492cd fix mis-spelling in request.go (#3213) 2019-08-27 09:01:17 -04:00
Miek Gieben
a5c405f6d7
Move to dns.Truncate (#2942)
Ditch our truncation code and use the upstream one in miekg/dns.
This saves code on our end, end upstream is also more efficient as every
RR is Len-ed only once. With our bin-search this is not guaranteed.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-07-11 12:54:47 +00:00
Miek Gieben
53f3f0b666
Remove context.Context from request.Request (#2726)
* Remove context.Context from request.Request

This removes the context from request.Request and makes all the changes
in the code to make it compile again. It's all mechanical. It did
unearth some weirdness in that the context was kept in handler structs
which may cause havoc with concurrently handling of requests.

Fixes #2721

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

* Make test compile

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-03-26 14:37:30 +00:00
Miek Gieben
f08f7e24d6
request.Request: remove useless function (#2714)
ErrorMessage was a very shallow function that didn't add anything.
Remove it and remove its usage.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-03-24 13:26:15 +00:00
Ye Ben
0eff7f3797 some typo fix (#2512)
Signed-off-by: yeya24 <ben.ye@daocloud.io>
2019-01-29 10:21:19 -05:00
Miek Gieben
fed307bfce
core: edns0 tweaks (#2385)
* core: edns0 tweaks

Per comment thread in https://github.com/coredns/coredns/pull/2357 which
spotted a bug; updated the code and added some comments.

This function should probably be redone as some point or made obsolete.

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

* Remove setting options when m is EDNS0 record

Assume upstream set them correctly or a plugin.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-12-10 19:43:46 +00:00
Miek Gieben
fc667b98e0
Fix EDNS0 compliance (#2357)
* Fix EDNS0 compliance

Do SizeAndDo in the server (ScrubWriter) and remove all uses of this
from the plugins. Also *always* do it. This is to get into compliance
for https://dnsflagday.net/.

The pkg/edns0 now exports the EDNS0 options we understand; this is
exported to allow plugins add things there. The *rewrite* plugin used
this to add custom EDNS0 option codes that the server needs to
understand.

This also needs a new release of miekg/dns because it triggered a
race-condition that was basicly there forever.

See:
* https://github.com/miekg/dns/issues/857
* https://github.com/miekg/dns/pull/859

Running a test instance and pointing the https://ednscomp.isc.org/ednscomp
to it shows the tests are now fixed:

~~~
EDNS Compliance Tester
Checking: 'miek.nl' as at 2018-12-01T17:53:15Z

miek.nl. @147.75.204.203 (drone.coredns.io.): dns=ok edns=ok edns1=ok edns@512=ok ednsopt=ok edns1opt=ok do=ok ednsflags=ok docookie=ok edns512tcp=ok optlist=ok
miek.nl. @2604:1380:2002:a000::1 (drone.coredns.io.): dns=ok edns=ok edns1=ok edns@512=ok ednsopt=ok edns1opt=ok do=ok ednsflags=ok docookie=ok edns512tcp=ok optlist=ok

All Ok
Codes
ok - test passed.
~~~

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

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

* typos in comments

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-12-06 21:18:11 +00:00
Miek Gieben
59a49c5ff7 Scrub: Do more to avoid fragmentation (#2333)
Automatically submitted.
2018-12-04 20:15:57 +00:00
stuart nelson
cac6fe1d07 fix truncation bug (#2261)
* fix truncation bug

* Generate records with generic RRs

* Remove SoundCloud from test name

* Comment for binary-search -1 adjustment

Explain why the binary search may have exited with
a reply size that is too large by one record.

* Refactor to remove sub variable

patch suggested by miek removes unnecessary sub
variable for removing a single line from the
reply.Extra length.
2018-11-03 10:01:56 +00:00
Miek Gieben
898b1ef316 server: actually scrub response (#2225)
* server: actually scrub response

Did all the worked, hooked it up wrongly :(

This also needs test, but those are hard(er) because we only receive
packets after they have been decoded; i.e. we never see the wirefmt.

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

* Add tests

Add a test for checking is compression pointers are set in the packet.
This also adds an undocumented 'large' feature to the erratic plugin to
send large responses that should be compressed.

Commenting the Scrub out in server results in:

=== RUN   TestCompressScrub
--- FAIL: TestCompressScrub (0.00s)
    compression_scrub_test.go:41: Expected returned packet to be < 512, got 839
FAIL
exit status 1
FAIL    github.com/coredns/coredns/test 0.036s

Actually checking the size might be easier, but lets be thorough here
and check the pointers them selves.

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

* Fix tests

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

* plugin erratic: fix e.large

always put an rr in the reply, fix e.large in erractic and add test to
check for it.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-10-23 09:55:40 -07: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
Karsten Weiss
6d8a078704 Typo fixes (#2031) 2018-08-14 08:55:55 -07:00
Miek Gieben
62df253371
request: re-adjust size for edns0 RR (#2007)
* Add regression test for broken DNS truncation

With the latest changes to the implementation, request.Scrub() returns
invalid response messages which are larger than the advertised buffer
size. This commit adds a failing test for that.

* Add benchmark for response truncation

* request: re-adjust size for edns0 RR

Cherry-picked the test and benchmark commits from #1962 and make the
failing test not fail, by adding minimal fix in request.go.

This makes size 12 bytes smaller if we need to add back the OPT RR in
the message.

Closes: #1962

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

* Scrub: correctly check for EDNS0, not only Do

Make Scrub check for EDNS0, not only if the Do bit is set.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-07-28 10:27:38 +01:00
Miek Gieben
908d4fbd23
request: add LocalIP (#1925)
* request: add LocalIP

Fix TODO that was added: Add LocalIP and test the Clear() method.

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

* Move to Errorf

PR feedback and move to Errorf instead Fatalf.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-07-03 09:47:26 +01:00
Miek Gieben
6dd2cf8c4b plugin/rewrite: use request.Request and other cleanups (#1920)
This was done anyway, but only deep in the functions, just do this
everywhere; allows for shorter code and request.Request allows for
caching as well.

Cleanups, make it more Go like.
* remove unneeded switches
* remove testdir (why was this there??)
* simplify the logic
* remove unneeded variables
* put short functions on a single line
* fix documentation.
* spin off wire funcs in wire.go, make them functions.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-07-02 07:39:50 -07:00
Miek Gieben
0b326e2686 request.Request: cache a few more value (#1921)
Cache IP's and ports as well.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-07-01 08:34:52 -07:00
Miek Gieben
f3afd70021
request: Add LocalAddr() and LocalPort() (#1907)
These are used in the rewrite plugin, makes sense to have a common place
for them.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-06-29 17:38:31 +01:00
Miek Gieben
4f0b36e57e
Extend presubmit to covert test and request (#1846)
Fix the casing *and* fix use of context as we were still referencing
the non-std lib context - no wondering how this could have worked...
2018-06-01 15:12:49 +01:00
Miek Gieben
0e5e59c327
request.Match check Response bit as well (#1775)
* request.Match check Response bit as well

We should check this bit and reject them as invalid.

* Fix test
2018-05-09 12:35:42 +01:00
Miek Gieben
5735292406
Do Compress only when need in request.Scrub (#1760)
* Remove Compress by default

Set Compress = true in Scrub only when the message doesn not fit the
advertized buffer. Doing compression is expensive, so try to avoid it.

Master vs this branch
pkg: github.com/coredns/coredns/plugin/cache
BenchmarkCacheResponse-2   	   50000	     24774 ns/op

pkg: github.com/coredns/coredns/plugin/cache
BenchmarkCacheResponse-2   	  100000	     21960 ns/op

* and make it compile
2018-05-01 21:04:06 +01:00
Miek Gieben
5c5a98ee29
request.Do: use pointer to bool (#1632)
Drop the doTrue and doFalse and use a pointer to a bool to do a proper
tri-bool.
2018-03-31 17:22:24 +01:00
Miek Gieben
a8d02d970c
request.Scrub: test for rl==size case (#1631)
* request.Scrub: test for rl==size case

Make a test case for the new break statement in Scrub and also
account for the OPT record that may get re-added in SizeAndDo() -
otherwise we may break clients that expect this.

* Fix comment
2018-03-24 11:50:55 +00:00
Mario Kleinsasser
1c6efbd962 Fix #1625 (#1629)
Signed-off-by: Mario Kleinsasser <mario.kleinsasser@gmail.com>
2018-03-23 16:59:06 +00:00
Miek Gieben
b813706baf
request: add match function (#1615) 2018-03-15 08:42:49 +00:00
Miek Gieben
455040c143
doc: some function/vars/const/package level updates (#1558)
* doc: some function/vars/const/package level updates

Various update that stood out while reading godoc.org for CoreDNS.

* Fix some misspellings as well
2018-02-23 15:02:05 +00:00
Miek Gieben
074d176f03
Scrub: use binary search (#1543)
Use binary search to find the minimal message size, that contains whole
RRs and fits the client's buffer. This is better then just setting
entire sections to `nil`. Extend the tests to test for additional and
answer section truncation. In the first case we *don't* set the TC bit.

This function now also set Compression to true.
2018-02-21 21:13:41 +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
Tobias Schmidt
697e2b4bda Fix truncation of messages longer than permitted by the client (#1417)
* Fix truncation of messages longer than permitted by the client

CoreDNS currently doesn't respect the maximum response size advertised
by the client and returns the full answer on a message with the TC bit
set. This breaks client implementations which rely on DNS servers
respecting the advertised size limit, for example the Ruby stdlib
client. It also has negative network performance implications, as large
messages will be split up into multiple UDP packets, even though the
client will discard the truncated response anyway.

While RFC 2181 permits the response of partial RRSets, finding the
correct number of records fitting into the advertised response size is
non-trivial. As clients should ignore truncated messages, this change
simply removes the full RRSet on truncated messages.

* Remove incorrect etcd test assertion

If a client requests a TXT record larger than its advertised buffer
size, a DNS server should _not_ respond with the answer, but truncate
the message and set the TC bit, so that the client can retry using TCP.
2018-01-24 13:28:26 +00: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
7ed44cb6ce core: add Zone in request.Request (#857)
Add a Zone field in request.Request and a dnsutil.Trimzone help
function.
2017-08-08 04:23:16 -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
Chris O'Haver
8495e48297 k8s/autopath: Add CNAMES (#771)
* Add unit tests & cnames

* more progress

* fix

* next mw dependent unit tests

* add tests for OnNXDOMAIN

* Add AAAA and ndots unit tests; fix request.NewWithQuestion

* Correct default value in README

* add CNAMEs to readme

* review

* fix autopath examples

* fix and test CNAME response order
2017-07-11 18:05:32 -04: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
8c8b37a30e middleware/metrics: export actual size (#448)
The `*_size*` metrics now export the actual packet length, not the
advertised one (although that might be nice as well).
2016-11-29 11:02:43 +00: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
560f11d148 EDNS0 unknown flags handling (#313)
Fix the unknown flags handling when receiving such message. We should
zero out all of the Z bits in the OPT record before returning.

Current behavior:

    dig +norec +noad +ednsflags=0x80 soa miek.nl @deb.atoom.net
    ...
    ; EDNS: version: 0, flags:; MBZ: 0080 , udp: 4096

New:

    dig +norec +noad +ednsflags=0x80 soa miek.nl @localhost -p 2053
    ...
    ; EDNS: version: 0, flags:; udp: 4096

Take care no to overwrite the Do bit.

We still accept *all* EDNS option; I do not consider that a bug in
itself.

Fixes #306
2016-10-02 17:23:25 +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
5301c5af5f Run golint and go vet (#276)
Cleanup the errors and removed deadcode along the way. The leaves
some error laying around, mostly about commenting exported identifier.
We should look hard if those really are needed.
2016-09-21 17:01:19 +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
Renamed from middleware/state.go (Browse further)