Skip to content

Commit

Permalink
ebpf: print a user-friendly error if kernel <4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
iaguis committed Mar 2, 2017
1 parent b33a13d commit 0fc6511
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions probe/endpoint/ebpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package endpoint

import (
"errors"
"fmt"
"regexp"
"strconv"
"sync"

log "github.com/Sirupsen/logrus"
"github.com/weaveworks/scope/probe/endpoint/procspy"
"github.com/weaveworks/scope/probe/host"
"github.com/weaveworks/tcptracer-bpf/pkg/tracer"
)

Expand Down Expand Up @@ -40,11 +43,49 @@ type EbpfTracker struct {
closedConnections []ebpfConnection
}

var releaseRegex = regexp.MustCompile(`^(\d+)\.(\d+).*$`)

func isKernelSupported() error {
release, _, err := host.GetKernelReleaseAndVersion()
if err != nil {
return err
}

releaseParts := releaseRegex.FindStringSubmatch(release)
if len(releaseParts) != 3 {
return fmt.Errorf("got invalid release version %q (expected format '4.4[.2-1]')", release)
}

major, err := strconv.Atoi(releaseParts[1])
if err != nil {
return err
}

minor, err := strconv.Atoi(releaseParts[2])
if err != nil {
return err
}

if major > 4 {
return nil
}

if major < 4 || minor < 4 {
return fmt.Errorf("got kernel %s but need kernel >=4.4", release)
}

return nil
}

func newEbpfTracker(useEbpfConn bool) (eventTracker, error) {
if !useEbpfConn {
return nil, errors.New("ebpf tracker not enabled")
}

if err := isKernelSupported(); err != nil {
return nil, fmt.Errorf("kernel not supported: %v", err)
}

t, err := tracer.NewTracer(tcpEventCbV4, tcpEventCbV6)
if err != nil {
return nil, err
Expand Down

0 comments on commit 0fc6511

Please sign in to comment.