TC-VLAN(8)
๐ 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 theidoption ๐ฆmodifyโ Replace mode. The existing 802.1Q tag gets swapped out. Needs at least theidoption ๐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 thedst_macandsrc_macoptions ๐id VLANIDโ the VLAN ID you want to encapsulate into ๐VLANIDis an unsigned 16bit integer, and the format gets detected automatically (so prefix with0xif 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
- 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