Skip to content

Commit

Permalink
error if no prefix is configured (#1918)
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
  • Loading branch information
kradalby authored Apr 30, 2024
1 parent 87e2ae4 commit d5ed8bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/headscale/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion hscontrol/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand Down

0 comments on commit d5ed8bc

Please sign in to comment.