Liking cljdoc? Tell your friends :D

clj-ebpf.dsl.tc

High-level TC (Traffic Control) DSL for BPF programs.

TC programs run on the traffic control layer and can be attached to qdisc (queueing discipline) ingress/egress points. They operate on sk_buff and provide access to more metadata than XDP.

TC Actions:

  • TC_ACT_OK (0): Continue processing
  • TC_ACT_SHOT (2): Drop packet
  • TC_ACT_UNSPEC (-1): Use default action
  • TC_ACT_PIPE (3): Continue to next action
  • TC_ACT_RECLASSIFY (1): Restart classification
  • TC_ACT_REDIRECT (7): Redirect packet

TC programs use __sk_buff as context, which provides richer packet metadata than XDP's xdp_md.

Example: (deftc-instructions simple-filter {:default-action :ok} ;; All packets passed [])

High-level TC (Traffic Control) DSL for BPF programs.

TC programs run on the traffic control layer and can be attached to
qdisc (queueing discipline) ingress/egress points. They operate on
sk_buff and provide access to more metadata than XDP.

TC Actions:
- TC_ACT_OK       (0): Continue processing
- TC_ACT_SHOT     (2): Drop packet
- TC_ACT_UNSPEC   (-1): Use default action
- TC_ACT_PIPE     (3): Continue to next action
- TC_ACT_RECLASSIFY (1): Restart classification
- TC_ACT_REDIRECT (7): Redirect packet

TC programs use __sk_buff as context, which provides richer
packet metadata than XDP's xdp_md.

Example:
  (deftc-instructions simple-filter
    {:default-action :ok}
    ;; All packets passed
    [])
raw docstring

build-tc-programclj

(build-tc-program {:keys [ctx-reg data-reg data-end-reg body default-action]
                   :or {data-reg :r2 data-end-reg :r3 default-action :ok}})

Build a complete TC program with standard structure.

Parameters:

  • opts: Map with: :ctx-reg - Register to save __sk_buff pointer (optional) :data-reg - Register for data pointer (default :r2) :data-end-reg - Register for data_end (default :r3) :body - Vector of body instructions :default-action - Default return action (default :ok)

Returns assembled program bytes.

Build a complete TC program with standard structure.

Parameters:
- opts: Map with:
  :ctx-reg - Register to save __sk_buff pointer (optional)
  :data-reg - Register for data pointer (default :r2)
  :data-end-reg - Register for data_end (default :r3)
  :body - Vector of body instructions
  :default-action - Default return action (default :ok)

Returns assembled program bytes.
sourceraw docstring

deftc-instructionscljmacro

(deftc-instructions fn-name options & body)

Define a TC program as a function returning instructions.

Parameters:

  • fn-name: Name for the defined function
  • options: Map with: :ctx-reg - Register to save context (optional) :data-reg - Register for data pointer (default :r2) :data-end-reg - Register for data_end (default :r3) :default-action - Default return action (default :ok)
  • body: Body expressions (should return vectors of instructions)

Example: (deftc-instructions drop-all {:default-action :shot} [])

Define a TC program as a function returning instructions.

Parameters:
- fn-name: Name for the defined function
- options: Map with:
  :ctx-reg - Register to save context (optional)
  :data-reg - Register for data pointer (default :r2)
  :data-end-reg - Register for data_end (default :r3)
  :default-action - Default return action (default :ok)
- body: Body expressions (should return vectors of instructions)

Example:
  (deftc-instructions drop-all
    {:default-action :shot}
    [])
sourceraw docstring

ethernet-header-sizeclj

source

ethernet-offsetsclj

source

ethertypesclj

source

ip-protocolsclj

source

ipv4-header-min-sizeclj

source

ipv4-offsetsclj

source

ipv4-to-intclj

source

ipv6-header-sizeclj

source

ipv6-offsetsclj

source

make-tc-program-infoclj

(make-tc-program-info program-name instructions)
(make-tc-program-info program-name instructions direction)
(make-tc-program-info program-name instructions direction interface)

Create program metadata for a TC program.

Parameters:

  • program-name: Name for the BPF program
  • instructions: Program instructions
  • direction: :ingress or :egress (optional)
  • interface: Optional interface name

Returns map with program metadata.

Create program metadata for a TC program.

Parameters:
- program-name: Name for the BPF program
- instructions: Program instructions
- direction: :ingress or :egress (optional)
- interface: Optional interface name

Returns map with program metadata.
sourceraw docstring

skb-offsetclj

(skb-offset field)

Get offset for __sk_buff field.

Parameters:

  • field: Field keyword

Returns offset in bytes.

Get offset for __sk_buff field.

Parameters:
- field: Field keyword

Returns offset in bytes.
sourceraw docstring

skb-offsetsclj

__sk_buff structure field offsets.

__sk_buff structure field offsets.
sourceraw docstring

tc-actionclj

(tc-action action)

Get TC action value by keyword.

Parameters:

  • action: Action keyword (:ok, :shot, :redirect, etc.)

Returns integer action value.

Example: (tc-action :shot) ;; => 2

Get TC action value by keyword.

Parameters:
- action: Action keyword (:ok, :shot, :redirect, etc.)

Returns integer action value.

Example:
  (tc-action :shot)  ;; => 2
sourceraw docstring

tc-actionsclj

TC action return values.

TC action return values.
sourceraw docstring

tc-bounds-checkclj

Generate verifier-friendly bounds check for TC programs. Same as XDP bounds check since both use data/data_end pointers.

Generate verifier-friendly bounds check for TC programs.
Same as XDP bounds check since both use data/data_end pointers.
sourceraw docstring

tc-classify-packetclj

(tc-classify-packet ctx-reg major minor)

Generate instructions to set TC classid.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • major: Major classid (upper 16 bits)
  • minor: Minor classid (lower 16 bits)

Returns vector of instructions.

Generate instructions to set TC classid.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- major: Major classid (upper 16 bits)
- minor: Minor classid (lower 16 bits)

Returns vector of instructions.
sourceraw docstring

tc-clone-redirectclj

(tc-clone-redirect ctx-reg ifindex flags)

Generate call to bpf_clone_redirect helper.

Clones and redirects packet to another interface.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • ifindex: Interface index to redirect to
  • flags: Redirect flags

Returns vector of instructions.

Generate call to bpf_clone_redirect helper.

Clones and redirects packet to another interface.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- ifindex: Interface index to redirect to
- flags: Redirect flags

Returns vector of instructions.
sourceraw docstring

tc-get-hashclj

(tc-get-hash ctx-reg dst-reg)

Get packet hash from sk_buff.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • dst-reg: Destination register

Returns ldx instruction.

Get packet hash from sk_buff.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- dst-reg: Destination register

Returns ldx instruction.
sourceraw docstring

tc-get-ifindexclj

(tc-get-ifindex ctx-reg dst-reg)

Get interface index from sk_buff.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • dst-reg: Destination register

Returns ldx instruction.

Get interface index from sk_buff.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- dst-reg: Destination register

Returns ldx instruction.
sourceraw docstring

tc-get-lenclj

(tc-get-len ctx-reg dst-reg)

Get packet length from sk_buff.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • dst-reg: Destination register

Returns ldx instruction.

Get packet length from sk_buff.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- dst-reg: Destination register

Returns ldx instruction.
sourceraw docstring

tc-get-markclj

(tc-get-mark ctx-reg dst-reg)

Get packet mark (fwmark) from sk_buff.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • dst-reg: Destination register

Returns ldx instruction.

Get packet mark (fwmark) from sk_buff.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- dst-reg: Destination register

Returns ldx instruction.
sourceraw docstring

tc-get-priorityclj

(tc-get-priority ctx-reg dst-reg)

Get packet priority from sk_buff.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • dst-reg: Destination register

Returns ldx instruction.

Get packet priority from sk_buff.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- dst-reg: Destination register

Returns ldx instruction.
sourceraw docstring

tc-get-protocolclj

(tc-get-protocol ctx-reg dst-reg)

Get protocol (ETH_P_*) from sk_buff.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • dst-reg: Destination register

Returns ldx instruction.

Get protocol (ETH_P_*) from sk_buff.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- dst-reg: Destination register

Returns ldx instruction.
sourceraw docstring

tc-get-tc-classidclj

(tc-get-tc-classid ctx-reg dst-reg)

Get TC classid from sk_buff.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • dst-reg: Destination register

Returns ldx instruction.

Get TC classid from sk_buff.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- dst-reg: Destination register

Returns ldx instruction.
sourceraw docstring

