Skip to content

Commit

Permalink
Better ebpf module errors
Browse files Browse the repository at this point in the history
Report to the GUI and the logs, whether the modules have been found
or not, and if found, whether there have been any errors loading them.

Closes #868
  • Loading branch information
gustavo-iniguez-goya committed Jul 23, 2023
1 parent cb4d82f commit 662cd2e
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions daemon/core/ebpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,29 @@ func LoadEbpfModule(module string) (m *elf.Module, err error) {
paths = []string{
fmt.Sprint("/usr/local/lib", modulesDir),
fmt.Sprint("/usr/lib", modulesDir),
fmt.Sprint("/etc/opensnitchd"), // deprecated
fmt.Sprint("/etc/opensnitchd"), // Deprecated: will be removed in future versions.
}
)
modulesPath := ""
modulePath := ""
moduleError := fmt.Errorf(`Module not found (%s) in any of the paths.
You may need to install the corresponding package`, module)

for _, p := range paths {
modulesPath = p
m = elf.NewModule(fmt.Sprint(modulesPath, "/", module))
modulePath = fmt.Sprint(p, "/", module)
log.Debug("[eBPF] trying to load %s", modulePath)
if !Exists(modulePath) {
continue
}
m = elf.NewModule(modulePath)

if err = m.Load(nil); err == nil {
log.Info("[eBPF] module loaded: %s/%s", modulesPath, module)
if m.Load(nil) == nil {
log.Info("[eBPF] module loaded: %s", modulePath)
return m, nil
}
log.Debug("ebpf module not found: %s, %s/%s", err, modulesPath, module)
}

return m, fmt.Errorf(`
moduleError = fmt.Errorf(`
unable to load eBPF module (%s). Your kernel version (%s) might not be compatible.
If this error persists, change process monitor method to 'proc'`, module, GetKernelVersion())
}

return m, moduleError
}

0 comments on commit 662cd2e

Please sign in to comment.