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 4528141E21; Thu, 9 Mar 2023 19:35:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2511640ED7; Thu, 9 Mar 2023 19:35:46 +0100 (CET) Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by mails.dpdk.org (Postfix) with ESMTP id 3313640695 for ; Thu, 9 Mar 2023 19:35:44 +0100 (CET) Received: by mail-wr1-f41.google.com with SMTP id j2so2829607wrh.9 for ; Thu, 09 Mar 2023 10:35:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678386944; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=YnuL8RL3GswPGOQcswmCgtJXIVR3BYYNMVNlJce/Vmc=; b=kWVUZKEozfgN9b4uaQg8HuF09hshFUz2iRnWrvwV2n+90KKmWHsrbaRyfp6sDQCYcq HTSi3qW55jPzSN3lBTCNi00Knu8eLUf7UZoZ3E4fSCXYHFmzHKqoMMLYsYtMjUdBrL+H 7VnuInn8e2HwY5UC3geoyaAHoHNIe45bqNaaJXtnEr21QWkRhDZ7GDOGCRoYb3HZXjLl kbDEMmf8sFQf7ecqRh7JIIxBT37wEqjy0Vgc5E66nNAvSnQybMfJaB3k70t5aJyyvwQk VRhD8D9jVeY4YbNtbJlf1gzMVMEEF5YWFg8CRcCYWKsVw9B7mImAo3g+nAJgakZUOh59 qOUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678386944; 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=YnuL8RL3GswPGOQcswmCgtJXIVR3BYYNMVNlJce/Vmc=; b=n/CmwlLjws1RrGKn4Bj/HzpOvkH2VGE32RwpViZf45JRiCZHtKd9Kt/4atO0wxUWTS Qr5+MYF9d6VpHWnV6Un3J0BX+esaduV+I1aFsdCGHTWFs1PXdQgSjSm4tvkAsdMWy5wP z5GbVrzH+GZ0v/3ZRNsCSGA9JnmDfhWmDhhH5CnZKZhGCkdTvOnxscOmLZwauaSKWzYe 8A0NUx9z7tXQWqHqFOv1sJoh9fPVmUsIG31AueUVZXToy4KAmkjMdnXRcI2S0CxU0ZWw T+vA92U8haV9if0OtZ5DNGGBLz+v9UL2oWH0pVee43UMlY+u8BFeiDpIszmgLu7aSVM2 OzVQ== X-Gm-Message-State: AO0yUKVlqzan7Hc3jQJCALCnU4pvMKax3jW0SCCFd4XAq/r+YinTIHrw rYvDWblO2dBbCSxuhY1YyOKmRSQOiW+GL/8KKyQxk4IKpfE= X-Google-Smtp-Source: AK7set9NKeiIExNfOwsBOO2besLjrjTW0lhm2zo6Y1HHKG78cJNL1rB15Kvp37oRhKpB1v471u26oDn1p2O79LpbCdA= X-Received: by 2002:adf:e3c3:0:b0:2c7:478:d1d7 with SMTP id k3-20020adfe3c3000000b002c70478d1d7mr5104034wrm.3.1678386943760; Thu, 09 Mar 2023 10:35:43 -0800 (PST) MIME-Version: 1.0 References: <20230219224334.309-1-tanxeel1.ahmed@gmail.com> <20230225135343.262-1-tanxeel1.ahmed@gmail.com> In-Reply-To: <20230225135343.262-1-tanxeel1.ahmed@gmail.com> From: Tanzeel Ahmed Date: Thu, 9 Mar 2023 23:35:08 +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="000000000000941fb105f67be9d0" 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 --000000000000941fb105f67be9d0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 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 > > --- > 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_LEN)= ; > + > + /* 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 bi= t > */ > + 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 > > --000000000000941fb105f67be9d0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Any updates?


On Sat, Feb 25, 202= 3 at 6:53=E2=80=AFPM Tanzeel-inline <tanxeel1.ahmed@gmail.com> wrote:
From: Tanzeel Ahmed <= tanxeel1.ahme= d@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

--000000000000941fb105f67be9d0--