trafficctl

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

README

Status of implementation

Objects:

qdisc

  • Show/List (library does not provide string functions for structures, hence limited output)
  • Add
  • Delete
  • Replace
  • Change
  • Link
Classless Qdiscs
  • choke
  • codel
  • [p|b]FIFO
  • fq
  • fq_codel
  • fq_pie
  • gred
  • hhf
  • ingress
  • mqprio
  • multiq
  • netem
  • pfifo_fast
  • pie
  • red
  • sfb
  • sfq
  • tbf
  • clsact

class (untested yet)

  • Show/List (library does not provide string functions for structures, hence limited output)
  • Add
  • Delete
  • Replace
  • Change
Classfull Qdiscs
  • ATM (not supported for adding byt go-tc library)
  • DRR (not supported for adding byt go-tc library)
  • ETS (not supported for adding byt go-tc library)
  • HFSC
    • qdisc args parsing
    • class args parsing
  • HTB
    • qdisc args parsing
    • class args parsing
  • PRIO (not supported for adding by go-tc library)
  • QFQ

filter (untested yet)

  • Show/List (library does not provide string functions for structures, hence limited output)
  • Add
  • Delete
  • Replace
  • Change
Filter types
  • basic
    • action
    • match
    • classid/flowid
  • bpf
    • object-file
    • section
    • export
    • verbose
    • direct-action (da)
    • skip-hw | skip-sw
    • police
    • action
    • classid/flowid
    • bytecode
    • bytecode-file
  • cgroup
    • action
    • match
  • flow,flower
    • action
    • baseclass
    • divisor
    • hash keys
    • map key
    • match
  • fw
    • classid
    • action
  • route
    • action
    • classid
    • from
    • fromif
    • to
  • u32
    • handle
    • offset
    • hashkey
    • classid
    • divisor
    • order
    • sample
    • link
    • indev
    • skip-sw
    • skip-hw
  • matchall
    • action
    • classid
    • skip-sw
    • skip-hw

chain

  • add
  • del
  • get
  • show

monitor

Documentation

Index

Constants

View Source
const (
	GActUnspec  = -1
	GActOk      = 0
	GActReclass = 1
	GActShot    = 2
	GActPipe    = 3
	GActTrap    = 8
	GActJump    = 1 << 28
	GActGoTo    = 2 << 28
)
View Source
const BasicHelp = `Usage: ... basic [ action ACTION_SPEC ] [ classid CLASSID | flowid CLASSID ]
`
View Source
const ClassHelp = `` /* 288-byte string literal not displayed */
View Source
const CodelHelp = `Usage: ... codel [ limit PACKETS ] [ target TIME ]
		 [ interval TIME ] [ ecn | noecn ]
		 [ ce_threshold TIME ]
`
View Source
const FilterHelp = `` /* 231-byte string literal not displayed */
View Source
const HFSCHelp = `Usage: ... hfsc [ default CLASSID ]

 default: default class for unclassified packets
 `
View Source
const HTBHelp = `` /* 979-byte string literal not displayed */
View Source
const QFQHelp = `Usage: ... qfq [ weight N ] [ maxpkt N ]
`
View Source
const QdiscHelp = `` /* 399-byte string literal not displayed */
View Source
const TCU32Terminal = 1
View Source
const (
	TimeUnitsPerSecs = 1000000
)
View Source
const U32Help = `` /* 150-byte string literal not displayed */

Variables

View Source
var (
	ErrNotEnoughArgs  = errors.New("not enough arguments")
	ErrInvalidArg     = errors.New("invalid argument in list")
	ErrNotImplemented = errors.New("not implemented")
	ErrOutOfBounds    = errors.New("integer argument out of bounds")
	ErrExitAfterHelp  = errors.New("exit after help message")
)
View Source
var ErrInvalidActionControl = errors.New("invalid action control parameter")
View Source
var ErrInvalidFilterType = errors.New("invalid filtertype")
View Source
var ErrNoDevice = errors.New("no such device")
View Source
var ErrNoValidProto = errors.New("invalid protocol name")
View Source
var ErrUnknownLinkLayer = errors.New("unknown linklayer value provided")

