Skip to content

Commit df35154

Browse files
aaronmhill01aaron
andauthored
[Bug Fix] speed_tester jumbo frames crash fix (#316)
Speed tester will no longer crash if you tell it to load a PCAP trace that contains jumbo frames without using the -j flag. Commit log: * [UPDATE] speed_tester jumbo frames crash fix * [UPDTE] speed_tester jumbo frame usability improvement Co-authored-by: aaron <aaron@localhost>
1 parent 67a4d1a commit df35154

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

examples/speed_tester/speed_tester.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ nf_setup(struct onvm_nf_local_ctx *nf_local_ctx) {
310310
const u_char *packet;
311311
struct pcap_pkthdr header;
312312
char errbuf[PCAP_ERRBUF_SIZE];
313+
uint32_t max_elt_size;
313314

314315
if (pcap_filename != NULL) {
315316
printf("Replaying %s pcap file\n", pcap_filename);
@@ -326,10 +327,24 @@ nf_setup(struct onvm_nf_local_ctx *nf_local_ctx) {
326327

327328
i = 0;
328329

330+
/*
331+
* max_elt_size is the maximum preallocated memory size permitted for each packet,
332+
* adjusted for the memory offset of the rte_mbuf struct and header/tail lengths
333+
*/
334+
335+
max_elt_size = pktmbuf_pool->elt_size - sizeof(struct rte_mbuf) - pktmbuf_pool->header_size - pktmbuf_pool->trailer_size;
336+
329337
while (((packet = pcap_next(pcap, &header)) != NULL) && (i < packet_number)) {
330338
struct onvm_pkt_meta *pmeta;
331339
struct onvm_ft_ipv4_5tuple key;
332340

341+
/* Length of the packet cannot exceed preallocated storage size */
342+
if (header.caplen > max_elt_size) {
343+
nf_local_ctx->nf->stats.tx_drop++;
344+
nf_local_ctx->nf->stats.act_drop++;
345+
continue;
346+
}
347+
333348
pkt = rte_pktmbuf_alloc(pktmbuf_pool);
334349
if (pkt == NULL)
335350
break;
@@ -355,7 +370,7 @@ nf_setup(struct onvm_nf_local_ctx *nf_local_ctx) {
355370
onvm_nflib_return_pkt_bulk(nf_local_ctx->nf, pkts, pkts_generated);
356371
} else {
357372
#endif
358-
/* use default number of initial packets if -c has not been used */
373+
/* Use default number of initial packets if -c has not been used */
359374
packet_number = (use_custom_pkt_count ? packet_number : DEFAULT_PKT_NUM);
360375
struct rte_mbuf *pkts[packet_number];
361376

0 commit comments

Comments
 (0)