Skip to content

Commit

Permalink
Wire dedup into optional packet dump -p
Browse files Browse the repository at this point in the history
  • Loading branch information
phaag committed Jul 5, 2024
1 parent 9562322 commit 0659254
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
16 changes: 9 additions & 7 deletions src/nfpcapd/packet_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,14 @@ void __attribute__((noreturn)) * bpf_packet_thread(void *args) {

size_t size = sizeof(struct pcap_sf_pkthdr) + hdr->bh_caplen;
u_char *data = (u_char *)(p + hdr->bh_hdrlen);
if (DoPacketDump) {
struct pcap_pkthdr phdr = {//
.ts.tv_sec = hdr->bh_tstamp.tv_sec,
.ts.tv_usec = hdr->bh_tstamp.tv_usec,
.caplen = hdr->bh_caplen,
.len = hdr->bh_datalen};
int ok = ProcessPacket(packetParam, &phdr, data);

if (DoPacketDump && ok) {
if ((packetBuffer->bufferSize + size) > BUFFSIZE) {
packetBuffer->timeStamp = 0;
dbg_printf("packet_thread() flush buffer - size %zu\n", packetBuffer->bufferSize);
Expand All @@ -336,12 +343,7 @@ void __attribute__((noreturn)) * bpf_packet_thread(void *args) {
}
PcapDump(packetBuffer, hdr, data);
}
struct pcap_pkthdr phdr;
phdr.ts.tv_sec = hdr->bh_tstamp.tv_sec;
phdr.ts.tv_usec = hdr->bh_tstamp.tv_usec;
phdr.caplen = hdr->bh_caplen;
phdr.len = hdr->bh_datalen;
ProcessPacket(packetParam, &phdr, data);

p += BPF_WORDALIGN(hdr->bh_hdrlen + hdr->bh_caplen);
}
done = done || *(packetParam->done);
Expand Down
18 changes: 10 additions & 8 deletions src/nfpcapd/packet_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,16 @@ void __attribute__((noreturn)) * linux_packet_thread(void *args) {
t_start = t_packet - (t_packet % t_win);
}

struct pcap_pkthdr phdr = {//
.ts.tv_sec = ppd->tp_sec,
.ts.tv_usec = ppd->tp_nsec / 1000,
.caplen = ppd->tp_snaplen,
.len = ppd->tp_len};
void *data = (void *)ppd + ppd->tp_mac;
int ok = ProcessPacket(packetParam, &phdr, data);

size_t size = sizeof(struct pcap_sf_pkthdr) + ppd->tp_len;
if (DoPacketDump) {
if (DoPacketDump && ok) {
if ((packetBuffer->bufferSize + size) > BUFFSIZE) {
packetBuffer->timeStamp = 0;
dbg_printf("packet_thread() flush buffer - size %zu\n", packetBuffer->bufferSize);
Expand All @@ -334,13 +342,7 @@ void __attribute__((noreturn)) * linux_packet_thread(void *args) {
}
PcapDump(packetBuffer, ppd);
}
struct pcap_pkthdr phdr;
phdr.ts.tv_sec = ppd->tp_sec;
phdr.ts.tv_usec = ppd->tp_nsec / 1000;
phdr.caplen = ppd->tp_snaplen;
phdr.len = ppd->tp_len;
void *data = (void *)ppd + ppd->tp_mac;
ProcessPacket(packetParam, &phdr, data);

ppd = (struct tpacket3_hdr *)((uint8_t *)ppd + ppd->tp_next_offset);
}
done = done || *(packetParam->done);
Expand Down
4 changes: 2 additions & 2 deletions src/nfpcapd/packet_pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,9 @@ void __attribute__((noreturn)) * pcap_packet_thread(void *args) {
t_start = t_packet - (t_packet % t_win);
}

int ok = ProcessPacket(packetParam, hdr, data);
size_t size = sizeof(struct pcap_sf_pkthdr) + hdr->caplen;
if (DoPacketDump) {
if (DoPacketDump && ok) {
if ((packetBuffer->bufferSize + size) > BUFFSIZE) {
packetBuffer->timeStamp = 0;
dbg_printf("packet_thread() flush buffer - size %zu\n", packetBuffer->bufferSize);
Expand All @@ -290,7 +291,6 @@ void __attribute__((noreturn)) * pcap_packet_thread(void *args) {
}
PcapDump(packetBuffer, hdr, data);
}
ProcessPacket(packetParam, hdr, data);
} break;
case 0: {
// live capture idle cycle
Expand Down

0 comments on commit 0659254

Please sign in to comment.