Skip to content

Commit

Permalink
feat(bpf): add constants for direction and protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
nullswan committed Sep 22, 2024
1 parent a731f74 commit 8d7dc63
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions bpf/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
#include <bpf/bpf_endian.h>
#include <bpf/bpf_core_read.h>

#define DIRECTION_INBOUND 0
#define DIRECTION_OUTBOUND 1

#define PROTOCOL_TCP 6
#define PROTOCOL_UDP 17

static inline int is_local_ip(__be32 ip);

struct {
Expand Down
8 changes: 4 additions & 4 deletions bpf/kprobe/trace_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ int trace_tcp_recvmsg(struct tcp_recvmsg_args *ctx) {
e.sport = sport;
e.dport = dport;
e.size = size;
e.direction = 0;
e.protocol = 6;
e.direction = DIRECTION_INBOUND;
e.protocol = PROTOCOL_TCP;

bpf_ringbuf_output(&network_events_rb, &e, sizeof(e), BPF_RB_FORCE_WAKEUP);
return 0;
Expand Down Expand Up @@ -99,8 +99,8 @@ int trace_tcp_sendmsg(struct tcp_sendmsg_args *ctx) {
e.sport = sport;
e.dport = dport;
e.size = size;
e.direction = 1;
e.protocol = 6;
e.direction = DIRECTION_OUTBOUND;
e.protocol = PROTOCOL_TCP;

bpf_ringbuf_output(&network_events_rb, &e, sizeof(e), BPF_RB_FORCE_WAKEUP);
return 0;
Expand Down
8 changes: 4 additions & 4 deletions bpf/kprobe/trace_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ int trace_udp_recvmsg(struct udp_recvmsg_args *ctx) {
e.sport = sport;
e.dport = dport;
e.size = size;
e.direction = 0;
e.protocol = 17;
e.direction = DIRECTION_INBOUND;
e.protocol = PROTOCOL_UDP;

bpf_ringbuf_output(&network_events_rb, &e, sizeof(e), BPF_RB_FORCE_WAKEUP);
return 0;
Expand Down Expand Up @@ -92,8 +92,8 @@ int trace_udp_sendmsg(struct udp_sendmsg_args *ctx) {
}

struct network_event e = {};
e.direction = 1;
e.protocol = 17;
e.direction = DIRECTION_OUTBOUND;
e.protocol = PROTOCOL_UDP;
e.pid = pid;
e.cgroup_id = cgroup_id;
e.saddr = saddr;
Expand Down

0 comments on commit 8d7dc63

Please sign in to comment.