From 0c418ffc4a34c864c09b8778cc0503fb60487775 Mon Sep 17 00:00:00 2001 From: Fred Klassen Date: Thu, 29 Apr 2021 08:50:25 -0700 Subject: [PATCH] Bug #582 calculate L2 length based on exporter DLT --- docs/CHANGELOG | 2 +- src/tcpedit/dlt.c | 12 ++++++++---- src/tcpedit/dlt.h | 2 +- src/tcpedit/edit_packet.c | 2 +- src/tcpedit/plugins/dlt_en10mb/en10mb.c | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/CHANGELOG b/docs/CHANGELOG index d7c5fd940..d4b1df78e 100644 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -17,7 +17,7 @@ - fix UNUSED macro declaration (#614) - handle malformed and unsupported packets as soft errors (#613) - compile failure on aarch64-linux-android (#612) - - tcprewrite --fixlen not working (#582) + - tcprewrite --fixlen not working on DLT conversion (#582) - fix configure --without-libdnet (#567) - ensure automake version is at least 1.15 (#553) - with multiplier option only first file can be sent and hang (#472) diff --git a/src/tcpedit/dlt.c b/src/tcpedit/dlt.c index 7cbc937bb..8f4bf5184 100644 --- a/src/tcpedit/dlt.c +++ b/src/tcpedit/dlt.c @@ -160,10 +160,14 @@ dlt2mtu(tcpedit_t *tcpedit, int dlt) * for it to be at all useful. */ int -layer2len(tcpedit_t *tcpedit) +layer2len(tcpedit_t *tcpedit, u_char *packet, uint32_t caplen) { - assert(tcpedit); - - return tcpedit->dlt_ctx->l2len; + assert(tcpedit); + assert(tcpedit->dlt_ctx); + assert(tcpedit->dlt_ctx->encoder); + + return tcpedit->dlt_ctx->encoder->plugin_l2len(tcpedit->dlt_ctx, + packet, + caplen); } diff --git a/src/tcpedit/dlt.h b/src/tcpedit/dlt.h index 088622e5f..8a592a25a 100644 --- a/src/tcpedit/dlt.h +++ b/src/tcpedit/dlt.h @@ -32,7 +32,7 @@ int dlt2layer2len(tcpedit_t *tcpedit, int dlt); int dltrequires(tcpedit_t *tcpedit, int dlt); int dlt2mtu(tcpedit_t *tcpedit, int dlt); -int layer2len(tcpedit_t *tcpedit); +int layer2len(tcpedit_t *tcpedit, u_char *packet, uint32_t caplen); #endif /* _DLT_H_ */ diff --git a/src/tcpedit/edit_packet.c b/src/tcpedit/edit_packet.c index 36818f53d..c5d7b0b4e 100644 --- a/src/tcpedit/edit_packet.c +++ b/src/tcpedit/edit_packet.c @@ -508,7 +508,7 @@ untrunc_packet(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, return(0); } - if ((l2len = layer2len(tcpedit)) < 0) { + if ((l2len = layer2len(tcpedit, packet, pkthdr->caplen)) < 0) { tcpedit_seterr(tcpedit, "Non-sensical layer 2 length: %d", l2len); return -1; } diff --git a/src/tcpedit/plugins/dlt_en10mb/en10mb.c b/src/tcpedit/plugins/dlt_en10mb/en10mb.c index caedbab84..db1b8d746 100644 --- a/src/tcpedit/plugins/dlt_en10mb/en10mb.c +++ b/src/tcpedit/plugins/dlt_en10mb/en10mb.c @@ -30,7 +30,7 @@ #include "en10mb.h" -static char _U_ dlt_name[] = "en10mb"; +static char dlt_name[] = "en10mb"; static char dlt_prefix[] = "enet"; static uint16_t dlt_value = DLT_EN10MB;