# README
tc

This is a work in progress version of tc
. It provides a C-binding free API to the netlink based traffic control system of rtnetlink.
Example
package main
import (
"fmt"
"net"
"os"
"github.com/mdlayher/netlink"
"github.com/florianl/go-tc"
)
func main() {
// open a rtnetlink socket
rtnl, err := tc.Open(&tc.Config{})
if err != nil {
fmt.Fprintf(os.Stderr, "could not open rtnetlink socket: %v\n", err)
return
}
defer func() {
if err := rtnl.Close(); err != nil {
fmt.Fprintf(os.Stderr, "could not close rtnetlink socket: %v\n", err)
}
}()
// For enhanced error messages from the kernel, it is recommended to set
// option `NETLINK_EXT_ACK`, which is supported since 4.12 kernel.
//
// If not supported, `unix.ENOPROTOOPT` is returned.
err = rtnl.SetOption(netlink.ExtendedAcknowledge, true)
if err != nil {
fmt.Fprintf(os.Stderr, "could not set option ExtendedAcknowledge: %v\n", err)
return
}
// get all the qdiscs from all interfaces
qdiscs, err := rtnl.Qdisc().Get()
if err != nil {
fmt.Fprintf(os.Stderr, "could not get qdiscs: %v\n", err)
return
}
for _, qdisc := range qdiscs {
iface, err := net.InterfaceByIndex(int(qdisc.Ifindex))
if err != nil {
fmt.Fprintf(os.Stderr, "could not get interface from id %d: %v", qdisc.Ifindex, err)
return
}
fmt.Printf("%20s\t%s\n", iface.Name, qdisc.Kind)
}
}
Requirements
- A version of Go that is supported by upstream
Privileges
This package processes information directly from the kernel and therefore it requires special privileges. You can provide this privileges by adjusting the CAP_NET_ADMIN
capabilities.
setcap 'cap_net_admin=+ep' /your/executable
# Packages
Package core contains some generic helper functions for the package github.com/florianl/go-tc.
# Functions
Open establishes a RTNETLINK socket for traffic control.
# Constants
Various action binding types.
Various action binding types.
Various action binding types.
Various action binding types.
Various action returns.
Various action returns.
Various action returns.
Various action returns.
Various action returns.
Various action returns.
Various action binding types.
Various action returns.
Various action returns.
Various action returns.
Various action binding types.
Flags defined by the kernel for the BPF filter.
Various flags.
Various byte alignments.
Various byte alignments.
Various byte alignments.
Various Ematch kinds.
Various Ematch kinds.
Various Ematch kinds.
Various Ematch flags.
Various Ematch kinds.
Various Ematch kinds.
Various Ematch network layers.
Various Ematch network layers.
Various Ematch network layers.
Various Ematch kinds.
Various Ematch kinds.
Various Ematch operands.
Various Ematch operands.
Various Ematch operands.
Various Ematch flags.
Various Ematch flags.
Various Ematch flags.
Various Ematch flags.
Various Ematch kinds.
Various Ematch kinds.
Various Ematch kinds.
Constants to define the direction.
Constants to define the direction.
Constants to define the direction.
Constants to define the direction.
Constants to define the direction.
filter is offloaded to HW.
Various IP packet directions.
Various IP packet directions.
To alter filter in shared blocks, set Msg.Ifindex to MagicBlock.
Various MPLS actions.
Various MPLS actions.
Various MPLS actions.
Various MPLS actions.
Various MPLS actions.
filter isn't offloaded to HW.
Various Plug actions.
Various Plug actions.
Various Plug actions.
Various Plug actions.
Default Policy actions.
Default Policy actions.
Default Policy actions.
Default Policy actions.
don't offload filter to HW.
don't use filter in SW.
verbose logging.
# Variables
ErrInvalidArg is returned on invalid given arguments.
Various errors.
ErrNoArg is returned for missing arguments.
Various errors.
ErrNotImplemented is returned for not yet implemented parts.
ErrUnknownKind is returned for unknown qdisc, filter or class types.
# Structs
ActBpf represents policing attributes of various filters and classes.
ActBpfParms from include/uapi/linux/tc_act/tc_bpf.h.
Action represents action attributes of various filters and classes.
Actions represents the actions part of rtnetlink.
Atm contains attributes of the atm discipline.
AtmPvc from include/uapi/linux/atm.h.
Attribute contains various elements for traffic control.
Basic contains attributes of the basic discipline.
Bpf contains attributes of the bpf discipline.
Cake contains attributes of the cake discipline.
Cbq contains attributes of the cbq discipline.
CbqFOpt from include/uapi/linux/pkt_sched.h.
CbqLssOpt from include/uapi/linux/pkt_sched.h.
CbqOvl from include/uapi/linux/pkt_sched.h.
CbqPolice from include/uapi/linux/pkt_sched.h.
CbqWrrOpt from include/uapi/linux/pkt_sched.h.
CbqXStats from include/uapi/linux/pkt_sched.h.
Cbs contains attributes of the cbs discipline.
CbsOpt contains attributes of the cbs discipline.
Cgroup contains attributes of the cgroup discipline.
Chain represents a collection of filter.
Choke contains attributes of the choke discipline.
ChokeXStats from include/uapi/linux/pkt_sched.h.
Class represents the class part of rtnetlink.
CmpMatch contains attributes of the cmp match discipline.
Codel contains attributes of the codel discipline.
CodelXStats from include/uapi/linux/pkt_sched.h.
Config contains options for RTNETLINK.
Connmark represents policing attributes of various filters and classes.
ConnmarkParam from include/uapi/linux/tc_act/tc_connmark.h.
ContainerMatch contains attributes of the container match discipline.
Csum contains attributes of the csum discipline.
CsumParms from include/uapi/linux/tc_act/tc_csum.h.
Ct contains attributes of the ct discipline.
CtParms contains further ct attributes.
Defact contains attributes of the defact discipline.
DefactParms from include/uapi/linux/tc_act/tc_defact.h.
Drr contains attributes of the drr discipline.
Dsmark contains attributes of the dsmark discipline.
Ematch contains attributes of the ematch discipline https://man7.org/linux/man-pages/man8/tc-ematch.8.html.
EmatchHdr from tcf_ematch_hdr in include/uapi/linux/pkt_cls.h.
EmatchMatch contains attributes of the ematch discipline.
EmatchTreeHdr from tcf_ematch_tree_hdr in include/uapi/linux/pkt_cls.h.
Ets represents a struct for Enhanced Transmission Selection, a 802.1Qaz-based Qdisc.
FifoOpt from include/uapi/linux/pkt_sched.h.
Filter represents the filtering part of rtnetlink.
Flow contains attributes of the flow discipline.
Flower contains attrobutes of the flower discipline.
Fq contains attributes of the fq discipline.
FqCodel contains attributes of the fq_codel discipline.
FqCodelClStats from include/uapi/linux/pkt_sched.h.
FqCodelQdStats from include/uapi/linux/pkt_sched.h.
FqCodelXStats from include/uapi/linux/pkt_sched.h.
FqPrioQopt according to tc_prio_qopt in /include/uapi/linux/pkt_sched.h.
FqQdStats from include/uapi/linux/pkt_sched.h.
Fw contains attributes of the fw discipline.
Gact contains attributes of the gact discipline.
GactParms from include/uapi/linux/tc_act/tc_gact.h.
GactProb from include/uapi/linux/tc_act/tc_gact.h.
Gate contains attributes of the gate discipline https://man7.org/linux/man-pages/man8/tc-gate.8.html.
GateParms from include/uapi/linux/tc_act/tc_gate.h.
GenBasic from include/uapi/linux/gen_stats.h.
GenQueue from include/uapi/linux/gen_stats.h.
GenRateEst from include/uapi/linux/gen_stats.h.
GenRateEst64 from include/uapi/linux/gen_stats.h.
GenStats from include/uapi/linux/gen_stats.h.
Hfsc contains attributes of the hfsc class.
HfscQOpt contains attributes of the hfsc qdisc.
HfscXStats from include/uapi/linux/pkt_sched.h.
Hhf contains attributes of the hhf discipline.
HhfXStats from include/uapi/linux/pkt_sched.h.
Htb contains attributes of the HTB discipline.
HtbGlob from include/uapi/linux/pkt_sched.h.
HtbOpt from include/uapi/linux/pkt_sched.h.
HtbXStats from include/uapi/linux/pkt_sched.h.
Ife contains attribute of the ife discipline.
IfeParms from include/uapi/linux/tc_act/tc_ife.h.
IPSetMatch contains attributes of the ipset match discipline.
Ipt contains attribute of the ipt discipline.
IptCnt as tc_cnt from include/uapi/linux/pkt_cls.h.
IptMatch contains attributes of the ipt match discipline.
Matchall contains attributes of the matchall discipline.
Mirred represents policing attributes of various filters and classes.
MirredParam from include/uapi/linux/tc_act/tc_mirred.h.
MPLS contains attributes of the mpls discipline https://man7.org/linux/man-pages/man8/tc-mpls.8.html.
MPLSParam contains further MPLS attributes.
MqPrio contains attributes of the mqprio discipline.
MqPrioQopt according to tc_mqprio_qopt in /include/uapi/linux/pkt_sched.h.
Msg represents a Traffic Control Message.
Nat contains attribute of the nat discipline.
NatParms from include/uapi/linux/tc_act/tc_nat.h.
NByteMatch contains attributes of the Nbyte match discipline.
Netem contains attributes of the netem discipline.
NetemCorr from include/uapi/linux/pkt_sched.h.
NetemCorrupt from include/uapi/linux/pkt_sched.h.
NetemQopt from include/uapi/linux/pkt_sched.h.
NetemRate from include/uapi/linux/pkt_sched.h.
NetemReorder from include/uapi/linux/pkt_sched.h.
NetemSlot from include/uapi/linux/pkt_sched.h.
Object represents a generic traffic control object.
Pie contains attributes of the pie discipline.
PieXStats from include/uapi/linux/pkt_sched.h.
Plug contains attributes of the plug discipline.
Police represents policing attributes of various filters and classes.
Policy from include/uapi/linux/pkt_sched.h.
Prio contains attributes of the prio discipline.
Qdisc represents the queueing discipline part of traffic control.
Qfq contains attributes of the qfq discipline.
RateSpec from include/uapi/linux/pkt_sched.h.
Red contains attributes of the red discipline.
RedQOpt from include/uapi/linux/pkt_sched.h.
RedXStats from include/uapi/linux/pkt_sched.h.
Route4 contains attributes of the route discipline.
Rsvp contains attributes of the rsvp discipline.
RsvpGpi from include/uapi/linux/pkt_sched.h.
RsvpPInfo from include/uapi/linux/pkt_sched.h.
Sample contains attribute of the Sample discipline.
SampleParms from include/uapi/linux/tc_act/tc_sample.h.
ServiceCurve from include/uapi/linux/pkt_sched.h.
Sfb contains attributes of the SBF discipline.
SfbQopt from include/uapi/linux/pkt_sched.h.
SfbXStats from include/uapi/linux/pkt_sched.h.
Sfq contains attributes of the SFQ discipline https://man7.org/linux/man-pages/man8/sfq.8.html.
SfqQopt contains SFQ attributes.
SfqXStats from include/uapi/linux/pkt_sched.h.
SizeSpec implements tc_sizespec.
SkbEdit contains attribute of the SkbEdit discipline.
SkbEditParms from include/uapi/linux/tc_act/tc_skbedit.h.
Stab contains attributes of a stab http://man7.org/linux/man-pages/man8/tc-stab.8.html.
Stats from include/uapi/linux/pkt_sched.h.
Stats2 from include/uapi/linux/pkt_sched.h.
TaPrio contains TaPrio attributes.
Tbf contains attributes of the TBF discipline.
TbfQopt from include/uapi/linux/pkt_sched.h.
Tc represents a RTNETLINK wrapper.
Tcft from include/uapi/linux/pkt_sched.h.
TcIndex contains attributes of the tcIndex discipline.
TunnelKey contains attribute of the TunnelKey discipline.
TunnelParms from include/uapi/linux/tc_act/tc_tunnel_key.h.
U32 contains attributes of the u32 discipline.
U32Key from include/uapi/linux/pkt_sched.h.
U32Mark from include/uapi/linux/pkt_sched.h.
U32Match contains attributes of the u32 match discipline.
U32Sel from include/uapi/linux/pkt_sched.h.
VLan contains attribute of the VLan discipline.
VLanParms from include/uapi/linux/tc_act/tc_vlan.h.
XStats contains further statistics to the TCA_KIND.
# Type aliases
CmpMatchAlign defines byte alignments.
CmpMatchFlag defines available flags.
EmatchKind defines the matching module.
EmatchLayer defines the layer the match will be applied upon.
EmatchOpnd defines how matches are concatenated.
ErrorFunc is a function that receives all errors that happen while reading from a Netlinkgroup.
HookFunc is a function, which is called for each altered RTNETLINK Object.
IPSetDir defines the packet direction.
MPLSAction defines MPS actions.
PlugAction defines actions for plug.
PolicyAction defines the action that is applied by Policy.