-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make external address, make validators package, make wg peer config g…
…eneration correctly append port
- Loading branch information
Showing
5 changed files
with
50 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package validators | ||
|
||
import ( | ||
"errors" | ||
"net" | ||
) | ||
|
||
func ValidExternalAddresses(ExternalAddress string) error { | ||
if len(ExternalAddress) == 0 { | ||
return errors.New("invalid ExternalAddress is empty") | ||
} | ||
|
||
host, _, err := net.SplitHostPort(ExternalAddress) | ||
if err == nil { | ||
// If the external address has a port, split it off and use that as the external address to check | ||
ExternalAddress = host | ||
} | ||
|
||
if net.ParseIP(ExternalAddress) == nil { | ||
|
||
addresses, err := net.LookupIP(ExternalAddress) | ||
if err != nil { | ||
return errors.New("invalid ExternalAddress: " + ExternalAddress + " unable to lookup as domain") | ||
} | ||
|
||
if len(addresses) == 0 { | ||
return errors.New("invalid ExternalAddress: " + ExternalAddress + " not IPv4 or IPv6 external addresses found") | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ func GetIP(addr string) string { | |
return addr[:i] | ||
} | ||
} | ||
|
||
return addr | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters