ifacestate

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package ifacestate implements the manager and state aspects responsible for the maintenance of interfaces the system.

Index

Constants

View Source
const (
	ConnectTaskEdge       = state.TaskSetEdge("connect-task")
	AfterConnectHooksEdge = state.TaskSetEdge("after-connect-hooks")
)

Variables

View Source
var DebugAutoConnectCheck func(*policy.ConnectCandidate, interfaces.SideArity, error)

DebugAutoConnectCheck is a hook that can be set to debug auto-connection candidates as they are checked.

Functions

func CheckInterfaces

func CheckInterfaces(st *state.State, snapInfo *snap.Info, deviceCtx snapstate.DeviceContext) error

CheckInterfaces checks whether plugs and slots of snap are allowed for installation.

func Connect

func Connect(st *state.State, plugSnap, plugName, slotSnap, slotName string) (*state.TaskSet, error)

Connect returns a set of tasks for connecting an interface.

func ConnectionStates

func ConnectionStates(st *state.State) (connStateByRef map[string]ConnectionState, err error)

ConnectionStates return the state of connections stored in the state. Note that this includes inactive connections (i.e. referring to non- existing plug/slots), so this map must be cross-referenced with current snap info if needed. The state must be locked by the caller.

func Disconnect

func Disconnect(st *state.State, conn *interfaces.Connection) (*state.TaskSet, error)

Disconnect returns a set of tasks for disconnecting an interface.

func Forget

func Forget(st *state.State, repo *interfaces.Repository, connRef *interfaces.ConnRef) (*state.TaskSet, error)

Forget returs a set of tasks for disconnecting and forgetting an interface. If the interface is already disconnected, it will be removed from the state (forgotten).

func MockConnectRetryTimeout

func MockConnectRetryTimeout(d time.Duration) (restore func())

func MockSecurityBackends

func MockSecurityBackends(be []interfaces.SecurityBackend) func()

MockSecurityBackends mocks the list of security backends that are used for setting up security.

This function is public because it is referenced in the daemon

func MockSnapMapper

func MockSnapMapper(new SnapMapper) (restore func())

MockSnapMapper mocks the currently used snap mapper.

func OnSnapLinkageChanged

func OnSnapLinkageChanged(st *state.State, instanceName string) error

OnSnapLinkageChanged is used to implement snapstate.LinkSnapParticipant follow activation changes for snaps so that we can track revisions with security profiles on disk for temporarily inactive snaps.

func RemapSnapFromRequest

func RemapSnapFromRequest(snapName string) string

RemapSnapFromRequest renames a snap as received from an API request according to the current mapper.

func RemapSnapFromState

func RemapSnapFromState(snapName string) string

RemapSnapFromState renames a snap when loaded from state according to the current mapper.

func RemapSnapToState

func RemapSnapToState(snapName string) string

RemapSnapToState renames a snap when saving to state according to the current mapper.

func SystemSnapName

func SystemSnapName() string

SystemSnapName returns actual name of the system snap.

Types

type ConnectionState

type ConnectionState struct {
	// Auto indicates whether the connection was established automatically
	Auto bool
	// ByGadget indicates whether the connection was trigged by the gadget
	ByGadget bool
	// Interface name of the connection
	Interface string
	// Undesired indicates whether the connection, otherwise established
	// automatically, was explicitly disconnected
	Undesired        bool
	StaticPlugAttrs  map[string]interface{}
	DynamicPlugAttrs map[string]interface{}
	StaticSlotAttrs  map[string]interface{}
	DynamicSlotAttrs map[string]interface{}
	HotplugGone      bool
}

func (ConnectionState) Active

func (c ConnectionState) Active() bool

Active returns true if connection is not undesired and not removed by hotplug.

type CoreCoreSystemMapper

type CoreCoreSystemMapper struct {
	IdentityMapper // Embedding the identity mapper allows us to cut on boilerplate.
}

CoreCoreSystemMapper implements SnapMapper and makes implicit slots appear to be on "core" in the state and in memory but as "system" in the API.

NOTE: This mapper can be used to prepare, as an intermediate step, for the transition to "snapd" mapper. Using it the state and API layer will look exactly the same as with the "snapd" mapper. This can be used to make any necessary adjustments the test suite.

func (*CoreCoreSystemMapper) RemapSnapFromRequest

func (m *CoreCoreSystemMapper) RemapSnapFromRequest(snapName string) string

RemapSnapFromRequest renames the "system" snap to the "core" snap.

This allows us to accept connection and disconnection requests that explicitly refer to "core" or using the "system" nickname.

func (*CoreCoreSystemMapper) SystemSnapName

func (m *CoreCoreSystemMapper) SystemSnapName() string

SystemSnapName returns actual name of the system snap.

type CoreSnapdSystemMapper

type CoreSnapdSystemMapper struct {
	IdentityMapper // Embedding the identity mapper allows us to cut on boilerplate.
}

CoreSnapdSystemMapper implements SnapMapper and makes implicit slots appear to be on "core" in the state and on "system" in the API while they are on "snapd" in memory.

func (*CoreSnapdSystemMapper) RemapSnapFromRequest

func (m *CoreSnapdSystemMapper) RemapSnapFromRequest(snapName string) string

RemapSnapFromRequest renames the "core" or "system" snaps to the "snapd" snap.

This allows us to accept connection and disconnection requests that explicitly refer to "core" or "system" even though we really want them to refer to "snapd". Note that this is not fully symmetric with RemapSnapToResponse as we explicitly always talk about "system" snap, even if the request used "core".

func (*CoreSnapdSystemMapper) RemapSnapFromState

func (m *CoreSnapdSystemMapper) RemapSnapFromState(snapName string) string

