|
|
@@ -23,6 +23,13 @@ struct {
|
|
|
__uint(max_entries, 1);
|
|
|
} socket_heap SEC(".maps");
|
|
|
|
|
|
+struct {
|
|
|
+ __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
|
|
|
+ __type(key, int);
|
|
|
+ __type(value, struct apm_span_context);
|
|
|
+ __uint(max_entries, 1);
|
|
|
+} apm_span_context_heap SEC(".maps");
|
|
|
+
|
|
|
struct {
|
|
|
__uint(type, BPF_MAP_TYPE_ARRAY);
|
|
|
__type(key, int); // 键类型为int
|
|
|
@@ -67,7 +74,7 @@ static __inline int is_http_header(const char *data)
|
|
|
SEC("uprobe/Java_sun_nio_ch_FileDispatcherImpl_read0")
|
|
|
int uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0(struct pt_regs *ctx) {
|
|
|
//计算 rbp-0x30
|
|
|
- bpf_printk("enter the uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0\n");
|
|
|
+ // bpf_printk("enter the uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0\n");
|
|
|
unsigned long jhttpdata_ptr;
|
|
|
jhttpdata_ptr = (ctx)->rbp;
|
|
|
jhttpdata_ptr = jhttpdata_ptr - 0x70;
|
|
|
@@ -80,7 +87,7 @@ int uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0(struct pt_regs *ctx) {
|
|
|
unsigned long jbytechar_ptr;
|
|
|
long ret = bpf_probe_read_user(&jbytechar_ptr, sizeof(unsigned long), (void *) jhttpdata_ptr);
|
|
|
// bpf_printk("x/1gx (p rbp-0x30) value is %llx.\n", jbytechar_ptr);
|
|
|
- bpf_printk("enter the uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0 ------22222222\n");
|
|
|
+ // bpf_printk("enter the uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0 ------22222222\n");
|
|
|
if (ret != 0) {
|
|
|
// bpf_printk("Failed to read first level ptr: %d\n", ret);
|
|
|
return 0;
|
|
|
@@ -89,7 +96,7 @@ int uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0(struct pt_regs *ctx) {
|
|
|
// bpf_printk("First level pointer is null.\n");
|
|
|
return 0;
|
|
|
}
|
|
|
- bpf_printk("enter the uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0 ----111111111\n");
|
|
|
+ // bpf_printk("enter the uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0 ----111111111\n");
|
|
|
|
|
|
//x/s addr
|
|
|
int key = 0;
|
|
|
@@ -103,7 +110,7 @@ int uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0(struct pt_regs *ctx) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- bpf_printk("read data is : %s\n", map_data->payload);
|
|
|
+ // bpf_printk("read data is : %s\n", map_data->payload);
|
|
|
// if (!is_http_request2(httpdata, 1024))
|
|
|
// {
|
|
|
// bpf_printk("not a http request\n");
|
|
|
@@ -112,25 +119,26 @@ int uprobe_Java_sun_nio_ch_FileDispatcherImpl_read0(struct pt_regs *ctx) {
|
|
|
|
|
|
|
|
|
int offset = is_http_header(map_data->payload);
|
|
|
- bpf_printk("found the header, %d\n", offset);
|
|
|
+ // bpf_printk("found the header, %d\n", offset);
|
|
|
char *data;
|
|
|
data = bpf_map_lookup_elem(&large_array_map, &key);
|
|
|
if (!data)
|
|
|
return 0;
|
|
|
- struct apm_span_context cw_parent_span_context = {};
|
|
|
+ // struct apm_span_context cw_parent_span_context = {};
|
|
|
+ struct apm_span_context *cw_parent_span_context = bpf_map_lookup_elem(&apm_span_context_heap, &key);
|
|
|
if(offset > 0 && offset < 512 - 123)
|
|
|
{
|
|
|
__builtin_memcpy(data, &(map_data->payload[offset]), 123);
|
|
|
- bpf_printk("found the data, %s\n", data);
|
|
|
+ // bpf_printk("found the data, %s\n", data);
|
|
|
|
|
|
- cw_string_to_span_context(data, &cw_parent_span_context);
|
|
|
+ cw_string_to_span_context(data, cw_parent_span_context);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- generate_random_bytes(cw_parent_span_context.trace_id, TRACE_ID_SIZE);
|
|
|
+ generate_random_bytes(cw_parent_span_context->trace_id, TRACE_ID_SIZE);
|
|
|
}
|
|
|
// 保存 trace_id 到psc
|
|
|
- cw_save_parent_tracking_span(&cw_parent_span_context);
|
|
|
+ cw_save_parent_tracking_span(cw_parent_span_context);
|
|
|
return 0;
|
|
|
}
|
|
|
|