Skip to content

Commit

Permalink
Update contents
Browse files Browse the repository at this point in the history
  • Loading branch information
feiskyer committed Dec 14, 2024
1 parent 79ce995 commit fe1dfe8
Show file tree
Hide file tree
Showing 38 changed files with 188,248 additions and 175,633 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ bpf-apps/xdppass
bpf-apps/http_trace
bpf-apps/https_trace
bpf-apps/https_trace_bad
bpf-apps/xdp_drop_test

# Debug files
*.dSYM/
Expand Down
2 changes: 1 addition & 1 deletion bcc-apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ sudo yum install bcc-tools bcc-devel
Please follow [INSTALL.md](https://github.com/iovisor/bcc/blob/master/INSTALL.md#source) to see the detailed guides. For example, on Ubuntu 20.04+:

```sh
sudo apt install -y bison build-essential cmake flex git libedit-dev llvm-dev libclang-dev python zlib1g-dev libelf-dev libfl-dev python3-distutils
sudo apt install -y bison build-essential cmake flex git libedit-dev llvm-dev libclang-dev python3 zlib1g-dev libelf-dev libfl-dev python3-setuptools libpolly-18-dev

git clone https://github.com/iovisor/bcc.git
mkdir bcc/build; cd bcc/build
Expand Down
4 changes: 2 additions & 2 deletions bpf-apps/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APPS = hello execsnoop execsnoop_v2 bashreadline hello_btf block_shell xdppass tc_block_tcp http_trace https_trace https_trace_bad
APPS = hello execsnoop execsnoop_v2 bashreadline hello_btf block_shell xdppass tc_block_tcp http_trace https_trace https_trace_bad xdp_drop_test
bpftool = $(shell which bpftool || ../tools/bpftool)
LIBBPF_SRC := $(abspath ../libbpf/src)
LIBBPF_OBJ := $(abspath libbpf/libbpf.a)
Expand All @@ -11,7 +11,7 @@ $(APPS): %: %.bpf.c %.c $(LIBBPF_OBJ) $(wildcard %.h)
clang -g -O2 -target bpf -D__TARGET_ARCH_x86 $(INCLUDES) -c $@.bpf.c -o $@.bpf.o
$(bpftool) gen skeleton $@.bpf.o > $@.skel.h
clang -g -O2 -Wall $(INCLUDES) -c $@.c -o $@.o
clang -Wall -O2 -g $@.o -static $(LIBBPF_OBJ) -lelf -lz -o $@
clang -Wall -O2 -g $@.o -static $(LIBBPF_OBJ) -lelf -lz -lzstd -o $@

vmlinux:
$(bpftool) btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h
Expand Down
3 changes: 2 additions & 1 deletion bpf-apps/bashreadline.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__uint(key_size, sizeof(__u32));
__uint(value_size, sizeof(__u32));
} events SEC(".maps");
}
events SEC(".maps");

SEC("uretprobe/readline")
int BPF_KRETPROBE(printret, const void *ret)
Expand Down
502 changes: 239 additions & 263 deletions bpf-apps/bashreadline.skel.h

Large diffs are not rendered by default.

69,266 changes: 35,160 additions & 34,106 deletions bpf-apps/block_shell.skel.h

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions bpf-apps/execsnoop.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__uint(key_size, sizeof(u32));
__uint(value_size, sizeof(u32));
}
events SEC(".maps");
} events SEC(".maps");

// tracepoint for sys_enter_execve.
SEC("tracepoint/syscalls/sys_enter_execve")
Expand Down
3,968 changes: 1,976 additions & 1,992 deletions bpf-apps/execsnoop.skel.h

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion bpf-apps/execsnoop_v2.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__uint(key_size, sizeof(u32));
__uint(value_size, sizeof(u32));
} events SEC(".maps");
}
events SEC(".maps");

static __always_inline bool valid_uid(uid_t uid)
{
Expand Down
71,093 changes: 36,081 additions & 35,012 deletions bpf-apps/execsnoop_v2.skel.h

Large diffs are not rendered by default.

490 changes: 234 additions & 256 deletions bpf-apps/hello.skel.h

Large diffs are not rendered by default.

519 changes: 247 additions & 272 deletions bpf-apps/hello_btf.skel.h

Large diffs are not rendered by default.

1,501 changes: 738 additions & 763 deletions bpf-apps/http_trace.skel.h

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions bpf-apps/https_trace.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ struct {
__uint(key_size, sizeof(__u32));
__uint(value_size, sizeof(__u32));
__uint(max_entries, 1024);
}
events SEC(".maps");
} events SEC(".maps");

// 用于存储大量数据的缓冲区(避免在BPF程序中分配大量内存)
struct {
Expand Down Expand Up @@ -51,13 +50,11 @@ static int SSL_rw_exit(struct pt_regs *ctx, int rw)
if (!bufp) {
return 0;
}

// 从寄存器中读取函数调用的返回值
int len = PT_REGS_RC(ctx);
if (len <= 0) {
return 0;
}

// 分配一个数据缓冲区
__u32 zero = 0;
struct event_t *event = bpf_map_lookup_elem(&data_buffer_heap, &zero);
Expand All @@ -71,12 +68,13 @@ static int SSL_rw_exit(struct pt_regs *ctx, int rw)
bpf_get_current_comm(&event->comm, sizeof(event->comm));

// 读取SSL读写缓冲区的数据
event->len = (size_t)MAX_BUF_LENGTH < (size_t)len ? (size_t) MAX_BUF_LENGTH : (size_t) len;
event->len =
(size_t)MAX_BUF_LENGTH <
(size_t)len ? (size_t)MAX_BUF_LENGTH : (size_t)len;
if (bufp != NULL) {
bpf_probe_read_user(event->buf, event->len,
(const char *)*bufp);
}

// 将数据缓冲区的数据发送到perf event
bpf_map_delete_elem(&bufs, &tid);
bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, event,
Expand Down
4 changes: 0 additions & 4 deletions bpf-apps/https_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ char *find_library_path(const char *libname)
fprintf(stderr, "Failed to run command: %s\n", cmd);
return NULL;
}

// 格式: libssl3.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libssl3.so
if (fgets(path, sizeof(path) - 1, fp) != NULL) {
char *p = strrchr(path, '>');
Expand Down Expand Up @@ -129,22 +128,19 @@ int main(int argc, char **argv)
fprintf(stderr, "Failed to find libssl.so\n");
return 1;
}

// 加载BPF程序
skel = https_trace_bpf__open_and_load();
if (!skel) {
fprintf(stderr, "Failed to open and load BPF skeleton\n");
return 1;
}

// 创建buffer并绑定事件处理回调
pb = perf_buffer__new(bpf_map__fd(skel->maps.events), 16,
handle_event, NULL, NULL, NULL);
if (!pb) {
fprintf(stderr, "Failed to create perf buffer\n");
goto cleanup;
}

// 挂载uprobe到OpenSSL库
printf("Attaching uprobe to %s\n", libssl_path);
// SSL_read
Expand Down
Loading

0 comments on commit fe1dfe8

Please sign in to comment.