TC-VLAN(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-VLAN(8) ๐ŸŽ€

VLAN manipulation action in tc(8) โ€” the Linux one, obviously ๐Ÿ’…

โœจ NAME โœจ

okay so the name is vlan, and it's a vlan manipulation module ๐Ÿฆ‹

๐ŸŒธ SYNOPSIS ๐ŸŒธ

tc ... action vlan { pop | pop_eth | PUSH | MODIFY | PUSH_ETH } [
        CONTROL ]

PUSH := push [ protocol VLANPROTO ]  [ priority VLANPRIO ] id VLANID

MODIFY := modify [ protocol VLANPROTO ]  [ priority VLANPRIO ] id VLANID

PUSH_ETH := push_eth dst_mac LLADDR src_mac LLADDR

CONTROL := { reclassify | pipe | drop | continue | pass | goto chain
        CHAIN_INDEX }

๐Ÿ’– DESCRIPTION ๐Ÿ’–

ngl this action is so iconic ๐Ÿ˜ญ The vlan action lets you do 802.1Q en- or decapsulation on a packet. It has three operation modes: POP, PUSH and MODIFY โœจ. POP is the easy one, since you don't need any extra info to just drop the outer-most VLAN encapsulation ๐Ÿ™ˆ. PUSH and MODIFY both need at least a VLANID, and you can optionally pick the VLANPROTO to use ๐ŸŽ€

It also goes beyond VLANs ๐Ÿ‘‘ The vlan action can add or remove the base Ethernet header too. The pop_eth mode takes no argument and removes the base Ethernet header, but all existing VLANs have to be dropped first ๐Ÿฅบ The opposite move is push_eth, which adds a base Ethernet header. For that one the packet must have no MAC header, because stacking MAC headers is not permitted ๐Ÿšซ This mode is mostly useful when a previous action has wrapped the whole original frame behind a network header, and you need to stick an Ethernet header on before forwarding the packet ๐Ÿงš

๐Ÿ“ OPTIONS ๐Ÿ“

  • pop โ€” Decapsulation mode. No further arguments allowed, bestie ๐Ÿ’…
  • push โ€” Encapsulation mode. Needs at least the id option ๐Ÿฆ‹
  • modify โ€” Replace mode. The existing 802.1Q tag gets swapped out. Needs at least the id option ๐Ÿ”
  • pop_eth โ€” Ethernet header decapsulation mode. It only works on a plain Ethernet header, so any VLANs have to be removed first ๐Ÿงผ
  • push_eth โ€” Ethernet header encapsulation mode. The Ethertype gets set automatically from the network header type โœจ Chaining Ethernet headers is not allowed: the packet must have no MAC header when you use this mode ๐Ÿšซ It requires the dst_mac and src_mac options ๐Ÿ’œ
  • id VLANID โ€” the VLAN ID you want to encapsulate into ๐ŸŒˆ VLANID is an unsigned 16bit integer, and the format gets detected automatically (so prefix with 0x if you want hexadecimal, etc.) ๐Ÿ”ข
  • protocol VLANPROTO โ€” pick the VLAN protocol to use ๐Ÿ‘‘ At the time of writing, the kernel only accepts 802.1Q or 802.1ad ๐Ÿ’€
  • priority VLANPRIO โ€” pick the VLAN priority to use ๐ŸŒŸ It's a decimal number from 0-7 ๐Ÿ“
  • dst_mac LLADDR โ€” the destination MAC address to use ๐Ÿ“ฌ
  • src_mac LLADDR โ€” the source MAC address to use ๐Ÿ“ฎ
  • CONTROL โ€” how to keep going after this action runs ๐Ÿซถ
    • reclassify โ€” restarts classification by jumping back to the first filter attached to this action's parent ๐Ÿ”„
    • pipe โ€” continues with the next action. This is the default, so you basically get it for free โœจ
    • drop โ€” the packet gets dropped without running any more actions ๐Ÿ—‘๏ธ
    • continue โ€” continues classification with the next filter in line โžก๏ธ
    • pass โ€” hands the packet back to the calling qdisc for processing. This ends the classification process ๐Ÿฆ‹

๐Ÿงš EXAMPLES ๐Ÿงš

okay so this first one encapsulates incoming ICMP packets on eth0 from 10.0.0.2 into VLAN ID 123 ๐Ÿ’–

#tc qdisc add dev eth0 handle ffff: ingress
#tc filter add dev eth0 parent ffff: pref 11 protocol ip \
     u32 match ip protocol 1 0xff flowid 1:1 \
         match ip src 10.0.0.2 flowid 1:1 \
     action vlan push id 123

And here's the pop function in action ๐ŸŽ€ Incoming VLAN packets on eth0 get decapsulated, and then classification restarts for the plain packet ๐Ÿ”ฅ

#tc qdisc add dev eth0 handle ffff: ingress
#tc filter add dev $ETH parent ffff: pref 1 protocol 802.1Q \
     u32 match u32 0 0 flowid 1:1 \
     action vlan pop reclassify

For an example of the pop_eth and push_eth modes, go check out tc-mpls(8) ๐ŸŒˆ

๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

tc(8), tc-mpls(8) ๐Ÿฆ‹


That's the whole tea, bestie ๐Ÿ’…โœจ Brought to you by iproute2, last touched on 12 Jan 2015 ๐ŸŒธ Stay iconic ๐Ÿซถ๐Ÿ’œ

๐Ÿ“ฆ where this page comes from