TC-MPLS(8)

๐ŸŽ€ MPLS manipulation action in tc(8) ๐ŸŽ€

Bestie, this is the manual for the mpls action, which is part of tc(8). It's the manual name, so you're reading it right now ๐Ÿ’…

โœจ NAME โœจ

mpls is the mpls manipulation module ๐Ÿฆ‹

๐Ÿ’œ SYNOPSIS ๐Ÿ’œ

tc ... action mpls { POP | PUSH | MODIFY | dec_ttl } [ CONTROL ]

POP := pop protocol MPLS_PROTO

PUSH := { push | mac_push } [ protocol MPLS_PROTO ]  [ tc MPLS_TC ]  [
        ttl MPLS_TTL ]  [ bos MPLS_BOS ] label MPLS_LABEL

MODIFY := modify [ label MPLS_LABEL ]  [ tc MPLS_TC ]  [ ttl MPLS_TTL ]

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

๐ŸŒธ DESCRIPTION ๐ŸŒธ

Okay so the mpls action does MPLS encapsulation or decapsulation on a packet ๐Ÿ”ฅ You pick one of four vibes: POP, PUSH, MODIFY, or DEC_TTL.

POP is the decapsulation mode, and it needs the ethertype of whatever header comes after the MPLS header (like IPv4, or another MPLS). It strips the outer MPLS header and swaps the ethertype in the MAC header for the one you passed in ๐Ÿซถ

PUSH and MODIFY either update the MPLS header that's already there or add a brand-new one. PUSH needs at least an MPLS_LABEL.

DEC_TTL needs no arguments at all. It just subtracts 1 from the MPLS header's TTL field. Simple, iconic โœจ

๐ŸŽ€ OPTIONS ๐ŸŽ€

  • pop โ€” Decapsulation mode. You have to give it the protocol of the next header ๐Ÿ’–
  • push โ€” Encapsulation mode. It slides the MPLS header in between the MAC and network headers. You need at least the label option.
  • mac_push โ€” Encapsulation mode, but this one adds the MPLS header before the MAC header. You need at least the label option.
  • modify โ€” Replace mode, where the existing MPLS tag gets swapped out. label, tc, and ttl are all optional here ๐Ÿฆ‹
  • dec_ttl โ€” Decrements the TTL field on the outermost MPLS header ๐Ÿงš
  • label MPLS_LABEL โ€” Sets the MPLS label for the outer MPLS header. MPLS_LABEL is an unsigned 20-bit integer, and the format gets detected automatically. Prefix it with 0x if you want hexadecimal, for example ๐ŸŒˆ
  • protocol MPLS_PROTO โ€” Picks the protocol to use. For push actions it has to be mpls_uc or mpls_mc, and mpls_uc is the default. For pop actions it should be the protocol of the next header. This option can't be used with modify ๐Ÿ™ˆ
  • tc MPLS_TC โ€” Sets the TC value for the outer MPLS header. It's a decimal number from 0-7, and it defaults to 0 ๐Ÿ“
  • ttl MPLS_TTL โ€” Sets the TTL value for the outer MPLS header. It's a number from 0-255. If you don't set it explicitly, a non-zero default gets picked for you ๐Ÿ’…
  • bos MPLS_BOS โ€” Lets you manually set the bottom of stack bit for an MPLS header push. By default, tc sets (or unsets) that bit automatically, based on the next header of the packet โญ

๐Ÿ‘‘ CONTROL ๐Ÿ‘‘

This is all about how things keep going after the action runs. It's the CONTROL part, bestie ๐Ÿซถ

  • 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 โœจ
  • drop โ€” The packet gets dropped without running any further 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, first one. This encapsulates incoming IP packets on eth0 into MPLS with label 123 and sends them out eth1 ๐Ÿ’–

#tc qdisc add dev eth0 handle ffff: ingress
#tc filter add dev eth0 protocol ip parent ffff: flower \
     action mpls push protocol mpls_uc label 123  \
     action mirred egress redirect dev eth1

Next, incoming MPLS unicast packets on eth0 get decapsulated and redirected to eth1. Main character energy ๐Ÿ‘‘

#tc qdisc add dev eth0 handle ffff: ingress
#tc filter add dev eth0 protocol mpls_uc parent ffff: flower \
     action mpls pop protocol ipv4  \
     action mirred egress redirect dev eth1

Here's another one ๐ŸŽ€ Incoming Ethernet frames get encapsulated into MPLS with label 123 and TTL 64. Then an outer Ethernet header is added, and the resulting frame is finally sent on eth1:

#tc qdisc add dev eth0 ingress
#tc filter add dev eth0 ingress matchall \
     action mpls mac_push label 123 ttl 64 \
     action vlan push_eth \
          dst_mac 02:00:00:00:00:02 \
          src_mac 02:00:00:00:00:01 \
     action mirred egress redirect dev eth1

Last one, and it's a good one ๐Ÿ˜ญ This assumes incoming MPLS packets with label 123 are carrying Ethernet frames. The outer Ethernet and MPLS headers get stripped, and then the inner Ethernet frame is sent on eth1:

#tc qdisc add dev eth0 ingress
#tc filter add dev eth0 ingress protocol mpls_uc \
     flower mpls_label 123 mpls_bos 1 \
     action vlan pop_eth \
     action mpls pop protocol teb \
     action mirred egress redirect dev eth1

๐Ÿ”— SEE ALSO ๐Ÿ”—

tc(8), tc-mirred(8), tc-vlan(8) ๐Ÿ“


Okay that's the whole page, bestie ๐Ÿซถ It came from iproute2, dated 22 May 2019, with the Linux source, and it's the MPLS manipulation action in tc(8) ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from