From e5f1053174ef3a912ae19e80e8222506e534880e Mon Sep 17 00:00:00 2001 From: Kaian Date: Mon, 10 May 2021 11:55:27 +0200 Subject: [PATCH] ip: skip IP headers from fragments data --- src/packet/packet_ip.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/packet/packet_ip.c b/src/packet/packet_ip.c index bf2bdd3..a761c0d 100644 --- a/src/packet/packet_ip.c +++ b/src/packet/packet_ip.c @@ -49,14 +49,12 @@ packet_ip_fragment_sort(const PacketIpFragment **a, const PacketIpFragment **b) } static PacketIpFragment * -packet_ip_fragment_new(Packet *packet, GBytes *data) +packet_ip_fragment_new(Packet *packet) { // Reserve memory for storing fragment information PacketIpFragment *fragment = g_malloc0(sizeof(PacketIpFragment)); // Store packet information fragment->packet = packet_ref(packet); - // Set fragment payload for future reassembly - fragment->data = g_bytes_ref(data); return fragment; } @@ -69,6 +67,13 @@ packet_ip_fragment_free(PacketIpFragment *fragment) g_free(fragment); } +static void +packet_ip_fragment_set_data(PacketIpFragment *fragment, GBytes *data) +{ + // Set fragment payload for future reassembly + fragment->data = g_bytes_ref(data); +} + static PacketIpDatagram * packet_ip_datagram_new(const PacketIpFragment *fragment) { @@ -160,7 +165,7 @@ packet_dissector_ip_dissect(PacketDissector *self, Packet *packet, GBytes *data) #endif // Create an IP fragment for current data - PacketIpFragment *fragment = packet_ip_fragment_new(packet, data); + PacketIpFragment *fragment = packet_ip_fragment_new(packet); // Set IP version fragment->version = ip4->ip_v; @@ -227,6 +232,9 @@ packet_dissector_ip_dissect(PacketDissector *self, Packet *packet, GBytes *data) // Get pending payload data = g_bytes_offset(data, fragment->hl); + // Set fragment data + packet_ip_fragment_set_data(fragment, data); + // If no fragmentation if (fragment->frag == 0) { // Single fragment packet