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()