Commit Graph

150 Commits

Author SHA1 Message Date
Kwitsch debac9eaa8
Refactoring/linter (#1447)
* update golangci-lint to v1.57.2

* linter fixes
2024-04-12 16:44:50 -04:00
ThinkChaos bcd1381e18 feat: update list config and code to use "allow/deny" language 2024-04-11 18:33:09 -04:00
ThinkChaos 73e5d6ab88 refactor: remove `model.Request.Log` in favor of use `Context` 2024-03-19 19:10:07 -04:00
ThinkChaos 0a47eaad09 feat: add a unique ID (`req_id`) to all logs related to a request 2024-03-19 19:10:07 -04:00
ThinkChaos 4919ffac0d fix(server): use RCode=ServFail instead of HTTP 500 for internal errors
RFC 8484 Section 4.2.1:
> A successful HTTP response with a 2xx status code (see
> Section 6.3 of RFC7231) is used for any valid DNS response,
> regardless of the DNS response code.  For example, a successful 2xx
> HTTP status code is used even with a DNS message whose DNS response
> code indicates failure, such as SERVFAIL or NXDOMAIN.
https://www.rfc-editor.org/rfc/rfc8484#section-4.2.1
2024-03-19 19:10:07 -04:00
ThinkChaos 3fcf379df7 refactor(util): make `LogOnError` get the log from a `Context` 2024-03-19 19:10:07 -04:00
ThinkChaos b335887992 refactor(log): store log in context so it's automatically propagated 2024-03-19 19:10:07 -04:00
Ben b8b4dc323a
feat: support CNAME records in customDNS mappings (#1352)
Co-authored-by: Ben McHone <ben@mchone.dev>
2024-01-29 11:22:03 -05:00
ThinkChaos ad1ef0bcfb fix: don't use upstream `ServFail` responses besides forwarding them
Don't consider `ServFail` as a TCP/UDP race win.
Use an error to also make sure we don't, for instance, cache such
responses.
2024-01-27 17:25:33 -05:00
ThinkChaos f0ad412d8d refactor(server): add `resolve` for common query code
Ensure all queries go through that common code path so we always enable
compression, truncate if required, etc.
2024-01-18 10:46:54 -05:00
ThinkChaos e9a1e8974d feat(api): support client name lookup when querying via the API 2024-01-18 10:46:54 -05:00
Kwitsch 03131c443c
Refactoring/config struct names (#1315)
* vscode config changed in new version

* FilteringConfig -> Filtering

* CachingConfig -> Caching

* QueryLogConfig -> QueryLog

* MetricsConfig -> Metrics

* HostsFileConfig -> HostsFile

* PortsConfig -> Ports

* BootstrapDNSConfig -> BootstrapDNS

* BootstrappedUpstreamConfig -> BootstrappedUpstream

* bootstrapDNSConfig -> bootstrapDNS

* bootstrappedUpstreamConfig -> bootstrappedUpstream

* SourceLoadingConfig -> SourceLoading

* DownloaderConfig -> Downloader
2023-12-20 15:38:33 -05:00
ThinkChaos df8c373ef1 feat(resolver): race UDP and TCP when connecting upstream
Inspired by https://en.wikipedia.org/wiki/Happy_Eyeballs this should
improve latency and fixes the long standing behavior where a single
resolve attempt could take 2x the timeout.
UpstreamResolver.Resolve can still take more than the configured timeout
so maybe that can be improved by splitting the retry algorithm into its
own resolver type.
2023-12-19 10:44:19 -05:00
ThinkChaos 8c7b89cbb3 refactor(tests): remove `TmpFile.Error` to centralize error checks 2023-12-01 15:53:11 -05:00
ThinkChaos 891d0fba74 refactor(tests): move `DeferCleanup` into helper functions 2023-12-01 15:53:11 -05:00
ThinkChaos a330174949 style(tests): `ShouldNot(Succeed())` -> `Should(HaveOccurred())` 2023-12-01 15:53:11 -05:00
Kwitsch 976d6198f1
Refactoring server.go (#1277)
* made Stop context aware

* added error check

* context aware OnRequest

* linter fix

* fixed some flakiness in tests

* made DoGetRequest context aware

* this doesn't belong there and produces flakyness
2023-11-28 07:02:51 +01:00
Kwitsch fda2dbe9df
Refactoring Redis (#1271)
* RedisConfig -> Redis

* moved redis config to seperate file

* bugfix in config test during parallel processing

* implement config.Configurable in Redis config

* use Context in GetRedisCache

* use Context in New

* caching resolver test fix

* use Context in PublishEnabled

* use Context in getResponse

* remove ctx field

* bugfix in api interface test

* propperly close channels

* set ruler for go files from 80 to 111

* line break because function length is to long

* only execute redis.New if it is enabled in config

* stabilized flaky tests

* Update config/redis.go

Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com>

* Update config/redis_test.go

Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com>

* Update config/redis_test.go

Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com>

* Update config/redis_test.go

Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com>

* Update config/redis.go

Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com>

* Update config/redis_test.go

Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com>

* fix ruler

* redis test refactoring

* vscode setting cleanup

* removed else if chain

* Update redis_test.go

* context race fix

* test fail on missing seintinel servers

* cleanup context usage

* cleanup2

* context fixes

* added context util

* disabled nil context rule for tests

* copy paste error ctxSend -> CtxSend

* use util.CtxSend

* fixed comment

* fixed flaky test

* failsafe and tests

---------

Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com>
2023-11-27 12:08:31 -05:00
ThinkChaos 270dc178dc refactor(config): add `TLSVersion` type 2023-11-23 08:45:18 -05:00
ThinkChaos e4be0c0c86 refactor(config): remove `GetConfig` and its last uses 2023-11-23 08:45:18 -05:00
ThinkChaos b386e22ebe refactor: embed `Upstreams` in `UpstreamGroup` to make values accessible
Move `startVerifyUpstream` to `upstreams.startVerify` so it's accessible
via `UpstreamGroup` and we don't need to pass `startVerify` to all
resolver constructors that call `NewUpstreamResolver`.

Also has the nice benefit of greatly reducing the usage of `GetConfig`.
2023-11-23 08:45:18 -05:00
Kwitsch e30e852c86 ClientLookupConfig -> ClientLookup 2023-11-21 21:35:41 -05:00
Kwitsch 9a77dcdccc BlockingConfig -> Blocking 2023-11-21 21:35:41 -05:00
Kwitsch 00d4341271 ConditionalUpstreamConfig -> ConditionalUpstream 2023-11-21 21:35:41 -05:00
Kwitsch 26d5f6215f CustomDNSConfig -> CustomDNS 2023-11-21 21:35:41 -05:00
Kwitsch 72352a968a UpstreamsConfig -> Upstreams 2023-11-21 21:35:41 -05:00
ThinkChaos eae99ec550 refactor: make use of contexts in more places
- `CacheControl.FlushCaches`
- `Querier.Query`
- `Resolver.Resolve`

Besides all the API churn, this leads to `ParallelBestResolver`,
`StrictResolver` and `UpstreamResolver` simplification: timeouts only
need to be setup in one place, `UpstreamResolver`.

We also benefit from using HTTP request contexts, so if the client
closes the connection we stop processing on our side.
2023-11-21 12:21:35 -05:00
Kwitsch 1a1891c8b6
symbol name refactoring (#1263)
* ECSConfig -> ECS

* EdeConfig -> EDE

* EdeResolver -> EDEResolver

* SUDNConfig -> SUDN

* FqdnOnlyConfig -> FQDNOnly

* FqdnOnlyResolver -> FQDNOnlyResolver
2023-11-21 06:33:38 +01:00
Kwitsch d37d18348f
EDNS: Client Subnet (#1007)
* added util for handling EDNS0 options

* disable caching if the request contains a netmask size greater than 1

* added config section for ECS handling and validation for it

*added ecs_resolver for enhancing and cleaning subnet and client IP information
2023-11-20 16:56:56 +01:00
ThinkChaos d52c598546
fix(tests): properly silence log output (#1259)
* fix(tests): properly silence log output

Using `init` allows it to also work for benchmarks.
And `log.Silence` was sometimes getting overridden by `log.init`.

* squash: fix(server): don't setup the logger again
2023-11-19 17:51:49 -05:00
DerRockWolf 94663eeaeb
feat: add upstream strategy `random` (#1221)
Also simplify code by getting rid of `resolversPerClient` and all surrounding logic.
2023-11-18 15:42:14 -05:00
ThinkChaos b498bc5094
feat(lists): add support for wildcard lists using a custom Trie (#1233) 2023-11-17 15:58:35 +01:00
Kwitsch 6c000090b1
Unit test refactoring & devcontainer enhancement(#1245)
* Whietlist dot imports for test packages

* improved generate-lcov script

* moved mock_call_sequence to helpertest

* removed default config for markdown

* generate seperate lcov.info for each directory

* path fix in lcov generation script

* ginkgo -> v2.13.1

* fixed redundant strings

* added exampleComKey

* added folder name to finish message

* hide lcov.info in devcontainer

* coverage plugin is bugged if lcov file is excluded

* moved all lcov files to coverage folder

* added requested toos #1251
2023-11-15 16:42:53 +01:00
Kwitsch 8ece708fe9
devcontainer & unit test refactoring (#1220)
* extension cleanup & added ginkgo watch

* added gcov2lcov

* added test explorer and reworked scripts

* go mod tidy

* use package cache volume

* script rework

* defined tasks

* defined launch

* don't try to convert if test was canceld

* generate lcov only in devcontainer

* disable coverage upload on forks

* wip: make lcov

* fixed unit tests for parallel

* parallel test for lists

* fix serve test for parallel

* parallel test fixes

* deleted accident commit

* wip: make lcov

* restructured settings location

* start script refactoring

* added GetProcessPort

* fixed parallel ports

* race fix

* changed port for github runner binding

* fixed local list var in test

* more local vars in tests fix

* less local vars

* run test & race parallel

* removed invalid error check

* fixed error  check

* less local variables

* fixed timing problem

* removed gcov2lcov

* added generate-lcov

* added GINKGO_PROCS to makefile

* fixed workflow

* run generate-lcov on save *.go

* added tooltitude
2023-11-11 11:58:31 -05:00
Kwitsch d87e6b4157
fix: ANSI color codes being printed on Windows (#1225)
* added go-colorable

* fixed bug which prevented windows builds
2023-11-08 00:29:53 +01:00
Dimitri Herzog 33ea933015
refactor: pass context for goroutine shutdown (#1187) 2023-10-07 16:21:40 -04:00
Dimitri Herzog d77f0ed54f
feat: add API endpoint to flush the DNS Cache (#1178) 2023-09-30 16:13:01 -04:00
Dimitri Herzog 72d747c16f
feat: API-first approach for REST interface (#1129)
* feat: embed OpenAPI definition file

* feat: use OpenAPI generated server and client

* feat: provide OpenAPI interface documentation

* chore(test): add additional tests
2023-09-09 19:30:55 +02:00
DerRockWolf c112e86740
feat: add upstream strategy `strict` (#1093) 2023-08-21 09:50:23 +02:00
ThinkChaos 639fba5323 refactor(config): allow more configuration for `upstreams`
Rename the `upstream` option to `upstreams.groups` so we can have
more `upstreams` options.
2023-08-01 15:01:40 -04:00
ThinkChaos 56633da0a7 feat(sudn): refactor and expand supported special use domains RFCs 2023-07-14 17:38:13 -04:00
ThinkChaos cfc3699ab5 feat: support multiple hosts files 2023-07-07 09:16:20 -04:00
Dimitri Herzog 8e70b8a975
chore(build): update golangci-lint (#931) 2023-03-16 07:49:09 +01:00
ThinkChaos 5088c75a78
refactor: configuration rework (usage and printing) (#920)
* refactor: make `config.Duration` a struct with `time.Duration` embed

Allows directly calling `time.Duration` methods.

* refactor(HostsFileResolver): don't copy individual config items

The idea is to make adding configuration options easier, and searching
for references straight forward.

* refactor: move config printing to struct and use a logger

Using a logger allows using multiple levels so the whole configuration
can be printed in trace/verbose mode, but only important parts are
shown by default.

* squash: rename `Cast` to `ToDuration`

* squash: revert `Duration` to a simple wrapper ("new type" pattern)

* squash: `Duration.IsZero` tests

* squash: refactor resolvers to rely on their config directly if possible

* squash: implement `IsEnabled` and `LogValues` for all resolvers

* refactor: use go-enum `--values` to simplify getting all log fields

* refactor: simplify `QType` unmarshaling

* squash: rename `ValueLogger` to `Configurable`

* squash: rename `UpstreamConfig` to `ParallelBestConfig`

* squash: rename `RewriteConfig` to `RewriterConfig`

* squash: config tests

* squash: resolver tests

* squash: add `ForEach` test and improve `Chain` ones

* squash: simplify implementing `config.Configurable`

* squash: minor changes for better coverage

* squash: more `UnmarshalYAML` -> `UnmarshalText`

* refactor: move `config.Upstream` into own file

* refactor: add `Resolver.Type` method

* squash: add `log` method to `typed` to use `Resolover.Type` as prefix

* squash: tweak startup config logging

* squash: add `LogResolverConfig` tests

* squash: make sure all options of type `Duration` use `%s`
2023-03-12 22:14:10 +01:00
Dimitri Herzog 2c108dabb8 chore: change branch name to "main" (#744) 2023-03-07 17:25:04 +01:00
Dimitri Herzog bcea1a93db
fix: query command doesn't show the client IP (#861) (#914) 2023-03-07 14:23:23 +01:00
Dimitri Herzog 53a7d4fccc
Test refactoring (#798)
* test: refactor tests

* chore: fix possible race condition in cache
2022-12-29 14:58:25 +01:00
Kwitsch 9abeaeddea
Added gofumpt (#805)
* fix linter errors

* added gofumpt

* Makefile cleanup

* gofumpt run

* Update Makefile

Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com>

* go mod tidy

* fmt + lint

* go mod tidy

Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com>
2022-12-26 22:11:45 +01:00
Kwitsch b73cd3b5ba
Config restructuring (#771)
To declutter the global top level config options i propose the grouping of ports and logging options as child options of top level options.

New structure:
ports:
  dns: 43
  http: 4000
  https: 4443
  tls: 853
log:
  level: warn
  format: json
  privacy: true
  timestamp: false
2022-12-02 21:55:40 +01:00
ThinkChaos c06c017a1a fix: `startVerifyUpstream` not disabling all start checks 2022-12-02 12:56:44 -05:00