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

[USMON-1319] usm: Add raw tracepoint for netif_receive_skb #32496

Merged
merged 2 commits into from
Dec 26, 2024
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
8 changes: 8 additions & 0 deletions pkg/network/ebpf/c/protocols/flush.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ int tracepoint__net__netif_receive_skb(void *ctx) {
return 0;
}

SEC("raw_tracepoint/net/netif_receive_skb")
int BPF_PROG(raw_tracepoint__net__netif_receive_skb) {
CHECK_BPF_PROGRAM_BYPASSED()
log_debug("raw_tracepoint/net/netif_receive_skb");
flush(ctx);
return 0;
}

#endif
38 changes: 31 additions & 7 deletions pkg/network/usm/ebpf_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import (
"slices"
"unsafe"

manager "github.com/DataDog/ebpf-manager"
"github.com/cilium/ebpf"
"github.com/cilium/ebpf/features"
"github.com/davecgh/go-spew/spew"

manager "github.com/DataDog/ebpf-manager"

ddebpf "github.com/DataDog/datadog-agent/pkg/ebpf"
"github.com/DataDog/datadog-agent/pkg/ebpf/bytecode"
"github.com/DataDog/datadog-agent/pkg/ebpf/prebuilt"
Expand Down Expand Up @@ -67,6 +69,9 @@ const (
sockFDLookup = "kprobe__sockfd_lookup_light"
sockFDLookupRet = "kretprobe__sockfd_lookup_light"

netifReceiveSkbTp = "tracepoint__net__netif_receive_skb"
netifReceiveSkbRawTp = "raw_tracepoint__net__netif_receive_skb"

tcpCloseProbe = "kprobe__tcp_close"

// maxActive configures the maximum number of instances of the
Expand All @@ -90,6 +95,23 @@ type ebpfProgram struct {
}

func newEBPFProgram(c *config.Config, connectionProtocolMap *ebpf.Map) (*ebpfProgram, error) {
netifProbe := manager.Probe{
ProbeIdentificationPair: manager.ProbeIdentificationPair{
EBPFFuncName: netifReceiveSkbTp,
UID: probeUID,
},
}
if features.HaveProgramType(ebpf.RawTracepoint) == nil {
netifProbe = manager.Probe{
ProbeIdentificationPair: manager.ProbeIdentificationPair{
EBPFFuncName: netifReceiveSkbRawTp,
UID: probeUID,
},
TracepointCategory: "net",
TracepointName: "netif_receive_skb",
}
}

mgr := &manager.Manager{
Maps: []*manager.Map{
{Name: protocols.TLSDispatcherProgramsMap},
Expand All @@ -114,12 +136,7 @@ func newEBPFProgram(c *config.Config, connectionProtocolMap *ebpf.Map) (*ebpfPro
UID: probeUID,
},
},
{
ProbeIdentificationPair: manager.ProbeIdentificationPair{
EBPFFuncName: "tracepoint__net__netif_receive_skb",
UID: probeUID,
},
},
&netifProbe,
{
ProbeIdentificationPair: manager.ProbeIdentificationPair{
EBPFFuncName: protocolDispatcherSocketFilterFunction,
Expand Down Expand Up @@ -462,6 +479,13 @@ func (e *ebpfProgram) init(buf bytecode.AssetReader, options manager.Options) er
}
}

// exclude unused netif_receive_skb probe
if features.HaveProgramType(ebpf.RawTracepoint) == nil {
options.ExcludedFunctions = append(options.ExcludedFunctions, netifReceiveSkbTp)
} else {
options.ExcludedFunctions = append(options.ExcludedFunctions, netifReceiveSkbRawTp)
}

err := e.InitWithOptions(buf, &options)
if err != nil {
cleanup()
Expand Down
Loading