shaping

package
v0.1.58 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package shaping applies per-container network egress rate limits using Linux traffic control (tc), entered through the container's network namespace with nsenter. It is image-independent: it uses the HOST's tc/nsenter against the container's netns (by init PID), so it works regardless of what the customer's image contains, and a tenant with dropped capabilities cannot remove it. On non-Linux dev builds every call is a no-op.

The host must give the agent the privilege to enter a netns and run tc (CAP_SYS_ADMIN + CAP_NET_ADMIN, granted as ambient capabilities on the agent's systemd unit) and have iproute2 (tc) + util-linux (nsenter) installed.

British English throughout. No em dashes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, pid int, bytesPerSecond int64) error

Apply sets an egress ceiling of bytesPerSecond on the container whose init process is pid, by replacing the root qdisc on its eth0 with a token-bucket filter (tbf). Idempotent (uses `replace`). A non-positive rate clears the cap instead.

func Available

func Available() bool

Available reports whether the host has the tooling to shape egress. It does not check privilege (that surfaces as an error on the first Apply); missing binaries are the common misconfiguration, so we detect those up front.

func Clear

func Clear(ctx context.Context, pid int) error

Clear removes egress shaping from the container at pid. Idempotent: a missing qdisc (nothing to delete) is treated as success.

Types

This section is empty.

Jump to

Keyboard shortcuts

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