Documentation ¶
Index ¶
- func GetAllWGConfigFiles(dir string) ([]string, error)
- func GetGateway(subnet string) (string, error)
- func IsIPv4(address string) bool
- func IsIPv6(address string) bool
- func ValidateIP(IP string, subnet string) error
- type Peers
- type WGSrv
- func (wg *WGSrv) GenPeerConf(Name string, AllowedIPs []string, DNS []string, PresharedKey bool, ...) (Peers, error)
- func (wg *WGSrv) GeneratePeerConfig(name string) (wgcfg string, err error)
- func (wg *WGSrv) GenerateSrvConfig() (wgcfg string, err error)
- func (wg *WGSrv) SaveWGConfig(dir string) error
- func (wg *WGSrv) UpdateWGConfig(dir string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAllWGConfigFiles ¶
func GetGateway ¶
GetGateway takes in a subnet and returns the first IP address after the network address. The function expects the subnet to be in CIDR notation (e.g., "192.168.0.0/24") and returns the IP address immediately following the network address.
Parameters:
subnet (string): The subnet in CIDR notation (e.g., "192.168.0.0/24").
Returns:
gateway (string): The IP address of the gateway. err (error): An error object if the provided subnet is not a valid.
Example usage: subnet := "192.168.0.0/24" gateway := GetGateway(subnet) fmt.Println("Gateway IP:", gateway)
func ValidateIP ¶
ValidateIP takes an IP address and the subnet that the IP address belongs to and performs various checks to validate the IP address.
Parameters: - IP (string): The IP address to validate. - subnet (string): The subnet in CIDR notation to which the IP address belongs.
Returns: - err (error): An error object if the IP address is not valid or does not belong to the specified subnet.
Description: The ValidateIP function checks the validity of the provided IP address within the context of the given subnet. It performs the following checks:
1. Empty IP or Subnet: The function checks if either the IP or subnet is empty. If either value is empty, it returns an error indicating the missing value.
2. Invalid Subnet: The function checks if the provided subnet is valid by parsing it using the netip.ParsePrefix function. If the subnet is invalid, an error is returned.
3. Network Address: The function compares the IP address with the network address of the subnet. If they match, it implies that the IP address is the network address and is considered invalid.
4. Subnet Containment: The function verifies if the IP address falls within the specified subnet by checking if it is contained within the network range. If the IP address is not within the subnet, an error is returned.
Example Usage: err := ValidateIP("192.168.0.10", "192.168.0.0/24")
if err != nil { fmt.Println("Invalid IP address:", err) }
Please note that this function provides basic IP address validation within a subnet and may require additional checks based on specific use cases and requirements.
Types ¶
type WGSrv ¶
type WGSrv struct { Name string `yaml:"name"` Endpoint string `yaml:"endpoint"` ListenPort int `yaml:"listenPort"` IPAddress []string `yaml:"IPAddress"` PrivateKey string `yaml:"privateKey"` PublicKey string `yaml:"publicKey"` Peers []Peers `yaml:"peers"` }