From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 30F5C42B55; Sat, 20 May 2023 21:53:53 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B752342BC9; Sat, 20 May 2023 21:53:52 +0200 (CEST) Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by mails.dpdk.org (Postfix) with ESMTP id A329F40395 for ; Sat, 20 May 2023 21:53:51 +0200 (CEST) Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-3095557dd99so1791412f8f.1 for ; Sat, 20 May 2023 12:53:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684612431; x=1687204431; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=8uhEFIOK+mzVFeliYBtTnAXmYTUyU587KEGp4gWroHM=; b=X+DssB7lqBgkPeHGHWaEIchN3fgQMFBFczl3di7innOXqvN12GYSKCYbM4OZlCJ7wf H0LuphPzc7TtzCj4+WM8VrRXislJ8y6hsYeKWNz08DMNQEesr+9czUgGswlUYK1BRJQ4 Gk+BcfLG1XkYfnP1JpKDRq0jvk5u0xDkWIX8lWanwQWKkdZFe+rdTEc9O2gbuf0gNmux JeRr7GVmwzux69zAb29O97VrUh1bXJTErE0bhpyRzvWOn8P9pxcMUTJa7dx9J7aPrLX+ qKgt7t/jIBBPj24MAXGboxHyhsaMulRrW3RijSi1k6muEwbz1MW7EbZ+W+PM7MuQctPb /Uvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684612431; x=1687204431; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8uhEFIOK+mzVFeliYBtTnAXmYTUyU587KEGp4gWroHM=; b=iU3UpOENyvilO/tisjU+0NS2Pq+i0SRI5hDMxrKhF84TcDAACe/cFhIST6deiThs2C CBksUja7hVb5Aayn544HitDWMf/JHQCgpJ2b94nlPTm8m8N1MeW3anntwGjx7gkk7fqZ 0Ff9YRAGfArU7Mhf3uk6xFBBJFZK7VkfYQsVh4/6xt5J+ExZG5nm/Q0Yvi3gEa6acnZ9 vYFQK5qSh/8qyOmZLVRkFby8WpBd/LTLASHDhhZj99V6GWyemVGm94tvjOKUK6ferOQM /beKQ6YpkAXfCCe/qCbbvd1roOYG7oigibJ0PuiVQaKcuWPMk8Es5lSm5QygzuNsYxHP sxxg== X-Gm-Message-State: AC+VfDzoGvT1xtIRbhxGwNf5IHhhUyyfFJ937mI3V8NHnmUGpllrcP4M k2LsKXImx50G0YArgcPFouLMVlf+sIh139GdPic= X-Google-Smtp-Source: ACHHUZ4JdSHIJLqtZgoD7UKlR7iYCqVsX7c0W/+lJ4Q1qAA68xcbAfWH2iYjoo1LgzcvbzM/sgHmCHbbCPLPVHyHzOc= X-Received: by 2002:adf:e689:0:b0:309:38af:d300 with SMTP id r9-20020adfe689000000b0030938afd300mr3877048wrm.33.1684612430898; Sat, 20 May 2023 12:53:50 -0700 (PDT) MIME-Version: 1.0 References: <20230219224334.309-1-tanxeel1.ahmed@gmail.com> <20230225135343.262-1-tanxeel1.ahmed@gmail.com> In-Reply-To: From: Tanzeel Ahmed Date: Sun, 21 May 2023 00:53:13 +0500 Message-ID: Subject: Re: [PATCH v4] lib/net: add MPLS insert and strip functionality To: olivier.matz@6wind.com, thomas@monjalon.net, tanzeelahmed713@gmail.com Cc: dev@dpdk.org Content-Type: multipart/alternative; boundary="000000000000872a7805fc256529" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org --000000000000872a7805fc256529 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Gentle Ping On Tue, Apr 18, 2023 at 6:18=E2=80=AFPM Tanzeel Ahmed wrote: > Ping. > > On Thu, Mar 9, 2023 at 11:35=E2=80=AFPM Tanzeel Ahmed > wrote: > >> Any updates? >> >> >> On Sat, Feb 25, 2023 at 6:53=E2=80=AFPM Tanzeel-inline >> wrote: >> >>> From: Tanzeel Ahmed >>> >>> This patch is new version of [PATCH] lib/net: added push MPLS header AP= I. >>> I have also added the MPLS strip functionality to address the question >>> asked in last patch. >>> >>> > 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. >>> >>> > I'm not sure it should be inline >>> I did for performance in high-traffic application. >>> >>> Signed-off-by: Tanzeel Ahmed >>> >>> --- >>> v4: >>> * Removed extra void cast. >>> * rte_pktmbuf_append/mtod now return void*. >>> The memmove result is casted to rte_ether_hdr*. >>> >>> v3: >>> * fixed patch check failure issue >>> >>> 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(+) >>> >>> diff --git a/.mailmap b/.mailmap >>> index a9f4f28..2af4e0d 100644 >>> --- a/.mailmap >>> +++ b/.mailmap >>> @@ -1312,6 +1312,7 @@ Takeshi Yoshimura < >>> t.yoshimura8869@gmail.com> >>> Takuya Asada >>> Tal Avraham >>> Tal Shnaiderman >>> +Tanzeel Ahmed >>> Tao Y Yang >>> Tao Zhu >>> Taripin Samuel >>> diff --git a/lib/net/rte_mpls.h b/lib/net/rte_mpls.h >>> index 51523e7..d7e267f 100644 >>> --- a/lib/net/rte_mpls.h >>> +++ b/lib/net/rte_mpls.h >>> @@ -13,6 +13,8 @@ >>> >>> #include >>> #include >>> +#include >>> +#include >>> >>> #ifdef __cplusplus >>> extern "C" { >>> @@ -36,6 +38,101 @@ struct rte_mpls_hdr { >>> uint8_t ttl; /**< Time to live. */ >>> } __rte_packed; >>> >>> +#define RTE_MPLS_HLEN 4 /**< Length of MPLS header. */ >>> + >>> +/** >>> + * @warning >>> + * @b EXPERIMENTAL: this API may change without prior notice. >>> + * >>> + * Insert MPLS header into the packet. >>> + * If it's first MPLS header to be inserted in the packet, >>> + * - Updates the ether type. >>> + * - Sets the MPLS bottom-of-stack bit to 1. >>> + * >>> + * @param m >>> + * The pointer to the mbuf. >>> + * @param mp >>> + * The pointer to the MPLS header. >>> + * @return >>> + * 0 on success, -1 on error >>> + */ >>> +__rte_experimental >>> +static inline int >>> +rte_mpls_push_over_l2(struct rte_mbuf **m, const struct rte_mpls_hdr >>> *mp) >>> +{ >>> + void *os, *ns; >>> + struct rte_ether_hdr *nh; >>> + struct rte_mpls_hdr *mph; >>> + >>> + /* Can't insert header if mbuf is shared */ >>> + if (!RTE_MBUF_DIRECT(*m) || rte_mbuf_refcnt_read(*m) > 1) >>> + return -EINVAL; >>> + >>> + /* Can't insert header if ethernet frame doesn't exist */ >>> + if (rte_pktmbuf_data_len(*m) < RTE_ETHER_HDR_LEN) >>> + return -EINVAL; >>> + >>> + os =3D rte_pktmbuf_mtod(*m, void *); >>> + ns =3D (void *)rte_pktmbuf_prepend(*m, sizeof(struct >>> rte_mpls_hdr)); >>> + if (ns =3D=3D NULL) >>> + return -ENOSPC; >>> + >>> + nh =3D (struct rte_ether_hdr *)memmove(ns, os, RTE_ETHER_HDR_LE= N); >>> + >>> + /* Copy the MPLS header after ethernet frame */ >>> + mph =3D rte_pktmbuf_mtod_offset(*m, struct rte_mpls_hdr*, >>> + sizeof(struct rte_ether_hdr)); >>> + memcpy(mph, mp, RTE_MPLS_HLEN); >>> + >>> + mph->tag_msb =3D rte_cpu_to_be_16(mp->tag_msb); >>> + >>> + /* If first MPLS header, update ether type and bottom-of-stack >>> bit */ >>> + if (nh->ether_type !=3D rte_cpu_to_be_16(RTE_ETHER_TYPE_MPLS)) = { >>> + nh->ether_type =3D rte_cpu_to_be_16(RTE_ETHER_TYPE_MPLS= ); >>> + mph->bs =3D 1; >>> + } else { >>> + mph->bs =3D 0; >>> + } >>> + >>> + return 0; >>> +} >>> + >>> +/** >>> + * @warning >>> + * @b EXPERIMENTAL: this API may change without prior notice. >>> + * >>> + * Strips MPLS from the packet. Doesn't update the ether type >>> + * >>> + * @param m >>> + * The pointer to the mbuf. >>> + * @return >>> + * 0 on success, -1 on error >>> + */ >>> +__rte_experimental >>> +static inline int >>> +rte_mpls_strip_over_l2(struct rte_mbuf *m) >>> +{ >>> + struct rte_ether_hdr *eh =3D rte_pktmbuf_mtod(m, struct >>> rte_ether_hdr *); >>> + struct rte_mpls_hdr *mph; >>> + bool mpls_exist =3D true; >>> + >>> + if (eh->ether_type !=3D rte_cpu_to_be_16(RTE_ETHER_TYPE_MPLS)) >>> + return -1; >>> + >>> + /* Stripping all MPLS header */ >>> + while (mpls_exist) { >>> + mph =3D rte_pktmbuf_mtod_offset(m, struct rte_mpls_hdr*= , >>> + sizeof(struct rte_ether_hdr)); >>> + if (mph->bs & 1) >>> + mpls_exist =3D false; >>> + memmove(rte_pktmbuf_adj(m, sizeof(struct rte_mpls_hdr))= , >>> + eh, sizeof(struct rte_ether_hdr)); >>> + eh =3D rte_pktmbuf_mtod(m, struct rte_ether_hdr *); >>> + } >>> + >>> + return 0; >>> +} >>> + >>> #ifdef __cplusplus >>> } >>> #endif >>> -- >>> 1.8.3.1 >>> >>> --000000000000872a7805fc256529 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Gentle Ping

