Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pcap crash #277

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/pktgen-cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ convert_bitfield(bf_spec_t *bf)
}

/**
* pktgen_save - Save a configuration as a startup script
* pktgen_script_save - Save a configuration as a startup script
*
* DESCRIPTION
* Save a configuration as a startup script
Expand Down Expand Up @@ -464,7 +464,7 @@ pktgen_lua_save(char *path)
fprintf(fd, "pktgen.mac_from_arp(\"%s\");\n\n",
(pktgen.flags & MAC_FROM_ARP_FLAG) ? "enable" : "disable");

for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
for (i = 0; i < pktgen.nb_ports; i++) {
pinfo = l2p_get_port_pinfo(i);
pkt = &pinfo->seq_pkt[SINGLE_PKT];
range = &pinfo->range;
Expand Down
28 changes: 15 additions & 13 deletions app/pktgen-pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pktgen_pcap_info(pcap_info_t *pcap, uint16_t port, int flag)
printf(" snaplen: %d,", pcap->info.snaplen);
printf(" sigfigs: %d,", pcap->info.sigfigs);
printf(" network: %d", pcap->info.network);
printf(" Endian: %s\n", pcap->convert ? "Big" : "Little");
printf(" Convert Endian: %s\n", pcap->convert ? "Yes" : "No");
if (flag)
printf(" Packet count: %d\n", pcap->pkt_count);
printf("\n");
Expand Down Expand Up @@ -58,17 +58,14 @@ static void
pcap_get_info(pcap_info_t *pcap)
{
pcap_record_hdr_t hdr;

if (fread(&pcap->info, 1, sizeof(pcap_hdr_t), pcap->fp) != sizeof(pcap_hdr_t))
rte_exit(EXIT_FAILURE, "%s: failed to read pcap header\n", __func__);

/* Make sure we have a valid PCAP file for Big or Little Endian formats. */
if (pcap->info.magic_number != PCAP_MAGIC_NUMBER)
pcap->convert = 0;
else if (pcap->info.magic_number != ntohl(PCAP_MAGIC_NUMBER))
pcap->convert = 1;
else
rte_exit(EXIT_FAILURE, "%s: invalid magic number 0x%08x\n", __func__,
pcap->info.magic_number);
pcap->convert = (PCAP_MAGIC_NUMBER == pcap->info.magic_number) ? 0 : 1;

printf("PCAP: MAGIC_NUMBER 0x%08x == 0x%08x, Convert: %s\n", PCAP_MAGIC_NUMBER,
pcap->info.magic_number, (pcap->convert) ? "Yes" : "No");

if (pcap->convert) {
pcap->info.magic_number = ntohl(pcap->info.magic_number);
Expand All @@ -80,6 +77,7 @@ pcap_get_info(pcap_info_t *pcap)
pcap->info.network = ntohl(pcap->info.network);
}

pcap->max_pkt_size = 0;
/* count the number of packets and get the largest size packet */
for (;;) {
if (fread(&hdr, 1, sizeof(pcap_record_hdr_t), pcap->fp) != sizeof(hdr))
Expand All @@ -95,15 +93,19 @@ pcap_get_info(pcap_info_t *pcap)
if (hdr.incl_len > pcap->max_pkt_size)
pcap->max_pkt_size = hdr.incl_len;
}
pcap->max_pkt_size += RTE_PKTMBUF_HEADROOM;
pcap->max_pkt_size = RTE_ALIGN_CEIL(pcap->max_pkt_size, RTE_CACHE_LINE_SIZE);
printf("PCAP: Max Packet Size: %d\n", pcap->max_pkt_size);

pcap_rewind(pcap);
}

static __inline__ void
mbuf_iterate_cb(struct rte_mempool *mp, void *opaque, void *obj, unsigned obj_idx __rte_unused)
{
pcap_info_t *pcap = (pcap_info_t *)opaque;
struct rte_mbuf *m = (struct rte_mbuf *)obj;
pcap_record_hdr_t hdr;
pcap_info_t *pcap = (pcap_info_t *)opaque;
struct rte_mbuf *m = (struct rte_mbuf *)obj;
pcap_record_hdr_t hdr = {0};

if (fread(&hdr, 1, sizeof(pcap_record_hdr_t), pcap->fp) != sizeof(hdr))
rte_exit(EXIT_FAILURE, "%s: failed to read pcap header\n", __func__);
Expand Down Expand Up @@ -569,4 +571,4 @@ pktgen_write_mbuf_to_pcap_file(FILE *fp, struct rte_mbuf *mbuf)
fflush(fp);

return 0;
}
}
Loading