Documentation ¶
Overview ¶
Package wgconfig provides examples of simple client and server configurations using the WireGuard API. It includes functionality to generate and manage basic WireGuard VPN configurations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateConfigPair ¶
func GenerateConfigPair(endpoint *net.UDPAddr, clientIP net.IP) (client *Client, server *Server, _ error)
GenerateConfigPair creates a paired client and server configuration that are pre-configured to connect to each other. It generates private/public key pairs for both client and server, a shared pre-shared key, and initializes the client and server structs with these and additional passed parameters.
The function requires an endpoint (UDP address of the server) and clientIP (IP address assigned to the client for VPN use). It returns either a configured client and server struct or the error encountered during the configuration process. The client and server are set to communicate with each other, with the client configured to allow all IPs and have a default persistent keepalive interval.
Parameters: - endpoint: A net.UDPAddr representing the server's address and port. - clientIP: A net.IP representing the IP address to be assigned to the client in the VPN.
Returns: - client: A pointer to an initialized Client. - server: A pointer to an initialized Server. - error: An error if the generation of keys fail, otherwise nil.
Types ¶
type Client ¶
type Client struct { Private wgapi.PrivateKey // Private is the private key of the peer. (required) Public wgapi.PublicKey // Public is the public key of the server that the peer intends to connect to. (required) Endpoint net.UDPAddr // Endpoint specifies the server's address and port as a UDP address. (required) PersistentKeepalive *uint16 // PersistentKeepalive is an optional field that specifies the frequency in seconds of keepalive messages sent to maintain the connection. (0 to disable, nil is ignored) AllowedIPs []net.IPNet // AllowedIPs specifies IP ranges that are allowed to be routed through this WireGuard tunnel. }
Client represents a WireGuard peer with necessary configuration parameters. It contains cryptographic keys, network settings, and other options to set up a WireGuard connection.
func (*Client) AllowAllIPs ¶
func (cfg *Client) AllowAllIPs()
AllowAllIPs clears Client.AllowedIPs and sets it to wgapi.EmptySubnet.
func (*Client) DefaultPersistentKeepAlive ¶
func (cfg *Client) DefaultPersistentKeepAlive()
DefaultPersistentKeepAlive sets Client.PersistentKeepalive to wgapi.DefaultPersistentKeepalive.
type Peer ¶
type Peer struct { Public wgapi.PublicKey // Public is the peer's public key used to identify and authenticate it in the network. (required) AllowedIPs []net.IPNet // AllowedIPs are the IP addresses that this peer is allowed to send and receive traffic from in the VPN tunnel. (required) }
Peer represents a client configuration that can establish a connection with a WireGuard server. It includes the client's public key, a pre-shared key for additional security, and a list of allowed IP addresses for routing traffic through the tunnel.
type Server ¶
type Server struct { Private wgapi.PrivateKey // Private is the server's private key used for establishing secure connections. ListenPort uint16 // ListenPort specifies the port number on which the WireGuard server listens for incoming connections. Peers []*Peer // Peers is a list of clients (peers) that are allowed to establish a connection with this server. }
Server represents a WireGuard server configuration. It holds details necessary to set up and manage a WireGuard server including its private key, the port it listens on, and the set of peers that can connect to it.
func (*Server) AddPeer ¶
AddPeer creates and adds a new peer to the server's peer list. It takes the peer's public and preshared keys, along with an IP address to define its identity subnet for allowed IPs. This method is used to dynamically expand the server's network with additional clients.
func (*Server) DefaultListenPort ¶
func (cfg *Server) DefaultListenPort()
DefaultListenPort sets Server.ListenPort to wgapi.DefaultListenPort.