268 Commits

Author SHA1 Message Date
Ville Vesilehto
4ca99cd7b6 fix(cache): isolate metadata in prefetch goroutine (#7631)
Wrap doPrefetch with a fresh metadata context to prevent concurrent
writes to the request-scoped metadata map during background prefetch.

Add a new integration test configuring a plugin chain, triggering
the issue seen here. Hammers concurrent queries while log reads
metadata fields repeatedly.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-10-22 15:47:41 -07:00
Ville Vesilehto
9a57d9693c fix(caddyfile): infinite loop on unclosed braces (#7571)
Update coredns/caddy to a version where Dispenser.NextBlock()
checks Next() and stops at EOF. This ensures forward progress
and prevents an infinite loop when a block is missing a closing '}'
under certain conditions.

Added a regression test.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-09-30 09:36:13 -07:00
Ville Vesilehto
6ec327836b fix: prevent SIGTERM/reload deadlock (#7562) 2025-09-19 04:01:53 -07:00
Ville Vesilehto
5532ba8484 fix(plugin): prevent panic when ListenHosts is empty (#7565) 2025-09-19 03:59:37 -07:00
Ville Vesilehto
a72a14d88b test(presubmit): prevent panic in TestImportOrdering on split import (#7540)
Fix a panic in presubmit test when import statements are split into
>3 logical blocks (e.g., std, coredns, then third party in multiple
blocks). The computed block index could exceed the fixed array
bounds.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-09-13 15:14:59 -07:00
Ville Vesilehto
39abf5aeba chore(lint): modernize Go (#7536)
Use modern Go constructs through the modernize analyzer from the
golang.org/x/tools package.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-09-10 13:08:27 -07:00
Syed Azeez
bc0467d1c0 test(multisocket): deflake restart by using a fresh port and coordinated cleanup (#7438)
Avoid transient EADDRINUSE and a previous negative WaitGroup panic:
- restart onto a different free port
- no Stop() around Restart()
- channel-coordinated Stop of the new instance

Fixes #7311

Signed-off-by: Syed Azeez <syedazeez337@gmail.com>
2025-08-11 11:07:09 -07:00
dependabot[bot]
e90db8e666 build(deps): bump github.com/quic-go/quic-go from 0.52.0 to 0.53.0 (#7392) 2025-07-14 18:57:36 -07:00
Cameron Steel
0aee758833 fix(auto/file): return REFUSED when no next plugin is available (#7381) 2025-07-04 02:39:19 -07:00
Ville Vesilehto
9f9aed31cf test: add t.Helper() calls to test helper functions (#7351) 2025-06-04 14:36:04 -07:00
Ville Vesilehto
53e9681a39 lint: enable protogetter linter (#7336)
Enable protogetter in golangci config and update all protobuf field
access to use getter methods instead of direct field access.
Getter methods provide safer nil pointer handling and return
appropriate default values, following protobuf best practices.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-05-30 15:29:32 -07:00
Ville Vesilehto
19a6ae4983 lint: enable intrange linter (#7331)
Enable intrange linter to enforce modern Go range syntax over
traditional for loops, by converting:

for i := 0; i < n; i++

to:

for i := range n

Adding type conversions where needed for compatibility
with existing uint64 parameters.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-05-28 17:50:55 -07:00
Ville Vesilehto
1948b6efc3 test: skip certain network-specific tests on non-Linux (#7318)
Add conditional test skipping for bind and readme tests that rely on
Linux-specific loopback interface behavior. These tests reference
network configurations that may not exist on for e.g. macOS or other
platforms, causing spurious test failures.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-05-23 09:23:14 -07:00
Ville Vesilehto
32ea433a29 fix(metrics): preserve request size from plugins (#7313)
The rewrite plugin modifies DNS messages, affecting the request
size observed in the coredns_dns_request_size_bytes metric.

This change captures the original request size before any plugins
can modify it. It adds a functional options pattern to Report() to
pass this information while maintaining API compatibility.

Tests have been added to verify the fix prevents rewrite from
affecting the request size metrics.

Docs included.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-05-22 06:38:22 -07:00
Ville Vesilehto
efaed02c6a feat: limit concurrent DoQ streams and goroutines (#7296) 2025-05-18 17:49:21 -07:00
momantech
1bb184aa09 chore: fix some comments (#7201)
Signed-off-by: momantech <cuimoman@qq.com>
2025-03-24 10:32:39 -04:00
Arthur Outhenin-Chalandre
d8ecde1080 test: fix cname with proxy test (#7083)
www.example.net is now behind akamai with various IP answered and a
chain of CNAME. Let's replace www.example.net by one of the root server
which answer a single IP and hopefully should remain this way.

Signed-off-by: Arthur Outhenin-Chalandre <arthur@cri.epita.fr>
2025-01-21 09:41:38 +01:00
Viktor
6c39f4bae7 multisocket plugin (#6882)
* multisocket plugin improves performance in multiprocessor systems

Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com>

* - refactoring
- update doc

Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com>

* remove port from reuseport plugin README

Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com>

* rename reuseport plugin to numsockets plugin

Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com>

* Add Recommendations to numsockets README

Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com>

* added numsockets test; made NUM_SOCKETS mandatory in doc

Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com>

* restart and whoami tests for numsockets plugin

Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com>

* default value for numsockets

Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com>

* caddy up

Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com>

* add numsockets to plugin.cfg

Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com>

* - rename numsockets plugin to multisocket
- default as GOMAXPROCS
- update README

Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com>

* resolve conflicts

Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com>

---------

Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com>
2024-11-13 09:40:25 -08:00
Ben Kochie
b48aeea3c4 Fixup grpc test (#6844)
Remove deprecated `grpc.WithBlock()`. This option is a noop with
`grpc.NewClient()`.

Signed-off-by: SuperQ <superq@gmail.com>
2024-08-18 16:18:00 +02:00
Ben Kochie
ec8e3844a9 Update grpc library use (#6826)
Replace deprecated grpc Dial/DialContext with grpc.NewClient.

Signed-off-by: SuperQ <superq@gmail.com>
2024-08-18 06:13:10 +02:00
Paco Xu
ae65f4e0c7 fix TestCorefile1 panic for nil handling (#6802)
Signed-off-by: Paco Xu <paco.xu@daocloud.io>
2024-08-05 06:47:04 -04:00
Frederic Hemery
db17037a25 Fix outdated test (#6747)
Signed-off-by: Frederic Hemery <frederic.hemery@datadoghq.com>
2024-07-01 10:52:11 -04:00
kindknow
4531515f2b chore: fix function name in comment (#6608)
Signed-off-by: kindknow <iturf@sina.com>
2024-04-26 15:08:09 -04:00
Zhizhen He
2fe5890d8b Fix typos (#6235)
* Fix typos and add todo to fix spelling of dnsutil.MaximumDefaulTTL

Signed-off-by: Zhizhen He <hezhizhen.yi@gmail.com>
2023-08-10 11:06:48 -04:00
João Henri
cc7a364633 [RFC-9250]: Add QUIC server support (#6182)
Add DNS-over-QUIC server 

Signed-off-by: jaehnri <joao.henri.cr@gmail.com>
Signed-off-by: João Henri <joao.henri.cr@gmail.com>
2023-07-31 15:34:31 -04:00
Eng Zer Jun
b868350fc2 test: use t.TempDir to create temporary test directory (#6164) 2023-06-17 15:21:01 +02:00
Ondřej Benkovský
8c489bd400 replace reviewdog fully by golangci-lint (#6139)
Signed-off-by: Ondřej Benkovský <ondrej.benkovsky@jamf.com>
2023-06-09 18:08:23 +02:00
Fish-pro
156da74ad3 Close the body after reading the response body information (#5907)
Signed-off-by: Fish-pro <zechun.chen@daocloud.io>
2023-02-15 12:41:51 -05:00
sanyo0714
9497644505 Fork TLSConfig for each encrypted connection (#5710)
* Fork TLSConfig for each encrypted connection

Signed-off-by: sanyo <sanyo0714@163.com>
Co-authored-by: sanyo <yeshengan.ysa@alibaba-inc.com>
2022-10-28 12:55:41 -04:00
Ondřej Benkovský
257ca65a17 GO linting bump and removal of deprecated linters (#5624)
* bump golangci-lint with support of go 1.19

Signed-off-by: Ondřej Benkovský <ondrej.benkovsky@jamf.com>

* remove deprecated usage of varcheck, deadcode, and structcheck

Signed-off-by: Ondřej Benkovský <ondrej.benkovsky@jamf.com>

Signed-off-by: Ondřej Benkovský <ondrej.benkovsky@jamf.com>
2022-09-19 05:53:43 -07:00
Chris O'Haver
b56b080a7c plugin/view: Advanced routing interface and new 'view' plugin (#5538)
* introduce new interface "dnsserver.Viewer", that allows a plugin implementing it to decide if a query should be routed into its server block.
* add new plugin "view", that uses the new interface to enable a user to define expression based conditions that must be met for a query to be routed to its server block.

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2022-09-08 14:56:27 -04:00
Chris O'Haver
29f3dcfa10 plugin/ready: Reset list of readiness plugins on startup (#5492)
* reset readiness plugins list on startup

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2022-07-18 09:50:15 -04:00
Marius Kimmina
9ea4c09485 Add test for DNS over TLS (#5511) 2022-07-15 17:00:42 +02:00
Ondřej Benkovský
c2dbb7141a add golangci-lint linter (#5499) 2022-07-10 11:06:33 -07: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
Qasim Sarfraz
74b84a1377 update all +build statements (#5271)
* update all +build statements

Signed-off-by: MQasimSarfraz <syed.qasim.sarfraz@gmail.com>

* remove old +build style

Signed-off-by: MQasimSarfraz <syed.qasim.sarfraz@gmail.com>
2022-03-18 07:11:14 -07:00
Yong Tang
2f020dcb30 Update to use the latest protobuf package to build pb (#5193)
* Update to use the latest protobuf package to build pb

The pb package was generated some time ago with old version
of https://github.com/golang/protobuf which was deprecated
and in favor of google.golang.org/protobuf (see
deprecation notice in https://pkg.go.dev/github.com/golang/protobuf)

This PR updates the generation of pb package with
v1.27.1 of google.golang.org/protobuf.

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

* Exclude pb from import test

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2022-02-17 23:11:45 -08:00
Chris O'Haver
911891f485 plugin/rewrite: Write failures with ResponseReverter (#5150)
* write failures with ResponseReverter instead of letting server write them

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* fix comment

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2022-02-01 16:54:06 -05: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
Zou Nengren
5191959bd7 cleanup deprecated package io/ioutil (#4920)
Signed-off-by: zounengren <zouyee1989@gmail.com>
2021-10-13 09:30:31 +02:00
Chris O'Haver
158ad2d738 plugin/file/auto: Write CNAME answer to client even if target lookup is SERVFAIL (#4863)
* write cname answer to client even if target lookup is servfail

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* fix existing unit test expectations

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2021-09-14 10:08:22 +02:00
Miek Gieben
39ab840263 deflake TestMultiZoneBlockConfigs (#4751)
Deflake by retrying and adding random port numbers. We try 3 times to
get an instance.

Also fix a bug where server.Stop() was called even if the server
creation failed - this was never hit due to t.Fatal() above it, but fix
that nontheless.

Signed-off-by: Miek Gieben <miek@miek.nl>
2021-07-14 10:36:25 +02:00
Chris O'Haver
bdaa2a5527 Share plugins among zones in the same server block (#4593)
* share plugins among zones in the same server block

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* update caddy dep

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* simp code

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* copy ListenHosts and Debug from first config

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* copy tls configs from first config

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* add test to validate debug setting is replicated to all configs in block

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* stop server

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2021-07-09 17:12:06 +02:00
Chris O'Haver
79d6795333 plugin/secondary: Retry initial transfer until successful (#4663)
* retry initial transfer

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* fix import grouping

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* add test; use backoff timeout

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* fix import order

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* manual backoff

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2021-06-10 10:49:31 +02:00
Miek Gieben
5d80a6e21e Fix obsure crash in Corefile parsing (#4637)
This was found by fuzzing.

We need to make this a fully qualified domain name to catch all errors
in dnsserver/register.go and not later when plugin.Normalize() is called again on these
strings, with the prime difference being that the domain name is fully
qualified. This was found by fuzzing where "ȶ" is deemed OK, but "ȶ." is
not (might be a bug in miekg/dns actually). But here we were checking ȶ,
which is OK, and later we barf in ȶ. leading to "index out of range".

Added a tests and check manually if it would crash with the current code
(yes), and fail with an error in this PR (yes).

Signed-off-by: Miek Gieben <miek@miek.nl>
2021-05-19 10:38:37 -07:00
Jason Du
d1f520a5b2 Fix etcd to use v3.5.0-alpha.0 (#4628)
Signed-off-by: Jason Du <xdu@infoblox.com>
2021-05-14 23:55:01 -07: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
Steve Greene
fdfc9bcdd2 test: Fix rare race condition in TestZoneReload (#4617)
The following test failure for `TestZoneReload` can be observed
periodically:

`file_reload_test.go:58: Expected two RR in answer section got 2`

This failure can be consistently reproduced using the following command
(on my machine, at least):

`( cd test ; go test -v -race -run "TestZoneReload" ./... -count=500)`

test/file_reload_test.go:

Address a typo in a test failure message.

Sleep for double the file reload interval to avoid a rare
race condition between test code and the file plugin's reload code,
which is presumably a result of the time it takes to actually reload.

Signed-off-by: Stephen Greene <sgreene@redhat.com>
2021-05-11 09:11:20 +02:00
Miek Gieben
56bc7f399a plugin/transfer: only allow outgoing axfr over tcp (#4452)
* plugin/transfer: only allow outgoing axfr over tcp

Return refused when the query comes in over udp.
No need to add a new test case as the current crop needed to be changed
to use TCP.

Fixes: #4450

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

* transfer tests: this needs tcp as well

Signed-off-by: Miek Gieben <miek@miek.nl>
2021-02-05 10:51:29 +01:00
Miek Gieben
38d4dacb88 Fix import ordering presubmit test (#4422)
Automatically submitted.
2021-01-24 17:28:49 +00:00