Skip to content

Commit

Permalink
feat(config): add /32 if not present for Wireguard addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Sep 24, 2023
1 parent 4d627bb commit 9b00763
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions internal/configuration/sources/files/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/configuration/sources/files/wireguard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 9b00763

Please sign in to comment.