@@ -397,17 +397,31 @@ dp_packet_size(const struct dp_packet *b)
static inline void
dp_packet_set_size(struct dp_packet *b, uint32_t v)
{
- /* netdev-dpdk does not currently support segmentation; consequently, for
- * all intents and purposes, 'data_len' (16 bit) and 'pkt_len' (32 bit) may
- * be used interchangably.
- *
- * On the datapath, it is expected that the size of packets
- * (and thus 'v') will always be <= UINT16_MAX; this means that there is no
- * loss of accuracy in assigning 'v' to 'data_len'.
- */
- b->mbuf.data_len = (uint16_t)v; /* Current seg length. */
- b->mbuf.pkt_len = v; /* Total length of all segments linked to
- * this segment. */
+ if (b->source == DPBUF_DPDK) {
+ struct rte_mbuf *seg = &b->mbuf;
+ uint16_t pkt_len = v;
+ uint16_t seg_len;
+
+ /* Trim 'v' length bytes from the end of the chained buffers, freeing
+ any buffers that may be left floating */
+ while (seg) {
+ seg_len = MIN(pkt_len, seg->data_len);
+ seg->data_len = seg_len;
+
+ pkt_len -= seg_len;
+ if (pkt_len <= 0) {
+ /* Free the rest of chained mbufs */
+ rte_pktmbuf_free(seg->next);
+ seg->next = NULL;
+ }
+ seg = seg->next;
+ }
+ } else {
+ b->mbuf.data_len = v;
+ }
+
+ /* Total length of all segments linked to this segment. */
+ b->mbuf.pkt_len = v;
}
static inline uint16_t
@@ -420,6 +434,8 @@ static inline void
__packet_set_data(struct dp_packet *b, uint16_t v)
{
b->mbuf.data_off = v;
+ /* When dealing with DPDK mbufs, keep data_off and data_len in sync */
+ b->mbuf.data_len = b->mbuf.buf_len - b->mbuf.data_off;
}
static inline void *