Functions

func CalcXMitSize

func CalcXMitSize(rate uint64, ticks uint32) (uint32, error)

CalcXMitSize is the inverse of CalcXMitTime

func CalcXMitTime

func CalcXMitTime(rate uint64, size uint32) (uint32, error)

CalcXMitTime takes a rate and size of uint64 and calculates the XMitTime.

func GetHz

func GetHz() (int, error)

GetHz reads the psched rate from /proc/net/psched and returns it.

func GetInfoFromPrefAndProto

func GetInfoFromPrefAndProto(hostPref, netProto uint16) uint32

GetInfoFromPrefAndProto combines the uint16 preference/priority value (in host byte order) and the uint16 EtherType protocol value (in network byte order) such that the combined value can be stored in the Info field of tc.Object.

func GetPrefFromInfo

func GetPrefFromInfo(info uint32) uint16

GetPrefFromInfo takes the uint32 representation of the Info field of tc.Object and returns the preference/priority value as uint16.

func GetProtoFromInfo

func GetProtoFromInfo(info uint32) uint16

GetProtoFromInfo extracts the uint16 EtherType protocol value (in network byte order) from the tc.Object's Info field.

func HFSCGetSC

func HFSCGetSC(args []string) (*tc.ServiceCurve, error)

func HToNL

func HToNL(hostLong uint32) uint32

HToNL converts a uint32 value from host (native) byte order to network (big endian) byte order.

func HToNS

func HToNS(hostShort uint16) uint16

HToNS converts a uint16 value from host (native) byte order to network (big endian) byte order.

func NToHL

func NToHL(netLong uint32) uint32

NToHL converts a uint32 value from network (big endian) byte order to host (native) byte order.

func NToHS

func NToHS(netShort uint16) uint16

NToHS converts a uint16 value from network (big endian) byte order to host (native) byte order.

func ParseActionGAT

func ParseActionGAT(out io.Writer, args []string) (*[]*tc.Action, error)

ParseActionGAT parses options of the filter action category and returns a pointer to a slice of []*tc.Action

func ParseBasicParams

func ParseBasicParams(out io.Writer, params []string) (*tc.Object, error)

ParseBasicParams parses the cmdline arguments for `tc filter ... basic ...` and returns a *tc.Object.

func ParseClassID

func ParseClassID(p string) (uint32, error)

ParseClassID takes a string which can have three forms: Form 1: "root", which returns tc.HandleRoot Form 2: "none", which returns 0 as classid Form 3: "XXXX:XXXX" (Major:Minor), will return uint32(major<<16)|uint32(minor)

func ParseCodelArgs

func ParseCodelArgs(out io.Writer, args []string) (*tc.Object, error)

ParseCodelArgs parses a []string from the commandline for the codel qdisc. and returns an *tc.Object accordingly.

func ParseHFSCClassArgs

func ParseHFSCClassArgs(out io.Writer, args []string) (*tc.Object, error)

ParseHFSCClassArgs parses the cmdline arguments for `tc class add ... hfsc ...` and returns a *tc.Object.

func ParseHFSCQDiscArgs

func ParseHFSCQDiscArgs(stdout io.Writer, args []string) (*tc.Object, error)

ParseHFSCQDiscArgs parses a []string from the commandline for the HFSC qdisc via `tc qdisc ... hfsc ...` and returns an *tc.Object accordingly.

func ParseHTBClassArgs

func ParseHTBClassArgs(out io.Writer, args []string) (*tc.Object, error)

ParseHTBClassArgs parses the cmdline arguments for `tc class add ... htb ...` and returns a *tc.Object.

func ParseHTBQDiscArgs

func ParseHTBQDiscArgs(out io.Writer, args []string) (*tc.Object, error)

ParseHTBQDiscArgs parses a []string from the commandline for the HTB qdisc via `tc qdisc ... htb ...` and returns an *tc.Object accordingly.

func ParseHandle

func ParseHandle(h string) (uint32, error)

