Skip to content

Commit 49b9e1a

Browse files
committed
Parser - Fix packet parsing issue when --with-pcap is enabled
Ensure correct packet parsing for input modules like dpdk, dpdk-ring, and nfb when compiled with --with-pcap. Previously, the parser relied on opt->datalink, which these inputs do not set, leading to incorrect layer detection. Now, it correctly defaults to Ethernet when necessary.
1 parent fee9b26 commit 49b9e1a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

input/parser.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -683,25 +683,31 @@ void parse_packet(parser_opt_t *opt, ParserStats& stats, struct timeval ts, cons
683683
uint32_t l3_hdr_offset = 0;
684684
uint32_t l4_hdr_offset = 0;
685685
try {
686-
#ifdef WITH_PCAP
687-
if (opt->datalink == DLT_EN10MB) {
686+
#ifdef WITH_PCAP
687+
if (!opt->datalink) {
688+
data_offset = parse_eth_hdr(data, caplen, pkt);
689+
} else if (opt->datalink == DLT_EN10MB) {
688690
data_offset = parse_eth_hdr(data, caplen, pkt);
689691
} else if (opt->datalink == DLT_LINUX_SLL) {
690692
data_offset = parse_sll(data, caplen, pkt);
691-
# ifdef DLT_LINUX_SLL2
693+
# ifdef DLT_LINUX_SLL2
692694
} else if (opt->datalink == DLT_LINUX_SLL2) {
693695
data_offset = parse_sll2(data, caplen, pkt);
694-
# endif /* DLT_LINUX_SLL2 */
696+
# endif /* DLT_LINUX_SLL2 */
695697
} else if (opt->datalink == DLT_RAW) {
696698
if ((data[0] & 0xF0) == 0x40) {
697699
pkt->ethertype = ETH_P_IP;
698700
} else if ((data[0] & 0xF0) == 0x60) {
699701
pkt->ethertype = ETH_P_IPV6;
700702
}
703+
} else {
704+
stats.unknown_packets++;
705+
DEBUG_MSG("Unknown datalink type %u\n", opt->datalink);
706+
return;
701707
}
702-
#else
708+
#else
703709
data_offset = parse_eth_hdr(data, caplen, pkt);
704-
#endif /* WITH_PCAP */
710+
#endif /* WITH_PCAP */
705711

706712
if (pkt->ethertype == ETH_P_TRILL) {
707713
data_offset += parse_trill(data + data_offset, caplen - data_offset, pkt);

0 commit comments

Comments
 (0)