socketset

package
v0.0.0-...-2561dba Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: GPL-3.0 Imports: 8 Imported by: 6

Documentation

Overview

Package socketset is in API for creating a select style netlink socket to receive events from the kernel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SocketSet

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

SocketSet is used to receive events from a socket and shut it down cleanly when asked. It contains a socket for events and a pipe socket to unblock receive on shutdown.

func NewSocketSet

func NewSocketSet(groups uint32, name string, proto int) (*SocketSet, error)

NewSocketSet returns a socketSet, initialized with the given parameters.

func (*SocketSet) Close

func (obj *SocketSet) Close() error

Close closes the pipe file descriptor. It must only be called after Shutdown has closed fdEvents, and unblocked receive. It should only be called once.

func (*SocketSet) ReceiveBytes

func (obj *SocketSet) ReceiveBytes() ([]byte, error)

ReceiveBytes waits for bytes from fdEvents and return a byte array truncated to the message length. It will block until an event is produced, or shutdown is called.

func (*SocketSet) ReceiveNetlinkMessages

func (obj *SocketSet) ReceiveNetlinkMessages() ([]syscall.NetlinkMessage, error)

ReceiveNetlinkMessages is a wrapper around ReceiveBytes that parses the bytes from the event and returns an array of NetlinkMessages.

func (*SocketSet) ReceiveUEvent

func (obj *SocketSet) ReceiveUEvent() (*UEvent, error)

ReceiveUEvent is a wrapper around ReceiveBytes. Parses the UEvent data receieved from the socket and puts it into a UEvent struct.

func (*SocketSet) Shutdown

func (obj *SocketSet) Shutdown() error

Shutdown closes the event file descriptor and unblocks receive by sending a message to the pipe file descriptor. It must be called before close, and should only be called once.

type UEvent

type UEvent struct {
	// default keys, as per https://github.com/torvalds/linux/blob/master/lib/kobject_uevent.c
	Action    string
	Devpath   string
	Subsystem string

	// every other KV pair
	Data map[string]string
}

UEvent struct has attributes for KOBJECT_NETWORK_UEVENT, passed from the kernel.

Jump to

Keyboard shortcuts

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