On Tue, Apr 18, 2023 at 6:18=E2=80=AFPM Tanze= el Ahmed <tanxeel1.ahmed@gma= il.com> wrote:
Ping.

On Thu, Mar 9, 2023 at 11:35=E2=80=AFPM Tanze= el Ahmed <= tanxeel1.ahmed@gmail.com> wrote:
Any updates?


On Sat, Feb 25, 2023 at 6:53=E2=80=AFPM Tanzeel-inline <tanxeel1.ahmed@gmail.com= > wrote:
= From: Tanzeel Ahmed <tanxeel1.ahmed@gmail.com>

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.

> 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.

> I'm not sure it should be inline
I did for performance in high-traffic application.

Signed-off-by: Tanzeel Ahmed <tanxeel1.ahmed@gmail.com>

---
v4:
* Removed extra void cast.
* rte_pktmbuf_append/mtod now return void*.
=C2=A0 The memmove result is casted to rte_ether_hdr*.

v3:
* fixed patch check failure issue

v2:
* marked experimental
* coding style fixed
* changed rte_memcpy to memcpy
* mpls header marked as const in parameter
* added MPLS stripping functionality
---
=C2=A0.mailmap=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 1 +
=C2=A0lib/net/rte_mpls.h | 97 +++++++++++++++++++++++++++++++++++++++++++++= +++++++++
=C2=A02 files changed, 98 insertions(+)

