Commit Graph

292 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 dbd1390589 tests(resolver): fix data race introduced by querylog ignore
Race only happens in tests: the write removed here can happen at the
same time as `writeLog` is reading the struct field since cancelling
the context doesn't guarantee immediate shutdown.
We can just use the existing channel so the field becomes read-only,
avoiding the race.

Example CI failure:
https://github.com/0xERR0R/blocky/actions/runs/8632315589/job/23662702020

For local repro, adding a 2ms sleep to `writeLog`'s startup was enough
for me.
2024-04-11 18:34:30 -04:00
ThinkChaos bcd1381e18 feat: update list config and code to use "allow/deny" language 2024-04-11 18:33:09 -04:00
ThinkChaos d5b6ee93b5 fix: use proxy env vars via Go default HTTP Transport values
Don't build `http.Transport` instances from scratch, but start from
`http.DefaultTransport` and override what is needed.
2024-04-10 09:43:57 -04:00
ThinkChaos 9d65b9395d feat: add `queryLog.ignore.sudn` option to ignore SUDN responses 2024-04-05 15:32:09 -04:00
ThinkChaos 73e5d6ab88 refactor: remove `model.Request.Log` in favor of use `Context` 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 9f633f18d0
feat: Support defining records by dns zone format (#1360)
* feat: Support zonefile configuration for custom dns mapping

* docs: Update configuration.md

* Rename var to ok

* Linter fixes

* Remove hashes in test describe description

* Implement PR comments; zoneFileMapping -> zone, initialize with proper sizes

* Remove custom CNAME parsing

* Utilize TTL defined in zone file

* Link to wikipedia's example file

* Test to confirm that a relative zone entry without an $ORIGIN returns an error

* Write a test covering the $INCLUDE directive

* Write a test confirming that a dns zone can result in more than 1 RR

* Linting

* fix: Use proper matchers in CustomDNS Zone tests; Update configuration.md description

* Pull in config directory to support relative $INCLUDE

* Added tests to ensure the ability to use both bare filenames as well as relative filenames when using the $INCLUDE directive

* Shorten test description (Linting error)

* Move Assignment of z.RRs to the end of the UnmarshallYAML function

* Moved tests for relative $INCLUDE zones to config_test. Added test case when config param passed to blocky is a directory

* Corrected test case to _actually_ test againt bare file names
2024-02-09 17:28:58 +01: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 dd76cf5bb0 fix: add `Resolver.String` so logs don't use Go's default format 2024-01-18 10:47:04 -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 dece894bd6 fix(rewrite): support the case where upstream doesn't echo the question
Apparently Tailscale's magic DNS does this.
2023-12-20 10:14:17 -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 29a5681b3c refactor(bootstap): prepare for resolver package split 2023-12-05 20:52:46 -05:00
ThinkChaos ef29cdc45e refactor(config): ensure `upstreams.timeout` is always valid 2023-12-05 20:52:46 -05:00
ThinkChaos 0f69630563 refactor(bootstrap): replace `Dialer.Timeout` with a `context` deadline 2023-12-05 20:52:46 -05:00
ThinkChaos 603d374405 refactor: remove no longer needed TLS handshake timeout
Since the whole resolve has a context w/ deadline it's no longer needed.
2023-12-05 20:52:46 -05:00
ThinkChaos a6654dcd57 refactor(config): rename `StartStrategyType` to `InitStrategy` 2023-12-05 20:52:46 -05:00
ThinkChaos 7a3c054b43 feat: add `upstreams.init.strategy`
Replaces `startVerifyUpstream` and behaves just like
`blocking.loading.strategy`.

We use the bootstrap resolver for any requests that arrive before the
upstreams are initialized.
2023-12-05 20:52:46 -05:00
ThinkChaos 659076dd7b refactor(resolvers): make `Bootstrap` implement `Resolver` 2023-12-05 20:52:46 -05:00
Kwitsch 11543356b6
Bugfix in ECS forward (#1290)
* fixed override bug in forward

* set prettier as default formatter for yaml

* added ecs to example config
2023-12-03 14:29:31 -05:00
ThinkChaos adb970af10 refactor(tests): use `MockUDPUpstreamServer.WithDelay` where possible 2023-12-01 15:53:11 -05:00
ThinkChaos 8ad83d0568 refactor(tests): use a `const timeout` to simplify race avoidance 2023-12-01 15:53:11 -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 fe5c753eed style(tests): `ShouldNot(HaveOccurred())` -> `Should(Succeed())` 2023-12-01 15:53:11 -05:00
ThinkChaos a330174949 style(tests): `ShouldNot(Succeed())` -> `Should(HaveOccurred())` 2023-12-01 15:53:11 -05:00
ThinkChaos 321680250a style(tests): `Should(Not(x))` -> `ShouldNot(x)` 2023-12-01 15:53:11 -05:00
Kwitsch 3378316982
Refactoring: FileDownloader (#1281)
* enabled containedctx & contextcheck

* enabled noctx

* less background context

* context metrics test

* use ginkgo context instead of background

* fix redis e2e tests

* made downloader context aware
2023-11-29 18:18:29 +01: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 e4be0c0c86 refactor(config): remove `GetConfig` and its last uses 2023-11-23 08:45:18 -05:00
ThinkChaos 9760735f3a refactor(config): move `dohUserAgent` to `upstreams.userAgent`
That way it can be accessed without using `GetConfig`
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
ThinkChaos 08a3df6e64 fix(tests): don't make following requests wait on the first
This could cause tests with delays much longer than the timeout to
timeout multiple times in a row just because the first `answerFn` call
was stalled.
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 2c71f91aca refactor: remove deprecated and no-op `SingleInflight` 2023-11-21 12:21:35 -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
ThinkChaos e4ebc16ccc fix(parallel_best): set `typeName` to "random" when appropriate 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
Dimitri Herzog 4a5a395655
fix: log.privacy option no longer hides domain names being resolved (#1255) 2023-11-17 15:59:22 +01:00