ParseHandle takes a string in the form of XXXX: and returns the XXXX value as uint32 type shifted left by 16 bits.

func ParseLinkLayer

func ParseLinkLayer(l string) (uint8, error)

ParseLinkLayer takes a string of LinkLayer name and returns the equivalent uint8 representation.

func ParseProto

func ParseProto(prot string) (uint16, error)

ParseProto takes an EtherType protocol string and returns the equivalent uint16 representation in network byte order.

func ParseQFQArgs

func ParseQFQArgs(out io.Writer, args []string) (*tc.Object, error)

ParseQFQArgs parses a []string from the commandline for the qfq qdisc via `tc qdisc ... qfq ...` and returns an *tc.Object accordingly.

func ParseRate

func ParseRate(arg string) (uint64, error)

ParseRate takes a string of the form `0123456789bBgGKkMmTitps` and returns the equivalent rate as uint64.

func ParseSize

func ParseSize(s string) (uint64, error)

ParseSize takes a string of the form `0123456789gkmbit` and returns the equivalent size as uint64.

func ParseU32Params

func ParseU32Params(out io.Writer, params []string) (*tc.Object, error)

ParseU32Params parses the cmdline arguments for `tc filter ... u32 ...` and returns a *tc.Object. ParseU32Params recognizes a limited sub-language of the language that "tc" of iproute2 recognizes. Reference: <https://linux-tc-notes.sourceforge.net/tc/doc/cls_u32.txt>.

func RenderClassID

func RenderClassID(classID uint32, printParent bool) string

RenderClassID is the inverse of ParseClassID.

func RenderProto

func RenderProto(proto uint16) string

RenderProto takes the uint16 representation of an EtherType protocol in network byte order and returns the equivalent string.

Types

type Args

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

Args holds all possible args for qdisc subcommand tc qdisc [ add | del | replace | change | show ] dev STRING [ handle QHANDLE ] [ root | ingress | clsact | parent CLASSID ] [ estimator INTERVAL TIME_CONSTANT ] [ stab [ help | STAB_OPTIONS] ] [ ingress_block BLOCK_INDEX ] [ egress_block BLOCK_INDEX ] [ [ QDISC_KIND ] [ help | OPTIONS ] ]

func ParseClassArgs

func ParseClassArgs(stdout io.Writer, args []string) (*Args, error)

ParseClassArgs takes an io.Writer for output operation and a []string with the provided arguments to parse. It builds a struct of type Args for further operation. Further more it selects the class and calls into the class related parsing function.

func ParseQdiscArgs

func ParseQdiscArgs(stdout io.Writer, args []string) (*Args, error)

ParseQDiscArgs takes an io.Writer and []string slice with arguments to parse. It returns a structure of type Args for qdisc operation.

type FArgs

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

FArgs hold all possible args for qdisc subcommand tc filter [ add | del | change | replace | show ] [ dev STRING ] tc filter [ add | del | change | replace | show ] [ block BLOCK_INDEX ] tc filter get dev STRING parent CLASSID protocol PROTO handle FILTERID pref PRIO FILTER_TYPE tc filter get block BLOCK_INDEX protocol PROTO handle FILTERID pref PRIO FILTER_TYPE [ pref PRIO ] protocol PROTO [ chain CHAIN_INDEX ] [ estimator INTERVAL TIME_CONSTANT ] [ root | ingress | egress | parent CLASSID ] [ handle FILTERID ] [ [ FILTER_TYPE ] [ help | OPTIONS ] ] tc filter show [ dev STRING ] [ root | ingress | egress | parent CLASSID ] tc filter show [ block BLOCK_INDEX ]

func ParseFilterArgs

func ParseFilterArgs(stdout io.Writer, args []string) (*FArgs, error)

ParseFilterArgs takes an io.Writer and []string with arguments from the commandline and returns an *FArgs structure

type Tctl

