Skip to content

Commit

Permalink
io-backend-pcap: Work around a problem with Debian stable pcap / kern…
Browse files Browse the repository at this point in the history
…el combo

- Reading packets is unreliable and incredibly jittery when TPACKET_V3
  support is on. (Maybe due to
  the-tcpdump-group/libpcap#380). Use a hack
  to force pcap to use TPACKET_V2 instead.
  • Loading branch information
jsnell committed Oct 10, 2015
1 parent a534367 commit 3376d04
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/io-backend-pcap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class IoBackendPcap : public IoBackend {
PCAP(pcap_, pcap_set_snaplen(pcap_, snaplen));
PCAP(pcap_, pcap_set_timeout(pcap_, 0));
PCAP(pcap_, pcap_set_promisc(pcap_, 1));
// pcap's TPACKET_V3 support doesn't work well in Linux <
// 3.19, packet delivery is unreliable and jittery. Luckily
// asking for unbuffered packet delivery makes it fall back to
// TPACKET_V2.
PCAP(pcap_, pcap_set_immediate_mode(pcap_, 1));

// 8MB buffer size. Not a totally arbitrary number. The assumptions:
//
Expand All @@ -61,7 +66,6 @@ class IoBackendPcap : public IoBackend {
PCAP(pcap_, pcap_set_buffer_size(pcap_, 8*1024*1024));
PCAP(pcap_, pcap_activate(pcap_));
PCAP(pcap_, pcap_setnonblock(pcap_, 1, errbuf));
PCAP(pcap_, pcap_setnonblock(pcap_, 1, errbuf));

return true;
}
Expand All @@ -72,7 +76,7 @@ class IoBackendPcap : public IoBackend {
}

virtual bool inject(Packet* p) {
return pcap_inject(pcap_, (char*) p->ethh_, p->length_);
return pcap_inject(pcap_, (char*) p->ethh_, p->length_) == p->length_;
}

virtual bool receive(Packet* p) {
Expand Down

0 comments on commit 3376d04

Please sign in to comment.