networking

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Package networking is the subsystem responsible for network/wifi management, and initial device setup via hotspot.

Index

Constants

View Source
const (
	SubsysName = "networking"

	DNSMasqFilepath          = "/etc/NetworkManager/dnsmasq-shared.d/80-viam.conf"
	DNSMasqContentsRedirect  = "address=/#/10.42.0.1\n"
	DNSMasqContentsSetupOnly = "address=/.setup/10.42.0.1\n"

	PortalBindAddr = "10.42.0.1"

	ConnCheckFilepath = "/etc/NetworkManager/conf.d/80-viam.conf"
	ConnCheckContents = "[connectivity]\nuri=http://packages.viam.com/check_network_status.txt\ninterval=300\n"

	NetworkTypeWifi    = "wifi"
	NetworkTypeWired   = "wired"
	NetworkTypeHotspot = "hotspot"

	HealthCheckTimeout = time.Minute
)

Variables

View Source
var (
	ErrBadPassword             = errors.New("bad or missing password")
	ErrConnCheckDisabled       = errors.New("NetworkManager connectivity checking disabled by user, network management will be unavailable")
	ErrNoActiveConnectionFound = errors.New("no active connection found")
)
View Source
var (
	ErrScanTimeout = errw.New("wifi scanning timed out")

	// how long is a scanned network "visible" for candidate selection?
	VisibleNetworkTimeout = time.Minute
)
View Source
var (
	ErrNM = errw.New("NetworkManager does not appear to be responding as expected. " +
		"Please ensure NetworkManger >= v1.30 is installed and enabled. Disabling networking until next restart.")
	ErrNoWifi = errw.New("No WiFi devices available. Disabling networking until next restart.")
)

Functions

func NetworkInfoToProto

func NetworkInfoToProto(net *NetworkInfo) *pb.NetworkInfo

func NewConnectionState

func NewConnectionState(logger logging.Logger) *connectionState

func NewNetworkState

func NewNetworkState(logger logging.Logger) *networkState

func NewSubsystem

func NewSubsystem(ctx context.Context, logger logging.Logger, cfg utils.AgentConfig) subsystems.Subsystem

func WriteDeviceConfig

func WriteDeviceConfig(file string, input userInput) error

Types

type CloudConfig

type CloudConfig struct {
	AppAddress string `json:"app_address"`
	ID         string `json:"id"`
	Secret     string `json:"secret"`
}

type MachineConfig

type MachineConfig struct {
	Cloud *CloudConfig `json:"cloud"`
}

MachineConfig represents the minimal needed for /etc/viam.json.

type NetworkInfo

type NetworkInfo struct {
	Type      string
	SSID      string
	Security  string
	Signal    int32
	Connected bool
	LastError string
}

func NetworkInfoFromProto

func NetworkInfoFromProto(buf *pb.NetworkInfo) *NetworkInfo

type Networking

type Networking struct {
	pb.UnimplementedProvisioningServiceServer
	// contains filtered or unexported fields
}

func (*Networking) ActivateConnection

func (n *Networking) ActivateConnection(ctx context.Context, ifName, ssid string) error

func (*Networking) AddOrUpdateConnection

func (n *Networking) AddOrUpdateConnection(cfg utils.NetworkDefinition) (bool, error)

func (*Networking) Config

func (*Networking) DeactivateConnection

func (n *Networking) DeactivateConnection(ifName, ssid string) error

func (*Networking) GetNetworkList

func (n *Networking) GetNetworkList(ctx context.Context,
	req *pb.GetNetworkListRequest,
) (*pb.GetNetworkListResponse, error)

func (*Networking) GetSmartMachineStatus

func (*Networking) HealthCheck

func (n *Networking) HealthCheck(ctx context.Context) error

HealthCheck reports if a subsystem is running correctly (it is restarted if not).

func (*Networking) SetNetworkCredentials

func (*Networking) Start

func (n *Networking) Start(ctx context.Context) error

func (*Networking) StartProvisioning

func (n *Networking) StartProvisioning(ctx context.Context, inputChan chan<- userInput) error

StartProvisioning puts the wifi in hotspot mode and starts a captive portal.

func (*Networking) Stop

func (n *Networking) Stop(ctx context.Context) error

func (*Networking) StopProvisioning

func (n *Networking) StopProvisioning() error

func (*Networking) Update

func (n *Networking) Update(ctx context.Context, cfg utils.AgentConfig) (needRestart bool)

Update validates and/or updates a subsystem, returns true if subsystem should be restarted.

Jump to

Keyboard shortcuts

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