Skip to content

Commit

Permalink
usm: sowatcher: Encapsulate probes initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
guyarb committed Dec 23, 2024
1 parent 725df4c commit 219e943
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pkg/network/usm/sharedlibraries/ebpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ type EbpfProgram struct {
// otherwise used to check if the program needs to be stopped and re-started
// when adding new libsets
isInitialized bool

// enabledProbes is a list of the probes that are enabled for the current system.
enabledProbes []manager.ProbeIdentificationPair
// disabledProbes is a list of the probes that are disabled for the current system.
disabledProbes []manager.ProbeIdentificationPair
}

// IsSupported returns true if the shared libraries monitoring is supported on the current system.
Expand Down Expand Up @@ -201,8 +206,8 @@ func (e *EbpfProgram) setupManagerAndPerfHandlers() {
handler.perfHandler = perfHandler
}

probeIDs := getSysOpenHooksIdentifiers()
for _, identifier := range probeIDs {
e.initializeProbes()
for _, identifier := range e.enabledProbes {
mgr.Probes = append(mgr.Probes,
&manager.Probe{
ProbeIdentificationPair: identifier,
Expand Down Expand Up @@ -485,13 +490,16 @@ func (e *EbpfProgram) stopImpl() {
func (e *EbpfProgram) init(buf bytecode.AssetReader, options manager.Options) error {
options.RemoveRlimit = true

for _, probe := range e.Probes {
for _, probe := range e.enabledProbes {
options.ActivatedProbes = append(options.ActivatedProbes,
&manager.ProbeSelector{
ProbeIdentificationPair: probe.ProbeIdentificationPair,
ProbeIdentificationPair: probe,
},
)
}
for _, probe := range e.disabledProbes {
options.ExcludedFunctions = append(options.ExcludedFunctions, probe.EBPFFuncName)
}

var enabledMsgs []string
for libset := range LibsetToLibSuffixes {
Expand Down Expand Up @@ -581,9 +589,8 @@ func fexitSupported(funcName string) bool {
return true
}

// getSysOpenHooksIdentifiers returns the enter and exit tracepoints for supported open*
// system calls.
func getSysOpenHooksIdentifiers() []manager.ProbeIdentificationPair {
// initializedProbes initializes the probes that are enabled for the current system
func (e *EbpfProgram) initializeProbes() {
openatProbes := []string{openatSysCall}
// amd64 has open(2), arm64 doesn't
if runtime.GOARCH == "amd64" {
Expand All @@ -606,7 +613,8 @@ func getSysOpenHooksIdentifiers() []manager.ProbeIdentificationPair {
UID: probeUID,
})
}
return res

e.enabledProbes = res
}

func getAssetName(module string, debug bool) string {
Expand Down

0 comments on commit 219e943

Please sign in to comment.