TC-SKBMOD(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

โœจ skbmod action in tc(8) โœจ

okay bestie, this is the manual page for skbmod, the action that makes packet editing way less painful ๐ŸŽ€

๐Ÿ’– NAME

skbmod - user-friendly packet editor action

๐Ÿงš SYNOPSIS

tc ... action skbmod { set SETTABLE | swap SWAPPABLE  | ecn } [ CONTROL
        ] [ index INDEX ]

SETTABLE :=  [ dmac DMAC ]  [ smac SMAC ]  [ etype ETYPE ]

SWAPPABLE := mac

CONTROL := { reclassify | pipe | drop | shot | continue | pass }

๐Ÿฆ‹ DESCRIPTION

so the skbmod action is basically a glow-up of the existing pedit action ๐Ÿ’… instead of hand-editing 8-, 16-, or 32-bit chunks of an ethernet header like it's 1999, skbmod lets you swap out whole supported elements in one go ๐Ÿซถ

you pick one of three actions: set, swap, or ecn. set and swap only touch Ethernet packets, while ecn only touches IP packets ๐ŸŒธ

๐ŸŽ€ OPTIONS

  • dmac DMAC โ€” change the destination mac to whatever address you give it ๐Ÿ’œ
  • smac SMAC โ€” change the source mac to the specified address ๐Ÿ“
  • etype ETYPE โ€” change the ethertype to the specified value โœจ
  • mac โ€” swaps the mac addresses ๐Ÿ”
  • ecn โ€” marks ECN Capable Transport (ECT) IP packets as Congestion Encountered (CE) ๐ŸŒˆ it does not touch Non ECN-Capable Transport (Non-ECT) packets, so those stay exactly as they are ๐Ÿ™ˆ
  • CONTROL โ€” these keywords decide how the tree of qdisc, classes, filters and actions gets traversed after this action runs ๐Ÿงญ
    • reclassify โ€” restart with the first filter in the current list ๐Ÿ”„
    • pipe โ€” continue with the next action attached to the same filter โžก๏ธ
    • drop or shot โ€” drop the packet ๐Ÿ’€
    • continue โ€” continue classification with the next filter in line ๐Ÿƒโ€โ™€๏ธ
    • pass โ€” finish classification and return to the calling qdisc for further packet processing. this is the default ๐Ÿ‘‘

๐Ÿ’… EXAMPLES

okay so first, let's look at a filter using the pedit action:

tc filter add dev eth1 parent 1: protocol ip prio 10 \
     u32 match ip protocol 1 0xff flowid 1:2 \
     action pedit munge offset -14 u8 set 0x02 \
     munge offset -13 u8 set 0x15 \
     munge offset -12 u8 set 0x15 \
     munge offset -11 u8 set 0x15 \
     munge offset -10 u16 set 0x1515 \
     pipe

with skbmod, that whole mess becomes:

tc filter add dev eth1 parent 1: protocol ip prio 10 \
     u32 match ip protocol 1 0xff flowid 1:2 \
     action skbmod set dmac 02:15:15:15:15:15 \
     pipe

it gets a little more involved if you also edit the source mac and ethertype. if all three fields are changing with skbmod:

tc filter add dev eth5 parent 1: protocol ip prio 10 \
     u32 match ip protocol 1 0xff flowid 1:2 \
     action skbmod \
     set etype 0xBEEF \
     set dmac 02:12:13:14:15:16 \
     set smac 02:22:23:24:25:26

to swap the destination and source mac addresses in the Ethernet header:

tc filter add dev eth3 parent 1: protocol ip prio 10 \
     u32 match ip protocol 1 0xff flowid 1:2 \
     action skbmod \
     swap mac

and finally, to mark the CE codepoint in the IP header for ECN Capable Transport (ECT) packets:

tc filter add dev eth0 parent 1: protocol ip prio 10 \
     u32 match ip protocol 1 0xff flowid 1:2 \
     action skbmod \
     ecn
โš ๏ธ bestie, listen up: only one of set, swap and ecn can be used in a single command. trying to use more than one in the same command is undefined behavior ๐Ÿ’€ if you need multiple, pipe multiple commands together instead ๐Ÿซถ

๐ŸŒˆ SEE ALSO

tc(8), tc-u32(8), tc-pedit(8) ๐Ÿฆ‹


that's a wrap, bestie ๐Ÿ’– this page is from iproute2, dated 21 Sep 2016, titled skbmod action in tc(8) โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from