summaryrefslogtreecommitdiffstats
path: root/src/vlib
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-01-07 09:15:47 -0500
committerFlorin Coras <florin.coras@gmail.com>2019-01-07 16:47:09 +0000
commit3a63fc5470caffda434064a439ffdbe8518963f9 (patch)
tree5413c1a884269a7c93c1ed468608222a2dbd9590 /src/vlib
parent9d7570ccde4ded1c5feea097b10272870bfc81da (diff)
Handle buffer alloc failure in vlib_buffer_add_data
It's not OK to crash due to a transient buffer allocation failure. Return 1 if the requested operation failed, otherwise 0. Buffer index parameter change to a value-result, so the caller can differentiate between partial and complete allocation failure: callers which request an initial allocation (inbound bi = ~0) need to check the (out) value to decide whether or not to call vlib_buffer_free(...). Change-Id: I03029d7f2714c17dca4630dfd95a1eb578b68384 Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vlib')
-rw-r--r--src/vlib/buffer.c13
-rw-r--r--src/vlib/buffer_funcs.h4
2 files changed, 9 insertions, 8 deletions
diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c
index d024aba1e0f..5370d501293 100644
--- a/src/vlib/buffer.c
+++ b/src/vlib/buffer.c
@@ -705,16 +705,16 @@ vlib_packet_template_get_packet (vlib_main_t * vm,
}
/* Append given data to end of buffer, possibly allocating new buffers. */
-u32
+int
vlib_buffer_add_data (vlib_main_t * vm,
vlib_buffer_free_list_index_t free_list_index,
- u32 buffer_index, void *data, u32 n_data_bytes)
+ u32 * buffer_index, void *data, u32 n_data_bytes)
{
u32 n_buffer_bytes, n_left, n_left_this_buffer, bi;
vlib_buffer_t *b;
void *d;
- bi = buffer_index;
+ bi = *buffer_index;
if (bi == ~0
&& 1 != vlib_buffer_alloc_from_free_list (vm, &bi, 1, free_list_index))
goto out_of_buffers;
@@ -756,11 +756,12 @@ vlib_buffer_add_data (vlib_main_t * vm,
b = vlib_get_buffer (vm, b->next_buffer);
}
- return bi;
+ *buffer_index = bi;
+ return 0;
out_of_buffers:
- clib_error ("out of buffers");
- return bi;
+ clib_warning ("out of buffers");
+ return 1;
}
u16
diff --git a/src/vlib/buffer_funcs.h b/src/vlib/buffer_funcs.h
index 54fc1f61598..b561a91c394 100644
--- a/src/vlib/buffer_funcs.h
+++ b/src/vlib/buffer_funcs.h
@@ -672,9 +672,9 @@ vlib_buffer_free_list_buffer_size (vlib_main_t * vm,
}
/* Append given data to end of buffer, possibly allocating new buffers. */
-u32 vlib_buffer_add_data (vlib_main_t * vm,
+int vlib_buffer_add_data (vlib_main_t * vm,
vlib_buffer_free_list_index_t free_list_index,
- u32 buffer_index, void *data, u32 n_data_bytes);
+ u32 * buffer_index, void *data, u32 n_data_bytes);
/* duplicate all buffers in chain */
always_inline vlib_buffer_t *