system

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package system contains utilities for managing network interfaces on the system.

Index

Constants

View Source
const DefaultMTU = 1420

DefaultMTU is the default MTU for wireguard interfaces. TODO: Try to determine this automatically.

Variables

This section is empty.

Functions

func DoInNetNS added in v0.11.2

func DoInNetNS(netNS string, fn func() error) error

func IsInterfaceNotExists

func IsInterfaceNotExists(err error) bool

IsInterfaceNotExists returns true if the given error is an interface not exists error.

func IsRouteExists

func IsRouteExists(err error) bool

IsRouteExists returns true if the given error is a route exists error.

Types

type Interface

type Interface interface {
	// Name returns the real name of the interface.
	Name() string
	// AddressV4 should return the current private IPv4 address of this interface.
	AddressV4() netip.Prefix
	// AddressV6 should return the current private IPv6 address of this interface.
	AddressV6() netip.Prefix
	// Up activates the interface.https://kind.sigs.k8s.io/
	Up(context.Context) error
	// Down deactivates the interface.
	Down(context.Context) error
	// Destroy destroys the interface.
	Destroy(context.Context) error
	// AddRoute adds a route for the given network.
	AddRoute(context.Context, netip.Prefix) error
	// RemoveRoute removes the route for the given network.
	RemoveRoute(context.Context, netip.Prefix) error
	// Link returns the underlying net.Interface.
	Link() (*net.Interface, error)
	// HardwareAddr returns the hardware address of the interface.
	HardwareAddr() (net.HardwareAddr, error)
}

Interface represents an underlying machine network interface for use with WireGuard.

func New

func New(ctx context.Context, opts *Options) (Interface, error)

New creates a new interface using the given options.

type Options

type Options struct {
	// Name is the name of the interface.
	Name string
	// NetNs is the network namespace to create the interface in.
	// This is only supported on Linux.
	NetNs string
	// AddressV4 is the private IPv4 network of this interface.
	AddressV4 netip.Prefix
	// AddressV6 is the private IPv6 network of this interface.
	AddressV6 netip.Prefix
	// ForceTUN forces the use of a TUN interface.
	ForceTUN bool
	// MTU is the MTU of the interface. If unset, it will be automatically
	// detected from the host.
	MTU uint32
	// DisableIPv4 disables IPv4 on the interface.
	DisableIPv4 bool
	// DisableIPv6 disables IPv6 on the interface.
	DisableIPv6 bool
}

Options represents the options for creating a new interface.

Directories

Path Synopsis
Package buffers contains facilities for changing system buffer sizes.
Package buffers contains facilities for changing system buffer sizes.
Package dns contains utility functions for DNS.
Package dns contains utility functions for DNS.
Package firewall contains an interface for interacting with the system firewall.
Package firewall contains an interface for interacting with the system firewall.

Jump to

Keyboard shortcuts

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