TC-SAMPLE(8)

๐Ÿ“ฆ
version 7.3.0 ยท 2 versions
  • 7.3.0 ยท alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 5.15.0 ยท ubuntu jammy
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

๐ŸŽ€ 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! RATE is the expected ratio between observed packets and sampled packets. So a RATE of 100 gives 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