tc-l3-csum-replaceclj

(tc-l3-csum-replace ctx-reg offset from to flags)

Generate call to bpf_l3_csum_replace helper.

Updates L3 (IP) checksum.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • offset: Offset to checksum field
  • from: Old value
  • to: New value
  • flags: Size flags

Returns vector of instructions.

Generate call to bpf_l3_csum_replace helper.

Updates L3 (IP) checksum.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- offset: Offset to checksum field
- from: Old value
- to: New value
- flags: Size flags

Returns vector of instructions.
sourceraw docstring

tc-l4-csum-replaceclj

(tc-l4-csum-replace ctx-reg offset from to flags)

Generate call to bpf_l4_csum_replace helper.

Updates L4 (TCP/UDP) checksum.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • offset: Offset to checksum field
  • from: Old value
  • to: New value
  • flags: Size and pseudo-header flags

Returns vector of instructions.

Generate call to bpf_l4_csum_replace helper.

Updates L4 (TCP/UDP) checksum.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- offset: Offset to checksum field
- from: Old value
- to: New value
- flags: Size and pseudo-header flags

Returns vector of instructions.
sourceraw docstring

tc-load-byteclj

source

tc-load-ctx-fieldclj

(tc-load-ctx-field ctx-reg field dst-reg)

Load a field from __sk_buff context.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer (typically :r1 at entry)
  • field: Field keyword from skb-offsets
  • dst-reg: Destination register

Returns ldx instruction.

Load a field from __sk_buff context.

Parameters:
- ctx-reg: Register containing __sk_buff pointer (typically :r1 at entry)
- field: Field keyword from skb-offsets
- dst-reg: Destination register

Returns ldx instruction.
sourceraw docstring

tc-load-data-pointersclj

(tc-load-data-pointers ctx-reg data-reg data-end-reg)

Load data and data_end pointers from __sk_buff.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • data-reg: Destination register for data pointer
  • data-end-reg: Destination register for data_end pointer

Returns vector of instructions.

Example: (tc-load-data-pointers :r1 :r2 :r3) ;; r2 = data, r3 = data_end

Load data and data_end pointers from __sk_buff.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- data-reg: Destination register for data pointer
- data-end-reg: Destination register for data_end pointer

Returns vector of instructions.

Example:
  (tc-load-data-pointers :r1 :r2 :r3)
  ;; r2 = data, r3 = data_end
sourceraw docstring

tc-load-halfclj

source

tc-load-wordclj

source

tc-mark-packetclj

(tc-mark-packet ctx-reg mark)

Generate instructions to set packet mark.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • mark: Mark value to set

Returns vector of instructions.

Generate instructions to set packet mark.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- mark: Mark value to set

Returns vector of instructions.
sourceraw docstring

tc-match-markclj

(tc-match-mark ctx-reg mark action-on-match)

Generate instructions to match packet mark.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • mark: Mark value to match
  • action-on-match: TC action if mark matches

Returns vector of instructions.

Generate instructions to match packet mark.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- mark: Mark value to match
- action-on-match: TC action if mark matches

Returns vector of instructions.
sourceraw docstring

tc-parse-ethernetclj

source

tc-parse-ipv4clj

source

tc-parse-ipv6clj

source

tc-parse-tcpclj

source

tc-parse-udpclj

source

tc-prologueclj

(tc-prologue data-reg data-end-reg)
(tc-prologue ctx-save-reg data-reg data-end-reg)

Generate standard TC program prologue.

Saves context and loads data pointers.

Parameters:

  • ctx-save-reg: Register to save __sk_buff pointer (optional)
  • data-reg: Register for data pointer
  • data-end-reg: Register for data_end pointer

Returns vector of instructions.

Generate standard TC program prologue.

Saves context and loads data pointers.

Parameters:
- ctx-save-reg: Register to save __sk_buff pointer (optional)
- data-reg: Register for data pointer
- data-end-reg: Register for data_end pointer

Returns vector of instructions.
sourceraw docstring

tc-redirectclj

(tc-redirect ifindex flags)

Generate call to bpf_redirect helper.

Redirects packet to another interface.

Parameters:

  • ifindex: Interface index to redirect to
  • flags: Redirect flags (usually 0)

Returns vector of instructions.

Generate call to bpf_redirect helper.

Redirects packet to another interface.

