TC-SAMPLE(8)
๐ TC-SAMPLE(8) ๐
Packet sample action in tc(8), so this is the page for the sample action of tc ๐
โจ NAME โจ
okay so the name is just sample, which is a packet sampling tc action ๐ฆ
๐ธ SYNOPSIS ๐ธ
tc ... action sample rate RATE group GROUP [ trunc SIZE ] [ index INDEX
]
tc ... action sample index INDEX
๐ DESCRIPTION ๐
okay the sample action lets you sample packets that match a classifier, and it's giving precision ๐ญโจ
The packets get picked randomly according to the rate parameter, and they're sampled through the psample generic netlink channel. You can also set up packet truncation to save user-kernel traffic, which is lowkey genius ๐ง Every sample comes with some informative metadata about the original packet. That metadata gets sent as netlink attributes, right alongside the original packet data ๐ซถ
You can either set the sample action parameters the way the first form in SYNOPSIS shows, or reuse an existing sample action by its index, like the second form does. Main character energy either way ๐
๐ง SAMPLED PACKETS METADATA FIELDS ๐ง
The metadata gets delivered to userspace apps through the psample generic netlink channel. Each sample includes these netlink attributes, and they are all so useful ๐
PSAMPLE_ATTR_IIFINDEXโ the input interface index of the packet, if there is one ๐PSAMPLE_ATTR_OIFINDEXโ the output interface index of the packet. This field is not relevant on ingress sampling ๐PSAMPLE_ATTR_ORIGSIZEโ the size of the original packet, before any truncation ๐PSAMPLE_ATTR_SAMPLE_GROUPโ the psample group the packet was sent to ๐PSAMPLE_ATTR_GROUP_SEQโ a sequence number for the sampled packet. It goes up by one with each sampled packet of the current psample group ๐ขPSAMPLE_ATTR_SAMPLE_RATEโ the rate the packet was sampled with ๐
๐ฆ OPTIONS ๐ฆ
rate RATEโ the packet sample rate!RATEis the expected ratio between observed packets and sampled packets. So aRATEof100gives you an average of one sampled packet out of every 100 observed ๐trunc SIZEโ once you set this, it defines the maximum size of the sampled packets and causes truncation if needed โ๏ธgroup GROUPโ the psample group the packet will be sent to. psample has this concept of groups, so when you've got multiple sampling rules you can match specific sampled packets and figure out which rule they came from. Iconic organization ๐๏ธโจindex INDEXโ a unique ID for an action. When you're creating a new action instance, this sets the new action's index. When you're using an existing action, this lets you specify that existing action's index. The index must be a 32bit unsigned integer greater than zero ๐ข๐ธ
๐ EXAMPLES ๐
Sample one of every 100 packets flowing into interface eth0 to psample group 12:
tc qdisc add dev eth0 handle ffff: ingress
tc filter add dev eth0 parent ffff: matchall \
action sample rate 100 group 12 index 19
Use that same action instance to sample eth1 too ๐ฅฐ
tc qdisc add dev eth1 handle ffff: ingress
tc filter add dev eth1 parent ffff: matchall \
action sample index 19
๐ซถ SEE ALSO ๐ซถ
tc(8), tc-matchall(8), psample(1)
bestie that's the whole thing ๐ iproute2, last updated 31 Jan 2017 ๐ stay sampling, stay slaying ๐ง๐
๐ฆ where this page comes from
- alpine 3.22: iproute2-doc 6.15.0-r0 ยท GPL-2.0-or-later
- alpine 3.23: iproute2-doc 6.17.0-r0 ยท GPL-2.0-or-later
- alpine 3.24: iproute2-doc 7.0.0-r0 ยท GPL-2.0-or-later
- arch rolling: iproute2 7.2.0-1
- arch rolling: iproute2 7.3.0-1 ยท GPL-2.0-or-later
- centos-stream 10: iproute-tc 7.0.0-2.el10 ยท GPL-2.0-or-later
- centos-stream 9: iproute-tc 6.17.0-3.el9 ยท GPL-2.0-or-later
- debian bookworm: iproute2 6.1.0-3 ยท GPL-2.0-only
- debian trixie: iproute2 6.15.0-1 ยท GPL-2.0-only
- fedora 43: iproute-tc 6.14.0-2.fc43 ยท GPL-2.0-or-later
- fedora 44: iproute-tc 6.17.0-2.fc44 ยท GPL-2.0-or-later
- nixos 26.05: iproute2 7.0.0
- nixpkgs unstable: iproute2 7.2.0
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- ubuntu noble: iproute2 6.1.0-1ubuntu6 ยท GPL-2.0-only
- ubuntu noble: iproute2 6.1.0-1ubuntu6.4 ยท GPL-2.0-only
- ubuntu questing: iproute2 6.16.0-1ubuntu2
- ubuntu questing: iproute2 6.16.0-1ubuntu2.1 ยท GPL-2.0-only
- ubuntu questing: iproute2 6.16.0-1ubuntu2.2
- ubuntu resolute: iproute2 6.19.0-1ubuntu1 ยท GPL-2.0-only
- ubuntu resolute: iproute2 6.19.0-1ubuntu1.1 ยท GPL-2.0-only
- ubuntu stonking: iproute2 7.2.0-1ubuntu1 ยท GPL-2.0-only
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms