wireguard

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Package wireguard manipulates wireguard interfaces

Index

Constants

View Source
const (
	// IGWDialTimeout is the timeout for dialing internet gateway.
	IGWDialTimeout = time.Second * 5
	// IGWMonitorInterval is the interval at which to check internet gateway's health.
	IGWMonitorInterval = time.Second * 30
	// IGWRecoveryThreshold is the number of consecutive successes before considering
	// internet gateway is up.
	IGWRecoveryThreshold = 3
	// IGWFailureThreshold is the number of consecutive failures before considering
	// internet gateway is down.
	IGWFailureThreshold = 3
)
View Source
const (
	IPv4Network = "0.0.0.0/0"
	IPv6Network = "::/0"
)
View Source
const (
	RouteTableName    = 111
	EgressRouteMetric = 256
)

Variables

View Source
var EgressResetCh = make(chan struct{}, 2)
View Source
var (
	ErrModuleNotFound = errors.New("module not found")
)
View Source
var HaEgressCheckInterval = time.Second * 2
View Source
var HaEgressTicker *time.Ticker

Functions

func ApplyWithoutWGQuick

func ApplyWithoutWGQuick(nc *NCIface) error

ApplyWithoutWGQuick - Function for running the equivalent of "wg-quick up" for linux if wg-quick is missing

func DeleteOldInterface added in v0.18.3

func DeleteOldInterface(iface string)

DeleteOldInterface - removes named interface

func EndpointDetectedAlready added in v0.22.0

func EndpointDetectedAlready(peerPubKey string) bool

EndpointDetectedAlready - checks if better endpoint has been detected already

func GetBetterEndpoint added in v1.0.0

func GetBetterEndpoint(peerKey string) (*net.UDPAddr, bool)

func GetDefaultGateway added in v0.23.0

func GetDefaultGateway() (gwRoute netlink.Route, err error)

GetDefaultGateway - get current default gateway

func GetDefaultGatewayIp added in v0.23.0

func GetDefaultGatewayIp() (ip net.IP, err error)

GetDefaultGatewayIp - get current default gateway

func GetDefaultGatewayV6 added in v0.25.0

func GetDefaultGatewayV6() (gwRoute netlink.Route, err error)

GetDefaultGatewayV6 - get current default gateway ipv6

func GetDomainAnsFromCache added in v1.1.0

func GetDomainAnsFromCache(egressDomain models.EgressDomain) (ips []string)

func GetEgressDomains added in v1.1.0

func GetEgressDomains() []models.EgressDomain

func GetIPNetfromIp added in v0.23.0

func GetIPNetfromIp(ip net.IP) (ipCidr *net.IPNet)

GetIPNetfromIp - converts ip into ipnet based network class

func GetOriginalDefaulGw added in v0.23.0

func GetOriginalDefaulGw() (gwIP net.IP, err error)

GetOriginalDefaulGw - fetches system's original default gw

func GetPeer added in v0.22.0

func GetPeer(ifaceName, peerPubKey string) (wgtypes.Peer, error)

GetPeer - gets the peerinfo from the wg interface

func GetPeersFromDevice added in v0.90.0

func GetPeersFromDevice(ifaceName string) (map[string]wgtypes.Peer, error)

func IfaceDelta

func IfaceDelta(currentNode *config.Node, newNode *config.Node) bool

IfaceDelta - checks if the new node causes an interface change

func IfaceExists

func IfaceExists(ifacename string) bool

IfaceExists - return true if you can find the iface

func RemoveEgressRoutes added in v0.24.1

func RemoveEgressRoutes()

func RemoveRoutes added in v0.24.1

func RemoveRoutes(addrs []ifaceAddress)

RemoveRoutes - Remove routes to the interface

func RemoveWithoutWGQuick

func RemoveWithoutWGQuick(ifacename string) error

RemoveWithoutWGQuick - Function for running the equivalent of "wg-quick down" for linux if wg-quick is missing

func RestoreInternetGw added in v0.23.0

func RestoreInternetGw() (err error)

RestoreInternetGw - delete the route in table ROUTE_TABLE_NAME and delet the rules

func SetDomainAnsInCache added in v1.1.0

func SetDomainAnsInCache(egressDomain models.EgressDomain, ips []string)

func SetEgressDomains added in v1.1.0

func SetEgressDomains(egressDomains []models.EgressDomain)

func SetEgressRoutes added in v0.20.4

func SetEgressRoutes(egressRoutes []models.EgressNetworkRoutes)

func SetEgressRoutesInCache added in v1.1.0

func SetEgressRoutesInCache(egressRoutesInfo []models.EgressNetworkRoutes)

func SetInternetGw added in v0.23.0

func SetInternetGw(publicKey string, networkIP net.IP) (err error)

SetInternetGw - set a new default gateway and add rules to activate it

func SetPeers

func SetPeers(replace bool) error

SetPeers - sets peers on netmaker WireGuard interface

func SetRoutes added in v0.20.4

func SetRoutes(addrs []ifaceAddress) error

SetRoutes - sets additional routes to the interface

func SetRoutesFromCache added in v0.24.1

func SetRoutesFromCache()

func ShouldReplace added in v0.22.0

func ShouldReplace(incomingPeers []wgtypes.PeerConfig) bool

ShouldReplace - checks curr peers and incoming peers to see if the peers should be replaced

func StartEgressHAFailOverThread added in v1.1.0

func StartEgressHAFailOverThread(ctx context.Context, waitg *sync.WaitGroup)

func UpdatePeer

func UpdatePeer(p *wgtypes.PeerConfig) error

UpdatePeer replaces a wireguard peer temporarily making public func to pass staticchecks this function will be required in future when update node on server is refactored

Types

type IGWMonitor added in v1.1.0

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

func GetIGWMonitor added in v1.1.0

func GetIGWMonitor() *IGWMonitor

func (*IGWMonitor) IsCurrentIGW added in v1.1.0

func (m *IGWMonitor) IsCurrentIGW(networkIP net.IP) bool

IsCurrentIGW returns true if the node represented by the networkIP is the current internet gateway.

func (*IGWMonitor) Monitor added in v1.1.0

func (m *IGWMonitor) Monitor(publicKey string, networkIP net.IP)

Monitor starts the monitor.

func (*IGWMonitor) Stop added in v1.1.0

func (m *IGWMonitor) Stop()

Stop stops the monitor.

type NCIface

type NCIface struct {
	Iface     netIface
	Name      string
	Addresses []ifaceAddress
	MTU       int
	Config    wgtypes.Config
}

NCIface - represents a Netclient network interface

func GetInterface

func GetInterface() *NCIface

func NewNCIface

func NewNCIface(host *config.Config, nodes config.NodeMap) *NCIface

NewNCIFace - creates a new Netclient interface in memory

func (*NCIface) ApplyAddrs

func (nc *NCIface) ApplyAddrs() error

netLink.ApplyAddrs - applies the assigned node addresses to given interface (netLink)

func (*NCIface) Close

func (n *NCIface) Close()

NCIface.Close closes netmaker interface

func (*NCIface) Configure

func (n *NCIface) Configure() error

Configure applies configuration to netmaker wireguard interface

func (*NCIface) Create

func (nc *NCIface) Create() error

NCIface.Create - creates a linux WG interface based on a node's host config

func (*NCIface) SetMTU

func (n *NCIface) SetMTU() error

NCIface.SetMTU - sets the mtu for the interface

func (*NCIface) UpdatePeer

func (n *NCIface) UpdatePeer(p wgtypes.PeerConfig)

NCIface.UpdatePeer - Updates Peers from provided PeerConfig

Jump to

Keyboard shortcuts

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