summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Wallace <dwallacelf@gmail.com>2024-07-16 15:32:55 -0400
committerDamjan Marion <dmarion@0xa5.net>2024-07-18 14:46:07 +0000
commit6ce5d5bcbbcd8c633c8ef0969d8501c73eb5f3b4 (patch)
treeee1795dbec2aed79b7292f55a8b8dd9d2ddbb317 /src
parent0da0883453e7855a65fea7db85aebe69eb4d69b0 (diff)
pg: fix pcap packet type when writing pcap file
- fixes incorrect pcap packet type for packet generator interfaces configured in ip mode. - corrects pcap file decode for pg output files - fixes scapy versions > 2.4.3 which now appear to use the packet type in the pcap file header which had been ignored in earlier versions Type: fix Change-Id: Idb1e3f8fbc7ca938fb5d2aaa72365e333c0ea2e9 Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/vnet/pg/output.c8
-rw-r--r--src/vnet/pg/pg.h9
2 files changed, 16 insertions, 1 deletions
diff --git a/src/vnet/pg/output.c b/src/vnet/pg/output.c
index 042591a7709..fa1a14cc4af 100644
--- a/src/vnet/pg/output.c
+++ b/src/vnet/pg/output.c
@@ -88,7 +88,13 @@ pg_output (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
pcap_add_buffer (&pif->pcap_main, vm, bi0, ETHERNET_MAX_PACKET_BYTES);
}
if (pif->pcap_file_name != 0)
- pcap_write (&pif->pcap_main);
+ {
+ pcap_packet_type_t pm_pt = pif->pcap_main.packet_type;
+ pif->pcap_main.packet_type =
+ pg_intf_mode_to_pcap_packet_type (pif->mode);
+ pcap_write (&pif->pcap_main);
+ pif->pcap_main.packet_type = pm_pt;
+ }
if ((pif->pcap_main.flags & PCAP_MAIN_INIT_DONE)
&& pif->pcap_main.n_packets_captured >=
pif->pcap_main.n_packets_to_capture)
diff --git a/src/vnet/pg/pg.h b/src/vnet/pg/pg.h
index 6d5b25ba25a..bede747428c 100644
--- a/src/vnet/pg/pg.h
+++ b/src/vnet/pg/pg.h
@@ -306,6 +306,15 @@ typedef enum pg_interface_mode_t_
PG_MODE_IP6,
} pg_interface_mode_t;
+always_inline pcap_packet_type_t
+pg_intf_mode_to_pcap_packet_type (pg_interface_mode_t mode)
+{
+ if ((mode == PG_MODE_IP4) || (mode == PG_MODE_IP6))
+ return PCAP_PACKET_TYPE_ip;
+ else
+ return PCAP_PACKET_TYPE_ethernet;
+}
+
typedef struct
{
/* TX lock */