|
@@ -301,6 +301,112 @@ static __always_inline struct map_bucket *get_map_bucket(void *headers_ptr_ptr)
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+MAP_BUCKET_DEFINITION(go_string_ot, go_slice_ot)
|
|
|
|
|
+
|
|
|
|
|
+static __always_inline char *extract_context_from_req_headers_go_map(void *headers_ptr_ptr)
|
|
|
|
|
+{
|
|
|
|
|
+ void *headers_ptr;
|
|
|
|
|
+ long res;
|
|
|
|
|
+ res = bpf_probe_read(&headers_ptr, sizeof(headers_ptr), headers_ptr_ptr);
|
|
|
|
|
+ if (res < 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ u64 headers_count = 0;
|
|
|
|
|
+ res = bpf_probe_read(&headers_count, sizeof(headers_count), headers_ptr);
|
|
|
|
|
+ if (res < 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (headers_count == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ unsigned char log_2_bucket_count;
|
|
|
|
|
+ res = bpf_probe_read(&log_2_bucket_count, sizeof(log_2_bucket_count), headers_ptr + 9);
|
|
|
|
|
+ if (res < 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ u64 bucket_count = 1 << log_2_bucket_count;
|
|
|
|
|
+ void *header_buckets;
|
|
|
|
|
+ /**/
|
|
|
|
|
+ __u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
|
|
+ __u32 tgid = pid_tgid >> 32;
|
|
|
|
|
+ struct ebpf_proc_info *proc_info =
|
|
|
|
|
+ bpf_map_lookup_elem(&proc_info_map, &tgid);
|
|
|
|
|
+ if(!proc_info)
|
|
|
|
|
+ {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ /**/
|
|
|
|
|
+
|
|
|
|
|
+ res = bpf_probe_read(&header_buckets, sizeof(header_buckets), (void*)(headers_ptr + proc_info->buckets_ptr_pos));
|
|
|
|
|
+ if (res < 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ u32 map_id = 0;
|
|
|
|
|
+ MAP_BUCKET_TYPE(go_string_ot, go_slice_ot) *map_value = bpf_map_lookup_elem(&golang_mapbucket_storage_map, &map_id);
|
|
|
|
|
+ if (!map_value)
|
|
|
|
|
+ {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (u64 j = 0; j < MAX_BUCKETS; j++)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (j >= bucket_count)
|
|
|
|
|
+ {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ res = bpf_probe_read(map_value, sizeof(MAP_BUCKET_TYPE(go_string_ot, go_slice_ot)), header_buckets + (j * sizeof(MAP_BUCKET_TYPE(go_string_ot, go_slice_ot))));
|
|
|
|
|
+ if (res < 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (u64 i = 0; i < 8; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (map_value->tophash[i] == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (map_value->keys[i].len != CW_HEADER_KEY_LENGTH)
|
|
|
|
|
+ {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ char current_header_key[CW_HEADER_KEY_LENGTH];
|
|
|
|
|
+ bpf_probe_read(current_header_key, sizeof(current_header_key), map_value->keys[i].str);
|
|
|
|
|
+ if (!bpf_memcmp(current_header_key, CW_HEADER_KEY_VAL, CW_HEADER_KEY_LENGTH) && !bpf_memcmp(current_header_key, CW_HEADER_KEY_UFIRST_VAL, CW_HEADER_KEY_LENGTH))
|
|
|
|
|
+ {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ void *traceparent_header_value_ptr = map_value->values[i].array;
|
|
|
|
|
+ struct go_string_ot traceparent_header_value_go_str;
|
|
|
|
|
+ res = bpf_probe_read(&traceparent_header_value_go_str, sizeof(traceparent_header_value_go_str), traceparent_header_value_ptr);
|
|
|
|
|
+ if (res < 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (traceparent_header_value_go_str.len != CW_HEADER_VAL_LENGTH)
|
|
|
|
|
+ {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ char traceparent_header_value2[CW_HEADER_VAL_LENGTH];
|
|
|
|
|
+ res = bpf_probe_read(&traceparent_header_value2, sizeof(traceparent_header_value2), traceparent_header_value_go_str.str);
|
|
|
|
|
+ if (res < 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ bpf_printk("has cw header111 j=%d i=%d %s", j, i,traceparent_header_value_go_str.str);
|
|
|
|
|
+
|
|
|
|
|
+ return traceparent_header_value_go_str.str;
|
|
|
|
|
+// w3c_string_to_span_context(traceparent_header_value, parent_span_context);
|
|
|
|
|
+// return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+}
|
|
|
// 获取 header_val
|
|
// 获取 header_val
|
|
|
static __always_inline char *get_header_val(struct map_bucket *map_value,u32 off,u32 count) {
|
|
static __always_inline char *get_header_val(struct map_bucket *map_value,u32 off,u32 count) {
|
|
|
for (u32 i = off; i < count; i++) {
|
|
for (u32 i = off; i < count; i++) {
|
|
@@ -387,13 +493,13 @@ int uprobe_HandlerFunc_ServeHTTP(struct pt_regs *ctx) {
|
|
|
|
|
|
|
|
// Propagate context
|
|
// Propagate context
|
|
|
void *req_ptr = get_argument(ctx, 4);
|
|
void *req_ptr = get_argument(ctx, 4);
|
|
|
- struct map_bucket * map_bucket_p = get_map_bucket((void *) (req_ptr + proc_info->headers_ptr_pos));
|
|
|
|
|
|
|
+// struct map_bucket * map_bucket_p = get_map_bucket((void *) (req_ptr + proc_info->headers_ptr_pos));
|
|
|
|
|
|
|
|
- if (map_bucket_p == NULL) {
|
|
|
|
|
- return 0;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ char *traceparent_header_value = extract_context_from_req_headers_go_map(
|
|
|
|
|
+ (void *) (req_ptr + proc_info->headers_ptr_pos));
|
|
|
|
|
+// bpf_printk("111 %s",traceparent_header_value);
|
|
|
|
|
|
|
|
- char * traceparent_header_value = get_header_val_off(map_bucket_p);
|
|
|
|
|
|
|
+// char * traceparent_header_value = get_header_val_off(map_bucket_p);
|
|
|
struct apm_span_context *cw_parent_span_context = bpf_map_lookup_elem(&cw_parent_span_context_storage_map, &map_id);
|
|
struct apm_span_context *cw_parent_span_context = bpf_map_lookup_elem(&cw_parent_span_context_storage_map, &map_id);
|
|
|
if (!cw_parent_span_context) {
|
|
if (!cw_parent_span_context) {
|
|
|
return 0;
|
|
return 0;
|