summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2017-03-01 11:38:02 -0500
committerDamjan Marion <damarion@cisco.com>2017-03-01 19:06:42 +0100
commitf869028740aaebeb0375077d4d84fa07a17fff1a (patch)
tree3621af03394a4875e135175c3d23e82b6883f0fd
parentb3bb10101ceffec1df0624c785acbd40858870ec (diff)
Fix buffer template copy
Change-Id: If451c9cb68719fc816999b0330b9be3a0169176a Signed-off-by: Dave Barach <dave@barachs.net>
-rw-r--r--src/vlib/buffer.h2
-rw-r--r--src/vlib/buffer_funcs.h33
2 files changed, 30 insertions, 5 deletions
diff --git a/src/vlib/buffer.h b/src/vlib/buffer.h
index b4015b302c3..1f723f3b677 100644
--- a/src/vlib/buffer.h
+++ b/src/vlib/buffer.h
@@ -61,6 +61,7 @@
typedef struct
{
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
+ STRUCT_MARK (template_start);
/* Offset within data[] that we are currently processing.
If negative current header points into predata area. */
i16 current_data; /**< signed offset in data[], pre_data[]
@@ -103,6 +104,7 @@ typedef struct
/**< Only valid for first buffer in chain. Current length plus
total length given here give total number of bytes in buffer chain.
*/
+ STRUCT_MARK (template_end);
u32 next_buffer; /**< Next buffer for this linked-list of buffers.
Only valid if VLIB_BUFFER_NEXT_PRESENT flag is set.
diff --git a/src/vlib/buffer_funcs.h b/src/vlib/buffer_funcs.h
index e0fde5f2194..f346676baee 100644
--- a/src/vlib/buffer_funcs.h
+++ b/src/vlib/buffer_funcs.h
@@ -792,14 +792,22 @@ vlib_buffer_init_for_free_list (vlib_buffer_t * dst,
/* Make sure buffer template is sane. */
ASSERT (fl->index == fl->buffer_init_template.free_list_index);
+ clib_memcpy (STRUCT_MARK_PTR (dst, template_start),
+ STRUCT_MARK_PTR (src, template_start),
+ STRUCT_OFFSET_OF (vlib_buffer_t, template_end) -
+ STRUCT_OFFSET_OF (vlib_buffer_t, template_start));
+
+ /* Not in the first 16 octets. */
+ dst->n_add_refs = src->n_add_refs;
+
/* Make sure it really worked. */
-#define _(f) dst->f = src->f
+#define _(f) ASSERT (dst->f == src->f);
_(current_data);
_(current_length);
_(flags);
_(free_list_index);
#undef _
- dst->total_length_not_including_first_buffer = 0;
+ ASSERT (dst->total_length_not_including_first_buffer == 0);
ASSERT (dst->n_add_refs == 0);
}
@@ -825,15 +833,30 @@ vlib_buffer_init_two_for_free_list (vlib_buffer_t * dst0,
/* Make sure buffer template is sane. */
ASSERT (fl->index == fl->buffer_init_template.free_list_index);
+ clib_memcpy (STRUCT_MARK_PTR (dst0, template_start),
+ STRUCT_MARK_PTR (src, template_start),
+ STRUCT_OFFSET_OF (vlib_buffer_t, template_end) -
+ STRUCT_OFFSET_OF (vlib_buffer_t, template_start));
+
+ clib_memcpy (STRUCT_MARK_PTR (dst1, template_start),
+ STRUCT_MARK_PTR (src, template_start),
+ STRUCT_OFFSET_OF (vlib_buffer_t, template_end) -
+ STRUCT_OFFSET_OF (vlib_buffer_t, template_start));
+
+ /* Not in the first 16 octets. */
+ dst0->n_add_refs = src->n_add_refs;
+ dst1->n_add_refs = src->n_add_refs;
+
/* Make sure it really worked. */
-#define _(f) dst0->f = src->f; dst1->f = src->f
+#define _(f) ASSERT (dst0->f == src->f); ASSERT( dst1->f == src->f)
_(current_data);
_(current_length);
_(flags);
_(free_list_index);
#undef _
- dst0->total_length_not_including_first_buffer = 0;
- dst1->total_length_not_including_first_buffer = 0;
+
+ ASSERT (dst0->total_length_not_including_first_buffer == 0);
+ ASSERT (dst1->total_length_not_including_first_buffer == 0);
ASSERT (dst0->n_add_refs == 0);
ASSERT (dst1->n_add_refs == 0);
}