From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Stephen Hemminger <sthemmin@microsoft.com>
Subject: [dpdk-dev] [RFC v2] net: fix rte_vlan_insert with shared mbuf
Date: Thu, 28 Mar 2019 13:53:22 -0700 [thread overview]
Message-ID: <20190328205322.852-1-stephen@networkplumber.org> (raw)
Message-ID: <20190328205322.2QiaAOBY2_QFICQkynXdF4CjRXUx3b8BRgCE08r5HEI@z> (raw)
In-Reply-To: <b2518429-e988-8bfa-24d2-d3bc6f95d446@intel.com>
If mbuf is shared then rte_vlan_insert() would clobber the original
Ethernet header. The changed version handles this by getting
an mbuf that will hold the new Ethernet and VLAN header followed
by another mbuf (cloned) for the data.
Fixes: c974021a5949 ("ether: add soft vlan encap/decap")
Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
v2 - compile tested only, do copy/clone.
lib/librte_net/rte_ether.h | 37 ++++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 9 deletions(-)
diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h
index c2c5e249ffe9..5fc306e5d08c 100644
--- a/lib/librte_net/rte_ether.h
+++ b/lib/librte_net/rte_ether.h
@@ -374,10 +374,10 @@ static inline int rte_vlan_strip(struct rte_mbuf *m)
* Software version of VLAN unstripping
*
* @param m
- * The packet mbuf.
+ * Pointer to the packet mbuf.
* @return
* - 0: On success
- * -EPERM: mbuf is is shared overwriting would be unsafe
+ * -ENOMEM: could not allocate mbuf for header
* -ENOSPC: not enough headroom in mbuf
*/
static inline int rte_vlan_insert(struct rte_mbuf **m)
@@ -385,15 +385,34 @@ static inline int rte_vlan_insert(struct rte_mbuf **m)
struct ether_hdr *oh, *nh;
struct vlan_hdr *vh;
- /* Can't insert header if mbuf is shared */
- if (rte_mbuf_refcnt_read(*m) > 1) {
- struct rte_mbuf *copy;
+ /* Can't safely directly insert header if mbuf is shared or indirect */
+ if (!RTE_MBUF_DIRECT(*m) || rte_mbuf_refcnt_read(*m) > 1) {
+ struct rte_mempool *mp = (*m)->pool;
+ struct rte_mbuf *md, *mh;
+
+ mh = rte_pktmbuf_alloc(mp);
+ if (unlikely(mh == NULL))
+ return -ENOMEM;
+
+ mh->tx_offload = (*m)->tx_offload;
+ mh->vlan_tci = (*m)->vlan_tci;
+ mh->vlan_tci_outer = (*m)->vlan_tci_outer;
+ mh->port = (*m)->port;
+ mh->ol_flags = (*m)->ol_flags;
+ mh->packet_type = (*m)->packet_type;
- copy = rte_pktmbuf_clone(*m, (*m)->pool);
- if (unlikely(copy == NULL))
+ md = rte_pktmbuf_clone(*m, mp);
+ if (unlikely(md == NULL)) {
+ rte_pktmbuf_free(mh);
return -ENOMEM;
- rte_pktmbuf_free(*m);
- *m = copy;
+ }
+
+ mh->next = md;
+ mh->nb_segs = md->nb_segs + 1;
+ memcpy(rte_pktmbuf_append(mh, ETHER_HDR_LEN),
+ rte_pktmbuf_mtod(md, void *), ETHER_HDR_LEN);
+ rte_pktmbuf_adj(md, ETHER_HDR_LEN);
+ *m = mh;
}
oh = rte_pktmbuf_mtod(*m, struct ether_hdr *);
--
2.17.1
next prev parent reply other threads:[~2019-03-28 20:53 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-26 19:15 [dpdk-dev] [PATCH] " Stephen Hemminger
2019-03-26 19:15 ` Stephen Hemminger
2019-03-26 22:38 ` Chas Williams
2019-03-26 22:38 ` Chas Williams
2019-03-27 15:18 ` Stephen Hemminger
2019-03-27 15:18 ` Stephen Hemminger
2019-03-27 15:31 ` Chas Williams
2019-03-27 15:31 ` Chas Williams
2019-03-28 14:04 ` Ferruh Yigit
2019-03-28 14:04 ` Ferruh Yigit
2019-03-28 20:53 ` Stephen Hemminger [this message]
2019-03-28 20:53 ` [dpdk-dev] [RFC v2] " Stephen Hemminger
2019-03-30 12:41 ` Chas Williams
2019-03-30 12:41 ` Chas Williams
2019-04-04 23:54 ` Stephen Hemminger
2019-04-04 23:54 ` Stephen Hemminger
2019-04-06 23:11 ` Chas Williams
2019-04-06 23:11 ` Chas Williams
2019-04-12 16:35 ` Ferruh Yigit
2019-04-12 16:35 ` Ferruh Yigit
2019-07-04 18:40 ` Ferruh Yigit
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=20190328205322.852-1-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=sthemmin@microsoft.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 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).