netdev: Free packets in netdev_send() for devices that don't support send.
[cascardo/ovs.git] / lib / dp-packet.h
index 9cae74d..bf4e758 100644 (file)
@@ -33,73 +33,56 @@ enum OVS_PACKED_ENUM dp_packet_source {
     DPBUF_STACK,               /* Un-movable stack space or static buffer. */
     DPBUF_STUB,                /* Starts on stack, may expand into heap. */
     DPBUF_DPDK,                /* buffer data is from DPDK allocated memory.
-                                  ref to build_dp_packet() in netdev-dpdk. */
+                                * ref to build_dp_packet() in netdev-dpdk. */
 };
 
-/* Buffer for holding arbitrary data.  An dp_packet is automatically reallocated
+/* Buffer for holding packet data.  A dp_packet is automatically reallocated
  * as necessary if it grows too large for the available memory.
- *
- * 'frame' and offset conventions:
- *
- * Network frames (aka "packets"): 'frame' MUST be set to the start of the
- *    packet, layer offsets MAY be set as appropriate for the packet.
- *    Additionally, we assume in many places that the 'frame' and 'data' are
- *    the same for packets.
- *
- * OpenFlow messages: 'frame' points to the start of the OpenFlow
- *    header, while 'l3_ofs' is the length of the OpenFlow header.
- *    When parsing, the 'data' will move past these, as data is being
- *    pulled from the OpenFlow message.
- *
- * Actions: When encoding OVS action lists, the 'frame' is used
- *    as a pointer to the beginning of the current action (see ofpact_put()).
- *
- * rconn: Reuses 'frame' as a private pointer while queuing.
  */
 struct dp_packet {
 #ifdef DPDK_NETDEV
     struct rte_mbuf mbuf;       /* DPDK mbuf */
 #else
-    void *base_;                 /* First byte of allocated space. */
-    void *data_;                 /* First byte actually in use. */
-    uint32_t size_;              /* Number of bytes in use. */
-    uint32_t dp_hash;           /* Packet hash. */
+    void *base_;                /* First byte of allocated space. */
+    uint16_t allocated_;        /* Number of bytes allocated. */
+    uint16_t data_ofs;          /* First byte actually in use. */
+    uint32_t size_;             /* Number of bytes in use. */
+    uint32_t rss_hash;          /* Packet hash. */
+    bool rss_hash_valid;        /* Is the 'rss_hash' valid? */
 #endif
-    uint32_t allocated;         /* Number of bytes allocated. */
-
-    void *frame;                /* Packet frame start, or NULL. */
     enum dp_packet_source source;  /* Source of memory allocated as 'base'. */
-    uint8_t l2_pad_size;        /* Detected l2 padding size.
-                                 * Padding is non-pullable. */
-    uint16_t l2_5_ofs;          /* MPLS label stack offset from 'frame', or
-                                 * UINT16_MAX */
-    uint16_t l3_ofs;            /* Network-level header offset from 'frame',
-                                   or UINT16_MAX. */
-    uint16_t l4_ofs;            /* Transport-level header offset from 'frame',
-                                   or UINT16_MAX. */
+    uint8_t l2_pad_size;           /* Detected l2 padding size.
+                                    * Padding is non-pullable. */
+    uint16_t l2_5_ofs;             /* MPLS label stack offset, or UINT16_MAX */
+    uint16_t l3_ofs;               /* Network-level header offset,
+                                    * or UINT16_MAX. */
+    uint16_t l4_ofs;               /* Transport-level header offset,
+                                      or UINT16_MAX. */
     struct pkt_metadata md;
-    struct ovs_list list_node;  /* Private list element for use by owner. */
 };
 
-static inline void * dp_packet_data(const struct dp_packet *);
+static inline void *dp_packet_data(const struct dp_packet *);
 static inline void dp_packet_set_data(struct dp_packet *, void *);
-static inline void * dp_packet_base(const struct dp_packet *);
+static inline void *dp_packet_base(const struct dp_packet *);
 static inline void dp_packet_set_base(struct dp_packet *, void *);
 
 static inline uint32_t dp_packet_size(const struct dp_packet *);
 static inline void dp_packet_set_size(struct dp_packet *, uint32_t);
 
