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

Create a proper ICMP only BPF filter #759

Merged
merged 1 commit into from
Jan 19, 2016
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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ https://github.com/elastic/beats/compare/1.0.0...master[Check the HEAD diff]
*Packetbeat*
- Fix setting direction to out and use its value to decide when dropping events if ignore_outgoing is enabled {pull}557[557]
- Allow PF_RING sniffer type to be configured using pf_ring or pfring {pull}671[671]
- Create a proper BPF filter when ICMP is the only enabled protocol {issue}757[757]

*Topbeat*

Expand Down
5 changes: 3 additions & 2 deletions packetbeat/protos/protos.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,11 @@ func (protocols ProtocolsStruct) BpfFilter(with_vlans bool, with_icmp bool) stri
}
}

filter := strings.Join(expressions, " or ")
if with_icmp {
filter = fmt.Sprintf("%s or icmp or icmp6", filter)
expressions = append(expressions, "icmp", "icmp6")
}

filter := strings.Join(expressions, " or ")
if with_vlans {
filter = fmt.Sprintf("%s or (vlan and (%s))", filter, filter)
}
Expand Down
10 changes: 10 additions & 0 deletions packetbeat/protos/protos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ func newProtocols() Protocols {
return p
}

func TestBpfFilterWithoutVlanOnlyIcmp(t *testing.T) {
p := ProtocolsStruct{}
p.all = make(map[Protocol]ProtocolPlugin)
p.tcp = make(map[Protocol]TcpProtocolPlugin)
p.udp = make(map[Protocol]UdpProtocolPlugin)

filter := p.BpfFilter(false, true)
assert.Equal(t, "icmp or icmp6", filter)
}

func TestBpfFilterWithoutVlanWithoutIcmp(t *testing.T) {
p := newProtocols()
filter := p.BpfFilter(false, false)
Expand Down