netlink

package
v0.0.0-...-3cfa28a Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: GPL-3.0, GPL-3.0 Imports: 10 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RawSockStopper

func RawSockStopper(fd int) (readableOrStop func() (bool, error), stop func(), err error)

RawSockStopper returns a pair of functions to manage stopping code reading from a raw socket, readableOrStop blocks until fd is readable or stop was called. To work properly it sets fd to non-blocking mode. TODO: with go 1.11+ it should be possible to just switch to setting fd to non-blocking and then wrapping the socket via os.NewFile and use Close to force a read to stop. c.f. https://github.com/golang/go/commit/ea5825b0b64e1a017a76eac0ad734e11ff557c8e

Types

type Env

type Env map[string]*regexp.Regexp

func (Env) Evaluate

func (e Env) Evaluate(env map[string]string) bool

type KObjAction

type KObjAction string
const (
	ADD     KObjAction = "add"
	REMOVE  KObjAction = "remove"
	CHANGE  KObjAction = "change"
	MOVE    KObjAction = "move"
	ONLINE  KObjAction = "online"
	OFFLINE KObjAction = "offline"
	BIND    KObjAction = "bind"
	UNBIND  KObjAction = "unbind"
)

func ParseKObjAction

func ParseKObjAction(raw string) (a KObjAction, err error)

func (KObjAction) String

func (a KObjAction) String() string

type Matcher

type Matcher interface {
	Evaluate(e UEvent) bool
	EvaluateAction(a KObjAction) bool
	EvaluateEnv(e map[string]string) bool
	Compile() error
	String() string
}

type Mode

type Mode int
const (
	KernelEvent Mode = 1
	// Events that are processed by udev - much richer, with more attributes (such as vendor info, serial numbers and more).
	UdevEvent Mode = 2
)

Mode determines event source: kernel events or udev-processed events. See libudev/libudev-monitor.c.

type NetlinkConn

type NetlinkConn struct {
	Fd   int
	Addr syscall.SockaddrNetlink
}

Generic connection

type RuleDefinition

type RuleDefinition struct {
	Action *string           `json:"action,omitempty"`
	Env    map[string]string `json:"env,omitempty"`
	// contains filtered or unexported fields
}

func (*RuleDefinition) Compile

func (r *RuleDefinition) Compile() error

Compile prepare rule definition to be able to Evaluate() an UEvent

func (RuleDefinition) Evaluate

func (r RuleDefinition) Evaluate(e UEvent) bool

Evaluate return true if all condition match uevent and envs in rule exists in uevent

func (RuleDefinition) EvaluateAction

func (r RuleDefinition) EvaluateAction(a KObjAction) (match bool)

EvaluateAction return true if the action match

func (RuleDefinition) EvaluateEnv

func (r RuleDefinition) EvaluateEnv(e map[string]string) bool

EvaluateEnv return true if all env match and exists

func (RuleDefinition) String

func (r RuleDefinition) String() string

type RuleDefinitions

type RuleDefinitions struct {
	Rules []RuleDefinition
}

RuleDefinitions is like chained rule with OR operator

func (*RuleDefinitions) AddRule

func (rs *RuleDefinitions) AddRule(r RuleDefinition)

func (*RuleDefinitions) Compile

func (rs *RuleDefinitions) Compile() error

func (RuleDefinitions) Evaluate

func (rs RuleDefinitions) Evaluate(e UEvent) bool

func (RuleDefinitions) EvaluateAction

func (rs RuleDefinitions) EvaluateAction(a KObjAction) (match bool)

EvaluateAction return true if the action match

func (RuleDefinitions) EvaluateEnv

func (rs RuleDefinitions) EvaluateEnv(e map[string]string) bool

EvaluateEnv return true if almost one env match all regexp

func (RuleDefinitions) String

func (rs RuleDefinitions) String() string

type UEvent

type UEvent struct {
	Action KObjAction
	KObj   string
	Env    map[string]string
}

func ParseUEvent

func ParseUEvent(raw []byte) (e *UEvent, err error)

func (UEvent) Bytes

func (e UEvent) Bytes() []byte

func (UEvent) Equal

func (e UEvent) Equal(e2 UEvent) (bool, error)

func (UEvent) String

func (e UEvent) String() string

type UEventConn

type UEventConn struct {
	NetlinkConn
}

func (*UEventConn) Close

func (c *UEventConn) Close() error

Close allow to close file descriptor and socket bound

func (*UEventConn) Connect

func (c *UEventConn) Connect(mode Mode) (err error)

Connect allow to connect to system socket AF_NETLINK with family NETLINK_KOBJECT_UEVENT to catch events about block/char device see: - http://elixir.free-electrons.com/linux/v3.12/source/include/uapi/linux/netlink.h#L23 - http://elixir.free-electrons.com/linux/v3.12/source/include/uapi/linux/socket.h#L11

func (*UEventConn) Monitor

func (c *UEventConn) Monitor(queue chan UEvent, errors chan error, matcher Matcher) (stop func(stopTimeout time.Duration) (ok bool))

Monitor run in background a worker to read netlink msg in loop and notify when msg receive inside a queue using channel. To be notified with only relevant message, use Matcher.

func (*UEventConn) ReadMsg

func (c *UEventConn) ReadMsg() (msg []byte, err error)

ReadMsg allow to read an entire uevent msg

func (*UEventConn) ReadUEvent

func (c *UEventConn) ReadUEvent() (*UEvent, error)

ReadMsg allow to read an entire uevent msg

Jump to

Keyboard shortcuts

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