xdp-loader(8)
π xdp-loader(8) β the XDP program loader, bestie edition π
okay so. welcome to xdp-loader, section 8 of the manual, and honestly? she's iconic. xdp-loader is a simple loader for XDP programs β and by "simple" we mean "simple to use", because under the hood she's got support for attaching multiple programs to the same interface. π
To pull that off she exposes the exact same load and unload semantics that the libxdp library exposes. If you wanna know how that actually works, and which kernel features it's leaning on, go read the libxdp(3) man page. no cap. π¦
β¨ SYNOPSIS β¨
πΈ Running xdp-loader πΈ
The syntax for running xdp-loader is, bestie, simply this:
xdp-loader COMMAND [options]
Where COMMAND can be one of:
loadβ load an XDP program on an interfaceunloadβ unload an XDP program from an interfacestatusβ show current XDP program statusfeaturesβ show XDP features supported by the NICcleanβ clean up detached program links in XDP bpffs directoryhelpβ show the list of available commands
Every single command, and all of its options, is explained below. Orrr, if you're feeling impatient (same, honestly), just run xdp-loader COMMAND --help to see the options for each command. slay. β
π₯ The LOAD command π₯
The load command loads one or more XDP programs onto an interface. Multiple?? On one interface?? yes bestie, that's the whole point. π
The syntax for the load command is:
xdp-loader load [options] <ifname> <programs>
Where <ifname> is the name of the interface to load the programs onto, and <programs> is one or more file names containing XDP programs. The programs will be loaded onto the interface in the order of their preference, as specified by the program metadata (see libxdp(3)). so the metadata is literally the vibe check for ordering. π
The supported options are:
-m,--mode <mode>β specifies which mode to load the XDP program to be loaded in. The valid values are:'native'β the default in-driver XDP mode'skb'β causes the so-called skb mode (also known as generic XDP) to be used'hw'β causes the program to be offloaded to the hardware'unspecified'β leaves it up to the kernel to pick a mode (which it will do by picking native mode if the driver supports it, or generic mode otherwise)
β οΈ note that using'unspecified'can make it difficult to predict what mode a program will end up being loaded in. For this reason, the default is'native'. Also note that hardware with support for the'hw'mode is rare: Netronome/Corigine cards (using the'nfp'driver) are the only devices with support for this in the mainline Linux kernel. rare king energy, honestly. π
-p,--pin-path <path>β this specifies a root path under which to pin any maps that define the'pinning'attribute in their definitions. This path must be located on a bpffs file system. If not set, maps will not be pinned, even if they specify pinning in their definitions. When pinning maps, if the pinned location for a map already exist, the map pinned there will be reused if it is compatible with the type of the map being loaded. π«Ά-s,--section <section>β specify which ELF section to load the XDP program(s) from in each file. The default is to use the first program in each file. If this option is set, it applies to all programs being loaded. π-n,--prog-name <prog_name>β specify which BPF program with the name to load the XDP program(s) from in each file. The default is to use the first program in each file. Only one of--sectionand--prog-namemay be specified. If this option is set, it applies to all programs being loaded.-P,--prio <priority>β specify the priority to load the XDP program(s) with (this affects the order of programs running on the interface). The default is to use the value from the metadata in the program ELF file, or a value of50if the program has no such metadata. If this option is set, it applies to all programs being loaded.-A,--actions <actions>β specify the "chain call actions" of the loaded XDP program(s). These are the XDP actions that will cause the next program loaded on the interface to be called, instead of returning immediately. The default is to use the value set in the metadata in the program ELF file, orXDP_PASSif no such metadata is set. If this option is set, it applies to all programs being loaded.-v,--verboseβ enable debug logging. Specify twice for even more verbosity. π-h,--helpβ display a summary of the available options
π The UNLOAD command π
The unload command is used for unloading programs from an interface. the breakup era.
The syntax for the unload command is:
xdp-loader unload [options] <ifname>
Where <ifname> is the name of the interface to load the programs onto. Either the --all or --id options must be used to specify which program(s) to unload. no ambiguity allowed, we're decisive here. β¨
The supported options are:
-i,--id <id>β unload a single program from the interface by ID. Usexdp-loader statusto obtain the ID of the program being unloaded. If this program is the last program loaded on the interface, the dispatcher program will also be removed, which makes the operation equivalent to specifying--all. π¦-a,--allβ unload all XDP programs on the interface, as well as the multi-program dispatcher. bye boo π-v,--verboseβ enable debug logging. Specify twice for even more verbosity.-h,--helpβ display a summary of the available options
πΈ The STATUS command πΈ
The status command displays a list of interfaces in the system, and the XDP program(s) loaded on each interface. For each interface, a list of programs are shown, with the run priority and "chain actions" for each program. See the section on program metadata for the meaning of this metadata. it's the receipts, basically. π
-v,--verboseβ enable debug logging. Specify twice for even more verbosity.-h,--helpβ display a summary of the available options
β The FEATURES command β
The features command displays the XDP features supported by the NIC. let's see what your network card is serving. π
Currently supported XDP features are:
NETDEV_XDP_ACT_BASICβ the networking device has basic support for running XDP programs, and can handle the base set of return codes (XDP_ABORTED,XDP_DROP,XDP_PASS,XDP_TX).NETDEV_XDP_ACT_REDIRECTβ the network device supports handling theXDP_REDIRECTreturn code. This means packets can be redirected from this device by XDP.NETDEV_XDP_ACT_NDO_XMITβ the networking interfaces implements thendo_xdp_xmitcallback. This means packets can be redirected to this device by XDP.NETDEV_XDP_ACT_XSK_ZEROCOPYβ the networking device supports AF_XDP in zero copy mode. π₯NETDEV_XDP_ACT_HW_OFFLOADβ the networking device supports XDP hw offloading.NETDEV_XDP_ACT_RX_SGβ the networking device supports non-linear XDP frames on the receive side. This means XDP can be used with big MTUs on this device (if the XDP program is compiled with fragments support).NETDEV_XDP_ACT_NDO_XMIT_SGβ the networking device supports non-linear XDP frames on the transmit side. This means non-linear frames can be redirected to this device.
π§ The CLEAN command π§
The syntax for the clean command is:
xdp-loader clean [options] [ifname]
The clean command cleans up any detached program links in the XDP bpffs directory. here's the lore: when a network interface disappears, any programs loaded in software mode (e.g. skb, native) remain pinned in the bpffs directory, but become detached from the interface. These need to be unlinked from the filesystem. The clean command takes an optional interface parameter to only unlink detached programs corresponding to the interface. By default, all detached programs for all interfaces are unlinked. spring cleaning but make it eBPF. π§Ήβ¨
The supported options are:
-v,--verboseβ enable debug logging. Specify twice for even more verbosity.-h,--helpβ display a summary of the available options
π Examples π
To load an XDP program on the eth0 interface simply do:
# xdp-loader load eth0 xdp_drop.o
# xdp-loader status
CURRENT XDP PROGRAM STATUS:
Interface Prio Program name Mode ID Tag Chain actions
-------------------------------------------------------------------------------------
lo <no XDP program>
eth0 xdp_dispatcher native 50 d51e469e988d81da
=> 50 xdp_drop 55 57cd311f2e27366b XDP_PASS
Which shows that a dispatcher program was loaded on the interface, and the xdp_drop program was installed as the first (and only) component program after it. In this instance, the program does not specify any of the metadata above, so the defaults (priority 50 and XDP_PASS as its chain call action) was used. default girlie behavior, and it ate. π
To use the automatic map pinning, include the pinning attribute into the map definition in the program, something like:
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 10);
__type(key, __u32);
__type(value, __u64);
__uint(pinning, LIBBPF_PIN_BY_NAME);
} my_map SEC(".maps");
And load it with the --pin-path attribute:
# xdp-loader load eth0 my_prog.o --pin-path /sys/fs/bpf/my-prog
This will pin the map at /sys/fs/bpf/my-prog/my_map. If this already exists, the pinned map will be reused instead of creating a new one, which allows different BPF programs to share the map. sharing is caring fr fr. π«Ά
π SEE ALSO π
libxdp(3) for details on the XDP loading semantics and kernel compatibility requirements. go read it bestie, it's giving essential context. π
π BUGS π
Please report any bugs on Github: https://github.com/xdp-project/xdp-tools/issues
not me asking you to file an issue β but like, actually please do, we wanna fix it. π
π AUTHOR π
xdp-loader and this man page were written by Toke HΓΈiland-JΓΈrgensen.
and that's the whole page, mwah π version V1.6.3, dated SEPTEMBER 12, 2024, and yeah it's still wearing the xdp-loader(8) name tag β go forth and load some programs, bestie. periodt. πβ¨
π¦ where this page comes from
- arch rolling: xdp-tools 1.6.3-2 Β· GPL AND LGPL AND BSD2
- ubuntu stonking: xdp-tools 1.6.3-1 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms