kernel

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package kernel contains funcs that interact with the kernel (sycalls, netlink).

Index

Constants

View Source
const (
	AttrDstIfIndex uint16 = iota
	AttrSrcIfIndex
	AttrContextValue
	AttrPayload
)

Constants sourced from https://github.com/sonic-net/sonic-pins/blob/main/p4rt_app/sonic/receive_genetlink.cc#L32

Variables

This section is empty.

Functions

This section is empty.

Types

type GenetlinkPort

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

GenetlinkPort is connect to a netlink socket that be written to.

func NewGenetlinkPort

func NewGenetlinkPort(family, group string) (*GenetlinkPort, error)

NewGenetlinkPort creates netlink socket for the given family and multicast group.

func (GenetlinkPort) Delete

func (p GenetlinkPort) Delete() error

Delete closes the netlink connection.

func (GenetlinkPort) Read

func (p GenetlinkPort) Read([]byte) (int, error)

Read is not implemented.

func (GenetlinkPort) Write

func (p GenetlinkPort) Write(frame []byte, md *PacketMetadata) (int, error)

Writes writes a layer2 frame to the port.

type Interfaces

type Interfaces struct{}

Interfaces contains methods for modifying networking interfaces.

func (*Interfaces) AddrSubscribe

func (k *Interfaces) AddrSubscribe(ch chan<- netlink.AddrUpdate, done <-chan struct{}) error

AddrSubscribe subscribes to address changes for all interfaces.

func (*Interfaces) CreateTAP

func (k *Interfaces) CreateTAP(name string) (int, error)

CreateTAP creates kernel TAP interface.

func (*Interfaces) DeleteIP

func (k *Interfaces) DeleteIP(name string, ip string, prefixLen int) error

DeleteIP delete an IP addresses from a network interface.

func (*Interfaces) LinkAdd

func (k *Interfaces) LinkAdd(link netlink.Link) error

LinkAdd adds a new network interface.

func (*Interfaces) LinkByIndex

func (k *Interfaces) LinkByIndex(idx int) (netlink.Link, error)

LinkByIndex finds a link by its index.

func (*Interfaces) LinkByName

func (k *Interfaces) LinkByName(name string) (netlink.Link, error)

LinkByName returns a network interface by name.

func (k *Interfaces) LinkList() ([]netlink.Link, error)

LinkList lists all Linux network interfaces.

func (*Interfaces) LinkModify

func (k *Interfaces) LinkModify(link netlink.Link) error

LinkModify modifies the link.

func (*Interfaces) LinkSetDown

func (k *Interfaces) LinkSetDown(link netlink.Link) error

LinkSetDown sets the admin state to down.

func (*Interfaces) LinkSetMaster

func (k *Interfaces) LinkSetMaster(member netlink.Link, link netlink.Link) error

LinkSetMaster sets the member link's master to the other link.

func (*Interfaces) LinkSetNoMaster

func (k *Interfaces) LinkSetNoMaster(link netlink.Link) error

LinkSetNoMaster removes the master from the link.

func (*Interfaces) LinkSetUp

func (k *Interfaces) LinkSetUp(link netlink.Link) error

LinkSetDown sets the admin state to up.

func (*Interfaces) LinkSubscribe

func (k *Interfaces) LinkSubscribe(ch chan<- netlink.LinkUpdate, done <-chan struct{}) error

LinkSubscribe subscribes to link status for all interfaces.

func (*Interfaces) NeighSubscribe

func (k *Interfaces) NeighSubscribe(ch chan<- netlink.NeighUpdate, done <-chan struct{}) error

NeighSubscribe subscribes to neighbor table updates.

func (*Interfaces) ReplaceIP

func (k *Interfaces) ReplaceIP(name string, ip string, prefixLen int) error

ReplaceIP sets the IP addresses of a network interface.

func (*Interfaces) SetHWAddr

func (k *Interfaces) SetHWAddr(name string, addr string) error

SetHWAddr sets the MAC address of a network interface.

func (*Interfaces) SetState

func (k *Interfaces) SetState(name string, up bool) error

SetState sets a links up or down.

type NLPacket

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

NLPacket contains a packet data.

func (*NLPacket) Encode

func (nl *NLPacket) Encode() ([]byte, error)

Encode encodes the packet into a netlink-compatible byte slice.

type PacketMetadata

type PacketMetadata struct {
	SrcIfIndex int
	DstIfIndex int
	Context    int // Context is extra value that can be set by the forwarding pipeline.
}

type TapInterface

type TapInterface struct {
	*os.File
	// contains filtered or unexported fields
}

TapInterface is Linux tap interface.

func NewTap

func NewTap(name string) (*TapInterface, error)

NewTap creates a new tap interface.

func (*TapInterface) Delete

func (t *TapInterface) Delete() error

Delete deletes the tap interface.

func (*TapInterface) IfIndex

func (t *TapInterface) IfIndex() int

func (*TapInterface) Write

func (t *TapInterface) Write(frame []byte, _ *PacketMetadata) (int, error)

Directories

Path Synopsis
package kerneltest contains fake implemetation of structs in kernel package
package kerneltest contains fake implemetation of structs in kernel package

Jump to

Keyboard shortcuts

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