Skip to contentSkip to conversation

tc: support for new MPLS L2 VPN actions

PATCH Applied Guillaume Nault 3 participants 9 messages Oct 19, 2020 – Oct 22, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover tc: support for new MPLS L2 VPN actions

This patch series adds the possibility for TC to tunnel Ethernet frames over MPLS.

Patch 1 allows adding or removing the Ethernet header. Patch 2 allows pushing an MPLS LSE before the MAC header.

By combining these actions, it becomes possible to encapsulate an entire Ethernet frame into MPLS, then add an outer Ethernet header and send the resulting frame to the next hop.

v2: trivial coding style fix (line wrap).

Guillaume Nault (2):
m_vlan: add pop_eth and push_eth actions
m_mpls: add mac_push action

 lib/ll_proto.c            |  1 +
 man/man8/tc-mpls.8        | 44 ++++++++++++++++++--
 man/man8/tc-vlan.8        | 44 ++++++++++++++++++--
 tc/m_mpls.c               | 43 ++++++++++++++------
 tc/m_vlan.c               | 69 +++++++++++++++++++++++++++++++
 testsuite/tests/tc/mpls.t | 69 +++++++++++++++++++++++++++++++
 testsuite/tests/tc/vlan.t | 86 +++++++++++++++++++++++++++++++++++++++
 7 files changed, 337 insertions(+), 19 deletions(-)
 create mode 100755 testsuite/tests/tc/mpls.t
 create mode 100755 testsuite/tests/tc/vlan.t
Signature · 1 line
2.21.3
#1 lore raw

PATCH v2 1/2 m_vlan: add pop_eth and push_eth actions