Parameters:
- ifindex: Interface index to redirect to
- flags: Redirect flags (usually 0)

Returns vector of instructions.
sourceraw docstring

tc-return-actionclj

(tc-return-action action)

Generate instructions to return a TC action.

Parameters:

  • action: Action keyword or integer

Returns vector of [mov, exit] instructions.

Generate instructions to return a TC action.

Parameters:
- action: Action keyword or integer

Returns vector of [mov, exit] instructions.
sourceraw docstring

tc-section-nameclj

(tc-section-name)
(tc-section-name direction)
(tc-section-name direction interface)

Generate ELF section name for TC program.

Parameters:

  • direction: :ingress or :egress
  • interface: Optional interface name

Returns section name like "tc" or "tc/ingress/eth0"

Generate ELF section name for TC program.

Parameters:
- direction: :ingress or :egress
- interface: Optional interface name

Returns section name like "tc" or "tc/ingress/eth0"
sourceraw docstring

tc-set-markclj

(tc-set-mark ctx-reg value-reg)

Set packet mark (fwmark) in sk_buff.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • value-reg: Register containing mark value

Returns stx instruction.

Set packet mark (fwmark) in sk_buff.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- value-reg: Register containing mark value

Returns stx instruction.
sourceraw docstring

tc-set-priorityclj

(tc-set-priority ctx-reg value-reg)

Set packet priority in sk_buff.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • value-reg: Register containing priority value

Returns stx instruction.

Set packet priority in sk_buff.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- value-reg: Register containing priority value

Returns stx instruction.
sourceraw docstring

tc-set-tc-classidclj

(tc-set-tc-classid ctx-reg value-reg)

Set TC classid in sk_buff.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • value-reg: Register containing classid value

Returns stx instruction.

Set TC classid in sk_buff.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- value-reg: Register containing classid value

Returns stx instruction.
sourceraw docstring

tc-skb-change-headclj

(tc-skb-change-head ctx-reg len-diff flags)

Generate call to bpf_skb_change_head helper.

Adjusts packet headroom.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • len-diff: Bytes to add (positive) or remove (negative)
  • flags: Flags (usually 0)

Returns vector of instructions.

Generate call to bpf_skb_change_head helper.

Adjusts packet headroom.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- len-diff: Bytes to add (positive) or remove (negative)
- flags: Flags (usually 0)

Returns vector of instructions.
sourceraw docstring

tc-skb-change-tailclj

(tc-skb-change-tail ctx-reg new-len flags)

Generate call to bpf_skb_change_tail helper.

Adjusts packet tail.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • new-len: New packet length
  • flags: Flags (usually 0)

Returns vector of instructions.

Generate call to bpf_skb_change_tail helper.

Adjusts packet tail.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- new-len: New packet length
- flags: Flags (usually 0)

Returns vector of instructions.
sourceraw docstring

tc-skb-load-bytesclj

(tc-skb-load-bytes ctx-reg offset dst-reg len)

Generate call to bpf_skb_load_bytes helper.

Loads bytes from packet data.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • offset: Offset into packet
  • dst-reg: Register with pointer to destination buffer
  • len: Length to load

Returns vector of instructions.

Generate call to bpf_skb_load_bytes helper.

Loads bytes from packet data.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- offset: Offset into packet
- dst-reg: Register with pointer to destination buffer
- len: Length to load

Returns vector of instructions.
sourceraw docstring

tc-skb-store-bytesclj

(tc-skb-store-bytes ctx-reg offset data-reg len flags)

Generate call to bpf_skb_store_bytes helper.

Stores bytes into packet data.

Parameters:

  • ctx-reg: Register containing __sk_buff pointer
  • offset: Offset into packet
  • data-reg: Register with pointer to data
  • len: Length to store
  • flags: Flags (usually 0)

Returns vector of instructions.

Generate call to bpf_skb_store_bytes helper.

Stores bytes into packet data.

Parameters:
- ctx-reg: Register containing __sk_buff pointer
- offset: Offset into packet
- data-reg: Register with pointer to data
- len: Length to store
- flags: Flags (usually 0)

Returns vector of instructions.
sourceraw docstring

tcp-flagsclj

source

tcp-header-min-sizeclj

source

tcp-offsetsclj

source

udp-header-sizeclj

source

udp-offsetsclj

source

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close