iface

package
v0.0.0-...-5f71cfe Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package iface provides wireguard network interface creation and management

Index

Constants

View Source
const (
	DefaultMTU    = 1280
	DefaultWgPort = 51820
)
View Source
const WgInterfaceDefault = "wt0"

WgInterfaceDefault is a default interface name of Oldsecway

Variables

View Source
var (
	// ErrModuleNotFound is the error resulting if a module can't be found.
	ErrModuleNotFound = errors.New("module not found")
)

Functions

func WireguardModuleIsLoaded

func WireguardModuleIsLoaded() bool

WireguardModuleIsLoaded check if we can load wireguard mod (linux only)

Types

type NativeLink struct {
	Link *netlink.Link
}

type NetInterface

type NetInterface interface {
	Close() error
}

NetInterface represents a generic network tunnel interface

type WGAddress

type WGAddress struct {
	IP      net.IP
	Network *net.IPNet
}

WGAddress Wireguard parsed address

func (*WGAddress) String

func (addr *WGAddress) String() string

type WGIface

type WGIface struct {
	Name      string
	Port      int
	MTU       int
	Address   WGAddress
	Interface NetInterface
	// contains filtered or unexported fields
}

WGIface represents a interface instance

func NewWGIFace

func NewWGIFace(iface string, address string, mtu int) (*WGIface, error)

NewWGIFace Creates a new Wireguard interface instance

func (*WGIface) AddAllowedIP

func (w *WGIface) AddAllowedIP(peerKey string, allowedIP string) error

AddAllowedIP adds a prefix to the allowed IPs list of peer

func (*WGIface) Close

func (w *WGIface) Close() error

Close closes the tunnel interface

func (*WGIface) Configure

func (w *WGIface) Configure(privateKey string, port int) error

Configure configures a Wireguard interface The interface must exist before calling this method (e.g. call interface.Create() before)

func (*WGIface) Create

func (w *WGIface) Create() error

Create creates a new Wireguard interface, sets a given IP and brings it up. Will reuse an existing one.

func (*WGIface) GetAddress

func (w *WGIface) GetAddress() WGAddress

GetAddress returns the interface address

func (*WGIface) GetListenPort

func (w *WGIface) GetListenPort() (*int, error)

GetListenPort returns the listening port of the Wireguard endpoint

func (*WGIface) GetName

func (w *WGIface) GetName() string

GetName returns the interface name

func (*WGIface) RemoveAllowedIP

func (w *WGIface) RemoveAllowedIP(peerKey string, allowedIP string) error

RemoveAllowedIP removes a prefix from the allowed IPs list of peer

func (*WGIface) RemovePeer

func (w *WGIface) RemovePeer(peerKey string) error

RemovePeer removes a Wireguard Peer from the interface iface

func (*WGIface) UpdateAddr

func (w *WGIface) UpdateAddr(newAddr string) error

UpdateAddr updates address of the interface

func (*WGIface) UpdatePeer

func (w *WGIface) UpdatePeer(peerKey string, allowedIps string, keepAlive time.Duration, endpoint *net.UDPAddr, preSharedKey *wgtypes.Key) error

UpdatePeer updates existing Wireguard Peer or creates a new one if doesn't exist Endpoint is optional

Jump to

Keyboard shortcuts

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