lib/net: add MPLS insert and strip functionality
PATCH v3 1/1 lib/net: add MPLS insert and strip functionality
From: Tanzeel Ahmed <[email protected]>
This patch is new version of [PATCH] lib/net: added push MPLS header API. I have also added the MPLS strip functionality to address the question asked in last patch.
Quoted 1 line
You should explain why you add this function.
None of the foundational NICs currently supports MPLS insertion and stripping, this functionality can help users who rely on MPLS in their network application.
Quoted 1 line
I'm not sure it should be inline
I did for performance in high-traffic application.
---
v3:
* fixed patch checks failure
v2:
* marked experimental
* coding style fixed
* changed rte_memcpy to memcpy
* mpls header marked as const in parameter
* added MPLS stripping functionality
--- .mailmap | 1 + lib/net/rte_mpls.h | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+)
.mailmap +1 -0
@@ -1312,6 +1312,7 @@ Takeshi Yoshimura <[email protected]> <[email protected]> Takuya Asada <[email protected]> Tal Avraham <[email protected]> Tal Shnaiderman <[email protected]> <[email protected]> +Tanzeel Ahmed <[email protected]> Tao Y Yang <[email protected]> Tao Zhu <[email protected]> Taripin Samuel <[email protected]>
lib/net/rte_mpls.h +97 -0
109 lines not on this page · raw message
Signature · 1 line
1.8.3.1
lib/net/rte_mpls.h struct rte_mpls_hdr { · line 124
Quoted 13 lines · On Fri, 24 Feb 2023 16:06:19 +0500 Tanzeel-inline <[email protected]>…
lib/net/rte_mpls.h +13
-0+static inline int +rte_mpls_strip_over_l2 (struct rte_mbuf *m) +{ + struct rte_ether_hdr *eh = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); +struct rte_mpls_hdr *mph; +bool mpls_exist = true; + +if (eh->ether_type !=rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) +return -1 ; + +/* Stripping all MPLS header */ +while (mpls_exist) { + mph = rte_pktmbuf_mtod_offset(m, struct rte_mpls_hdr*,
space required (i.e "struct rte_mpls_hdr *")
lib/net/rte_mpls.h struct rte_mpls_hdr { · line 134
Quoted 10 lines
lib/net/rte_mpls.h +10
-0+ sizeof(struct rte_ether_hdr)); +if (mph->bs &1 ) + mpls_exist = false; +memmove (rte_pktmbuf_adj (m,sizeof (struct rte_mpls_hdr )), + eh,sizeof (struct rte_ether_hdr )); + eh = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); + } + +return 0 ; +}
This function will fail for the case of segmented mbuf.
Also need to handle case where mbuf is corrupted and just has stack of mpls tags and the last one is incomplete.