From a727ade00608b526f0388e9d60c21705136be75c Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Tue, 6 Jul 2021 19:13:48 +0300 Subject: [PATCH] Fix BPF filter when listen on all interfaces It was caching bpf filter of first interface --- capture/capture.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/capture/capture.go b/capture/capture.go index 074c24d2..93fb6683 100644 --- a/capture/capture.go +++ b/capture/capture.go @@ -284,14 +284,16 @@ func (l *Listener) PcapHandle(ifi pcap.Interface) (handle *pcap.Handle, err erro if err != nil { return nil, fmt.Errorf("PCAP Activate device error: %q, interface: %q", err, ifi.Name) } - if l.BPFFilter == "" { - l.BPFFilter = l.Filter(ifi) + + bpfFilter := l.BPFFilter + if bpfFilter == "" { + bpfFilter = l.Filter(ifi) } - fmt.Println("Interface:", ifi.Name, ". BPF Filter:", l.BPFFilter) - err = handle.SetBPFFilter(l.BPFFilter) + fmt.Println("Interface:", ifi.Name, ". BPF Filter:", bpfFilter) + err = handle.SetBPFFilter(bpfFilter) if err != nil { handle.Close() - return nil, fmt.Errorf("BPF filter error: %q%s, interface: %q", err, l.BPFFilter, ifi.Name) + return nil, fmt.Errorf("BPF filter error: %q%s, interface: %q", err, bpfFilter, ifi.Name) } return }