Add support for the new TCA_VLAN_ACT_POP_ETH and TCA_VLAN_ACT_PUSH_ETH actions (kernel commit 19fbcb36a39e ("net/sched: act_vlan:
Add {POP,PUSH}_ETH actions"). These action let TC remove or add the Ethernet at the head of a frame.

Drop an Ethernet header:

 # tc filter add dev ethX matchall action vlan pop_eth

Push an Ethernet header (the original frame must have no MAC header):

 # tc filter add dev ethX matchall action vlan \
       push_eth dst_mac 0a:00:00:00:00:02 src_mac 0a:00:00:00:00:01

Also add a test suite for m_vlan, which covers these new actions and the pre-existing ones.

---
 man/man8/tc-vlan.8        | 39 +++++++++++++++++-
 tc/m_vlan.c               | 69 +++++++++++++++++++++++++++++++
 testsuite/tests/tc/vlan.t | 86 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 192 insertions(+), 2 deletions(-)
 create mode 100755 testsuite/tests/tc/vlan.t
man/man8/tc-vlan.8 +37 -2
index f5ffc25f..5c2808b1 100644
@@ -5,8 +5,8 @@ vlan - vlan manipulation module
 .SH SYNOPSIS
 .in +8
 .ti -8
-.BR tc " ... " "action vlan" " { " pop " |"
-.IR PUSH " | " MODIFY " } [ " CONTROL " ]"
+.BR tc " ... " "action vlan" " { " pop " | " pop_eth " |"
+.IR PUSH " | " MODIFY " | " PUSH_ETH " } [ " CONTROL " ]"
 
 .ti -8
 .IR PUSH " := "
@@ -24,6 +24,11 @@ vlan - vlan manipulation module
 .IR VLANPRIO " ] "
 .BI id " VLANID"
 
+.ti -8
+.IR PUSH_ETH " := "
+.B push_eth
+.BI dst_mac " LLADDR " src_mac " LLADDR "
+
 .ti -8
 .IR CONTROL " := { "
 .BR reclassify " | " pipe " | " drop " | " continue " | " pass " | " goto " " chain " " CHAIN_INDEX " }"
@@ -43,6 +48,20 @@ modes require at least a
 and allow to optionally choose the
 .I VLANPROTO
 to use.
+
+The
+.B vlan
+action can also be used to add or remove the base Ethernet header. The
+.B pop_eth
+mode, which takes no argument, is used to remove the base Ethernet header. All
+existing VLANs must have been previously dropped. The opposite operation,
+adding a base Ethernet header, is done with the
+.B push_eth
+mode. In that case, the packet must have no MAC header (stacking MAC headers is
+not permitted). This mode is mostly useful when a previous action has
+encapsulated the whole original frame behind a network header and one needs
+to prepend an Ethernet header before forwarding the resulting packet.
+
 .SH OPTIONS
 .TP
 .B pop
@@ -58,6 +77,16 @@ Replace mode. Existing 802.1Q tag is replaced. Requires at least
 .B id
 option.
 .TP
+.B pop_eth
+Ethernet header decapsulation mode. Only works on a plain Ethernet header:
+VLANs, if any, must be removed first.
+.TP
+.B push_eth
+Ethernet header encapsulation mode. The Ethertype is automatically set
+using the network header type. Chaining Ethernet headers is not allowed: the
+packet must have no MAC header when using this mode. Requires the
+.BR "dst_mac " and " src_mac " options.
+.TP
 .BI id " VLANID"
 Specify the VLAN ID to encapsulate into.
 .I VLANID
@@ -73,6 +102,12 @@ Choose the VLAN protocol to use. At the time of writing, the kernel accepts only
 .BI priority " VLANPRIO"
 Choose the VLAN priority to use. Decimal number in range of 0-7.
 .TP
+.BI dst_mac " LLADDR"
+Choose the destination MAC address to use.
+.TP
+.BI src_mac " LLADDR"
+Choose the source MAC address to use.
+.TP
 .I CONTROL
 How to continue after executing this action.
 .RS
tc/m_vlan.c +69 -0

117 lines not on this page · raw message

testsuite/tests/tc/vlan.t new file +86 -0

86 lines not on this page · raw message

Signature · 1 line
2.21.3
#2 lore raw

Re: [PATCH v2 iproute2-next 1/2] m_vlan: add pop_eth and push_eth actions

tc/m_vlan.c static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p, · line 106

Quoted 1 line · On Mon, 19 Oct 2020 17:23:01 +0200 Guillaume Nault <[email protected]> wrote:
tc/m_vlan.c +1 -0
+		} else if (matches(*argv, "pop_eth") == 0) {

Using matches allows for shorter command lines but can be make for bad user experience if strings overlap.

For example 'p' here will match the pop_eth and not the push_eth.

Is it time to use full string compare for these options?

#3 lore raw

Re: [PATCH v2 iproute2-next 1/2] m_vlan: add pop_eth and push_eth actions

Quoted 12 lines · Stephen Hemminger

tc/m_vlan.c static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p, · line 106

Quoted 1 line · On Mon, 19 Oct 2020 17:23:01 +0200 Guillaume Nault <[email protected]> wrote:
tc/m_vlan.c +1 -0
+		} else if (matches(*argv, "pop_eth") == 0) {

Using matches allows for shorter command lines but can be make for bad user experience if strings overlap.

For example 'p' here will match the pop_eth and not the push_eth.

Is it time to use full string compare for these options?

I thought the same, but let it go given the pervasive use of 'matches'.

I do think iproute2 needs to stop adding more uses of it and forcing full strcmp's.

#4 lore raw

Re: [PATCH v2 iproute2-next 1/2] m_vlan: add pop_eth and push_eth actions

In reply to Stephen Hemminger
Quoted 9 lines · Stephen Hemminger

tc/m_vlan.c static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p, · line 106

Quoted 1 line · On Mon, 19 Oct 2020 17:23:01 +0200 Guillaume Nault <[email protected]> wrote:
tc/m_vlan.c +1 -0
+		} else if (matches(*argv, "pop_eth") == 0) {

Using matches allows for shorter command lines but can be make for bad user experience if strings overlap.

For example 'p' here will match the pop_eth and not the push_eth.

Well, the action names are tested in the following order:
* pop (old action)
* push (old action)
* pop_eth (new action)
* push_eth (new action)

Therefore, 'p' matches 'pop', thus retaining the original behaviour.

I realise that for m_mpls.c, I put the 'mac_push' action before 'modify', and thus changed the behaviour of 'm'. I'll send a patch to move the 'mac_push' test.

Quoted 1 line

Is it time to use full string compare for these options?

If there's consensus that matches() should be avoided for new options, I'll also follow up on this and replace it with strcmp(). However, that should be a clear project-wide policy IMHO.

#5 lore raw

Re: [PATCH v2 iproute2-next 1/2] m_vlan: add pop_eth and push_eth actions

Quoted 7 lines · Guillaume Nault
Quoted 2 lines

Is it time to use full string compare for these options?

If there's consensus that matches() should be avoided for new options, I'll also follow up on this and replace it with strcmp(). However, that should be a clear project-wide policy IMHO.

we can't change existing uses of 'matches'; it needs to be a policy change going forward hence the discussion now.

#6 lore raw

Re: [PATCH v2 iproute2-next 1/2] m_vlan: add pop_eth and push_eth actions

Quoted 11 lines · David Ahern
Quoted 7 lines · Guillaume Nault
Quoted 2 lines

Is it time to use full string compare for these options?

If there's consensus that matches() should be avoided for new options, I'll also follow up on this and replace it with strcmp(). However, that should be a clear project-wide policy IMHO.

we can't change existing uses of 'matches'; it needs to be a policy change going forward hence the discussion now.

Yes, that's what I meant. Sorry if I wasn't clear.

#7 lore raw

PATCH v2 2/2 m_mpls: add mac_push action

In reply to Guillaume Nault

Add support for the new TCA_MPLS_ACT_MAC_PUSH action (kernel commit a45294af9e96 ("net/sched: act_mpls: Add action to push MPLS LSE before Ethernet header")). This action let TC push an MPLS header before the MAC header of a frame.

Example (encapsulate all outgoing frames with label 20, then add an outer Ethernet header):

 # tc filter add dev ethX matchall \
       action mpls mac_push label 20 ttl 64 \
       action vlan push_eth dst_mac 0a:00:00:00:00:02 \
                            src_mac 0a:00:00:00:00:01

This patch also adds an alias for ETH_P_TEB, since it is useful when decapsulating MPLS packets that contain an Ethernet frame.

With MAC_PUSH, there's no previous Ethertype to modify. However, the "protocol" option is still needed, because the kernel uses it to set skb->protocol. So rename can_modify_ethtype() to can_set_ethtype().

Also add a test suite for m_mpls, which covers the new action and the pre-existing ones.

---
 lib/ll_proto.c            |  1 +
 man/man8/tc-mpls.8        | 44 +++++++++++++++++++++++--
 man/man8/tc-vlan.8        |  5 ++-
 tc/m_mpls.c               | 43 ++++++++++++++++--------
 testsuite/tests/tc/mpls.t | 69 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 145 insertions(+), 17 deletions(-)
 create mode 100755 testsuite/tests/tc/mpls.t
lib/ll_proto.c +1 -0
index 2a0c1cb3..78179311 100644
@@ -80,6 +80,7 @@ __PF(8021Q,802.1Q)
 __PF(8021AD,802.1ad)
 __PF(MPLS_UC,mpls_uc)
 __PF(MPLS_MC,mpls_mc)
+__PF(TEB,teb)
 
 { 0x8100, "802.1Q" },
 { 0x88cc, "LLDP" },
man/man8/tc-mpls.8 +41 -3

60 lines not on this page · raw message

man/man8/tc-vlan.8 +4 -1
index 5c2808b1..264053d3 100644
@@ -157,5 +157,8 @@ process then restarted for the plain packet:
 .EE
 .RE
 
+For an example of the
+.BR pop_eth " and " push_eth " modes, see " tc-mpls (8).
+
 .SH SEE ALSO
-.BR tc (8)
+.BR tc "(8), " tc-mpls (8)
tc/m_mpls.c +30 -13

110 lines not on this page · raw message

testsuite/tests/tc/mpls.t new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.21.3
Applied
#8 lore raw
In reply to Guillaume Nault
Quoted 10 lines · Guillaume Nault

This patch series adds the possibility for TC to tunnel Ethernet frames over MPLS.

Patch 1 allows adding or removing the Ethernet header. Patch 2 allows pushing an MPLS LSE before the MAC header.

By combining these actions, it becomes possible to encapsulate an entire Ethernet frame into MPLS, then add an outer Ethernet header and send the resulting frame to the next hop.

Quoted 5 lines

v2: trivial coding style fix (line wrap).

Guillaume Nault (2):
m_vlan: add pop_eth and push_eth actions
m_mpls: add mac_push action

applied to iproute2-next. Thanks, Guillaume.