]> git.ipfire.org Git - thirdparty/linux.git/commit
bpftool: Add 'prepend' option for tcx attach to insert at chain start
authorGyutae Bae <gyutae.bae@navercorp.com>
Mon, 12 Jan 2026 03:45:16 +0000 (12:45 +0900)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 16 Jan 2026 22:51:23 +0000 (14:51 -0800)
commit999b2395e3c32273dec98f811f0ab5c8a7441850
tree1709ec11eaebbc7273810951abd95a3a66fafd9d
parent4787eaf7c17131bf0cce93336f8f411f832ad05a
bpftool: Add 'prepend' option for tcx attach to insert at chain start

Add support for the 'prepend' option when attaching tcx_ingress and
tcx_egress programs. This option allows inserting a BPF program at
the beginning of the TCX chain instead of appending it at the end.

The implementation uses BPF_F_BEFORE flag which automatically inserts
the program at the beginning of the chain when no relative reference
is specified.

This change includes:
- Modify do_attach_tcx() to support prepend insertion using BPF_F_BEFORE
- Update documentation to describe the new 'prepend' option
- Add bash completion support for the 'prepend' option on tcx attach types
- Add example usage in the documentation
- Add validation to reject 'overwrite' for non-XDP attach types

The 'prepend' option is only valid for tcx_ingress and tcx_egress attach
types. For XDP attach types, the existing 'overwrite' option remains
available.

Example usage:
  # bpftool net attach tcx_ingress name tc_prog dev lo prepend

This feature is useful when the order of program execution in the TCX
chain matters and users need to ensure certain programs run first.

Co-developed-by: Siwan Kim <siwan.kim@navercorp.com>
Signed-off-by: Siwan Kim <siwan.kim@navercorp.com>
Signed-off-by: Gyutae Bae <gyutae.bae@navercorp.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Quentin Monnet <qmo@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20260112034516.22723-1-gyutae.opensource@navercorp.com
tools/bpf/bpftool/Documentation/bpftool-net.rst
tools/bpf/bpftool/bash-completion/bpftool
tools/bpf/bpftool/net.c