Filter outbound packets in the kernel

It turns out that under Linux, libpcap implements the SetDirection
filtering in userspace, causing some spurious wake ups of the packet
capture thread.  So set a BPF filter to discard outbound packets inside
the kernel.
This commit is contained in:
David Wragg committed 2014-09-17 23:42:48 +01:00
1 parent ce1d40afb8
commit 12b969004e
1 file changed
+13 -3
+13 -3
View File
@@ -8,9 +8,19 @@ type PcapIO struct {
handle *pcap.Handle
}
func NewPcapIO(ifName string, bufSz int) (pio PacketSourceSink, err error) {
pio, err = newPcapIO(ifName, true, 65535, bufSz)
return
func NewPcapIO(ifName string, bufSz int) (PacketSourceSink, error) {
pio, err := newPcapIO(ifName, true, 65535, bufSz)
if err != nil {
return pio, err
}
// Under Linux, libpcap implements the SetDirection filtering
// in userspace. So set a BPF filter to discard outbound
// packets inside the kernel. We do this here rather than in
// newPcapIO because libpcap doesn't like this in combination
// with a 0 snaplen.
err = pio.handle.SetBPFFilter("inbound")
return pio, err
}
func NewPcapO(ifName string) (po PacketSink, err error) {