xdp-filter(8)
π NAME π
okay so bestie, meet xdp-filter β a simple XDP-powered packet filter β¨ it's the manual page xdp-filter(8), and it's exactly what it says on the tin: an XDP-powered utility for filtering packets, no drama, no nonsense π
π¦ SYNOPSIS π¦
XDP-filter is a packet filtering utility powered by XDP. And the whole point of it? It is deliberately simple β which means nope, it does not have the same matching capabilities as, like, netfilter. But here's the trade-off that makes it iconic: thanks to XDP, it can achieve very high drop rates β literally tens of millions of packets per second on a single CPU core π₯ one (1) core. periodt.
β¨ Running xdp-filter β¨
The syntax for running xdp-filter is:
xdp-filter COMMAND [options]
Where COMMAND can be one of:
loadβ load xdp-filter on an interfaceunloadβ unload xdp-filter from an interfaceportβ add a port to the filter listipβ add an IP address to the filter listetherβ add an Ethernet MAC address to the filter liststatusβ show current xdp-filter statuspollβ poll statistics outputhelpβ show the list of available commands
Each command, and its options are explained below. Or use xdp-filter COMMAND --help to see the options for each command π«Ά no gatekeeping here.
π The LOAD command π
To use xdp-filter, it must first be loaded onto an interface β like, it can't filter anything while it's just vibing in your shell. This is accomplished with the load command, which takes the name of the interface as a parameter, and optionally allows specifying the features that should be included. By default all features are loaded, but de-selecting some features can speed up the packet matching, and increase performance by a substantial amount π so being picky is genuinely a flex.
The syntax for the load command is:
xdp-filter load [options] <ifname>
Where <ifname> is the name of the interface to load xdp-filter onto, and must be specified. The supported options are:
-m,--mode <mode>β specifies which mode to load the XDP program to be loaded in. The valid values arenative, which is the default in-driver XDP mode,skb, which causes the so-called skb mode (also known as generic XDP) to be used, orhwwhich causes the program to be offloaded to the hardware π¦-p,--policy <policy>β this sets the policy xdp-filter applies to packets not matched by any of the filter rules. The default isallow, in which packets not matching any rules are allowed to pass. The other option isdeny, in which all packets are dropped except those matched by the filter options π
xdp-filter cannot be loaded simultaneously in deny and allow policy modes on the system. Note that loading xdp-filter in deny mode will drop all traffic on the interface until suitable allow rules are installed, so some care is needed to avoid being locked out of a remote system.
π¨ bestie I mean this SO seriously: deny mode drops everything until you install the allow rules you actually want. if you're on a remote box and you fumble this, you're not coming back. no cap.
-f,--features <feats>β use this option to select which features to include when loaded xdp-filter. The default is to load all available features. So select individual features specify one or more of these:tcp: Support filtering on TCP port numberudp: Support filtering on UDP port numberipv6: Support filtering on IPv6 addressesipv4: Support filtering on IPv4 addressesethernet: Support filtering on Ethernet MAC addresses
Specify multiple features by separating them with a comma. E.g.: tcp,udp,ipv6.
-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 unloads xdp-filter from one (or all) interfaces, and cleans up the program state π§Ή closure, but make it networking.
(yes, the original page says "load" right here β it's a typo, we're very clearly talking about unload, and I'm keeping the receipts for you.)
The syntax for the unload command is:
xdp-filter unload [options] <ifname>
Where <ifname> is the name of the interface to unload xdp-filter from, and must be specified unless the --all option is used. The supported options are:
-a,--allβ specify this option to remove xdp-filter from all interfaces it was loaded onto. If this option is specified, no<ifname>is needed π
This option can also be used to clean up all xdp-filter state if the XDP program(s) were unloaded by other means.
-k,--keep-mapsβ specify this option to prevent xdp-filter from clearing its map state. By default, all BPF maps no longer needed by any loaded program are removed. However, this will also remove the contents of the maps (the filtering rules), so this option can be used to keep the maps around so the rules persist until xdp-filter is loaded again π«Ά-v,--verboseβ enable debug logging. Specify twice for even more verbosity π-h,--helpβ display a summary of the available options
πΈ The PORT command πΈ
Use the port command to add a TCP or UDP port to the xdp-filter match list. For this to work, xdp-filter must be loaded with either the udp or the tcp feature (or both) on at least one interface β οΈ otherwise it's just shouting into the void.
The syntax for the port command is:
xdp-filter port [options] <port>
Where <port> is the port number to add (or remove if the --remove is specified). The supported options are:
-r,--removeβ remove the port instead of adding it.-m,--mode <mode>β select filtering mode. Valid options aresrcanddst, both of which may be specified assrc,dst. Ifsrcis specified, the port number will added as a source port match, while ifdstis specified, the port number will be added as a destination port match. If both are specified, a packet will be matched if either its source or destination port is the specified port number β¨-p,--proto <proto>β specify one (or both) ofudpand/ortcpto match UDP or TCP ports, respectively.-s,--statusβ if this option is specified, the current list of matched ports will be printed after inserting the port number. Otherwise, nothing will be printed π€«-v,--verboseβ enable debug logging. Specify twice for even more verbosity π-h,--helpβ display a summary of the available options
π The IP command π
Use the ip command to add an IPv6 or an IPv4 address to the xdp-filter match list.
The syntax for the ip command is:
xdp-filter ip [options] <ip>
Where <ip> is the IP address to add (or remove if the --remove is specified). Either IPv4 or IPv6 addresses can be specified, but xdp-filter must be loaded with the corresponding features (ipv4 and ipv6, respectively) π The supported options are:
-r,--removeβ remove the IP address instead of adding it.-m,--mode <mode>β select filtering mode. Valid options aresrcanddst, both of which may be specified assrc,dst. Ifsrcis specified, the IP address will added as a source IP match, while ifdstis specified, the IP address will be added as a destination IP match. If both are specified, a packet will be matched if either its source or destination IP is the specified IP address π-s,--statusβ if this option is specified, the current list of matched ips will be printed after inserting the IP address. Otherwise, nothing will be printed π€«-v,--verboseβ enable debug logging. Specify twice for even more verbosity π-h,--helpβ display a summary of the available options
π The ETHER command π
Use the ether command to add an Ethernet MAC address to the xdp-filter match list. For this to work, xdp-filter must be loaded with either the ethernet feature on at least one interface β οΈ
The syntax for the ether command is:
xdp-filter ether [options] <addr>
Where <addr> is the MAC address to add (or remove if the --remove is specified). The supported options are:
-r,--removeβ remove the MAC address instead of adding it.-m,--mode <mode>β select filtering mode. Valid options aresrcanddst, both of which may be specified assrc,dst. Ifsrcis specified, the MAC address will added as a source MAC match, while ifdstis specified, the MAC address will be added as a destination MAC match. If both are specified, a packet will be matched if either its source or destination MAC is the specified MAC address π¦-s,--statusβ if this option is specified, the current list of matched ips will be printed after inserting the MAC address. Otherwise, nothing will be printed π€« (yep, the original text says "ips" here even though we're doing MACs β keeping the lore intact, bestie)-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 prints the current status of xdp-filter: which interfaces it is loaded on, the current list of rules, and some statistics for how many packets have been processed in total, and how many times each rule has been hit π it's giving main character energy for your ruleset.
The syntax for the status command is:
xdp-filter status [options]
Where the supported options are:
-v,--verboseβ enable debug logging. Specify twice for even more verbosity π-h,--helpβ display a summary of the available options
π The POLL command π
The poll command periodically polls the xdp-filter statistics map and prints out the total number of packets and bytes processed by xdp-filter, as well as the number in the last polling interval, converted to packets (and bytes) per second β±οΈ This can be used to inspect the performance of xdp-filter, and to compare the performance of the different feature sets selectable by the load parameter π₯
The syntax for the poll command is:
xdp-filter poll [options]
Where the supported options are:
-i,--interval <interval>β the polling interval, in milliseconds. Defaults to1000(1 second).-v,--verboseβ enable debug logging. Specify twice for even more verbosity π-h,--helpβ display a summary of the available options
π Examples π
To filter all packets arriving on port 80 on eth0, issue the following commands:
# xdp-filter load eth0 -f tcp,udp
# xdp-filter port 80
To filter all packets except those from IP address fc00:dead:cafe::1 issue the following commands (careful, this can lock you out of remote access!):
# xdp-filter load eth0 -f ipv6 -p deny
# xdp-filter ip fc00:dead:cafe::1 -m src
To allow packets from either IP fc00:dead:cafe::1 or arriving on port 22, issue the following (careful, this can lock you out of remote access!):
# xdp-filter load eth0 -f ipv6,tcp -p deny
# xdp-filter port 22
# xdp-filter ip fc00:dead:cafe::1 -m src
π bestie, see those two "(careful, this can lock you out of remote access!)" notes? they are NOT decorative. -p deny means everything gets dropped until your allow rules land. respect the deny.
π BUGS π
Please report any bugs on Github: https://github.com/xdp-project/xdp-tools/issues
(they want your bug reports, fr fr β don't suffer in silence π)
π«Ά AUTHOR π«Ά
xdp-filter was written by Toke HΓΈiland-JΓΈrgensen and Jesper Dangaard Brouer. This man page was written by Toke HΓΈiland-JΓΈrgensen. legends only π
and that's the whole page, bestie π this was xdp-filter V1.6.3, dated SEPTEMBER 5, 2022 πΈ go forth and drop packets at tens of millions per second on a single CPU core β¨
π¦ 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