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

packetbeat/beater: deduplicate interface configs #36576

Merged
merged 1 commit into from
Sep 21, 2023
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.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]

*Packetbeat*

- Improve efficiency of sniffers by deduplicating interface configurations. {issue}36574[36574] {pull}36576[36576]

*Winlogbeat*

Expand Down
23 changes: 20 additions & 3 deletions packetbeat/beater/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,31 @@ func setupSniffer(id string, cfg config.Config, protocols *protos.ProtocolsStruc
return nil, err
}

for i, iface := range cfg.Interfaces {
// Ensure interfaces are uniquely represented so we don't listen on the
// same interface with multiple sniffers.
interfaces := make([]config.InterfaceConfig, 0, len(cfg.Interfaces))
seen := make(map[uint64]bool)
for _, iface := range cfg.Interfaces {
// Currently we hash on all fields in the config. We can revise this in future.
h, err := hashstructure.Hash(iface, nil)
if err != nil {
return nil, fmt.Errorf("could not deduplicate interface configurations: %w", err)
}
if seen[h] {
continue
}
seen[h] = true
interfaces = append(interfaces, iface)
}

for i, iface := range interfaces {
if iface.BpfFilter != "" || cfg.Flows.IsEnabled() {
continue
}
cfg.Interfaces[i].BpfFilter = protocols.BpfFilter(iface.WithVlans, icmp.Enabled())
interfaces[i].BpfFilter = protocols.BpfFilter(iface.WithVlans, icmp.Enabled())
}

return sniffer.New(id, false, "", decoders, cfg.Interfaces)
return sniffer.New(id, false, "", decoders, interfaces)
}

// CheckConfig performs a dry-run creation of a Packetbeat pipeline based
Expand Down