From f898521f15b09c8ba5dc7753ff29ca6eb3128a7d Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 28 Aug 2019 18:05:56 +0200 Subject: [PATCH] Fix timeout and append bug --- src/algo_thunder.c | 3 ++- src/packet.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/algo_thunder.c b/src/algo_thunder.c index 469ce5c..0ac5269 100644 --- a/src/algo_thunder.c +++ b/src/algo_thunder.c @@ -192,7 +192,7 @@ void classify(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct b struct block_info *bi = malloc(sizeof(struct block_info)); bi->i = i; bi->app_ctx = app_ctx; bi->missing = expected; - set_timeout (ctx, timeout, &bi, on_block); + set_timeout (ctx, timeout, bi, on_block); if (ctx->verbose > 1) { fprintf(stderr, " [algo_thunder] Set timeout on link %d of %ld ms (packets expected: %ld, seen: %ld)\n", i, timeout, expected, thunderc->received_pkts_on_link[i]); @@ -245,6 +245,7 @@ void adapt(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buff } struct buffer_packet *bp_dest = inject_buffer_tow (&app_ctx->br, to_fdinfo); + dump_buffer_packet (bp_dest); buffer_append_ap (bp_dest, ui->ap_arr_pl[i]); main_on_udp_write(ctx, to_fdinfo); } diff --git a/src/packet.c b/src/packet.c index b6c5a20..c447f3d 100644 --- a/src/packet.c +++ b/src/packet.c @@ -1,7 +1,15 @@ #include "packet.h" +int ap_exists(union abstract_packet* ap) { + return ap->fmt.headers.cmd != 0; +} + +int buffer_has_ap(struct buffer_packet* bp) { + return ap_exists(buffer_first_ap (bp)); +} + union abstract_packet* ap_next(union abstract_packet* ap) { - if (ap->fmt.headers.flags & FLAG_READ_NEXT) + if (ap_exists (ap) && ap->fmt.headers.flags & FLAG_READ_NEXT) return (union abstract_packet*)(&ap->raw + ap->fmt.headers.size); return NULL; @@ -37,7 +45,9 @@ size_t buffer_full_size(struct buffer_packet* bp) { } union abstract_packet* buffer_append_ap(struct buffer_packet* bp, union abstract_packet* ap) { - buffer_last_ap(bp)->fmt.headers.flags |= FLAG_READ_NEXT; + if (buffer_has_ap (bp)) + buffer_last_ap(bp)->fmt.headers.flags |= FLAG_READ_NEXT; + union abstract_packet *new_ap = buffer_last_ap(bp); memcpy(new_ap, ap, ap->fmt.headers.size); bp->ap_count++;