1
0
mirror of https://github.com/juanfont/headscale.git synced 2024-12-20 19:09:07 +01:00

error if no prefix is configured (#1918)

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2024-04-30 11:11:29 +02:00 committed by GitHub
parent 87e2ae4d52
commit d5ed8bc074
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -51,7 +51,7 @@ func initConfig() {
cfg, err := types.GetHeadscaleConfig() cfg, err := types.GetHeadscaleConfig()
if err != nil { 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() machineOutput := HasMachineOutputFlag()

View File

@ -650,6 +650,10 @@ func GetHeadscaleConfig() (*Config, error) {
return nil, err 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") allocStr := viper.GetString("prefixes.allocation")
var alloc IPAllocationStrategy var alloc IPAllocationStrategy
switch allocStr { switch allocStr {
@ -658,7 +662,7 @@ func GetHeadscaleConfig() (*Config, error) {
case string(IPAllocationStrategyRandom): case string(IPAllocationStrategyRandom):
alloc = IPAllocationStrategyRandom alloc = IPAllocationStrategyRandom
default: 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() dnsConfig, baseDomain := GetDNSConfig()