From 9b00763a69610c385abcd89a091f5a316e8038b3 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Sun, 24 Sep 2023 15:23:24 +0000 Subject: [PATCH] feat(config): add `/32` if not present for Wireguard addresses --- internal/configuration/sources/files/wireguard.go | 3 +++ internal/configuration/sources/files/wireguard_test.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/configuration/sources/files/wireguard.go b/internal/configuration/sources/files/wireguard.go index 5ed3a8129..658cb895c 100644 --- a/internal/configuration/sources/files/wireguard.go +++ b/internal/configuration/sources/files/wireguard.go @@ -101,6 +101,9 @@ func parseINIWireguardAddress(section *ini.Section) ( addresses = make([]netip.Prefix, len(addressStrings)) for i, addressString := range addressStrings { addressString = strings.TrimSpace(addressString) + if !strings.ContainsRune(addressString, '/') { + addressString += "/32" + } addresses[i], err = netip.ParsePrefix(addressString) if err != nil { return nil, fmt.Errorf("parsing address: %w", err) diff --git a/internal/configuration/sources/files/wireguard_test.go b/internal/configuration/sources/files/wireguard_test.go index c74aab438..a93102ebc 100644 --- a/internal/configuration/sources/files/wireguard_test.go +++ b/internal/configuration/sources/files/wireguard_test.go @@ -131,7 +131,7 @@ PreSharedKey = x iniData: `[Interface] Address = x `, - errMessage: "parsing address: netip.ParsePrefix(\"x\"): no '/'", + errMessage: "parsing address: netip.ParsePrefix(\"x/32\"): ParseAddr(\"x\"): unable to parse IP", }, "success": { iniData: ` @@ -238,7 +238,7 @@ func Test_parseINIWireguardAddress(t *testing.T) { "bad address": { fileContent: `[Interface] Address = x`, - errMessage: "parsing address: netip.ParsePrefix(\"x\"): no '/'", + errMessage: "parsing address: netip.ParsePrefix(\"x/32\"): ParseAddr(\"x\"): unable to parse IP", }, "success": { fileContent: `[Interface]