From: Xavier Simonart Date: Wed, 6 Dec 2017 15:54:05 +0000 (+0100) Subject: Fix checks done when changing generator pkt_size X-Git-Tag: opnfv-5.1.RC1~2^2 X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F71%2F48471%2F1;p=samplevnf.git Fix checks done when changing generator pkt_size Different checks were done when setting the generator pkt_size. In case of wrong pkt_size (e.g. too big) an error was printed but the pkt_size was still set causing a potential corruption. In addition, in case of a packet size incompatible with some of the packet fields (e.g. latency data) PROX was panicing while this should not happen runtime for such an error. Change-Id: Ifa11475bf295aaac7b0255c1bf9b5feed8ef90c4 Signed-off-by: Xavier Simonart --- diff --git a/VNFs/DPPD-PROX/handle_gen.c b/VNFs/DPPD-PROX/handle_gen.c index f8c99ee5..c48b4c13 100644 --- a/VNFs/DPPD-PROX/handle_gen.c +++ b/VNFs/DPPD-PROX/handle_gen.c @@ -790,31 +790,45 @@ static int check_all_pkt_size(struct task_gen *task, int do_panic) return 0; } -static void check_fields_in_bounds(struct task_gen *task) +static int check_fields_in_bounds(struct task_gen *task, uint32_t pkt_size, int do_panic) { - const uint32_t pkt_size = task->pkt_template[0].len; - if (task->lat_enabled) { uint32_t pos_beg = task->lat_pos; uint32_t pos_end = task->lat_pos + 3U; - PROX_PANIC(pkt_size <= pos_end, "Writing latency at %u-%u, but packet size is %u bytes\n", + if (do_panic) + PROX_PANIC(pkt_size <= pos_end, "Writing latency at %u-%u, but packet size is %u bytes\n", pos_beg, pos_end, pkt_size); + else if (pkt_size <= pos_end) { + plog_err("Writing latency at %u-%u, but packet size is %u bytes\n", pos_beg, pos_end, pkt_size); + return -1; + } } if (task->packet_id_pos) { uint32_t pos_beg = task->packet_id_pos; uint32_t pos_end = task->packet_id_pos + 4U; - PROX_PANIC(pkt_size <= pos_end, "Writing packet at %u-%u, but packet size is %u bytes\n", + if (do_panic) + PROX_PANIC(pkt_size <= pos_end, "Writing packet at %u-%u, but packet size is %u bytes\n", pos_beg, pos_end, pkt_size); + else if (pkt_size <= pos_end) { + plog_err("Writing packet at %u-%u, but packet size is %u bytes\n", pos_beg, pos_end, pkt_size); + return -1; + } } if (task->accur_pos) { uint32_t pos_beg = task->accur_pos; uint32_t pos_end = task->accur_pos + 3U; - PROX_PANIC(pkt_size <= pos_end, "Writing accuracy at %u%-u, but packet size is %u bytes\n", + if (do_panic) + PROX_PANIC(pkt_size <= pos_end, "Writing accuracy at %u%-u, but packet size is %u bytes\n", pos_beg, pos_end, pkt_size); + else if (pkt_size <= pos_end) { + plog_err("Writing accuracy at %u%-u, but packet size is %u bytes\n", pos_beg, pos_end, pkt_size); + return -1; + } } + return 0; } static void task_gen_pkt_template_recalc_metadata(struct task_gen *task) @@ -919,7 +933,7 @@ static void task_init_gen_load_pkt_inline(struct task_gen *task, struct task_arg task->pkt_template_orig[0].len = targ->pkt_size; task_gen_reset_pkt_templates(task); check_all_pkt_size(task, 1); - check_fields_in_bounds(task); + check_fields_in_bounds(task, task->pkt_template[0].len, 1); } static void task_init_gen_load_pcap(struct task_gen *task, struct task_args *targ) @@ -976,10 +990,11 @@ int task_gen_set_pkt_size(struct task_base *tbase, uint32_t pkt_size) struct task_gen *task = (struct task_gen *)tbase; int rc; - task->pkt_template[0].len = pkt_size; - if ((rc = check_all_pkt_size(task, 0)) != 0) + if ((rc = check_pkt_size(task, pkt_size, 0)) != 0) return rc; - check_fields_in_bounds(task); + if ((rc = check_fields_in_bounds(task, pkt_size, 0)) != 0) + return rc; + task->pkt_template[0].len = pkt_size; return rc; }