From d5ed8bc0747351a5e2d8645f3883ff544f7667ac Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Tue, 30 Apr 2024 11:11:29 +0200 Subject: [PATCH] error if no prefix is configured (#1918) Signed-off-by: Kristoffer Dalby --- cmd/headscale/cli/root.go | 2 +- hscontrol/types/config.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/headscale/cli/root.go b/cmd/headscale/cli/root.go index 68298c55..72c72a20 100644 --- a/cmd/headscale/cli/root.go +++ b/cmd/headscale/cli/root.go @@ -51,7 +51,7 @@ func initConfig() { cfg, err := types.GetHeadscaleConfig() if err != nil { - log.Fatal().Caller().Err(err).Msg("Failed to get headscale configuration") + log.Fatal().Err(err).Msg("Failed to read headscale configuration") } machineOutput := HasMachineOutputFlag() diff --git a/hscontrol/types/config.go b/hscontrol/types/config.go index 20591a6c..fa3a64c6 100644 --- a/hscontrol/types/config.go +++ b/hscontrol/types/config.go @@ -650,6 +650,10 @@ func GetHeadscaleConfig() (*Config, error) { return nil, err } + if prefix4 == nil && prefix6 == nil { + return nil, fmt.Errorf("no IPv4 or IPv6 prefix configured, minimum one prefix is required") + } + allocStr := viper.GetString("prefixes.allocation") var alloc IPAllocationStrategy switch allocStr { @@ -658,7 +662,7 @@ func GetHeadscaleConfig() (*Config, error) { case string(IPAllocationStrategyRandom): alloc = IPAllocationStrategyRandom default: - log.Fatal().Msgf("config error, prefixes.allocation is set to %s, which is not a valid strategy, allowed options: %s, %s", allocStr, IPAllocationStrategySequential, IPAllocationStrategyRandom) + return nil, fmt.Errorf("config error, prefixes.allocation is set to %s, which is not a valid strategy, allowed options: %s, %s", allocStr, IPAllocationStrategySequential, IPAllocationStrategyRandom) } dnsConfig, baseDomain := GetDNSConfig()