From: Tanzeel-inline <tanxeel1.ahmed@gmail.com>
To: olivier.matz@6wind.com
Cc: dev@dpdk.org, Tanzeel-inline <tanxeel1.ahmed@gmail.com>,
Tanzeel Ahmed <tanzeelahmed713@gmail.com>
Subject: [PATCH] lib/net: added push MPLS header API
Date: Sat, 17 Dec 2022 12:59:57 -0500 [thread overview]
Message-ID: <1671299997-13001-1-git-send-email-tanxeel1.ahmed@gmail.com> (raw)
Push MPLS header after ethernet header, updates ethernet type and MPLS bs bit if required.
Signed-off-by: Tanzeel Ahmed <tanzeelahmed713@gmail.com>
---
.mailmap | 1 +
lib/net/rte_mpls.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+)
diff --git a/.mailmap b/.mailmap
index 75884b6..5e06669 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1301,6 +1301,7 @@ Takeshi Yoshimura <tyos@jp.ibm.com> <t.yoshimura8869@gmail.com>
Takuya Asada <syuu@cloudius-systems.com>
Tal Avraham <talavr@annapurnalabs.com>
Tal Shnaiderman <talshn@nvidia.com> <talshn@mellanox.com>
+Tanzeel Ahmed <tanzeelahmed713@gmail.com>
Tao Y Yang <tao.y.yang@intel.com>
Tao Zhu <taox.zhu@intel.com>
Taripin Samuel <samuel.taripin@intel.com>
diff --git a/lib/net/rte_mpls.h b/lib/net/rte_mpls.h
index 3e8cb90..6ae72df 100644
--- a/lib/net/rte_mpls.h
+++ b/lib/net/rte_mpls.h
@@ -13,6 +13,8 @@
#include <stdint.h>
#include <rte_byteorder.h>
+#include <rte_mbuf.h>
+#include <rte_ether.h>
#ifdef __cplusplus
extern "C" {
@@ -36,6 +38,63 @@ struct rte_mpls_hdr {
uint8_t ttl; /**< Time to live. */
} __rte_packed;
+#define RTE_MPLS_HLEN 4 /**< Length of MPLS header. */
+
+/**
+ * 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 (If no ethernet header exists)
+ */
+static inline int
+rte_mpls_push_over_l2(struct rte_mbuf **m, struct rte_mpls_hdr *mp)
+{
+ struct rte_ether_hdr *oh, *nh;
+
+ /* 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;
+
+ oh = rte_pktmbuf_mtod(*m, struct rte_ether_hdr *);
+ nh = (struct rte_ether_hdr *)(void *)
+ rte_pktmbuf_prepend(*m, sizeof(struct rte_mpls_hdr));
+ if (nh == NULL)
+ return -ENOSPC;
+
+ memmove(nh, oh, RTE_ETHER_HDR_LEN);
+
+ mp->tag_msb = rte_cpu_to_be_16(mp->tag_msb);
+
+ /* If first MPLS header, update ether type and bottom-of-stack bit */
+ if (nh->ether_type != rte_cpu_to_be_16(RTE_ETHER_TYPE_MPLS))
+ {
+ nh->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_MPLS);
+ mp->bs = 1;
+ }
+ else
+ {
+ mp->bs = 0;
+ }
+
+ /* Copy the MPLS header after ethernet frame */
+ rte_memcpy(rte_pktmbuf_mtod_offset(*m, char*, sizeof(struct rte_ether_hdr)), mp, RTE_MPLS_HLEN);
+
+ (*m)->data_len += RTE_MPLS_HLEN;
+ return 0;
+}
+
#ifdef __cplusplus
}
#endif
--
1.8.3.1
next reply other threads:[~2022-12-17 18:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-17 17:59 Tanzeel-inline [this message]
2022-12-17 19:46 ` [PATCH] lib/net: added push MPLS header API Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1671299997-13001-1-git-send-email-tanxeel1.ahmed@gmail.com \
--to=tanxeel1.ahmed@gmail.com \
--cc=dev@dpdk.org \
--cc=olivier.matz@6wind.com \
--cc=tanzeelahmed713@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.