Skip to content

Commit b10e7db

Browse files
authored
Added event containing full payload for all packets (#4122)
1 parent d83c07b commit b10e7db

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

pkg/ebpf/c/common/network.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,17 @@ typedef struct nethdrs_t {
9898

9999
typedef enum net_packet {
100100
CAP_NET_PACKET = 1 << 0,
101+
SUB_NET_PACKET_RAW = 1 << 1,
101102
// Layer 3
102-
SUB_NET_PACKET_IP = 1 << 1,
103+
SUB_NET_PACKET_IP = 1 << 2,
103104
// Layer 4
104-
SUB_NET_PACKET_TCP = 1 << 2,
105-
SUB_NET_PACKET_UDP = 1 << 3,
106-
SUB_NET_PACKET_ICMP = 1 << 4,
107-
SUB_NET_PACKET_ICMPV6 = 1 << 5,
105+
SUB_NET_PACKET_TCP = 1 << 3,
106+
SUB_NET_PACKET_UDP = 1 << 4,
107+
SUB_NET_PACKET_ICMP = 1 << 5,
108+
SUB_NET_PACKET_ICMPV6 = 1 << 6,
108109
// Layer 7
109-
SUB_NET_PACKET_DNS = 1 << 6,
110-
SUB_NET_PACKET_HTTP = 1 << 7,
110+
SUB_NET_PACKET_DNS = 1 << 7,
111+
SUB_NET_PACKET_HTTP = 1 << 8,
111112
} net_packet_t;
112113

113114
typedef struct net_event_contextmd {

pkg/ebpf/c/tracee.bpf.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5238,6 +5238,8 @@ statfunc enum event_id_e net_packet_to_net_event(net_packet_t packet_type)
52385238
case CAP_NET_PACKET:
52395239
return NET_CAPTURE_BASE;
52405240
// Packets
5241+
case SUB_NET_PACKET_RAW:
5242+
return NET_PACKET_RAW;
52415243
case SUB_NET_PACKET_IP:
52425244
return NET_PACKET_IP;
52435245
case SUB_NET_PACKET_TCP:
@@ -6201,7 +6203,10 @@ CGROUP_SKB_HANDLE_FUNCTION(proto)
62016203
if (!dest)
62026204
return 1; // satisfy verifier for clang-12 generated binaries
62036205

6204-
// fastpath: submit the IP base event
6206+
// fastpath: submit the raw packet and IP base events
6207+
6208+
if (should_submit_net_event(neteventctx, SUB_NET_PACKET_RAW))
6209+
cgroup_skb_submit_event(ctx, neteventctx, NET_PACKET_RAW, FULL);
62056210

62066211
if (should_submit_net_event(neteventctx, SUB_NET_PACKET_IP))
62076212
cgroup_skb_submit_event(ctx, neteventctx, NET_PACKET_IP, HEADERS);

pkg/ebpf/c/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ enum event_id_e
4242
{
4343
// Net events IDs
4444
NET_PACKET_BASE = 700,
45+
NET_PACKET_RAW,
4546
NET_PACKET_IP,
4647
NET_PACKET_TCP,
4748
NET_PACKET_UDP,

pkg/events/core.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type ID int32
2525
// Common events (used by all architectures).
2626
const (
2727
NetPacketBase ID = iota + 700
28+
NetPacketRaw
2829
NetPacketIPBase
2930
NetPacketTCPBase
3031
NetPacketUDPBase
@@ -13236,6 +13237,21 @@ var CoreEvents = map[ID]Definition{
1323613237
sets: []string{"network_events"},
1323713238
params: []trace.ArgMeta{},
1323813239
},
13240+
NetPacketRaw: {
13241+
id: NetPacketRaw,
13242+
id32Bit: Sys32Undefined,
13243+
name: "net_packet_raw",
13244+
version: NewVersion(1, 0, 0),
13245+
dependencies: Dependencies{
13246+
ids: []ID{
13247+
NetPacketBase,
13248+
},
13249+
},
13250+
sets: []string{"packets"},
13251+
params: []trace.ArgMeta{
13252+
{Type: "bytes", Name: "data"},
13253+
},
13254+
},
1323913255
NetPacketIPBase: {
1324013256
id: NetPacketIPBase,
1324113257
id32Bit: Sys32Undefined,

0 commit comments

Comments
 (0)