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 271304297D; Tue, 18 Apr 2023 15:19:09 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A69C3410EA; Tue, 18 Apr 2023 15:19:08 +0200 (CEST) Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by mails.dpdk.org (Postfix) with ESMTP id 0B8EB40EDF for ; Tue, 18 Apr 2023 15:19:07 +0200 (CEST) Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-2fa2fc747easo1129155f8f.2 for ; Tue, 18 Apr 2023 06:19:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681823946; x=1684415946; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=QJt1dm89hY1OIaRCs/wxyTBbw+QBEMP9o9fzQYvflwE=; b=iQ5cG+o6ttH2lNYh1QjpF++8j0NALlQX6m0FcG6zsHPjkaIsBpdXxlPCKuRJgBZu+6 cGAP7qf8oMH48Ql9OblS+mw5oNPpYWxl6tB1QvOs/WWjvTo8F4s5SVYD/hu9Wj0ywH1c Qar5dYl29grAZRCfu0Z8U3EdU6xWjRmLWeyihYNLWCeki/ylI2fQ+7ur0dL1LHlcWB4Z HNXr2olScs9BzW4PMdmV6rM9hdXxvN8D7ZLOTLdQ3WsV5i1ytQ732U/qLnmsM16LF7qS rjn/1ToozXxNFDHh9r2YzIuJ1/Ee4Fv5n147EuTD9Dcq/8I1wHXeJdsYy8f6aiI4yDla 2pHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681823946; x=1684415946; 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=QJt1dm89hY1OIaRCs/wxyTBbw+QBEMP9o9fzQYvflwE=; b=hQ9d7JbhvF8Pwb+HlIJqecfsev8WCHmXNwxTM9TDFju1LZ92dfEcXff4dzefqnpEC/ UbAVTAnQ0IelfnZ7aeHYGFwLrLseuTNCCnhhnYWm/nZEHz73Xj1vWASDu5jez1Ebnmic k7F9uO595y+BtUuMlitjEu6HMY/NK2GILTToOYDQUqmvDZ17FbObPuWc6iknni51vRxo rHg00glCktwjMLgfnSEUoZfRnrT/Qz7mMuYYUvy9ATrViFuCFcRrqLRwn3jtaByu/5og mHIaZrVuJgqbU8Cvm7K34yuuUN6pNovz14d+m2alled3d8HsUGMnqTGYR8GEoMyjpLyu BZ0w== X-Gm-Message-State: AAQBX9dcBoNmIv2ClMt5w6hFXJ9VnVYGFHwZjWeQ49t7cdqPOu0uRIEK viwWxlkFGiC+3W83HuNDrwNBDodmV8KgbTXOKBw= X-Google-Smtp-Source: AKy350bqydnsDixfhn/fPDIlR4BBxyIkIkEMmp49Ad05TMFcYulDYyvA8ACOg/OgqX/BtCGtvbPz6ntUYAHOO9G+oS0= X-Received: by 2002:a5d:4d4f:0:b0:2f5:c399:b299 with SMTP id a15-20020a5d4d4f000000b002f5c399b299mr1604878wru.46.1681823946471; Tue, 18 Apr 2023 06:19:06 -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: Tue, 18 Apr 2023 18:18:30 +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="000000000000e77b7a05f99c26eb" 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 --000000000000e77b7a05f99c26eb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 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 *m= p) >> +{ >> + 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_hd= r)); >> + 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 >> 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 >> >> --000000000000e77b7a05f99c26eb Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Ping.

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


=
From: Tanzeel Ahmed <<= a href=3D"mailto:tanxeel1.ahmed@gmail.com" target=3D"_blank">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

--000000000000e77b7a05f99c26eb--