-void * dp_packet_resize_l2(struct dp_packet *, int increment);
-void * dp_packet_resize_l2_5(struct dp_packet *, int increment);
-static inline void * dp_packet_l2(const struct dp_packet *);
-static inline void dp_packet_set_frame(struct dp_packet *, void *);
+static inline uint16_t dp_packet_get_allocated(const struct dp_packet *);
+static inline void dp_packet_set_allocated(struct dp_packet *, uint16_t);
+
+void *dp_packet_resize_l2(struct dp_packet *, int increment);
+void *dp_packet_resize_l2_5(struct dp_packet *, int increment);
+static inline void *dp_packet_l2(const struct dp_packet *);
+static inline void dp_packet_reset_offsets(struct dp_packet *);
 static inline uint8_t dp_packet_l2_pad_size(const struct dp_packet *);
 static inline void dp_packet_set_l2_pad_size(struct dp_packet *, uint8_t);
-static inline void * dp_packet_l2_5(const struct dp_packet *);
+static inline void *dp_packet_l2_5(const struct dp_packet *);
 static inline void dp_packet_set_l2_5(struct dp_packet *, void *);
-static inline void * dp_packet_l3(const struct dp_packet *);
+static inline void *dp_packet_l3(const struct dp_packet *);
 static inline void dp_packet_set_l3(struct dp_packet *, void *);
-static inline void * dp_packet_l4(const struct dp_packet *);
+static inline void *dp_packet_l4(const struct dp_packet *);
 static inline void dp_packet_set_l4(struct dp_packet *, void *);
 static inline size_t dp_packet_l4_size(const struct dp_packet *);
 static inline const void *dp_packet_get_tcp_payload(const struct dp_packet *);
@@ -112,26 +95,25 @@ void dp_packet_use(struct dp_packet *, void *, size_t);
 void dp_packet_use_stub(struct dp_packet *, void *, size_t);
 void dp_packet_use_const(struct dp_packet *, const void *, size_t);
 
-void dp_packet_init_dpdk(struct dp_packet *b, size_t allocated);
+void dp_packet_init_dpdk(struct dp_packet *, size_t allocated);
 
 void dp_packet_init(struct dp_packet *, size_t);
 void dp_packet_uninit(struct dp_packet *);
-static inline void *dp_packet_get_uninit_pointer(struct dp_packet *);
 
 struct dp_packet *dp_packet_new(size_t);
 struct dp_packet *dp_packet_new_with_headroom(size_t, size_t headroom);
 struct dp_packet *dp_packet_clone(const struct dp_packet *);
 struct dp_packet *dp_packet_clone_with_headroom(const struct dp_packet *,
-                                          size_t headroom);
+                                                size_t headroom);
 struct dp_packet *dp_packet_clone_data(const void *, size_t);
 struct dp_packet *dp_packet_clone_data_with_headroom(const void *, size_t,
-                                               size_t headroom);
+                                                     size_t headroom);
 static inline void dp_packet_delete(struct dp_packet *);
 
 static inline void *dp_packet_at(const struct dp_packet *, size_t offset,
-                              size_t size);
-static inline void *dp_packet_at_assert(const struct dp_packet *, size_t offset,
-                                     size_t size);
+                                 size_t size);
+static inline void *dp_packet_at_assert(const struct dp_packet *,
+                                        size_t offset, size_t size);
 static inline void *dp_packet_tail(const struct dp_packet *);
 static inline void *dp_packet_end(const struct dp_packet *);
 
@@ -140,11 +122,11 @@ void *dp_packet_put_zeros(struct dp_packet *, size_t);
 void *dp_packet_put(struct dp_packet *, const void *, size_t);
 char *dp_packet_put_hex(struct dp_packet *, const char *s, size_t *n);
 void dp_packet_reserve(struct dp_packet *, size_t);
-void dp_packet_reserve_with_tailroom(struct dp_packet *b, size_t headroom,
-                                  size_t tailroom);
-void *dp_packet_push_uninit(struct dp_packet *b, size_t);
+void dp_packet_reserve_with_tailroom(struct dp_packet *, size_t headroom,
+                                     size_t tailroom);
+void *dp_packet_push_uninit(struct dp_packet *, size_t);
 void *dp_packet_push_zeros(struct dp_packet *, size_t);
