From: Stephen Hemminger <stephen-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>
To: Ouyang Changchun
<changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: dev-VfR2kkLFssw@public.gmane.org
Subject: [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: 2533 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-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.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
next prev parent reply other threads:[~2014-08-26 2:07 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-26 2:07 [RFC 00/10] virtio patches Stephen Hemminger
2014-08-26 2:07 ` [RFC 01/10] virtio: rearrange resource initialization Stephen Hemminger
[not found] ` <20140826020837.898427212-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>
2014-08-26 7:14 ` Ouyang, Changchun
2014-08-26 2:07 ` [RFC 02/10] virtio: use weak barriers Stephen Hemminger
2014-08-26 2:07 ` [RFC 03/10] virtio: allow starting with link down Stephen Hemminger
2014-08-26 2:07 ` [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 ` [RFC 06/10] virtio: use software vlan stripping Stephen Hemminger
[not found] ` <20140826020848.386074683-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>
2014-08-26 8:37 ` Ouyang, Changchun
[not found] ` <F52918179C57134FAEC9EA62FA2F96251183B285-E2R4CRU6q/6iAffOGbnezLfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-08-26 16:24 ` Stephen Hemminger
2014-08-27 5:42 ` Ouyang, Changchun
[not found] ` <F52918179C57134FAEC9EA62FA2F96251183B79C-E2R4CRU6q/6iAffOGbnezLfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-08-27 18:04 ` Stephen Hemminger
2014-08-26 2:07 ` [RFC 07/10] virtio: remove unnecessary adapter structure Stephen Hemminger
[not found] ` <20140826020851.474452281-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>
2014-08-26 6:43 ` Ouyang, Changchun
2014-08-26 2:07 ` [RFC 08/10] virtio: remove redundant vq_alignment Stephen Hemminger
[not found] ` <20140826020853.851222673-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>
2014-08-26 8:41 ` Ouyang, Changchun
2014-08-26 2:07 ` [RFC 09/10] virtio: fix how states are handled during initialization Stephen Hemminger
2014-08-26 2:07 ` [RFC 10/10] virtio: add support for promiscious and multicast Stephen Hemminger
[not found] ` <20140826020858.448904783-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>
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-otpzqlsittunbdjkjebofr2eb7je58tq@public.gmane.org \
--cc=changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=dev-VfR2kkLFssw@public.gmane.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 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.