Commit Graph

173 Commits

Author SHA1 Message Date
Ville Vesilehto
2f981ff797 fix(forward): use netip package for parsing (#7472)
Replace manual host:port parsing using net.SplitHostPort +
strconv.ParseUint with the standard library net/netip function
ParseAddrPort. This eliminates integer conversion warnings and
improves type safety.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-08-25 13:06:44 -07:00
harshith-2411-2002
6ba43927b6 fix: handle cached connection closure in forward plugin (#7427) 2025-07-28 12:06:26 -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
Parfenov Ivan
e16162dd3c Added SetProxyOptions function for forward plugin (#7229)
Signed-off-by: Paramoshka <parfenov_ivan_42a@mail.ru>
2025-04-04 12:27:47 -04:00
Puneet Loya
4de8fb57b2 plugin/forward: added option failfast_all_unhealthy_upstreams to return servfail if all upstreams are down (#6999)
* feat: option to return servfail if upstreams are down

Signed-off-by: Puneet Loya <puneetloya@Puneets-MBP.attlocal.net>

* fix based on review comments and added to Readme

Signed-off-by: Puneet Loya <puneetloya@Puneets-MBP.attlocal.net>

* add tests to improve code coverage

Signed-off-by: Puneet Loya <puneetloya@Puneets-MBP.attlocal.net>

* added failfast_all_unhealthy_upstreams option to forward plugin

Signed-off-by: Puneet Loya <puneetloya@Puneets-MBP.attlocal.net>

---------

Signed-off-by: Puneet Loya <puneetloya@Puneets-MBP.attlocal.net>
Co-authored-by: Puneet Loya <puneetloya@Puneets-MBP.attlocal.net>
2025-03-07 11:37:25 -05:00
AdamKorcz
04d00b0083 fuzzing: fix broken oss-fuzz build (#6880)
Signed-off-by: Adam Korczynski <adam@adalogics.com>
2024-10-24 14:33:58 -04:00
Jasper Bernhardt
2e9986c622 Add alternate option to forward plugin (#6681)
Allows the forward plugin to execute the next plugin based on the return code. Similar to the externally mainted alternate plugin https://github.com/coredns/alternate

Based on the idea of chrisohaver@ in #6549 (comment)
Also incoperated the request to rename `alternate` to `next` as an option

I am having issues adding a proper test for functionality. Primarily, I do not know the code base enough and having multiple `dnstest.NewServer` with ResponseWriter does not work. From my testing these are "Singletons'' and only the last defined response writer is used for all servers

Signed-off-by: Jasper Bernhardt <jasper.bernhardt@live.de>
2024-07-01 11:20:12 -04:00
Manuel Alejandro de Brito Fontes
5b6d8e356c [plugin/forward] Strip local zone from IPV6 nameservers (#6635)
Signed-off-by: Alejandro de Brito Fontes <aledbf@gmail.com>
2024-04-26 13:12:25 -04:00
Snawoot
8e783897a2 forward: respect context (#6483)
Signed-off-by: Vladislav Yarmak <vladislav-ex-src@vm-0.com>
2024-03-07 14:54:28 -05:00
Marius Kimmina
92ec849acb plugin/tls: respect the path specified by root plugin (#6138)
* plugin/tls: respect the path specified by root plugin

Signed-off-by: Marius Kimmina <mar.kimmina@gmail.com>

* improve readme

Signed-off-by: Marius Kimmina <mar.kimmina@gmail.com>

---------

Signed-off-by: Marius Kimmina <mar.kimmina@gmail.com>
2023-12-08 10:50:30 -05:00
Yuheng
90d55611a2 Plugin dnstap: add support for "extra" field in payload (#6226)
* dnstap: add 'extra' field

Signed-off-by: chenyuheng <chenyuheng99@qq.com>

* dnstap: add setup_test for 'extra' field

Signed-off-by: chenyuheng <chenyuheng99@qq.com>

* udnstap: update document and test

Signed-off-by: chenyuheng <chenyuheng99@qq.com>

* dnstap: update setup_test for more coverage

Signed-off-by: chenyuheng <chenyuheng99@qq.com>

* dnstap: add TapMessageWithMetadata function to Dnstap

Signed-off-by: chenyuheng <chenyuheng99@qq.com>

* dnstap: adapt dnstap and forward plugins to use TapMessageWithMetadata

Signed-off-by: chenyuheng <chenyuheng99@qq.com>

* change TapMessageWithMetadata function

Signed-off-by: chenyuheng <chenyuheng99@qq.com>

* tab inconsistency fix

Signed-off-by: chenyuheng <chenyuheng99@qq.com>

* fix replacer to support empty state

Signed-off-by: chenyuheng <chenyuheng99@qq.com>

* add replacer test for empty status parameter

Signed-off-by: chenyuheng <chenyuheng99@qq.com>

* dnstap: update unit test for 'extra' field

Signed-off-by: chenyuheng <chenyuheng99@qq.com>

* clean up code

Signed-off-by: chenyuheng <chenyuheng99@qq.com>

* gofmt fix & static analysis fix

Signed-off-by: chenyuheng <chenyuheng99@qq.com>

* dnstap: refactor

Signed-off-by: chenyuheng <chenyuheng99@qq.com>

---------

Signed-off-by: chenyuheng <chenyuheng99@qq.com>
2023-08-14 11:01:13 -07:00
Pat Downey
ea293da1d6 Fix forward metrics for backwards compatibility (#6178) 2023-07-04 16:35:55 +02:00
Chris O'Haver
d3965b8b60 Revert "plugin/tls: respect the path specified by root plugin (#5944)" (#6136)
This reverts commit d0375bc026.
2023-06-01 14:07:58 -04:00
Marius Kimmina
d0375bc026 plugin/tls: respect the path specified by root plugin (#5944)
Signed-off-by: Marius Kimmina <mar.kimmina@gmail.com>
2023-06-01 08:56:57 -04:00
Justin
7231bb0881 plugin/forward: fix descriptions in README.md (#6123)
Signed-off-by: Justin <cattyhouse@users.noreply.github.com>
2023-05-26 17:01:06 -04:00
Catena cyber
31ff926ea1 fuzz: fix forward plugin target (#6115)
Signed-off-by: Philippe Antoine <contact@catenacyber.fr>
2023-05-25 09:09:56 -04:00
Pat Downey
f823825f8a plugin/forward: Allow Proxy to be used outside of forward plugin. (#5951)
* plugin/forward: Move Proxy into pkg/plugin/proxy, to allow forward.Proxy to be used outside of forward plugin.

Signed-off-by: Patrick Downey <patrick.downey@dioadconsulting.com>
2023-03-24 08:55:51 -04:00
Gerhard Tan
b7279d1f66 plugin/forward: fix broken tap plugins when dnstap plugins specified (#5890)
* plugin/forward: fix broken tap plugins when dnstap plugins specified

---------

Signed-off-by: Gerhard Tan <gwohau.tan@gmail.com>
2023-01-30 14:38:15 -05:00
Chris O'Haver
04a30198c3 plugin/dnstap: Fix behavior when multiple dnstap plugins specified (#5773)
* fix multiple dnstap plugins behavior

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2022-11-28 10:33:31 -05:00
Yong Tang
26aae951e7 plugin/forward: fix ticker leak in golang (#5689) 2022-10-11 15:28:24 +02:00
Vancl
4033d7aeba plugin/forward: health_check needs to normalize a specified domain name (#5543)
* plugin/forward: convert the specified domain of health_check to Fqdn
* plugin/forward: update readme for health check

Signed-off-by: vanceli <vanceli@tencent.com>
2022-08-15 10:16:15 -04:00
Chris O'Haver
513f27b9a9 plugin/forward: Enable multiple forward declarations (#5127)
* enable multiple declarations of forward plugin

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2022-07-20 10:35:04 -04:00
Ondřej Benkovský
c2dbb7141a add golangci-lint linter (#5499) 2022-07-10 11:06:33 -07:00
Ondřej Benkovský
dcc3d76018 remove unused coredns_forward_sockets_open metric (#5431)
Signed-off-by: Ondřej Benkovský <ondrej.benkovsky@jamf.com>
2022-06-13 07:30:34 -07:00
RetoHaslerMGB
d594d61341 Correct timeout description (#5388) 2022-05-19 02:48:25 -07:00
hansedong
0622a6c66c plugin/forward: configurable domain support for healthcheck (#5281)
* plugin/forward: configurable domain support for healthcheck

Signed-off-by: hansedong <admin@yinxiaoluo.com>
2022-04-12 12:39:48 -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
aa7818e1d3 Update to avoid pseudo-random number (#5225)
* Update to avoid pseudo-random number

This PR update the usage of rand so that non-global seed is used.

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

* Add concurrency-safe random source

See https://stackoverflow.com/questions/48958886/how-to-create-a-thread-safe-rand-source

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2022-03-16 12:24:58 -04:00
Chris O'Haver
f8a02aaf58 dont panic when from-zone cannot be normalized (#5170)
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2022-02-17 15:13:18 -05:00
Tomas Hulata
b0edae07f1 Health-checks should respect force_tcp (#5109)
* health check should respect force_tcp

Signed-off-by: tombokombo <tombo@sysart.tech>
2022-02-09 09:45:52 -05:00
Yong Tang
041e1eabc6 Fix a couple of code scanning alerts (#5157)
This PR fixed a couple of code scanning alerts:

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2022-02-07 09:09:12 -05:00
OctoHuman
29f6d0a6b2 Docs: Add warning to use tls_servername (#4992)
Signed-off-by: OctoHuman <17958767+OctoHuman@users.noreply.github.com>
2021-11-22 08:49:13 +01:00
Chris O'Haver
3288b111b2 Revert "Initial implementation of ForwardCRD plugin (#4512)" (#4981)
This reverts commit 2e6953c7db.
2021-11-12 13:19:16 -05:00
Christian Ang
2e6953c7db Initial implementation of ForwardCRD plugin (#4512)
* Add forwardcrd plugin README.md

Co-authored-by: Aidan Obley <aobley@vmware.com>

Signed-off-by: Christian Ang <angc@vmware.com>

* Create forwardcrd plugin

- Place forwardcrd before forward plugin in plugin list. This will avoid
forward from preventing the forwardcrd plugin from handling any queries
in the case of having a default upstream forwarder in a server block (as
is the case in the default kubernetes Corefile).

Co-authored-by: Aidan Obley <aobley@vmware.com>

Signed-off-by: Christian Ang <angc@vmware.com>

* Add Forward CRD

Signed-off-by: Christian Ang <angc@vmware.com>

* Add NewWithConfig to forward plugin

- allows external packages to instanciate forward plugins

Co-authored-by: Aidan Obley <aobley@vmware.com>

Signed-off-by: Christian Ang <angc@vmware.com>

* ForwardCRD plugin handles requests for Forward CRs

- add a Kubernetes controller that can read Forward CRs
- instances of the forward plugin are created based on Forward CRs from
the Kubernetes controller
- DNS requests are handled by calling matching Forward plugin instances
based on zone name
- Defaults to the kube-system namespace to align with Corefile RBAC

Signed-off-by: Christian Ang <angc@vmware.com>

Use klog v2 in forwardcrd plugin

* Refactor forward setup to use NewWithConfig

Co-authored-by: Christian Ang <angc@vmware.com>

Signed-off-by: Edwin Xie <exie@vmware.com>

* Use ParseInt instead of Atoi

- to ensure that the bitsize is 32 for later casting to uint32

Signed-off-by: Christian Ang <angc@vmware.com>

* Add @christianang to CODEOWNERS for forwardcrd

Signed-off-by: Christian Ang <angc@vmware.com>

Co-authored-by: Edwin Xie <exie@vmware.com>
2021-11-12 11:22:34 -05: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
coredns[bot]
5b65a58d48 auto go fmt
Signed-off-by: coredns[bot] <bot@bot.coredns.io>
2021-10-11 10:28:01 +00:00
Vector
0f5e7bdfb3 plugin/forward: Use new msg.Id for upstream queries (#4841)
* restore 1.8.3 question revert logic; add tests (#4840)

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

* change origin message id

Signed-off-by: Vector <815926354@qq.com>
Signed-off-by: IIvyPy <815926354@qq.com>

* Revert "restore 1.8.3 question revert logic; add tests (#4840)"

This reverts commit 95e44d91d0.

Signed-off-by: IIvyPy <815926354@qq.com>

Co-authored-by: Chris O'Haver <cohaver@infoblox.com>
2021-10-08 19:34:22 +02:00
Ondřej Benkovský
e0110264cc plugin/forward : add proxy address as tag (#4757)
Signed-off-by: Ondrej Benkovsky <ondrej.benkovsky@wandera.com>
2021-07-16 14:35:39 +02:00
Chris O'Haver
09b63df9c1 fix cidr multi-zone check (#4682)
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2021-06-10 10:50:20 +02:00
Chris O'Haver
d8a0d97df2 deprecate Normalize and MustNormalize (#4648)
* deprecate normalize and mustnormalize

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

* add runtime warning

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

* elaborate runtime warning

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

* include caller info

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2021-05-27 13:26:14 +02:00
Chris O'Haver
0348b019be plugin/forward: Document and warn for unsupported FROM CIDR notations (#4639)
* trap unsupported FROM cidr notations

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

* make is a warning

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2021-05-20 09:24:36 +02:00
Miek Gieben
5f41d8eb1f reverse zone: fix Normalize (#4621)
Make normalize return multiple "hosts" (= reverse zones) when a
non-octet boundary cidr is given.

Added pkg/cidr package that holds the cidr calculation routines; felt
they didn't really fit dnsutil.

This change means the IPNet return parameter isn't needed, the hosts are
all correct. The tests that tests this is also removed: TestSplitHostPortReverse
The fallout was that zoneAddr _also_ doesn't need the IPNet member, that
in turn make it visible that zoneAddr in address.go duplicated a bunch
of stuff from register.go; removed/refactored that too.

Created a plugin.OriginsFromArgsOrServerBlock to help plugins do the
right things, by consuming ZONE arguments; this now expands reverse
zones correctly. This is mostly mechanical.

Remove the reverse test in plugin/kubernetes which is a copy-paste from
a core test (which has since been fixed).

Remove MustNormalize as it has no plugin users.

This change is not backwards compatible to plugins that have a ZONE
argument that they parse in the setup util.

All in-tree plugins have been updated.

Signed-off-by: Miek Gieben <miek@miek.nl>
2021-05-17 13:19:54 -07:00
Miek Gieben
ed3f287fe8 metrics: remove RR type (#4534)
To combat label cardinality explosions remove the type from metrics.
This was most severe in the histogram for request duration, remove it
there.

It's also highlighted difference between grpc and forward code, where
forward did use type and grpc didn't; getting rid of all that "fixes"
that discrepancy

Move monitor.go back into the vars directory and make it private again.
Also name it slightly better

Fixes: #4507

Signed-off-by: Miek Gieben <miek@miek.nl>
2021-03-19 12:59:26 +01:00
Chris O'Haver
929aa3886e add metadata section to docs (#4525)
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2021-03-16 13:51:21 +01:00
Chris O'Haver
32cc745dc2 add forward/upstream metadata (#4521)
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2021-03-16 13:34:22 +01:00
Maxime Ginters
b1173ed2a5 plugin/forward Add rcode and rtype to request_duration_seconds metric (#4391)
* plugin/forward Add rcode and rtype to request_duration_seconds metric

Signed-off-by: Maxime Ginters <maxime.ginters@shopify.com>

* Control the cardinality of query type

Signed-off-by: Maxime Ginters <maxime.ginters@shopify.com>
2021-01-28 16:37:17 +01:00
Frank Riley
eba74389c4 Fix #4395, fix out of order messages and fix forward perspective. (#4396)
Signed-off-by: Frank Riley <fhriley@gmail.com>
2021-01-21 10:00:27 +01:00
Chris O'Haver
9cb53487ec respond with REFUSED when max_concurrent is exceeded to avoid caching it (#4326)
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2020-12-15 14:02:15 +01:00
Miek Gieben
8759d00edd forward doc update (#4254)
* forward: add example with multiple DoT upstreams

Remove Bugs section as this is a nice work around.

h/t https://twitter.com/mholt6/status/1284250606673080321

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

* Actually remove bugs section

Signed-off-by: Miek Gieben <miek@miek.nl>
2020-11-03 06:32:49 -08:00
Miek Gieben
c840caf1ef Speed up testing (#4239)
* Speed up testing

* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload

* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
  ... ? A few minutes staring didn't reveal wth it is actually testing.
  Making values smaller revealed race conditions in the tests. Remove
  entirely.

* Move many interval values to variables so we can reset them to short
  values for the tests.

* test_large_axfr: make the zone smaller. The number used 64K has no
  rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout

A few random tidbits in other tests.

Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:

this branch:

~~~
ok  	github.com/coredns/coredns/test	10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~

master:

~~~
ok  	github.com/coredns/coredns/test	35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s

This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.

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

* Also 0.01

Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00