Documentation
¶
Overview ¶
package awgctrl provides internal access to Linux's WireGuard generic netlink interface.
Index ¶
Constants ¶
const ( WGDEVICE_A_JC = iota + 1 + unix.WGDEVICE_A_PEERS // uint16 WGDEVICE_A_JMIN // uint16 WGDEVICE_A_JMAX // uint16 WGDEVICE_A_S1 // uint16 WGDEVICE_A_S2 // uint16 WGDEVICE_A_H1 // uint32 WGDEVICE_A_H2 // uint32 WGDEVICE_A_H3 // uint32 WGDEVICE_A_H4 // uint32 )
Additional attribute types added in amneziawg.
const KeyLen = 32
KeyLen is the expected key length for a WireGuard key.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client provides access to Linux WireGuard netlink information.
func New ¶
New creates a new Client and returns whether or not the generic netlink interface is available.
func (*Client) ConfigureDevice ¶
ConfigureDevice configures a WireGuard device.
type Config ¶
type Config struct {
// PrivateKey specifies a private key configuration, if not nil.
//
// A non-nil, zero-value Key will clear the private key.
PrivateKey *Key
// ListenPort specifies a device's listening port, if not nil.
ListenPort *uint16
// FirewallMark specifies a device's firewall mark, if not nil.
//
// If non-nil and set to 0, the firewall mark will be cleared.
FirewallMark *uint32
// JunkCount sets the number of junk packets, if not nil.
//
// Values: 1-128
// Recommended: 4-12
JunkCount *uint16
// JunkMin specifies the minimum size of junk packets, if not nil.
//
// Values: JunkMax > JunkMin < MTU
// Recommended: 8
JunkMin *uint16
// JunkMax specifies the maximum size of junk packets, if not nil.
//
// Values: JunkMin < JunkMax <= MTU
// Recommended: 80
JunkMax *uint16
// S1 specifies init packet junk size, if not nil.
// Values: S1 <= (MTU - 148) && S1 + 56 != S2
// Recommended: 15-150
S1 *uint16
// S2 specifies response packet junk size, if not nil.
// Values: S2 <= (MTU - 92)
// Recommended: 15-150
S2 *uint16
// H* specifies packet magic header, if not nil.
// H1 - init | H2 - response | H3 - underload | H4 - transport.
// Values: (H* <= MaxInt32); unique among each other
// Recommended: 5-MaxInt32
H1, H2, H3, H4 *uint32
// ReplacePeers specifies if the Peers in this configuration should replace
// the existing peer list, instead of appending them to the existing list.
ReplacePeers bool
// Peers specifies a list of peer configurations to apply to a device.
Peers []PeerConfig
}
A Config is a WireGuard device configuration.
Because the zero value of some Go types may be significant to WireGuard for Config fields, pointer types are used for some of these fields. Only pointer fields which are not nil will be applied when configuring a device.
type Device ¶
type Device struct {
// Name is the name of the device.
Name string
// PrivateKey is the device's private key.
PrivateKey Key
// PublicKey is the device's public key, computed from its PrivateKey.
PublicKey Key
// ListenPort is the device's network listening port.
ListenPort uint16
// FirewallMark is the device's current firewall mark.
//
// The firewall mark can be used in conjunction with firewall software to
// take action on outgoing WireGuard packets.
FirewallMark uint32
// JunkCount is a number of junk packets.
JunkCount uint16
// JunkMin and JunkMax specify the minimum and maximum size of junk packets.
JunkMin, JunkMax uint16
// S1 and S2 is a init and response junk packet sizes.
S1, S2 uint16
// H* is a packet magic header.
// H1 - init | H2 - response | H3 - underload | H4 - transport.
H1, H2, H3, H4 uint32
// Peers is the list of network peers associated with this device.
Peers []Peer
}
Device is a WireGuard device.
func (*Device) Decode ¶
func (d *Device) Decode(ad *netlink.AttributeDecoder)
Decode decodes a Device from a single generic netlink message under the attribute decoder.
type Encoder ¶
type Encoder struct{ *netlink.AttributeEncoder }
Encoder is a netlink attribute encoder but encodes only not nil values.
type Key ¶
A Key is a public, private, or pre-shared secret key. The Key constructor functions in this package can be used to create Keys suitable for each of these applications.
func GenerateKey ¶
func GenerateKey() (k Key)
GenerateKey generates a Key suitable for use as a pre-shared secret key from a cryptographically safe source.
The output Key should not be used as a private key; use GeneratePrivateKey instead.
func GeneratePrivateKey ¶
func GeneratePrivateKey() Key
GeneratePrivateKey generates a Key suitable for use as a private key from a cryptographically safe source.
func NewKey ¶
NewKey creates a Key from an existing byte slice. The byte slice must be exactly 32 bytes in length.
func ParseKey ¶
ParseKey parses a Key from a base64-encoded string, as produced by the Key.String method.
type Peer ¶
type Peer struct {
// PublicKey is the public key of a peer, computed from its private key.
//
// PublicKey is always present in a Peer.
PublicKey Key
// additional layer of security for peer communications.
//
// A zero-value Key means no preshared key is configured.
PresharedKey Key
// Endpoint is the most recent source address used for communication by
// this Peer.
Endpoint *net.UDPAddr
// PersistentKeepaliveInterval specifies how often an "empty" packet is sent
// to a peer to keep a connection alive.
//
// A value of 0 indicates that persistent keepalives are disabled.
PersistentKeepaliveInterval time.Duration
// LastHandshakeTime indicates the most recent time a handshake was performed
// with this peer.
//
// A zero-value time.Time indicates that no handshake has taken place with
// this peer.
LastHandshakeTime time.Time
// ReceiveBytes indicates the number of bytes received from this peer.
ReceiveBytes int64
// TransmitBytes indicates the number of bytes transmitted to this peer.
TransmitBytes int64
// AllowedIPs specifies which IPv4 and IPv6 addresses this peer is allowed
// to communicate on.
//
// 0.0.0.0/0 indicates that all IPv4 addresses are allowed, and ::/0
// indicates that all IPv6 addresses are allowed.
AllowedIPs []net.IPNet
// ProtocolVersion specifies which version of the WireGuard protocol is used
// for this Peer.
//
// A value of 0 indicates that the most recent protocol version will be used.
ProtocolVersion int
}
A Peer is a WireGuard peer to a Device.
func (*Peer) Decode ¶
func (p *Peer) Decode(ad *netlink.AttributeDecoder)
Decode decodes a Peer from a netlink attribute payload.
type PeerConfig ¶
type PeerConfig struct {
// PublicKey specifies the public key of this peer. PublicKey is a
// mandatory field for all PeerConfigs.
PublicKey Key
// Remove specifies if the peer with this public key should be removed
// from a device's peer list.
Remove bool
// UpdateOnly specifies that an operation will only occur on this peer
// if the peer already exists as part of the interface.
UpdateOnly bool
//
// A non-nil, zero-value Key will clear the preshared key.
PresharedKey *Key
// Endpoint specifies the endpoint of this peer entry, if not nil.
Endpoint *net.UDPAddr
// PersistentKeepaliveInterval specifies the persistent keepalive interval
// for this peer, if not nil.
//
// A non-nil value of 0 will clear the persistent keepalive interval.
PersistentKeepaliveInterval *time.Duration
// ReplaceAllowedIPs specifies if the allowed IPs specified in this peer
// configuration should replace any existing ones, instead of appending them
// to the allowed IPs list.
ReplaceAllowedIPs bool
// AllowedIPs specifies a list of allowed IP addresses in CIDR notation
// for this peer.
AllowedIPs []net.IPNet
}
A PeerConfig is a WireGuard device peer configuration.
Because the zero value of some Go types may be significant to WireGuard for PeerConfig fields, pointer types are used for some of these fields. Only pointer fields which are not nil will be applied when configuring a peer.
func (PeerConfig) Encode ¶
func (p PeerConfig) Encode(nae *netlink.AttributeEncoder) error
Encode encodes the PeerConfig into a netlink format.