|
|
@@ -55,7 +55,8 @@ struct {
|
|
|
// Injected in init
|
|
|
volatile const u64 clientconn_target_ptr_pos;
|
|
|
volatile const u64 httpclient_nextid_pos;
|
|
|
-volatile const u64 headerFrame_streamid_pos;
|
|
|
+// volatile const u64 headerFrame_streamid_pos;
|
|
|
+u64 headerFrame_streamid_pos = 0;
|
|
|
// volatile const u64 headerFrame_hf_pos;
|
|
|
u64 headerFrame_hf_pos = 8;
|
|
|
volatile const u64 error_status_pos;
|
|
|
@@ -193,87 +194,206 @@ done:
|
|
|
}
|
|
|
|
|
|
// func (l *loopyWriter) headerHandler(h *headerFrame) error
|
|
|
+// SEC("uprobe/loopyWriter_headerHandler")
|
|
|
+// int uprobe_LoopyWriter_HeaderHandler(struct pt_regs *ctx) {
|
|
|
+// bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler \n");
|
|
|
+// void *headerFrame_ptr = get_argument(ctx, 2);
|
|
|
+// // u32 stream_id = 0;
|
|
|
+// // bpf_probe_read(
|
|
|
+// // &stream_id, sizeof(stream_id), (void *)(headerFrame_ptr + (headerFrame_streamid_pos)));
|
|
|
+// // void *sc_ptr = bpf_map_lookup_elem(&streamid_to_span_contexts, &stream_id);
|
|
|
+// // if (sc_ptr == NULL) {
|
|
|
+// // return 0;
|
|
|
+// // }
|
|
|
+// bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler1111 \n");
|
|
|
+// __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 0;
|
|
|
+// }
|
|
|
+
|
|
|
+// bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler2222222\n");
|
|
|
+// // struct span_context current_span_context = {};
|
|
|
+// // bpf_probe_read(¤t_span_context, sizeof(current_span_context), sc_ptr);
|
|
|
+
|
|
|
+// char tp_key[CW_HEADER_KEY_LENGTH] = CW_HEADER_KEY_VAL;
|
|
|
+// struct go_string_ot key_str = write_user_go_string(tp_key, sizeof(tp_key));
|
|
|
+// if (key_str.len == 0) {
|
|
|
+// bpf_printk("key write failed, aborting ebpf probe");
|
|
|
+// goto done;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+// bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler333333\n");
|
|
|
+// u32 map_id = 0;
|
|
|
+// struct grpc_client_request_t *grpcClientReq = bpf_map_lookup_elem(&grpc_client_storage_map, &map_id);
|
|
|
+// if (grpcClientReq == NULL)
|
|
|
+// {
|
|
|
+// cw_bpf_debug("uprobe_LoopyWriter_HeaderHandler: grpcClientReq is NULL");
|
|
|
+// return 0;
|
|
|
+// }
|
|
|
+
|
|
|
+// __builtin_memset(grpcClientReq, 0, sizeof(struct grpc_client_request_t));
|
|
|
+// grpcClientReq->start_time = bpf_ktime_get_ns();
|
|
|
+
|
|
|
+// bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler444444\n");
|
|
|
+// struct apm_span_context *cw_psc = cw_get_parent_tracking_span();
|
|
|
+// if(cw_psc){
|
|
|
+// bpf_probe_read(&grpcClientReq->apm_psc, sizeof(grpcClientReq->apm_psc), cw_psc);
|
|
|
+// copy_byte_arrays(grpcClientReq->apm_psc.trace_id, grpcClientReq->apm_sc.trace_id, APM_TRACE_ID_SIZE);
|
|
|
+// generate_random_bytes(grpcClientReq->apm_sc.span_id, APM_SPAN_ID_SIZE);
|
|
|
+// }
|
|
|
+
|
|
|
+// u32 k0 = 0;
|
|
|
+// struct trace_conf_t *trace_conf = trace_conf_map__lookup(&k0);
|
|
|
+// if (trace_conf) {
|
|
|
+// copy_byte_arrays(trace_conf->host_id, grpcClientReq->apm_sc.host_id, APM_HOST_ID_SIZE);
|
|
|
+// }
|
|
|
+
|
|
|
+// copy_byte_arrays(proc_info->instance_id, grpcClientReq->apm_sc.instance_id, APM_APP_ID_SIZE);
|
|
|
+// copy_byte_arrays(proc_info->app_id, grpcClientReq->apm_sc.app_id, APM_APP_ID_SIZE);
|
|
|
+
|
|
|
+// // set assumed_app_id
|
|
|
+// // set_assumed_app_id_arrays(httpReq->host, httpReq->apm_sc.assumed_app_id, APM_ASSUMED_APP_ID_STRING_SIZE);
|
|
|
+// cw_save_current_tracking_span(&grpcClientReq->apm_sc);
|
|
|
+
|
|
|
+// // Write headers
|
|
|
+// char val[CW_HEADER_VAL_LENGTH];
|
|
|
+// span_context_to_cw_string(&grpcClientReq->apm_sc, val);
|
|
|
+// struct go_string_ot val_str = write_user_go_string(val, sizeof(val));
|
|
|
+// if (val_str.len == 0) {
|
|
|
+// bpf_printk("val write failed, aborting ebpf probe");
|
|
|
+// goto done;
|
|
|
+// }
|
|
|
+// bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler6666\n");
|
|
|
+// struct hpack_header_field hf = {};
|
|
|
+// hf.name = key_str;
|
|
|
+// hf.value = val_str;
|
|
|
+// append_item_to_slice(&hf, sizeof(hf), (void *)(headerFrame_ptr + (headerFrame_hf_pos)));
|
|
|
+// done:
|
|
|
+// // bpf_map_delete_elem(&streamid_to_span_contexts, &stream_id);
|
|
|
+
|
|
|
+// return 0;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+static __always_inline void
|
|
|
+cw_append_item_to_slice(void *new_item, u32 item_size, void *slice_user_ptr) {
|
|
|
+ // read the slice descriptor
|
|
|
+ struct go_slice_ot slice = {0};
|
|
|
+ bpf_probe_read(&slice, sizeof(slice), slice_user_ptr);
|
|
|
+ long res = 0;
|
|
|
+
|
|
|
+ bpf_printk("cw_append_item_to_slice len is %d\n", slice.len);
|
|
|
+ bpf_printk("cw_append_item_to_slice cap is %d\n", slice.cap);
|
|
|
+
|
|
|
+ u64 slice_len = slice.len;
|
|
|
+ u64 slice_cap = slice.cap;
|
|
|
+ if (slice_len < slice_cap && slice.array != NULL) {
|
|
|
+ // Room available on current array, append to the underlying array
|
|
|
+ bpf_printk("enter the cw_append_item_to_slice11111\n");
|
|
|
+ // struct hpack_header_field hf = {};
|
|
|
+ // bpf_probe_read(&hf, sizeof(hf), slice.array + (item_size * 6));
|
|
|
+ // bpf_printk("cw_append_item_to_slice hf.name.str is %s\n", hf.name.str);
|
|
|
+ // bpf_printk("cw_append_item_to_slice hf.value.str is %s\n", hf.value.str);
|
|
|
+ res = bpf_probe_write_user(slice.array + (item_size * slice_len), new_item, item_size);
|
|
|
+ } else {
|
|
|
+ // No room on current array - try to copy new one of size item_size * (len + 1)
|
|
|
+ u32 alloc_size = item_size * slice_len;
|
|
|
+ if (alloc_size >= MAX_SLICE_ARRAY_SIZE) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Get temporary buffer
|
|
|
+ u32 index = 0;
|
|
|
+ struct slice_array_buff *map_buff = bpf_map_lookup_elem(&slice_array_buff_map, &index);
|
|
|
+ if (!map_buff) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned char *new_slice_array = map_buff->buff;
|
|
|
+ // help the verifier
|
|
|
+ alloc_size &= (MAX_SLICE_ARRAY_SIZE - 1);
|
|
|
+ if (alloc_size + item_size > MAX_SLICE_ARRAY_SIZE) {
|
|
|
+ // No room for new item
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // Append to buffer
|
|
|
+ if (slice.array != NULL) {
|
|
|
+ bpf_probe_read_user(new_slice_array, alloc_size, slice.array);
|
|
|
+ bpf_printk("append_item_to_slice: copying %d bytes to new array from address 0x%llx",
|
|
|
+ alloc_size,
|
|
|
+ slice.array);
|
|
|
+ }
|
|
|
+ copy_byte_arrays(new_item, new_slice_array + alloc_size, item_size);
|
|
|
+
|
|
|
+ // Copy buffer to userspace
|
|
|
+ u32 new_array_size = alloc_size + item_size;
|
|
|
+
|
|
|
+ void *new_array = write_target_data(new_slice_array, new_array_size);
|
|
|
+ if (new_array == NULL) {
|
|
|
+ bpf_printk("append_item_to_slice: failed to copy new array to userspace");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Update array pointer of slice
|
|
|
+ slice.array = new_array;
|
|
|
+ slice.cap++;
|
|
|
+
|
|
|
+ bpf_printk("enter the cw_append_item_to_slice222222\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Update len
|
|
|
+ slice.len++;
|
|
|
+ bpf_printk("after cw_append_item_to_slice len is %d\n", slice.len);
|
|
|
+ long success = bpf_probe_write_user(slice_user_ptr, &slice, sizeof(slice));
|
|
|
+ if (success != 0) {
|
|
|
+ bpf_printk("append_item_to_slice: failed to update slice in userspace");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
SEC("uprobe/loopyWriter_headerHandler")
|
|
|
int uprobe_LoopyWriter_HeaderHandler(struct pt_regs *ctx) {
|
|
|
- bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler \n");
|
|
|
void *headerFrame_ptr = get_argument(ctx, 2);
|
|
|
- // u32 stream_id = 0;
|
|
|
- // bpf_probe_read(
|
|
|
- // &stream_id, sizeof(stream_id), (void *)(headerFrame_ptr + (headerFrame_streamid_pos)));
|
|
|
+ u32 stream_id = 0;
|
|
|
+ bpf_probe_read(
|
|
|
+ &stream_id, sizeof(stream_id), (void *)(headerFrame_ptr + (headerFrame_streamid_pos)));
|
|
|
// void *sc_ptr = bpf_map_lookup_elem(&streamid_to_span_contexts, &stream_id);
|
|
|
// if (sc_ptr == NULL) {
|
|
|
// return 0;
|
|
|
// }
|
|
|
- bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler1111 \n");
|
|
|
- __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 0;
|
|
|
- }
|
|
|
|
|
|
- bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler2222222\n");
|
|
|
// struct span_context current_span_context = {};
|
|
|
// bpf_probe_read(¤t_span_context, sizeof(current_span_context), sc_ptr);
|
|
|
|
|
|
- char tp_key[CW_HEADER_KEY_LENGTH] = CW_HEADER_KEY_VAL;
|
|
|
+ char tp_key[11] = "traceparent";
|
|
|
struct go_string_ot key_str = write_user_go_string(tp_key, sizeof(tp_key));
|
|
|
if (key_str.len == 0) {
|
|
|
bpf_printk("key write failed, aborting ebpf probe");
|
|
|
goto done;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler333333\n");
|
|
|
- u32 map_id = 0;
|
|
|
- struct grpc_client_request_t *grpcClientReq = bpf_map_lookup_elem(&grpc_client_storage_map, &map_id);
|
|
|
- if (grpcClientReq == NULL)
|
|
|
- {
|
|
|
- cw_bpf_debug("uprobe_LoopyWriter_HeaderHandler: grpcClientReq is NULL");
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- __builtin_memset(grpcClientReq, 0, sizeof(struct grpc_client_request_t));
|
|
|
- grpcClientReq->start_time = bpf_ktime_get_ns();
|
|
|
-
|
|
|
- bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler444444\n");
|
|
|
- struct apm_span_context *cw_psc = cw_get_parent_tracking_span();
|
|
|
- if(cw_psc){
|
|
|
- bpf_probe_read(&grpcClientReq->apm_psc, sizeof(grpcClientReq->apm_psc), cw_psc);
|
|
|
- copy_byte_arrays(grpcClientReq->apm_psc.trace_id, grpcClientReq->apm_sc.trace_id, APM_TRACE_ID_SIZE);
|
|
|
- generate_random_bytes(grpcClientReq->apm_sc.span_id, APM_SPAN_ID_SIZE);
|
|
|
- }
|
|
|
-
|
|
|
- u32 k0 = 0;
|
|
|
- struct trace_conf_t *trace_conf = trace_conf_map__lookup(&k0);
|
|
|
- if (trace_conf) {
|
|
|
- copy_byte_arrays(trace_conf->host_id, grpcClientReq->apm_sc.host_id, APM_HOST_ID_SIZE);
|
|
|
- }
|
|
|
-
|
|
|
- copy_byte_arrays(proc_info->instance_id, grpcClientReq->apm_sc.instance_id, APM_APP_ID_SIZE);
|
|
|
- copy_byte_arrays(proc_info->app_id, grpcClientReq->apm_sc.app_id, APM_APP_ID_SIZE);
|
|
|
-
|
|
|
- // set assumed_app_id
|
|
|
- // set_assumed_app_id_arrays(httpReq->host, httpReq->apm_sc.assumed_app_id, APM_ASSUMED_APP_ID_STRING_SIZE);
|
|
|
- cw_save_current_tracking_span(&grpcClientReq->apm_sc);
|
|
|
-
|
|
|
// Write headers
|
|
|
- char val[CW_HEADER_VAL_LENGTH];
|
|
|
- span_context_to_cw_string(&grpcClientReq->apm_sc, val);
|
|
|
+ char val[SPAN_CONTEXT_STRING_SIZE] = "11111111";
|
|
|
+ // span_context_to_w3c_string(¤t_span_context, val);
|
|
|
struct go_string_ot val_str = write_user_go_string(val, sizeof(val));
|
|
|
if (val_str.len == 0) {
|
|
|
bpf_printk("val write failed, aborting ebpf probe");
|
|
|
goto done;
|
|
|
}
|
|
|
- bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler6666\n");
|
|
|
struct hpack_header_field hf = {};
|
|
|
hf.name = key_str;
|
|
|
hf.value = val_str;
|
|
|
- append_item_to_slice(&hf, sizeof(hf), (void *)(headerFrame_ptr + (headerFrame_hf_pos)));
|
|
|
+ hf.sensitive = false;
|
|
|
+ bpf_printk("uprobe_LoopyWriter_HeaderHandler hf.name.str is %s\n", key_str.str);
|
|
|
+ bpf_printk("uprobe_LoopyWriter_HeaderHandler hf.value.str is %s\n", val_str.str);
|
|
|
+ cw_append_item_to_slice(&hf, sizeof(hf), (void *)(headerFrame_ptr + (headerFrame_hf_pos)));
|
|
|
done:
|
|
|
- // bpf_map_delete_elem(&streamid_to_span_contexts, &stream_id);
|
|
|
+ bpf_map_delete_elem(&streamid_to_span_contexts, &stream_id);
|
|
|
|
|
|
return 0;
|
|
|
}
|