-void *dp_packet_push(struct dp_packet *b, const void *, size_t);
+void *dp_packet_push(struct dp_packet *, const void *, size_t);
 
 static inline size_t dp_packet_headroom(const struct dp_packet *);
 static inline size_t dp_packet_tailroom(const struct dp_packet *);
@@ -158,23 +140,13 @@ static inline void *dp_packet_try_pull(struct dp_packet *, size_t);
 
 void *dp_packet_steal_data(struct dp_packet *);
 
-char *dp_packet_to_string(const struct dp_packet *, size_t maxbytes);
-static inline struct dp_packet *dp_packet_from_list(const struct ovs_list *);
-void dp_packet_list_delete(struct ovs_list *);
-static inline bool dp_packet_equal(const struct dp_packet *, const struct dp_packet *);
+static inline bool dp_packet_equal(const struct dp_packet *,
+                                   const struct dp_packet *);
 
 \f
-/* Returns a pointer that may be passed to free() to accomplish the same thing
- * as dp_packet_uninit(b).  The return value is a null pointer if dp_packet_uninit()
- * would not free any memory. */
-static inline void *dp_packet_get_uninit_pointer(struct dp_packet *b)
-{
-    /* XXX: If 'source' is DPBUF_DPDK memory gets leaked! */
-    return b && b->source == DPBUF_MALLOC ? dp_packet_base(b) : NULL;
-}
-
 /* Frees memory that 'b' points to, as well as 'b' itself. */
