Browse Source

Fixed #TASK_QT-9810 [arm适配/4.18适配]tail修正,go client调整

Carl 1 year ago
parent
commit
5dd5a2206f

+ 1 - 1
ebpftracer/ebpf/utrace/go/include/alloc.h

@@ -158,7 +158,7 @@ static __always_inline void *write_target_data(void *data, s32 size)
 
 static __always_inline void *cw_write_target_data(void *data, s32 size, struct ebpf_proc_info* info)
 {
-    if (data == NULL)
+    if (!data || data == NULL)
     {
         return NULL;
     }

+ 1 - 1
ebpftracer/ebpf/utrace/go/include/go_types.h

@@ -48,9 +48,9 @@ struct map_bucket {
     struct go_slice_ot values[8];
     void *overflow;
 
-	void *header_value_str_p;
 	void *headers_ptr;
 	void *bucket_ptr;
+	char header_str[CW_HEADER_VAL_LENGTH];
 	u64 curr_keyvalue_count;
 	u8 bucket_index;
 

+ 82 - 20
ebpftracer/ebpf/utrace/go/net/client.probe.bpf.c

@@ -453,6 +453,26 @@ static __always_inline long cw_inject_header_half(void* headers_ptr, char * head
 
     u8 bucket_index = curr_keyvalue_count & 0x7;
 
+//	bucket_map_value->header_value_str_p = ptr;
+
+	bucket_map_value->headers_ptr = headers_ptr;
+	bucket_map_value->bucket_ptr = bucket_ptr;
+
+	bucket_map_value->curr_keyvalue_count = curr_keyvalue_count;
+	bucket_map_value->bucket_index = bucket_index;
+	bpf_probe_read(bucket_map_value->header_str, sizeof(bucket_map_value->header_str),header_str);
+	cw_bpf_debug("bucket_map_value->header_str %s",bucket_map_value->header_str);
+//	bucket_map_value->header_str = header_str;
+
+//	void * header_str_ptr = cw_write_target_data(header_str, CW_HEADER_VAL_LENGTH,proc_info);
+//	if(header_str_ptr == NULL) {
+//		cw_bpf_debug("inject_header: Failed to write value to user");
+//		return -1;
+//	}
+//	bucket_map_value->header_str_p = header_str;
+
+	return 0;
+
 //    char traceparent_tophash = 0xee;
 //    bucket_map_value->tophash[bucket_index] = traceparent_tophash;
 
@@ -479,19 +499,14 @@ static __always_inline long cw_inject_header_half(void* headers_ptr, char * head
     // First the value string which constains the span context
 //    char val[CW_HEADER_VAL_LENGTH];
 //	span_context_to_cw_string(propagated_ctx, val);
+// 往前提
     ptr = cw_write_target_data(header_str, CW_HEADER_VAL_LENGTH,proc_info);
     if(ptr == NULL) {
         cw_bpf_debug("inject_header: Failed to write value to user");
         return -1;
     }
-	bucket_map_value->header_value_str_p = ptr;
-
-	bucket_map_value->curr_keyvalue_count = curr_keyvalue_count;
-	bucket_map_value->bucket_index = bucket_index;
-	bucket_map_value->headers_ptr = headers_ptr;
-	bucket_map_value->bucket_ptr = bucket_ptr;
 
-	return 0;
+//	return 0;
     // The go string pointing to the above val
     struct go_string_ot header_value = {.len = CW_HEADER_VAL_LENGTH, .str = ptr};
     ptr = cw_write_target_data((void*)&header_value, sizeof(header_value),proc_info);
@@ -704,40 +719,87 @@ PROGUP(go_update_header)(struct pt_regs *ctx) {
 	if (!bucket_map_value) {
 		return -1;
 	}
-	if (!bucket_map_value->header_value_str_p){
-		return -1;
-	}
+//	if (!bucket_map_value->header_value_str_p){
+//		return -1;
+//	}
 	if (!bucket_map_value->headers_ptr){
 		return -1;
 	}
 	if (!bucket_map_value->bucket_ptr){
 		return -1;
 	}
+//	if (!bucket_map_value->header_str){
+//		return -1;
+//	}
+//	if (!bucket_map_value->header_str_p){
+//		return -1;
+//	}
+	if (bucket_map_value->bucket_index >=8) {
+		return -1;
+	}
+
+	void *headers_ptr = bucket_map_value->headers_ptr;
+	void *bucket_ptr = bucket_map_value->bucket_ptr;
+
+//	u8 bucket_index = 0;
+//	bucket_index = bucket_map_value->bucket_index;
+
+	u64 curr_keyvalue_count = bucket_map_value->curr_keyvalue_count;
+	char * header_str = bucket_map_value->header_str;
+
+//	cw_bpf_debug("header_str %s",bucket_map_value->header_str);
+
+
+	char key[CW_HEADER_KEY_LENGTH] = CW_HEADER_KEY_VAL;
+	void *ptr = cw_write_target_data(key, CW_HEADER_KEY_LENGTH,proc_info);
+	if (ptr == NULL) {
+//		cw_bpf_debug("inject_header: Failed to write key to user");
+		return -1;
+	}
+//    bucket_map_value->keys[bucket_index] = (struct go_string_ot) {.len = CW_HEADER_KEY_LENGTH, .str = ptr};
+
+	// 往前提
+//	char val[CW_HEADER_VAL_LENGTH];
+//	bpf_probe_read(val, sizeof(val),&header_str);
+	void * header_str_ptr = cw_write_target_data(header_str, CW_HEADER_VAL_LENGTH,proc_info);
+	if(header_str_ptr == NULL) {
+//		cw_bpf_debug("inject_header: Failed to write value to user");
+		return -1;
+	}
+
+//	if (bucket_index < 0 || bucket_index >= 8){
+//		return -1;
+//	}
+
 
 	// The go string pointing to the above val
-	struct go_string_ot header_value = {.len = CW_HEADER_VAL_LENGTH, .str = bucket_map_value->header_value_str_p};
-	void * ptr = cw_write_target_data((void*)&header_value, sizeof(header_value),proc_info);
-	if(ptr == NULL) {
+	struct go_string_ot header_value = {.len = CW_HEADER_VAL_LENGTH, .str = header_str_ptr};
+	void * header_value_ptr = cw_write_target_data((void*)&header_value, sizeof(header_value),proc_info);
+	if(header_value_ptr == NULL) {
 		cw_bpf_debug("inject_header: Failed to write go_string to user");
 		return -1;
 	}
 
+	char traceparent_tophash = 0xee;
+	u8 bucket_index = curr_keyvalue_count & 0x7;
+	bucket_map_value->tophash[bucket_index] = traceparent_tophash;
+	bucket_map_value->keys[bucket_index] = (struct go_string_ot) {.len = CW_HEADER_KEY_LENGTH, .str = ptr};
+	bucket_map_value->values[bucket_index] = (struct go_slice_ot) {.array = header_value_ptr, .cap = 1, .len = 1};
+
 	// Last, go_slice pointing to the above go_string
-	if (bucket_map_value->bucket_index >=8) {
-		return -1;
-	}
-	bucket_map_value->values[bucket_map_value->bucket_index] = (struct go_slice_ot) {.array = ptr, .cap = 1, .len = 1};
+//	return 1;
+//	bucket_map_value->values[bucket_index] = (struct go_slice_ot) {.array = ptr, .cap = 1, .len = 1};
 
 	// Update the map header count field
-	bucket_map_value->curr_keyvalue_count += 1;
-	long res = bpf_probe_write_user(bucket_map_value->headers_ptr, &bucket_map_value->curr_keyvalue_count, sizeof(bucket_map_value->curr_keyvalue_count));
+	curr_keyvalue_count = curr_keyvalue_count + 1;
+	long res = bpf_probe_write_user(headers_ptr, &curr_keyvalue_count, sizeof(curr_keyvalue_count));
 	if (res < 0) {
 		cw_bpf_debug("Failed to update key-value count in map header");
 		return -1;
 	}
 
 	// Update the bucket
-	res = bpf_probe_write_user(bucket_map_value->bucket_ptr, bucket_map_value, sizeof(struct map_bucket));
+	res = bpf_probe_write_user(bucket_ptr, bucket_map_value, sizeof(struct map_bucket));
 	if (res < 0) {
 		cw_bpf_debug("Failed to update bucket content");
 		return -1;