mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-10-26 11:27:18 +00:00
home: imp code
This commit is contained in:
parent
f2c13cdc7d
commit
7412e28774
@ -626,7 +626,7 @@ func validateBindHosts(
|
||||
|
||||
for i, addr := range conf.DNS.BindHosts {
|
||||
if !addr.IsValid() {
|
||||
logIPv6Hint(ctx, l, fileData)
|
||||
logIPHint(ctx, l, fileData)
|
||||
|
||||
return fmt.Errorf("dns.bind_hosts at index %d is not a valid ip address", i)
|
||||
}
|
||||
@ -688,15 +688,10 @@ func parseConfig(ctx context.Context, l *slog.Logger) (err error) {
|
||||
return validateTLSCipherIDs(config.TLS.OverrideTLSCiphers)
|
||||
}
|
||||
|
||||
// hintIPv6 is printed when the "::" IPv6 address in the config is not quoted.
|
||||
const hintIPv6 = `NOTE: Quote IPv6 addresses in 'dns.bind_hosts'. For example:
|
||||
dns:
|
||||
bind_hosts:
|
||||
- '::'`
|
||||
|
||||
// logIPv6Hint logs an informational message if the "::" IPv6 address in the
|
||||
// config is not quoted.
|
||||
func logIPv6Hint(ctx context.Context, l *slog.Logger, data []byte) {
|
||||
// logIPHint logs an informational message when the config contains an unquoted
|
||||
// IP address with a trailing colon. It's a best-effort check for a YAML
|
||||
// parsing behavior where a list item is decoded as {key: null}.
|
||||
func logIPHint(ctx context.Context, l *slog.Logger, data []byte) {
|
||||
var conf struct {
|
||||
DNS struct {
|
||||
BindHosts []any `yaml:"bind_hosts"`
|
||||
@ -706,7 +701,11 @@ func logIPv6Hint(ctx context.Context, l *slog.Logger, data []byte) {
|
||||
err := yaml.Unmarshal(data, &conf)
|
||||
if err != nil {
|
||||
// This should not happen since this is already the validation process.
|
||||
l.DebugContext(ctx, "failed to unmarshal the config to print ipv6 hint")
|
||||
l.DebugContext(
|
||||
ctx,
|
||||
"failed to unmarshal config while logging ip hint",
|
||||
slogutil.KeyError, err,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
@ -717,15 +716,27 @@ func logIPv6Hint(ctx context.Context, l *slog.Logger, data []byte) {
|
||||
continue
|
||||
}
|
||||
|
||||
v, ok := m[":"]
|
||||
if !ok || v != nil {
|
||||
if !hasNilValue(m) {
|
||||
continue
|
||||
}
|
||||
|
||||
slogutil.PrintLines(ctx, l, slog.LevelInfo, "", hintIPv6)
|
||||
l.WarnContext(ctx, "quote addresses that end with a colon in 'dns.bind_hosts'")
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// hasNilValue returns true if m contains a nil value.
|
||||
func hasNilValue(m map[string]any) (ok bool) {
|
||||
for _, v := range m {
|
||||
if v == nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// validateConfig returns error if the configuration is invalid. l must not be
|
||||
// nil.
|
||||
func validateConfig(ctx context.Context, l *slog.Logger, fileData []byte) (err error) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user