wireguard

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Interface  string           `yaml:"interface" valid:"alphanum,required"`
	ServerIPv4 string           `yaml:"server_ipv4" valid:"ipv4"`
	Keepalive  int              `yaml:"keepalive" valid:"natural,required"`
	Subnet     validator.Subnet `yaml:"subnet" valid:"subnet,required"`
	DNS        []string         `yaml:"dns" valid:"ipv4list"`

	// Listen port for wireguard connections.
	ListenPort int `yaml:"server_port" valid:"port,required"`
	// NAT'ed port to access the Listen one, this one announced to the client
	// as part of its configuration. If not specified - `ListenPort` is used.
	// e.g container starts with the -p 3333:3000 option, 3000 here is ListenPort value,
	// so NATedPort must be set to `3333` to push the valid configuration to the client.
	NATedPort int `yaml:"nated_port,omitempty" valid:"port"`

	// PrivateKey of WireGuard, serialized to the string.
	// Generated automatically on the startup.
	PrivateKey string `yaml:"private_key"`
	// contains filtered or unexported fields
}

func DefaultConfig

func DefaultConfig() Config

func (Config) ClientPort

func (c Config) ClientPort() int

ClientPort returns the port to announce to a client. See Config.NATedPort for details.

func (Config) GetPrivateKey

func (c Config) GetPrivateKey() types.WGPrivateKey

func (*Config) OnLoad

func (c *Config) OnLoad() error

func (Config) ServerAddr

func (c Config) ServerAddr() string

ServerAddr returns IPAddr/mask to use as a wireguard interface address.

type Wireguard

type Wireguard struct {
	// contains filtered or unexported fields
}

func New

func New(config Config) (*Wireguard, error)

func (*Wireguard) GetLinkStatistic

func (wg *Wireguard) GetLinkStatistic() (*netlink.LinkStatistics, error)

func (*Wireguard) GetPeers

func (wg *Wireguard) GetPeers() (map[string]wgtypes.Peer, error)

GetPeers returns peers configured for the underlying device. Map's key is a peer's public key string.

func (*Wireguard) Running

func (wg *Wireguard) Running() bool

func (*Wireguard) SetPeer

func (wg *Wireguard) SetPeer(info *types.PeerInfo) error

SetPeer sets peer on wireguard interface Note: it's caller responsibility to provide fully valid peer

func (*Wireguard) Shutdown

func (wg *Wireguard) Shutdown() error

func (*Wireguard) UnsetPeer

func (wg *Wireguard) UnsetPeer(info *types.PeerInfo) error

UnsetPeer removes peer from wireguard interface Note: it's caller responsibility to provide fully valid peer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL