From 49cd3bad66cba83f0364d94ed34de2457694f545 Mon Sep 17 00:00:00 2001 From: Kingwel Xie Date: Fri, 26 Oct 2018 23:55:47 -0400 Subject: pg: incrementing len should be truncated by stream->max_packet_bytes This length is the payload length, and will impact the ip length when ip length is not specified. iplen = header_len + payload_len SO, better to make it comply with max_packet_bytes Change-Id: I8b0f7485e29fcaccae656f2d03b3b5e614300fb8 Signed-off-by: Kingwel Xie --- src/vnet/pg/edit.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/vnet/pg/edit.c b/src/vnet/pg/edit.c index cb4d070fb19..8d1437e96bc 100644 --- a/src/vnet/pg/edit.c +++ b/src/vnet/pg/edit.c @@ -129,17 +129,13 @@ unformat_pg_payload (unformat_input_t * input, va_list * args) pg_stream_t *s = va_arg (*args, pg_stream_t *); vlib_main_t *vm = vlib_get_main (); pg_edit_t *e; - u32 i, node_index, len, max_len; + u32 i, node_index, len, max_len, ilen; u8 *v; v = 0; - if (unformat (input, "incrementing %d", &len)) - { - vec_resize (v, len); - for (i = 0; i < len; i++) - v[i] = i; - } + if (unformat (input, "incrementing %d", &ilen)) + ; else if (unformat (input, "hex 0x%U", unformat_hex_string, &v)) ; @@ -156,13 +152,20 @@ unformat_pg_payload (unformat_input_t * input, va_list * args) /* Length not including this payload. */ max_len = pg_edit_group_n_bytes (s, 0); - if (max_len + vec_len (v) >= s->max_packet_bytes) + if (max_len >= s->max_packet_bytes) { - if (s->max_packet_bytes >= max_len) - _vec_len (v) = s->max_packet_bytes - max_len; - else - _vec_len (v) = 0; + /* no payload */ + len = 0; } + else + { + /* make a bigger v to hold the data */ + len = s->max_packet_bytes - max_len; + } + + vec_resize (v, len); + for (i = 0; i < len; i++) + v[i] = i % ilen; e = pg_create_edit_group (s, sizeof (e[0]), vec_len (v), 0); -- cgit 1.2.3-korg