networker

package
v0.0.0-...-bb7b52f Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package networker abstracts network configuration from the rest of the system.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrMeshNotActive to report to outside
	ErrMeshNotActive = errors.New("mesh is not active")
	// ErrMeshPeerIsNotRoutable to report to outside
	ErrMeshPeerIsNotRoutable = errors.New("mesh peer is not routable")
	// ErrMeshPeerNotFound to report to outside
	ErrMeshPeerNotFound = errors.New("mesh peer not found")
	// ErrNothingToCancel is returned when `Cancel()` is called but there is no in progress
	// connection to be canceled
	ErrNothingToCancel = errors.New("nothing to cancel")
)

Functions

This section is empty.

Types

type Combined

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

Combined configures networking for VPN connections.

It is implemented in such a way, that all public methods use sync.Mutex and all private ones don't.

func NewCombined

func NewCombined(
	vpnet vpn.VPN,
	mesh meshnet.Mesh,
	gateway routes.GatewayRetriever,
	publisher events.Publisher[string],
	allowlistRouter routes.Service,
	dnsSetter dns.Setter,
	fw firewall.Service,
	allowlist allowlist.Routing,
	devices device.ListFunc,
	policyRouter routes.PolicyService,
	dnsHostSetter dns.HostnameSetter,
	router routes.Service,
	peerRouter routes.Service,
	exitNode forwarder.ForwardChainManager,
	fwmark uint32,
	lanDiscovery bool,
	ipv6Blocker ipv6.Blocker,
) *Combined

NewCombined returns a ready made version of Combined.

func (*Combined) AllowFileshare

func (netw *Combined) AllowFileshare(uniqueAddress meshnet.UniqueAddress) error

func (*Combined) DisableFirewall

func (netw *Combined) DisableFirewall() error

DisableFirewall turns all firewall operations to noop.

func (*Combined) DisableRouting

func (netw *Combined) DisableRouting()

func (*Combined) EnableFirewall

func (netw *Combined) EnableFirewall() error

EnableFirewall activates the firewall and applies the rules according to the user's settings. (killswitch, allowlist)

func (*Combined) EnableRouting

func (netw *Combined) EnableRouting()

func (*Combined) ForbidFileshare

func (netw *Combined) ForbidFileshare() error

func (*Combined) GetConnectionParameters

func (netw *Combined) GetConnectionParameters() (vpn.ServerData, bool)

func (*Combined) IsMeshnetActive

func (netw *Combined) IsMeshnetActive() bool

IsMeshnetActive returns true when meshnet was activated. Otherwise false is returned.

Thread safe.

func (*Combined) IsNetworkSet

func (netw *Combined) IsNetworkSet() bool

func (*Combined) IsVPNActive

func (netw *Combined) IsVPNActive() bool

IsVPNActive returns true when connection to VPN server is established. Otherwise false is returned.

Thread safe.

func (*Combined) LastServerName

func (netw *Combined) LastServerName() string

LastServerName returns last used server hostname

func (*Combined) PermitFileshare

func (netw *Combined) PermitFileshare() error

func (*Combined) Reconnect

func (c *Combined) Reconnect(stateIsUp bool)

Reconnect refresh connectivity on network state change

func (*Combined) Refresh

func (netw *Combined) Refresh(c mesh.MachineMap) error

Refresh peer list.

func (*Combined) ResetRouting

func (netw *Combined) ResetRouting(peer mesh.MachinePeer, peers mesh.MachinePeers) error

func (*Combined) SetAllowlist

func (netw *Combined) SetAllowlist(allowlist config.Allowlist) error

func (*Combined) SetDNS

func (netw *Combined) SetDNS(nameservers []string) error

SetDNS to the given nameservers.

func (*Combined) SetKillSwitch

func (netw *Combined) SetKillSwitch(allowlist config.Allowlist) error

func (*Combined) SetLanDiscovery

func (netw *Combined) SetLanDiscovery(enabled bool)

func (*Combined) SetMesh

func (netw *Combined) SetMesh(
	cfg mesh.MachineMap,
	self netip.Addr,
	privateKey string,
) (err error)

func (*Combined) SetVPN

func (netw *Combined) SetVPN(v vpn.VPN)

func (*Combined) Start

func (netw *Combined) Start(
	ctx context.Context,
	creds vpn.Credentials,
	serverData vpn.ServerData,
	allowlist config.Allowlist,
	nameservers config.DNS,
	enableLocalTraffic bool,
) (err error)

Start VPN connection after preparing the network.

func (*Combined) StatusMap

func (netw *Combined) StatusMap() (map[string]string, error)

func (*Combined) Stop

func (netw *Combined) Stop() error

Stop VPN connection and clean up network after it stopped.

func (*Combined) UnSetMesh

func (netw *Combined) UnSetMesh() error

func (*Combined) UnsetDNS

func (netw *Combined) UnsetDNS() error

UnsetDNS to original settings.

func (*Combined) UnsetFirewall

func (netw *Combined) UnsetFirewall() error

func (*Combined) UnsetKillSwitch

func (netw *Combined) UnsetKillSwitch() error

type ErrNoSuchRule

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

ErrNoSuchRule is returned when networker tried to remove a rule, but such rule does not exist

func (ErrNoSuchRule) Error

func (e ErrNoSuchRule) Error() string

type Networker

type Networker interface {
	Start(
		context.Context,
		vpn.Credentials,
		vpn.ServerData,
		config.Allowlist,
		config.DNS,
		bool,
	) error
	// Cancel is created instead of using context.Context because `Start` is shared between VPN
	// and meshnet networkers
	Stop() error      // stop vpn
	UnSetMesh() error // stop meshnet
	SetDNS(nameservers []string) error
	UnsetDNS() error
	IsVPNActive() bool
	IsMeshnetActive() bool
	EnableFirewall() error
	DisableFirewall() error
	EnableRouting()
	DisableRouting()
	SetAllowlist(allowlist config.Allowlist) error
	IsNetworkSet() bool
	SetKillSwitch(config.Allowlist) error
	UnsetKillSwitch() error
	SetVPN(vpn.VPN)
	LastServerName() string
	SetLanDiscovery(bool)
	UnsetFirewall() error
	GetConnectionParameters() (vpn.ServerData, bool)
}

Networker configures networking for connections.

At the moment interface is designed to support only VPN connections.

Jump to

Keyboard shortcuts

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