bbeequeue

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

README

bbeequeue

PkgGoDev GitHub build and test Coverage goroutines

Package bbeequeue supports receiving data from type BPF_MAP_TYPE_RINGBUF eBPF maps using idiomatic Go channels. This package does not attempt to be a jack-of-all-trades implementation, but instead to cover the basic use case of providing channel access to eBPF ringbuffer maps.

Trivia

The package name "bbeequeue" is a terrible pun on eBPF's bee mascot, ringbuffers or queues, and finally, burning things beyond recognition, also known as "BBQ".

DevContainer

[!CAUTION]

Do not use VSCode's "Dev Containers: Clone Repository in Container Volume" command, as it is utterly broken by design, ignoring .devcontainer/devcontainer.json.

  1. git clone https://github.com/thediveo/bbeequeue
  2. in VSCode: Ctrl+Shift+P, "Dev Containers: Open Workspace in Container..."
  3. select bbeequeue.code-workspace and off you go...

The devcontainer setup includes bpf2go and bpftool. Run go generate . to (re)generate the eBPF-derived Go source files.

Supported Go Versions

bbeequeue supports versions of Go that are noted by the Go release policy, that is, major versions N and N-1 (where N is the current major version).

bbeequeue is Copyright 2025 Harald Albrecht, and licensed under the Apache License, Version 2.0.

The header files in _headers/ are licensed under a BSD-2-Clause; they originate from @cilium/ebpf/examples/headers, with the libbpf-originating files having been updated to 1.5.0.

test.bpf.c is licensed under a dual MIT/GPL license.

Documentation

Overview

Package bbeequeue supports receiving data from type BPF_MAP_TYPE_RINGBUF eBPF maps using idiomatic Go channels. This package does not attempt to be a jack-of-all-trades implementation, but instead to cover the basic use case of providing channel access to eBPF ringbuffer maps.

Usage

New returns a new channel producing T values until the passed context gets done. The default is an unbuffered channel, specify WithSize in the call to New in order to create a buffered channel of the configured size.

import "github.com/thediveo/bbeequeue"

ctx, cancel := context.WithCancel(context.TODO())
ch, err := bbeequeue.New[Foo](ctx, mymap)
for {
    event, ok := <-ch
    if !ok {
        break
    }
}

Trivia

The package name “bbeequeue” is a terrible pun on eBPF's bee mascot, ringbuffers or queues, and finally, burning things beyond recognition, also known as “BBQ”.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[T any](ctx context.Context, rbmap *ebpf.Map, opts ...Option) (<-chan T, error)

New returns a new channel for receiving T values from the specified eBPF ringbuffer map until the passed context gets done. When the context is done, the channel will close automatically.

New optionally takes configuration options (that's why they are called options ... “my name is Option, Optional Option”):

  • WithSize configures the channel buffer size; it defaults to 0 in which case the returned channel is unbuffered. New will return an error when trying to configure a negative size.
  • WithErrorChannel configures a caller-supplied channel that will receive any errors occurring when reading and unmarshalling data from the ringbuffer. Please note that this channel will never be closed automatically.

Types

type Option

type Option func(o *options) error

Option configures optional settings.

func WithErrorChannel

func WithErrorChannel(errch chan error) Option

WithErrorChannel configures a caller-supplied error channel on which ringbuffer receive und data unmarshalling errors are reported. This channel will not be automatically closed.

func WithSize

func WithSize(size int) Option

WithSize configures the buffer size of the channel returned by New. 0 configures an unbuffered channel. New will return an error when trying to configure a size less than zero.

Jump to

Keyboard shortcuts

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