From 7412e287742eb16501a188031f389cea329644a7 Mon Sep 17 00:00:00 2001 From: Stanislav Chzhen Date: Fri, 17 Oct 2025 09:09:05 +0300 Subject: [PATCH] home: imp code --- internal/home/config.go | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/internal/home/config.go b/internal/home/config.go index 5c0d4eab..d65dff77 100644 --- a/internal/home/config.go +++ b/internal/home/config.go @@ -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) {