Skip to content

Commit

Permalink
clean ebpf folder
Browse files Browse the repository at this point in the history
  • Loading branch information
orishavit committed Aug 28, 2024
1 parent 27cece8 commit a10cd0b
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 62 deletions.
8 changes: 7 additions & 1 deletion build/agent.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ FROM golang:1.22.1 AS ebpf-buildenv
RUN apt-get update
RUN apt-get install -y clang libelf-dev libbpf-dev

COPY . /src/
WORKDIR /src

COPY go.mod go.sum ./
RUN --mount=type=cache,target="/root/.cache/go-build" <<EOR
set -ex
go mod download
EOR

COPY . /src/

RUN --mount=type=cache,target="/root/.cache/go-build" <<EOR
set -ex
go generate -tags ebpf ./ebpf/...
EOR

Expand Down
12 changes: 12 additions & 0 deletions src/ebpf/include/headers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifdef TARGET_ARCH_amd64
#include "vmlinux_x86_64.h"
#endif

#ifdef TARGET_ARCH_arm64
#include "vmlinux_aarch64.h"
#endif

#include <bpf/bpf_tracing.h>
#include <bpf/bpf_endian.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>
47 changes: 47 additions & 0 deletions src/ebpf/include/maps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const __u32 MAX_SIZE = 4096;
const __u32 MAX_ENTRIES_HASH = 4096;

struct ssl_event_meta_t {
__u32 pid;
__u64 timestamp;
__u32 dataSize;
};

struct ssl_event_t {
struct ssl_event_meta_t meta;
__u8 data[MAX_SIZE];
};

struct ssl_context_t {
__u64 size;
__u64 buffer;
};

struct target_t {
_Bool enabled;
};

struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 1024);
__type(key, __u64);
__type(value, struct ssl_context_t);
} ssl_contexts SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__type(key, __u32);
__type(value, struct ssl_event_t);
__uint(max_entries, 1);
} ssl_event SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
} ssl_events SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, MAX_ENTRIES_HASH);
__type(key, __u32);
__type(value, struct target_t);
} targets SEC(".maps");
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ebpf/openssl/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

package openssl

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -target $GOARCH -cc clang -no-strip -cflags "-O2 -g -Wall" openssl ./openssl.ebpf.c -- -I.:/usr/include/bpf:/usr/include/linux -DTARGET_ARCH_$GOARCH
//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -target $GOARCH -cc clang -no-strip -cflags "-O2 -g -Wall" openssl ./openssl.ebpf.c -- -I.:/usr/include/bpf:/usr/include/linux -I/src/ebpf/include -DTARGET_ARCH_$GOARCH
62 changes: 2 additions & 60 deletions src/ebpf/openssl/openssl.ebpf.c
Original file line number Diff line number Diff line change
@@ -1,65 +1,7 @@
//go:build ignore

#ifdef TARGET_ARCH_amd64
#include "vmlinux_x86_64.h"
#endif

#ifdef TARGET_ARCH_arm64
#include "vmlinux_aarch64.h"
#endif

#include <bpf/bpf_tracing.h>
#include <bpf/bpf_endian.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>

const __u32 MAX_SIZE = 4096;
const __u32 MAX_ENTRIES_HASH = 4096;

struct ssl_event_meta_t {
__u32 pid;
__u64 timestamp;
__u32 dataSize;
};

struct ssl_event_t {
struct ssl_event_meta_t meta;
__u8 data[MAX_SIZE];
};

struct ssl_context_t {
__u64 size;
__u64 buffer;
};

struct target_t {
_Bool enabled;
};

struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 1024);
__type(key, __u64);
__type(value, struct ssl_context_t);
} ssl_contexts SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__type(key, __u32);
__type(value, struct ssl_event_t);
__uint(max_entries, 1);
} ssl_event SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
} ssl_events SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, MAX_ENTRIES_HASH);
__type(key, __u32);
__type(value, struct target_t);
} targets SEC(".maps");
#include "headers.h"
#include "maps.h"

int shouldTrace() {
// gets the current (real) PID
Expand Down

0 comments on commit a10cd0b

Please sign in to comment.