This section is a comment. Make sure to start the actual text at the margin.
+
+* **Added software parser for packet type.**
+
+ * Added a new function ``rte_pktmbuf_read()`` to read the packet data from an
+ mbuf chain, linearizing if required.
+
* **Added vhost-user indirect descriptors support.**
If indirect descriptor feature is negotiated, each packet sent by the guest
#include <rte_string_fns.h>
#include <rte_hexdump.h>
#include <rte_errno.h>
+#include <rte_memcpy.h>
/*
* ctrlmbuf constructor, given as a callback function to
}
}
+/* read len data bytes in a mbuf at specified offset (internal) */
+const void *__rte_pktmbuf_read(const struct rte_mbuf *m, uint32_t off,
+ uint32_t len, void *buf)
+{
+ const struct rte_mbuf *seg = m;
+ uint32_t buf_off = 0, copy_len;
+
+ if (off + len > rte_pktmbuf_pkt_len(m))
+ return NULL;
+
+ while (off >= rte_pktmbuf_data_len(seg)) {
+ off -= rte_pktmbuf_data_len(seg);
+ seg = seg->next;
+ }
+
+ if (off + len <= rte_pktmbuf_data_len(seg))
+ return rte_pktmbuf_mtod_offset(seg, char *, off);
+
+ /* rare case: header is split among several segments */
+ while (len > 0) {
+ copy_len = rte_pktmbuf_data_len(seg) - off;
+ if (copy_len > len)
+ copy_len = len;
+ rte_memcpy((char *)buf + buf_off,
+ rte_pktmbuf_mtod_offset(seg, char *, off), copy_len);
+ off = 0;
+ buf_off += copy_len;
+ len -= copy_len;
+ seg = seg->next;
+ }
+
+ return buf;
+}
+
/*
* Get the name of a RX offload flag. Must be kept synchronized with flag
* definitions in rte_mbuf.h.
return !!(m->nb_segs == 1);
}
+/**
+ * @internal used by rte_pktmbuf_read().
+ */
+const void *__rte_pktmbuf_read(const struct rte_mbuf *m, uint32_t off,
+ uint32_t len, void *buf);
+
+/**
+ * Read len data bytes in a mbuf at specified offset.
+ *
+ * If the data is contiguous, return the pointer in the mbuf data, else
+ * copy the data in the buffer provided by the user and return its
+ * pointer.
+ *
+ * @param m
+ * The pointer to the mbuf.
+ * @param off
+ * The offset of the data in the mbuf.
+ * @param len
+ * The amount of bytes to read.
+ * @param buf
+ * The buffer where data is copied if it is not contigous in mbuf
+ * data. Its length should be at least equal to the len parameter.
+ * @return
+ * The pointer to the data, either in the mbuf if it is contiguous,
+ * or in the user buffer. If mbuf is too small, NULL is returned.
+ */
+static inline const void *rte_pktmbuf_read(const struct rte_mbuf *m,
+ uint32_t off, uint32_t len, void *buf)
+{
+ if (likely(off + len <= rte_pktmbuf_data_len(m)))
+ return rte_pktmbuf_mtod_offset(m, char *, off);
+ else
+ return __rte_pktmbuf_read(m, off, len, buf);
+}
+
/**
* Chain an mbuf to another, thereby creating a segmented packet.
*