feat(dns): replace unbound with qdm12/dns@v2.0.0-beta-rc6 (#1742)

- Faster start up
- Clearer error messages
- Allow for more Gluetun-specific customization
- DNSSEC validation is dropped for now (it's sort of unneeded)
- Fix #137
This commit is contained in:
Quentin McGaw
2024-08-21 14:35:41 +02:00
committed by GitHub
parent 3f130931d2
commit 4d60b71583
30 changed files with 387 additions and 762 deletions

View File

@@ -1,35 +1,46 @@
package dns
import "context"
import (
"context"
"fmt"
"github.com/qdm12/dns/v2/pkg/blockbuilder"
"github.com/qdm12/dns/v2/pkg/middlewares/filter/update"
)
func (l *Loop) updateFiles(ctx context.Context) (err error) {
l.logger.Info("downloading DNS over TLS cryptographic files")
if err := l.conf.SetupFiles(ctx); err != nil {
return err
}
settings := l.GetSettings()
unboundSettings, err := settings.DoT.Unbound.ToUnboundFormat()
if err != nil {
return err
}
l.logger.Info("downloading hostnames and IP block lists")
blacklistSettings, err := settings.DoT.Blacklist.ToBlacklistFormat()
blacklistSettings := settings.DoT.Blacklist.ToBlockBuilderSettings(l.client)
blockBuilder, err := blockbuilder.New(blacklistSettings)
if err != nil {
return fmt.Errorf("creating block builder: %w", err)
}
result := blockBuilder.BuildAll(ctx)
for _, resultErr := range result.Errors {
if err != nil {
err = fmt.Errorf("%w, %w", err, resultErr)
continue
}
err = resultErr
}
if err != nil {
return err
}
blockedHostnames, blockedIPs, blockedIPPrefixes, errs :=
l.blockBuilder.All(ctx, blacklistSettings)
for _, err := range errs {
l.logger.Warn(err.Error())
updateSettings := update.Settings{
IPs: result.BlockedIPs,
IPPrefixes: result.BlockedIPPrefixes,
}
updateSettings.BlockHostnames(result.BlockedHostnames)
err = l.filter.Update(updateSettings)
if err != nil {
return fmt.Errorf("updating filter: %w", err)
}
// TODO change to BlockHostnames() when migrating to qdm12/dns v2
unboundSettings.Blacklist.FqdnHostnames = blockedHostnames
unboundSettings.Blacklist.IPs = blockedIPs
unboundSettings.Blacklist.IPPrefixes = blockedIPPrefixes
return l.conf.MakeUnboundConf(unboundSettings)
return nil
}