Documentation
¶
Index ¶
- func AddClientHandler(im *InterfaceManager, smdClient smdclient.SMDClientInterface) http.HandlerFunc
- func AddWireGuardPeer(interfaceID, publicKey, vpnIP, clientIP string) error
- func GetUsableIP(network *net.IPNet) (net.IP, error)
- type IPAllocator
- type InterfaceManager
- func (m *InterfaceManager) AddPeer(peerName, publicKey, vpnIP, clientIP string) error
- func (m *InterfaceManager) GetInterfaceName() string
- func (m *InterfaceManager) GetPeers() map[string]PeerConfig
- func (m *InterfaceManager) GetServerConfig() (ServerConfig, error)
- func (m *InterfaceManager) IpForPeer(peerName string, publicKey string) string
- func (m *InterfaceManager) PublicKey() (string, error)
- func (m *InterfaceManager) RemovePeer(peerName string) error
- func (m *InterfaceManager) StartServer() error
- func (m *InterfaceManager) StopServer() error
- type PeerConfig
- type PublicKeyRequest
- type ServerConfig
- type Store
- type WGResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddClientHandler ¶
func AddClientHandler(im *InterfaceManager, smdClient smdclient.SMDClientInterface) http.HandlerFunc
AddClientHandler godoc
@Summary Add a WireGuard client
@Description Initiate a WireGuard tunnel from a client using its public key
@Description and peer name (IP address).
@Description
@Description The source IP of the request is read and is used as the peer
@Description name along with the public key to authenticate unless the
@Description `X-Forward-For` header is set. In that case, the value of the
@Description header is used as the peer name. If the peer exists in the
@Description internal tunnel manager, the IP presented is the one used.
@Description Otherwise, the next available IP in range is assigned.
@Accept json
@Produce json
@Success 200 {object} WGResponse
@Failure 400 {object} nil
@Failure 500 {object} nil
@Param pubkey body PublicKeyRequest true "WireGuard public key of client"
@Param X-Forwarded-For header string false "Override source IP"
@Router /cloud-init/wg-init [post]
func AddWireGuardPeer ¶
AddWireGuardPeer adds a peer to the WireGuard configuration.
Types ¶
type IPAllocator ¶
type IPAllocator struct {
// contains filtered or unexported fields
}
IPAllocator manages IP address allocation within a network range.
func NewIPAllocator ¶
func NewIPAllocator(cidr string) (*IPAllocator, error)
NewIPAllocator initializes a new IPAllocator for a given network.
func (*IPAllocator) IsAllocated ¶
func (a *IPAllocator) IsAllocated(ipAddr net.IPAddr) bool
IsAllocated checks if an IP address is currently allocated.
func (*IPAllocator) NextAvailable ¶
func (a *IPAllocator) NextAvailable() (net.IPAddr, error)
NextAvailable returns the next available IP address in the range.
type InterfaceManager ¶
type InterfaceManager struct {
// contains filtered or unexported fields
}
func NewInterfaceManager ¶
func (*InterfaceManager) AddPeer ¶ added in v1.0.4
func (m *InterfaceManager) AddPeer(peerName, publicKey, vpnIP, clientIP string) error
func (*InterfaceManager) GetInterfaceName ¶
func (m *InterfaceManager) GetInterfaceName() string
func (*InterfaceManager) GetPeers ¶
func (m *InterfaceManager) GetPeers() map[string]PeerConfig
func (*InterfaceManager) GetServerConfig ¶
func (m *InterfaceManager) GetServerConfig() (ServerConfig, error)
func (*InterfaceManager) IpForPeer ¶
func (m *InterfaceManager) IpForPeer(peerName string, publicKey string) string
IpForPeer allocates an IP address for a given peer based on its name and public key. If the peer already exists, it returns the existing IP address. Otherwise, it allocates a new IP address for the peer and stores the peer configuration.
func (*InterfaceManager) PublicKey ¶
func (m *InterfaceManager) PublicKey() (string, error)
func (*InterfaceManager) RemovePeer ¶
func (m *InterfaceManager) RemovePeer(peerName string) error
func (*InterfaceManager) StartServer ¶
func (m *InterfaceManager) StartServer() error
func (*InterfaceManager) StopServer ¶ added in v1.0.4
func (m *InterfaceManager) StopServer() error
type PeerConfig ¶
type PublicKeyRequest ¶
type PublicKeyRequest struct {
PublicKey string `` /* 133-byte string literal not displayed */
}
PublicKeyRequest represents the JSON payload for a WireGuard public key.
type ServerConfig ¶
type Store ¶
type Store interface {
IpForPeer(peerName, publicKey string) string
GetInterfaceName() string
GetServerConfig() (ServerConfig, error)
}
type WGResponse ¶ added in v1.1.0
type WGResponse struct {
Message string `json:"message" yaml:"message" example:"WireGuard tunnel created successfully"`
ClientVPNIP string `json:"client-vpn-ip" yaml:"client-vpn-ip" example:"10.89.0.7" description:"Assigned WireGuard VPN IP address"`
ServerPubKey string `json:"server-public-key" yaml:"server-public-key" example:"dHMOGL8vTGhTgqXyYdu6cLGXEPmTcWm+vS18GcQseyg="`
ServerIP string `json:"server-ip" yaml:"server-ip" example:"10.87.0.1" description:"WireGuard server IP"`
ServerPort string `json:"server-port" yaml:"server-port" example:"51820" description:"WireGuard server port"`
}
WGResponse represents the JSON payload for a response from the WireGuard server.