diff --git a/.mailmap b/.mailmap
index a9f4f28..2af4e0d 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1312,6 +1312,7 @@ Takeshi Yoshimura <tyos@jp.ibm.com> <t.yoshimura8869@gmail.com>
=C2=A0Takuya Asada <syuu@cloudius-systems.com>
=C2=A0Tal Avraham <talavr@annapurnalabs.com>
=C2=A0Tal Shnaiderman <talshn@nvidia.com> <talshn@mellanox.com>
+Tanzeel Ahmed <tanxeel1.ahmed@gmail.com>
=C2=A0Tao Y Yang <tao.y.yang@intel.com>
=C2=A0Tao Zhu <t= aox.zhu@intel.com>
=C2=A0Taripin Samuel <samuel.taripin@intel.com>
diff --git a/lib/net/rte_mpls.h b/lib/net/rte_mpls.h
index 51523e7..d7e267f 100644
--- a/lib/net/rte_mpls.h
+++ b/lib/net/rte_mpls.h
@@ -13,6 +13,8 @@

=C2=A0#include <stdint.h>
=C2=A0#include <rte_byteorder.h>
+#include <rte_ether.h>
+#include <rte_mbuf.h>

=C2=A0#ifdef __cplusplus
=C2=A0extern "C" {
@@ -36,6 +38,101 @@ struct rte_mpls_hdr {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 uint8_t=C2=A0 ttl;=C2=A0 =C2=A0 =C2=A0 =C2=A0/*= *< Time to live. */
=C2=A0} __rte_packed;

+#define RTE_MPLS_HLEN 4 /**< Length of MPLS header. */
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Insert MPLS header into the packet.
+ * If it's first MPLS header to be inserted in the packet,
+ *=C2=A0 - Updates the ether type.
+ *=C2=A0 - Sets the MPLS bottom-of-stack bit to 1.
+ *
+ * @param m
+ *=C2=A0 =C2=A0The pointer to the mbuf.
+ * @param mp
+ *=C2=A0 =C2=A0The pointer to the MPLS header.
+ * @return
+ *=C2=A0 =C2=A00 on success, -1 on error
+ */
+__rte_experimental
+static inline int
+rte_mpls_push_over_l2(struct rte_mbuf **m, const struct rte_mpls_hdr *mp)<= br> +{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0void *os, *ns;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct rte_ether_hdr *nh;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct rte_mpls_hdr *mph;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Can't insert header if mbuf is shared */=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!RTE_MBUF_DIRECT(*m) || rte_mbuf_refcnt_rea= d(*m) > 1)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -EINVAL;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Can't insert header if ethernet frame do= esn't exist */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (rte_pktmbuf_data_len(*m) < RTE_ETHER_HDR= _LEN)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -EINVAL;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0os =3D rte_pktmbuf_mtod(*m, void *);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0ns =3D (void *)rte_pktmbuf_prepend(*m, sizeof(s= truct rte_mpls_hdr));
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (ns =3D=3D NULL)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -ENOSPC;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0nh =3D (struct rte_ether_hdr *)memmove(ns, os, = RTE_ETHER_HDR_LEN);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Copy the MPLS header after ethernet frame */=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0mph =3D rte_pktmbuf_mtod_offset(*m, struct rte_= mpls_hdr*,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0sizeof(struct rte_ether_hdr));
+=C2=A0 =C2=A0 =C2=A0 =C2=A0memcpy(mph, mp, RTE_MPLS_HLEN);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0mph->tag_msb =3D rte_cpu_to_be_16(mp->tag= _msb);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* If first MPLS header, update ether type and = bottom-of-stack bit */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (nh->ether_type !=3D rte_cpu_to_be_16(RTE= _ETHER_TYPE_MPLS)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0nh->ether_type = =3D rte_cpu_to_be_16(RTE_ETHER_TYPE_MPLS);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0mph->bs =3D 1; +=C2=A0 =C2=A0 =C2=A0 =C2=A0} else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0mph->bs =3D 0; +=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return 0;
+}
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Strips MPLS from the packet. Doesn't update the ether type
+ *
+ * @param m
+ *=C2=A0 =C2=A0The pointer to the mbuf.
+ * @return
+ *=C2=A0 =C2=A00 on success, -1 on error
+ */
+__rte_experimental
+static inline int
+rte_mpls_strip_over_l2(struct rte_mbuf *m)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct rte_ether_hdr *eh =3D rte_pktmbuf_mtod(m= , struct rte_ether_hdr *);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct rte_mpls_hdr *mph;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool mpls_exist =3D true;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (eh->ether_type !=3D rte_cpu_to_be_16(RTE= _ETHER_TYPE_MPLS))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -1;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Stripping all MPLS header */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0while (mpls_exist) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0mph =3D rte_pktmbuf= _mtod_offset(m, struct rte_mpls_hdr*,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sizeof(struct rte_e= ther_hdr));
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (mph->bs &= ; 1)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0mpls_exist =3D false;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0memmove(rte_pktmbuf= _adj(m, sizeof(struct rte_mpls_hdr)),
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0eh, sizeof(struct r= te_ether_hdr));
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0eh =3D rte_pktmbuf_= mtod(m, struct rte_ether_hdr *);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return 0;
+}
+
=C2=A0#ifdef __cplusplus
=C2=A0}
=C2=A0#endif
--
1.8.3.1

--000000000000872a7805fc256529--