Skip to content

Commit

Permalink
dp-packet: Use memcpy on dp_packet elements.
Browse files Browse the repository at this point in the history
memcpy replaces the several single copies inside
dp_packet_clone_with_headroom().

Signed-off-by: Antonio Fischetti <[email protected]>
Signed-off-by: Darrell Ball <[email protected]>
  • Loading branch information
FischettiAntonio authored and darball1 committed Aug 25, 2017
1 parent 94053e6 commit 84b7057
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 9 additions & 9 deletions lib/dp-packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ dp_packet_clone(const struct dp_packet *buffer)
return dp_packet_clone_with_headroom(buffer, 0);
}

/* Creates and returns a new dp_packet whose data are copied from 'buffer'. The
* returned dp_packet will additionally have 'headroom' bytes of headroom. */
/* Creates and returns a new dp_packet whose data are copied from 'buffer'.
* The returned dp_packet will additionally have 'headroom' bytes of
* headroom. */
struct dp_packet *
dp_packet_clone_with_headroom(const struct dp_packet *buffer, size_t headroom)
{
Expand All @@ -170,13 +171,12 @@ dp_packet_clone_with_headroom(const struct dp_packet *buffer, size_t headroom)
new_buffer = dp_packet_clone_data_with_headroom(dp_packet_data(buffer),
dp_packet_size(buffer),
headroom);
new_buffer->l2_pad_size = buffer->l2_pad_size;
new_buffer->l2_5_ofs = buffer->l2_5_ofs;
new_buffer->l3_ofs = buffer->l3_ofs;
new_buffer->l4_ofs = buffer->l4_ofs;
new_buffer->md = buffer->md;
new_buffer->cutlen = buffer->cutlen;
new_buffer->packet_type = buffer->packet_type;
/* Copy the following fields into the returned buffer: l2_pad_size,
* l2_5_ofs, l3_ofs, l4_ofs, cutlen, packet_type and md. */
memcpy(&new_buffer->l2_pad_size, &buffer->l2_pad_size,
sizeof(struct dp_packet) -
offsetof(struct dp_packet, l2_pad_size));

#ifdef DPDK_NETDEV
new_buffer->mbuf.ol_flags = buffer->mbuf.ol_flags;
#else
Expand Down
6 changes: 5 additions & 1 deletion lib/dp-packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ 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 dp_packet_init_dpdk() in dp-packet.c. */
* ref to dp_packet_init_dpdk() in dp-packet.c.
*/
};

#define DP_PACKET_CONTEXT_SIZE 64
Expand All @@ -61,6 +62,9 @@ struct dp_packet {
bool rss_hash_valid; /* Is the 'rss_hash' valid? */
#endif
enum dp_packet_source source; /* Source of memory allocated as 'base'. */

/* All the following elements of this struct are copied in a single call
* of memcpy in dp_packet_clone_with_headroom. */
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 */
Expand Down

0 comments on commit 84b7057

Please sign in to comment.