-static inline void dp_packet_delete(struct dp_packet *b)
+static inline void
+dp_packet_delete(struct dp_packet *b)
 {
     if (b) {
         if (b->source == DPBUF_DPDK) {
@@ -191,52 +163,59 @@ static inline void dp_packet_delete(struct dp_packet *b)
 
 /* If 'b' contains at least 'offset + size' bytes of data, returns a pointer to
  * byte 'offset'.  Otherwise, returns a null pointer. */
-static inline void *dp_packet_at(const struct dp_packet *b, size_t offset,
-                              size_t size)
+static inline void *
+dp_packet_at(const struct dp_packet *b, size_t offset, size_t size)
 {
-    return offset + size <= dp_packet_size(b) ? (char *) dp_packet_data(b) + offset : NULL;
+    return offset + size <= dp_packet_size(b)
+           ? (char *) dp_packet_data(b) + offset
+           : NULL;
 }
 
 /* Returns a pointer to byte 'offset' in 'b', which must contain at least
  * 'offset + size' bytes of data. */
-static inline void *dp_packet_at_assert(const struct dp_packet *b, size_t offset,
-                                     size_t size)
+static inline void *
+dp_packet_at_assert(const struct dp_packet *b, size_t offset, size_t size)
 {
     ovs_assert(offset + size <= dp_packet_size(b));
     return ((char *) dp_packet_data(b)) + offset;
 }
 
 /* Returns a pointer to byte following the last byte of data in use in 'b'. */
-static inline void *dp_packet_tail(const struct dp_packet *b)
+static inline void *
+dp_packet_tail(const struct dp_packet *b)
 {
     return (char *) dp_packet_data(b) + dp_packet_size(b);
 }
 
 /* Returns a pointer to byte following the last byte allocated for use (but
  * not necessarily in use) in 'b'. */
-static inline void *dp_packet_end(const struct dp_packet *b)
+static inline void *
+dp_packet_end(const struct dp_packet *b)
 {
-    return (char *) dp_packet_base(b) + b->allocated;
+    return (char *) dp_packet_base(b) + dp_packet_get_allocated(b);
 }
 
 /* Returns the number of bytes of headroom in 'b', that is, the number of bytes
  * of unused space in dp_packet 'b' before the data that is in use.  (Most
- * commonly, the data in a dp_packet is at its beginning, and thus the dp_packet's
- * headroom is 0.) */
-static inline size_t dp_packet_headroom(const struct dp_packet *b)
+ * commonly, the data in a dp_packet is at its beginning, and thus the
+ * dp_packet's headroom is 0.) */
+static inline size_t
+dp_packet_headroom(const struct dp_packet *b)
 {
-    return (char*)dp_packet_data(b) - (char*)dp_packet_base(b);
+    return (char *) dp_packet_data(b) - (char *) dp_packet_base(b);
 }
 
-/* Returns the number of bytes that may be appended to the tail end of dp_packet
- * 'b' before the dp_packet must be reallocated. */
-static inline size_t dp_packet_tailroom(const struct dp_packet *b)
+/* Returns the number of bytes that may be appended to the tail end of
+ * dp_packet 'b' before the dp_packet must be reallocated. */
+static inline size_t
+dp_packet_tailroom(const struct dp_packet *b)
 {
-    return (char*)dp_packet_end(b) - (char*)dp_packet_tail(b);
+    return (char *) dp_packet_end(b) - (char *) dp_packet_tail(b);
 }
 
 /* Clears any data from 'b'. */
-static inline void dp_packet_clear(struct dp_packet *b)
+static inline void
+dp_packet_clear(struct dp_packet *b)
 {
     dp_packet_set_data(b, dp_packet_base(b));
     dp_packet_set_size(b, 0);
@@ -244,11 +223,12 @@ static inline void dp_packet_clear(struct dp_packet *b)
 
 /* Removes 'size' bytes from the head end of 'b', which must contain at least
  * 'size' bytes of data.  Returns the first byte of data removed. */
-static inline void *dp_packet_pull(struct dp_packet *b, size_t size)
+static inline void *
+dp_packet_pull(struct dp_packet *b, size_t size)
 {
     void *data = dp_packet_data(b);
     ovs_assert(dp_packet_size(b) - dp_packet_l2_pad_size(b) >= size);
-    dp_packet_set_data(b, (char*)dp_packet_data(b) + size);
+    dp_packet_set_data(b, (char *) dp_packet_data(b) + size);
     dp_packet_set_size(b, dp_packet_size(b) - size);
     return data;
 }
@@ -256,83 +236,98 @@ static inline void *dp_packet_pull(struct dp_packet *b, size_t size)
 /* If 'b' has at least 'size' bytes of data, removes that many bytes from the
  * head end of 'b' and returns the first byte removed.  Otherwise, returns a
  * null pointer without modifying 'b'. */
-static inline void *dp_packet_try_pull(struct dp_packet *b, size_t size)
+static inline void *
+dp_packet_try_pull(struct dp_packet *b, size_t size)
 {
     return dp_packet_size(b) - dp_packet_l2_pad_size(b) >= size
         ? dp_packet_pull(b, size) : NULL;
 }
 
-static inline struct dp_packet *dp_packet_from_list(const struct ovs_list *list)
-{
-    return CONTAINER_OF(list, struct dp_packet, list_node);
-}
-
-static inline bool dp_packet_equal(const struct dp_packet *a, const struct dp_packet *b)
+static inline bool
+dp_packet_equal(const struct dp_packet *a, const struct dp_packet *b)
 {
     return dp_packet_size(a) == dp_packet_size(b) &&
-           memcmp(dp_packet_data(a), dp_packet_data(b), dp_packet_size(a)) == 0;
+           !memcmp(dp_packet_data(a), dp_packet_data(b), dp_packet_size(a));
 }
 
-/* Get the start if the Ethernet frame.  'l3_ofs' marks the end of the l2
+/* Get the start of the Ethernet frame.  'l3_ofs' marks the end of the l2
  * headers, so return NULL if it is not set. */
-static inline void * dp_packet_l2(const struct dp_packet *b)
+static inline void *
+dp_packet_l2(const struct dp_packet *b)
 {
-    return (b->l3_ofs != UINT16_MAX) ? b->frame : NULL;
+    return (b->l3_ofs != UINT16_MAX) ? dp_packet_data(b) : NULL;
 }
 
-/* Sets the packet frame start pointer and resets all layer offsets.
- * l3 offset must be set before 'l2' can be retrieved. */
-static inline void dp_packet_set_frame(struct dp_packet *b, void *packet)
+/* Resets all layer offsets.  'l3' offset must be set before 'l2' can be
+ * retrieved. */
+static inline void
+dp_packet_reset_offsets(struct dp_packet *b)
 {
-    b->frame = packet;
     b->l2_pad_size = 0;
     b->l2_5_ofs = UINT16_MAX;
     b->l3_ofs = UINT16_MAX;
     b->l4_ofs = UINT16_MAX;
 }
 
-static inline uint8_t dp_packet_l2_pad_size(const struct dp_packet *b)
+static inline uint8_t
+dp_packet_l2_pad_size(const struct dp_packet *b)
 {
     return b->l2_pad_size;
 }
 
-static inline void dp_packet_set_l2_pad_size(struct dp_packet *b, uint8_t pad_size)
+static inline void
+dp_packet_set_l2_pad_size(struct dp_packet *b, uint8_t pad_size)
 {
     ovs_assert(pad_size <= dp_packet_size(b));
     b->l2_pad_size = pad_size;
 }
 
-static inline void * dp_packet_l2_5(const struct dp_packet *b)
+static inline void *
+dp_packet_l2_5(const struct dp_packet *b)
 {
-    return b->l2_5_ofs != UINT16_MAX ? (char *)b->frame + b->l2_5_ofs : NULL;
+    return b->l2_5_ofs != UINT16_MAX
+           ? (char *) dp_packet_data(b) + b->l2_5_ofs
+           : NULL;
 }
 
-static inline void dp_packet_set_l2_5(struct dp_packet *b, void *l2_5)
+static inline void
+dp_packet_set_l2_5(struct dp_packet *b, void *l2_5)
 {
-    b->l2_5_ofs = l2_5 ? (char *)l2_5 - (char *)b->frame : UINT16_MAX;
+    b->l2_5_ofs = l2_5
+                  ? (char *) l2_5 - (char *) dp_packet_data(b)
+                  : UINT16_MAX;
 }
 
-static inline void * dp_packet_l3(const struct dp_packet *b)
+static inline void *
+dp_packet_l3(const struct dp_packet *b)
 {
-    return b->l3_ofs != UINT16_MAX ? (char *)b->frame + b->l3_ofs : NULL;
+    return b->l3_ofs != UINT16_MAX
+           ? (char *) dp_packet_data(b) + b->l3_ofs
+           : NULL;
 }
 
-static inline void dp_packet_set_l3(struct dp_packet *b, void *l3)
+static inline void
+dp_packet_set_l3(struct dp_packet *b, void *l3)
 {
-    b->l3_ofs = l3 ? (char *)l3 - (char *)b->frame : UINT16_MAX;
+    b->l3_ofs = l3 ? (char *) l3 - (char *) dp_packet_data(b) : UINT16_MAX;
 }
 
-static inline void * dp_packet_l4(const struct dp_packet *b)
+static inline void *
+dp_packet_l4(const struct dp_packet *b)
 {
-    return b->l4_ofs != UINT16_MAX ? (char *)b->frame + b->l4_ofs : NULL;
+    return b->l4_ofs != UINT16_MAX
+           ? (char *) dp_packet_data(b) + b->l4_ofs
+           : NULL;
 }
 
-static inline void dp_packet_set_l4(struct dp_packet *b, void *l4)
+static inline void
+dp_packet_set_l4(struct dp_packet *b, void *l4)
 {
-    b->l4_ofs = l4 ? (char *)l4 - (char *)b->frame : UINT16_MAX;
+    b->l4_ofs = l4 ? (char *) l4 - (char *) dp_packet_data(b) : UINT16_MAX;
 }
 
-static inline size_t dp_packet_l4_size(const struct dp_packet *b)
+static inline size_t
+dp_packet_l4_size(const struct dp_packet *b)
 {
     return b->l4_ofs != UINT16_MAX
         ? (const char *)dp_packet_tail(b) - (const char *)dp_packet_l4(b)
@@ -340,7 +335,8 @@ static inline size_t dp_packet_l4_size(const struct dp_packet *b)
         : 0;
 }
 
-static inline const void *dp_packet_get_tcp_payload(const struct dp_packet *b)
+static inline const void *
+dp_packet_get_tcp_payload(const struct dp_packet *b)
 {
     size_t l4_size = dp_packet_l4_size(b);
 
@@ -355,25 +351,29 @@ static inline const void *dp_packet_get_tcp_payload(const struct dp_packet *b)
     return NULL;
 }
 
-static inline const void *dp_packet_get_udp_payload(const struct dp_packet *b)
+static inline const void *
+dp_packet_get_udp_payload(const struct dp_packet *b)
 {
     return OVS_LIKELY(dp_packet_l4_size(b) >= UDP_HEADER_LEN)
         ? (const char *)dp_packet_l4(b) + UDP_HEADER_LEN : NULL;
 }
 
-static inline const void *dp_packet_get_sctp_payload(const struct dp_packet *b)
+static inline const void *
+dp_packet_get_sctp_payload(const struct dp_packet *b)
 {
     return OVS_LIKELY(dp_packet_l4_size(b) >= SCTP_HEADER_LEN)
         ? (const char *)dp_packet_l4(b) + SCTP_HEADER_LEN : NULL;
 }
 
-static inline const void *dp_packet_get_icmp_payload(const struct dp_packet *b)
+static inline const void *
+dp_packet_get_icmp_payload(const struct dp_packet *b)
 {
     return OVS_LIKELY(dp_packet_l4_size(b) >= ICMP_HEADER_LEN)
         ? (const char *)dp_packet_l4(b) + ICMP_HEADER_LEN : NULL;
 }
 
-static inline const void *dp_packet_get_nd_payload(const struct dp_packet *b)
+static inline const void *
+dp_packet_get_nd_payload(const struct dp_packet *b)
 {
     return OVS_LIKELY(dp_packet_l4_size(b) >= ND_MSG_LEN)
         ? (const char *)dp_packet_l4(b) + ND_MSG_LEN : NULL;
@@ -382,94 +382,179 @@ static inline const void *dp_packet_get_nd_payload(const struct dp_packet *b)
 #ifdef DPDK_NETDEV
 BUILD_ASSERT_DECL(offsetof(struct dp_packet, mbuf) == 0);
 
-static inline void * dp_packet_data(const struct dp_packet *b)
+static inline void *
+dp_packet_base(const struct dp_packet *b)
 {
-    return b->mbuf.pkt.data;
+    return b->mbuf.buf_addr;
 }
 
-static inline void dp_packet_set_data(struct dp_packet *b, void *d)
+static inline void
+dp_packet_set_base(struct dp_packet *b, void *d)
 {
-    b->mbuf.pkt.data = d;
+    b->mbuf.buf_addr = d;
 }
 
-static inline void * dp_packet_base(const struct dp_packet *b)
+static inline uint32_t
+dp_packet_size(const struct dp_packet *b)
 {
-    return b->mbuf.buf_addr;
+    return b->mbuf.pkt_len;
 }
 
-static inline void dp_packet_set_base(struct dp_packet *b, void *d)
+static inline void
+dp_packet_set_size(struct dp_packet *b, uint32_t v)
 {
-    b->mbuf.buf_addr = d;
+    /* 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. */
 }
 
-static inline uint32_t dp_packet_size(const struct dp_packet *b)
+static inline uint16_t
+__packet_data(const struct dp_packet *b)
 {
-    return b->mbuf.pkt.pkt_len;
+    return b->mbuf.data_off;
 }
 
-static inline void dp_packet_set_size(struct dp_packet *b, uint32_t v)
+static inline void
+__packet_set_data(struct dp_packet *b, uint16_t v)
 {
-    b->mbuf.pkt.data_len = v;    /* Current seg length. */
-    b->mbuf.pkt.pkt_len = v;     /* Total length of all segments linked to
-                                  * this segment. */
+    b->mbuf.data_off = v;
 }
 
-#else
-static inline void * dp_packet_data(const struct dp_packet *b)
+static inline uint16_t
+dp_packet_get_allocated(const struct dp_packet *b)
 {
-    return b->data_;
+    return b->mbuf.buf_len;
 }
 
-static inline void dp_packet_set_data(struct dp_packet *b, void *d)
+static inline void
+dp_packet_set_allocated(struct dp_packet *b, uint16_t s)
 {
-    b->data_ = d;
+    b->mbuf.buf_len = s;
 }
-
-static inline void * dp_packet_base(const struct dp_packet *b)
+#else
+static inline void *
+dp_packet_base(const struct dp_packet *b)
 {
     return b->base_;
 }
 
-static inline void dp_packet_set_base(struct dp_packet *b, void *d)
+static inline void
+dp_packet_set_base(struct dp_packet *b, void *d)
 {
     b->base_ = d;
 }
 
-static inline uint32_t dp_packet_size(const struct dp_packet *b)
+static inline uint32_t
+dp_packet_size(const struct dp_packet *b)
 {
     return b->size_;
 }
 
-static inline void dp_packet_set_size(struct dp_packet *b, uint32_t v)
+static inline void
+dp_packet_set_size(struct dp_packet *b, uint32_t v)
 {
     b->size_ = v;
 }
+
+static inline uint16_t
+__packet_data(const struct dp_packet *b)
+{
+    return b->data_ofs;
+}
+
+static inline void
+__packet_set_data(struct dp_packet *b, uint16_t v)
+{
+    b->data_ofs = v;
+}
+
+static inline uint16_t
+dp_packet_get_allocated(const struct dp_packet *b)
+{
+    return b->allocated_;
+}
+
+static inline void
+dp_packet_set_allocated(struct dp_packet *b, uint16_t s)
+{
+    b->allocated_ = s;
+}
 #endif
 
-static inline void dp_packet_reset_packet(struct dp_packet *b, int off)
+static inline void *
+dp_packet_data(const struct dp_packet *b)
+{
+    return __packet_data(b) != UINT16_MAX
+           ? (char *) dp_packet_base(b) + __packet_data(b) : NULL;
+}
+
+static inline void
+dp_packet_set_data(struct dp_packet *b, void *data)
+{
+    if (data) {
+        __packet_set_data(b, (char *) data - (char *) dp_packet_base(b));
+    } else {
+        __packet_set_data(b, UINT16_MAX);
+    }
+}
+
+static inline void
+dp_packet_reset_packet(struct dp_packet *b, int off)
 {
     dp_packet_set_size(b, dp_packet_size(b) - off);
-    dp_packet_set_data(b, (void *) ((unsigned char *) b->frame + off));
-    b->frame = NULL;
+    dp_packet_set_data(b, ((unsigned char *) dp_packet_data(b) + off));
     b->l2_5_ofs = b->l3_ofs = b->l4_ofs = UINT16_MAX;
 }
 
-static inline uint32_t dp_packet_get_dp_hash(struct dp_packet *p)
+/* Returns the RSS hash of the packet 'p'.  Note that the returned value is
+ * correct only if 'dp_packet_rss_valid(p)' returns true */
+static inline uint32_t
+dp_packet_get_rss_hash(struct dp_packet *p)
+{
+#ifdef DPDK_NETDEV
+    return p->mbuf.hash.rss;
+#else
+    return p->rss_hash;
+#endif
+}
+
+static inline void
+dp_packet_set_rss_hash(struct dp_packet *p, uint32_t hash)
+{
+#ifdef DPDK_NETDEV
+    p->mbuf.hash.rss = hash;
+    p->mbuf.ol_flags |= PKT_RX_RSS_HASH;
+#else
+    p->rss_hash = hash;
+    p->rss_hash_valid = true;
+#endif
+}
+
+static inline bool
+dp_packet_rss_valid(struct dp_packet *p)
 {
 #ifdef DPDK_NETDEV
-    return p->mbuf.pkt.hash.rss;
+    return p->mbuf.ol_flags & PKT_RX_RSS_HASH;
 #else
-    return p->dp_hash;
+    return p->rss_hash_valid;
 #endif
 }
 
-static inline void dp_packet_set_dp_hash(struct dp_packet *p,
-                                           uint32_t hash)
+static inline void
+dp_packet_rss_invalidate(struct dp_packet *p)
 {
 #ifdef DPDK_NETDEV
-    p->mbuf.pkt.hash.rss = hash;
+    p->mbuf.ol_flags &= ~PKT_RX_RSS_HASH;
 #else
-    p->dp_hash = hash;
+    p->rss_hash_valid = false;
 #endif
 }