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

[8.1](backport #30509) packetbeat/beater: don't attempt to install npcap when already installed #30511

Merged
merged 1 commit into from
Feb 22, 2022
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
2 changes: 1 addition & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ https:/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

*Packetbeat*

- Add automated OEM Npcap installation handling. {pull}29112[29112] {pull}30438[30438]
- Add automated OEM Npcap installation handling. {pull}29112[29112] {pull}30438[30438] {pull}30493[30493]
- Add support for capturing TLS random number and OCSP status request details. {issue}29962[29962] {pull}30102[30102]

*Functionbeat*
Expand Down
3 changes: 3 additions & 0 deletions packetbeat/beater/install_npcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func installNpcap(b *beat.Beat) error {
log.Infof("npcap version: %s", npcapVersion)
}
}()
if !npcap.Upgradeable() {
return nil
}

ctx, cancel := context.WithTimeout(context.Background(), installTimeout)
defer cancel()
Expand Down
14 changes: 13 additions & 1 deletion packetbeat/npcap/npcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ func Install(ctx context.Context, log *logp.Logger, path, dst string, compat boo
}

func install(ctx context.Context, log *logp.Logger, path, dst string, compat bool) error {
if pcap.Version() != "" {
// If we are here there is a runtime Npcap DLL loaded. We need to
// unload this to prevent the application being killed during the
// install.
//
// See https://npcap.com/guide/npcap-users-guide.html#npcap-installation-uninstall-options.
err := unloadWinPCAP()
if err != nil {
return fmt.Errorf("npcap: failed to unload Npcap DLL: %w", err)
}
}

args := []string{"/S", "/winpcap_mode=no"}
if compat {
args[1] = "/winpcap_mode=yes"
Expand Down Expand Up @@ -96,7 +108,7 @@ func install(ctx context.Context, log *logp.Logger, path, dst string, compat boo
return fmt.Errorf("npcap: failed to install Npcap: %w", err)
}

return reloadWinPCAP()
return loadWinPCAP()
}

func Upgradeable() bool {
Expand Down
2 changes: 1 addition & 1 deletion packetbeat/npcap/npcap_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ package npcap

func loadWinPCAP() error { return nil }

func reloadWinPCAP() error { return nil }
func unloadWinPCAP() error { return nil }
8 changes: 1 addition & 7 deletions packetbeat/npcap/npcap_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,4 @@ import "github.com/google/gopacket/pcap"

func loadWinPCAP() error { return pcap.LoadWinPCAP() }

func reloadWinPCAP() error {
err := pcap.UnloadWinPCAP()
if err != nil {
return err
}
return pcap.LoadWinPCAP()
}
func unloadWinPCAP() error { return pcap.UnloadWinPCAP() }