From da7f7b6164e976a97ff0afb13f488c60461402bc Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Mon, 11 Mar 2019 13:15:54 +0100 Subject: ICMP46 error: Clone first buffer instead of "truncating" original buffer Previous code was walked buffer chain, effectively trying to "truncate" the chain, reset the length of first buffer and reused that as the ICMP error message. That could have issues in cases there were other users of the buffer chain. Update to clone the first buffer in chain, and use that for the ICMP error message instead. Change-Id: Ibc1a0bf2d854dae41874808c8297028ed93dd69d Signed-off-by: Ole Troan --- src/vlib/buffer_funcs.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/vlib/buffer_funcs.h') diff --git a/src/vlib/buffer_funcs.h b/src/vlib/buffer_funcs.h index 3e0234b6b51..483a990731f 100644 --- a/src/vlib/buffer_funcs.h +++ b/src/vlib/buffer_funcs.h @@ -976,6 +976,27 @@ vlib_buffer_copy (vlib_main_t * vm, vlib_buffer_t * b) return fd; } +/* duplicate first buffer in chain */ +always_inline vlib_buffer_t * +vlib_buffer_copy_no_chain (vlib_main_t * vm, vlib_buffer_t * b, u32 * di) +{ + vlib_buffer_t *d; + + if ((vlib_buffer_alloc (vm, di, 1)) != 1) + return 0; + + d = vlib_get_buffer (vm, *di); + /* 1st segment */ + d->current_data = b->current_data; + d->current_length = b->current_length; + clib_memcpy_fast (d->opaque, b->opaque, sizeof (b->opaque)); + clib_memcpy_fast (d->opaque2, b->opaque2, sizeof (b->opaque2)); + clib_memcpy_fast (vlib_buffer_get_current (d), + vlib_buffer_get_current (b), b->current_length); + + return d; +} + /** \brief Create a maximum of 256 clones of buffer and store them in the supplied array -- cgit 1.2.3-korg