type Tctl interface {
	ShowQdisc(io.Writer, *Args) error
	AddQdisc(io.Writer, *Args) error
	DeleteQdisc(io.Writer, *Args) error
	ReplaceQdisc(io.Writer, *Args) error
	ChangeQdisc(io.Writer, *Args) error
	ShowClass(io.Writer, *Args) error
	AddClass(io.Writer, *Args) error
	DeleteClass(io.Writer, *Args) error
	ReplaceClass(io.Writer, *Args) error
	ChangeClass(io.Writer, *Args) error
	ShowFilter(io.Writer, *FArgs) error
	AddFilter(io.Writer, *FArgs) error
	DeleteFilter(io.Writer, *FArgs) error
	ReplaceFilter(io.Writer, *FArgs) error
	ChangeFilter(io.Writer, *FArgs) error
	GetFilter(io.Writer, *FArgs) error
}

type Trafficctl

type Trafficctl struct {
	*tc.Tc
}

func (*Trafficctl) AddClass

func (t *Trafficctl) AddClass(stdout io.Writer, args *Args) error

AddClass realizes the `tc class add dev <DEV> ... ` functionality

func (*Trafficctl) AddFilter

func (t *Trafficctl) AddFilter(stdout io.Writer, fArgs *FArgs) error

AddFilter implements the functionality of `tc filter add ...`

func (*Trafficctl) AddQdisc

func (t *Trafficctl) AddQdisc(stdout io.Writer, args *Args) error

AddQdisc implements the functionality of `tc qdisc add ... `

func (*Trafficctl) ChangeClass

func (t *Trafficctl) ChangeClass(stdout io.Writer, args *Args) error

ChangeClass implements the changing of a classful qdisc with `tc class change ...`

func (*Trafficctl) ChangeFilter

func (t *Trafficctl) ChangeFilter(stdout io.Writer, fArgs *FArgs) error

ChangeFilter implements the functionality of `tc filter change ... ` Note: Not implemented yet

func (*Trafficctl) ChangeQdisc

func (t *Trafficctl) ChangeQdisc(stdout io.Writer, args *Args) error

ChangeQdisc implements the functionality of `tc qdisc change ... `

func (*Trafficctl) DeleteClass

func (t *Trafficctl) DeleteClass(stdout io.Writer, args *Args) error

DeleteClass realizes the `tc class del dev <DEV> ...` functionality

func (*Trafficctl) DeleteFilter

func (t *Trafficctl) DeleteFilter(stdout io.Writer, fArgs *FArgs) error

DeleteFilter implements the functionality of `tc filter del ... `

func (*Trafficctl) DeleteQdisc

func (t *Trafficctl) DeleteQdisc(stdout io.Writer, args *Args) error

DeleteQdisc implements the functionality of `tc qdisc del ... `

func (*Trafficctl) GetFilter

func (t *Trafficctl) GetFilter(stdout io.Writer, fArgs *FArgs) error

GetFilter implements the functionality of `tc filter get ... ` Note: Not implemented yet

func (*Trafficctl) ReplaceClass

func (t *Trafficctl) ReplaceClass(stdout io.Writer, args *Args) error

ReplaceClass implements the replacement of a classful qdisc with `tc class replace ...`

func (*Trafficctl) ReplaceFilter

func (t *Trafficctl) ReplaceFilter(stdout io.Writer, fArgs *FArgs) error

ReplaceFilter implements the functionality of `tc filter replace ... ` Note: Not implemented yet

func (*Trafficctl) ReplaceQdisc

func (t *Trafficctl) ReplaceQdisc(stdout io.Writer, args *Args) error

ReplaceQdisc implements the functionality of `tc qdisc replace ... `

func (*Trafficctl) ShowClass

func (t *Trafficctl) ShowClass(stdout io.Writer, args *Args) error

ShowClass realizes the `tc class show dev <DEV>` functionality

func (*Trafficctl) ShowFilter

func (t *Trafficctl) ShowFilter(stdout io.Writer, fArgs *FArgs) error

ShowFilter implements the functionality of `tc filter show ...`

func (*Trafficctl) ShowQdisc

func (t *Trafficctl) ShowQdisc(stdout io.Writer, args *Args) error

ShowQdisc implements the functionality of `tc qdisc show ... `

Jump to

Keyboard shortcuts

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