RemapSnapFromState renames the "core" snap to the "snapd" snap.

This allows modern snapd to load an old state that remembers connections between slots on the "core" snap and other snaps. In memory we are actually using "snapd" snap for hosting those slots and this lets us stay compatible.

func (*CoreSnapdSystemMapper) RemapSnapToState

func (m *CoreSnapdSystemMapper) RemapSnapToState(snapName string) string

RemapSnapToState renames the "snapd" snap to the "core" snap.

This allows the state to stay backwards compatible as all the connections seem to refer to the "core" snap, as in pre core{16,18} days where there was only one core snap.

func (*CoreSnapdSystemMapper) SystemSnapName

func (m *CoreSnapdSystemMapper) SystemSnapName() string

SystemSnapName returns actual name of the system snap.

type ErrAlreadyConnected

type ErrAlreadyConnected struct {
	Connection interfaces.ConnRef
}

ErrAlreadyConnected describes the error that occurs when attempting to connect already connected interface.

func (ErrAlreadyConnected) Error

func (e ErrAlreadyConnected) Error() string

type HotplugSlotInfo

type HotplugSlotInfo struct {
	Name        string                 `json:"name"`
	Interface   string                 `json:"interface"`
	StaticAttrs map[string]interface{} `json:"static-attrs,omitempty"`
	HotplugKey  snap.HotplugKey        `json:"hotplug-key"`

	// device was unplugged but has connections, so slot is remembered
	HotplugGone bool `json:"hotplug-gone"`
}

type IdentityMapper

type IdentityMapper struct{}

IdentityMapper implements SnapMapper and performs no transformations at all.

func (*IdentityMapper) RemapSnapFromRequest

func (m *IdentityMapper) RemapSnapFromRequest(snapName string) string

RemapSnapFromRequest doesn't change the snap name in any way.

func (*IdentityMapper) RemapSnapFromState

func (m *IdentityMapper) RemapSnapFromState(snapName string) string

RemapSnapFromState doesn't change the snap name in any way.

func (*IdentityMapper) RemapSnapToState

func (m *IdentityMapper) RemapSnapToState(snapName string) string

RemapSnapToState doesn't change the snap name in any way.

type InterfaceManager

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

InterfaceManager is responsible for the maintenance of interfaces in the system state. It maintains interface connections, and also observes installed snaps to track the current set of available plugs and slots.

func Manager

func Manager(s *state.State, hookManager *hookstate.HookManager, runner *state.TaskRunner, extraInterfaces []interfaces.Interface, extraBackends []interfaces.SecurityBackend) (*InterfaceManager, error)

Manager returns a new InterfaceManager. Extra interfaces can be provided for testing.

func (*InterfaceManager) ConnectionStates

func (m *InterfaceManager) ConnectionStates() (connStateByRef map[string]ConnectionState, err error)

ConnectionStates return the state of connections tracked by the manager

func (*InterfaceManager) DisableUDevMonitor

func (m *InterfaceManager) DisableUDevMonitor()

DisableUDevMonitor disables the instantiation of udev monitor, but has no effect if udev is already created; it should be called after creating InterfaceManager, before first Ensure. This method is meant for tests only.

func (*InterfaceManager) Ensure

func (m *InterfaceManager) Ensure() error

Ensure implements StateManager.Ensure.

func (*InterfaceManager) MockObservedDevicePath

func (m *InterfaceManager) MockObservedDevicePath(devPath, ifaceName string, hotplugKey snap.HotplugKey) func()

MockObservedDevicePath adds the given device to the map of observed devices. This function is used for tests only.

func (*InterfaceManager) Repository

func (m *InterfaceManager) Repository() *interfaces.Repository

Repository returns the interface repository used internally by the manager.

This method has two use-cases: - it is needed for setting up state in daemon tests - it is needed to return the set of known interfaces in the daemon api

In the second case it is only informational and repository has internal locks to ensure consistency.

func (*InterfaceManager) ResolveDisconnect

func (m *InterfaceManager) ResolveDisconnect(plugSnapName, plugName, slotSnapName, slotName string, forget bool) ([]*interfaces.ConnRef, error)

ResolveDisconnect resolves potentially missing plug or slot names and returns a list of fully populated connection references that can be disconnected.

It can be used in two different ways: 1: snap disconnect <snap>:<plug> <snap>:<slot> 2: snap disconnect <snap>:<plug or slot>

In the first case the referenced plug and slot must be connected. In the second case any matching connection are returned but it is not an error if there are no connections.

In both cases the snap name can be omitted to implicitly refer to the core snap. If there's no core snap it is simply assumed to be called "core" to provide consistent error messages.

func (*InterfaceManager) StartUp

func (m *InterfaceManager) StartUp() error

StartUp implements StateStarterUp.Startup.

func (*InterfaceManager) Stop

func (m *InterfaceManager) Stop()

Stop implements StateStopper. It stops the udev monitor, if running.

type SnapMapper

type SnapMapper interface {
	// re-map functions for loading and saving objects in the state.
	RemapSnapFromState(snapName string) string
	RemapSnapToState(snapName string) string
	// RamapSnapFromRequest can replace snap names in API requests.
	// There is no corresponding mapping function for API responses anymore.
	// The API responses always reflect the real system state.
	RemapSnapFromRequest(snapName string) string
	// Returns actual name of the system snap.
	SystemSnapName() string
}

SnapMapper offers APIs for re-mapping snap names in interfaces and the configuration system. The mapper is designed to apply transformations around the edges of snapd (state interactions and API interactions) to offer one view on the inside of snapd and another view on the outside.

Directories

Path Synopsis
Package schema holds structs for reading and writing interface-related state data.
Package schema holds structs for reading and writing interface-related state data.

Jump to

Keyboard shortcuts

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