DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Ouyang Changchun <changchun.ouyang@intel.com>
Cc: dev@dpdk.org
Subject: [dpdk-dev] [RFC 05/10] ether: add soft vlan encap/decap functions
Date: Mon, 25 Aug 2014 19:07:51 -0700	[thread overview]
Message-ID: <20140826020845.804064642@networkplumber.org> (raw)
In-Reply-To: <20140826020746.062748014@networkplumber.org>

[-- Attachment #1: vlan-encap-decap.patch --]
[-- Type: text/plain, Size: 2502 bytes --]

It is helpful to allow device drivers that don't support hardware
VLAN stripping to emulate this in software.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>


---
 lib/librte_ether/rte_ether.h |   69 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

--- a/lib/librte_ether/rte_ether.h	2014-08-25 19:00:06.978533976 -0700
+++ b/lib/librte_ether/rte_ether.h	2014-08-25 19:00:06.978533976 -0700
@@ -48,6 +48,8 @@ extern "C" {
 
 #include <rte_memcpy.h>
 #include <rte_random.h>
+#include <rte_mbuf.h>
+#include <rte_byteorder.h>
 
 #define ETHER_ADDR_LEN  6 /**< Length of Ethernet address. */
 #define ETHER_TYPE_LEN  2 /**< Length of Ethernet type field. */
@@ -294,6 +296,73 @@ struct vlan_hdr {
 #define ETHER_TYPE_VLAN 0x8100 /**< IEEE 802.1Q VLAN tagging. */
 #define ETHER_TYPE_1588 0x88F7 /**< IEEE 802.1AS 1588 Precise Time Protocol. */
 
+/**
+ * Extract VLAN tag information into mbuf
+ *
+ * Software version of VLAN stripping
+ *
+ * @param m
+ *   The packet mbuf.
+ * @return
+ *   - 0: Success
+ *   - 1: not a vlan packet
+ */
+static inline int rte_vlan_strip(struct rte_mbuf *m)
+{
+	struct ether_hdr *eh
+		 = rte_pktmbuf_mtod(m, struct ether_hdr *);
+
+	if (eh->ether_type != ETHER_TYPE_VLAN)
+		return -1;
+
+	struct vlan_hdr *vh = (struct vlan_hdr *)(eh + 1);
+	m->ol_flags |= PKT_RX_VLAN_PKT;
+	m->pkt.vlan_macip.f.vlan_tci = rte_be_to_cpu_16(vh->vlan_tci);
+
+	/* Copy ether header over rather than moving whole packet */
+	memmove(rte_pktmbuf_adj(m, sizeof(struct vlan_hdr)),
+		eh, 2 * ETHER_ADDR_LEN);
+
+	return 0;
+}
+
+/**
+ * Insert VLAN tag into mbuf.
+ *
+ * Software version of VLAN unstripping
+ *
+ * @param m
+ *   The packet mbuf.
+ * @return
+ *   - 0: On success
+ *   -EPERM: mbuf is is shared overwriting would be unsafe
+ *   -ENOSPC: not enough headroom in mbuf
+ */
+static inline int rte_vlan_insert(struct rte_mbuf *m)
+{
+	struct ether_hdr *oh, *nh;
+	struct vlan_hdr *vh;
+
+#ifdef RTE_MBUF_SCATTER_GATHER
+	/* Can't insert header if mbuf is shared */
+	if (rte_mbuf_refcnt_read(m) > 1)
+		return -EINVAL;
+#endif
+	oh = rte_pktmbuf_mtod(m, struct ether_hdr *);
+	nh = (struct ether_hdr *)
+		rte_pktmbuf_prepend(m, sizeof(struct vlan_hdr));
+	if (nh == NULL)
+		return -ENOSPC;
+
+	memmove(nh, oh, 2 * ETHER_ADDR_LEN);
+	nh->ether_type = ETHER_TYPE_VLAN;
+
+	vh = (struct vlan_hdr *) (nh + 1);
+	vh->vlan_tci = rte_cpu_to_be_16(m->pkt.vlan_macip.f.vlan_tci);
+
+	return 0;
+}
+
 #ifdef __cplusplus
 }
 #endif

  parent reply	other threads:[~2014-08-26  2:04 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-26  2:07 [dpdk-dev] [RFC 00/10] virtio patches Stephen Hemminger
2014-08-26  2:07 ` [dpdk-dev] [RFC 01/10] virtio: rearrange resource initialization Stephen Hemminger
2014-08-26  7:14   ` Ouyang, Changchun
2014-08-26  2:07 ` [dpdk-dev] [RFC 02/10] virtio: use weak barriers Stephen Hemminger
2014-08-26  2:07 ` [dpdk-dev] [RFC 03/10] virtio: allow starting with link down Stephen Hemminger
2014-08-26  2:07 ` [dpdk-dev] [RFC 04/10] virtio: add support for Link State interrupt Stephen Hemminger
2014-08-26  2:07 ` Stephen Hemminger [this message]
2014-08-26  2:07 ` [dpdk-dev] [RFC 06/10] virtio: use software vlan stripping Stephen Hemminger
2014-08-26  8:37   ` Ouyang, Changchun
2014-08-26 16:24     ` Stephen Hemminger
2014-08-27  5:42       ` Ouyang, Changchun
2014-08-27 18:04         ` Stephen Hemminger
2014-08-26  2:07 ` [dpdk-dev] [RFC 07/10] virtio: remove unnecessary adapter structure Stephen Hemminger
2014-08-26  6:43   ` Ouyang, Changchun
2014-08-26  2:07 ` [dpdk-dev] [RFC 08/10] virtio: remove redundant vq_alignment Stephen Hemminger
2014-08-26  8:41   ` Ouyang, Changchun
2014-08-26  2:07 ` [dpdk-dev] [RFC 09/10] virtio: fix how states are handled during initialization Stephen Hemminger
2014-08-26  2:07 ` [dpdk-dev] [RFC 10/10] virtio: add support for promiscious and multicast Stephen Hemminger
2014-08-26  6:55   ` Ouyang, Changchun

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=20140826020845.804064642@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=changchun.ouyang@intel.com \
    --cc=dev@dpdk.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).