|
@@ -51,15 +51,15 @@ struct
|
|
|
//} events SEC(".maps");
|
|
//} events SEC(".maps");
|
|
|
|
|
|
|
|
// Injected in init
|
|
// Injected in init
|
|
|
-volatile const u64 method_ptr_pos;
|
|
|
|
|
-volatile const u64 url_ptr_pos;
|
|
|
|
|
-volatile const u64 path_ptr_pos;
|
|
|
|
|
-volatile const u64 headers_ptr_pos;
|
|
|
|
|
-volatile const u64 ctx_ptr_pos;
|
|
|
|
|
-volatile const u64 buckets_ptr_pos;
|
|
|
|
|
-volatile const u64 status_code_pos;
|
|
|
|
|
-volatile const u64 request_host_pos;
|
|
|
|
|
-volatile const u64 request_proto_pos;
|
|
|
|
|
|
|
+// volatile const u64 method_ptr_pos;
|
|
|
|
|
+// volatile const u64 url_ptr_pos;
|
|
|
|
|
+// volatile const u64 path_ptr_pos;
|
|
|
|
|
+// volatile const u64 headers_ptr_pos;
|
|
|
|
|
+// volatile const u64 ctx_ptr_pos;
|
|
|
|
|
+// volatile const u64 buckets_ptr_pos;
|
|
|
|
|
+// volatile const u64 status_code_pos;
|
|
|
|
|
+// volatile const u64 request_host_pos;
|
|
|
|
|
+// volatile const u64 request_proto_pos;
|
|
|
|
|
|
|
|
static __always_inline long inject_header(void* headers_ptr, struct span_context* propagated_ctx) {
|
|
static __always_inline long inject_header(void* headers_ptr, struct span_context* propagated_ctx) {
|
|
|
// Read the key-value count - this field must be the first one in the hmap struct as documented in src/runtime/map.go
|
|
// Read the key-value count - this field must be the first one in the hmap struct as documented in src/runtime/map.go
|
|
@@ -83,8 +83,16 @@ static __always_inline long inject_header(void* headers_ptr, struct span_context
|
|
|
if (!bucket_map_value) {
|
|
if (!bucket_map_value) {
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
|
|
+ __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 -1;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- void *buckets_ptr_ptr = (void*) (headers_ptr + buckets_ptr_pos);
|
|
|
|
|
|
|
+ void *buckets_ptr_ptr = (void*) (headers_ptr + proc_info->buckets_ptr_pos);
|
|
|
void *bucket_ptr = 0; // The actual pointer to the buckets
|
|
void *bucket_ptr = 0; // The actual pointer to the buckets
|
|
|
|
|
|
|
|
if (curr_keyvalue_count == 0) {
|
|
if (curr_keyvalue_count == 0) {
|
|
@@ -185,7 +193,16 @@ static __always_inline long cw_inject_header(void* headers_ptr, struct apm_span_
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void *buckets_ptr_ptr = (void*) (headers_ptr + buckets_ptr_pos);
|
|
|
|
|
|
|
+ __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 -1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void *buckets_ptr_ptr = (void*) (headers_ptr + proc_info->buckets_ptr_pos);
|
|
|
void *bucket_ptr = 0; // The actual pointer to the buckets
|
|
void *bucket_ptr = 0; // The actual pointer to the buckets
|
|
|
|
|
|
|
|
if (curr_keyvalue_count == 0) {
|
|
if (curr_keyvalue_count == 0) {
|
|
@@ -286,8 +303,16 @@ static __always_inline long cw_inject_header2(void* headers_ptr, struct apm_span
|
|
|
if (!bucket_map_value) {
|
|
if (!bucket_map_value) {
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
|
|
+ __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 -1;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- void *buckets_ptr_ptr = (void*) (headers_ptr + buckets_ptr_pos);
|
|
|
|
|
|
|
+ void *buckets_ptr_ptr = (void*) (headers_ptr + proc_info->buckets_ptr_pos);
|
|
|
void *bucket_ptr = 0; // The actual pointer to the buckets
|
|
void *bucket_ptr = 0; // The actual pointer to the buckets
|
|
|
|
|
|
|
|
if (curr_keyvalue_count == 0) {
|
|
if (curr_keyvalue_count == 0) {
|
|
@@ -374,8 +399,17 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
|
|
|
u64 request_pos = 2;
|
|
u64 request_pos = 2;
|
|
|
void *req_ptr = get_argument(ctx, request_pos);
|
|
void *req_ptr = get_argument(ctx, request_pos);
|
|
|
|
|
|
|
|
|
|
+ __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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Get parent if exists
|
|
// Get parent if exists
|
|
|
- void *context_ptr_val = get_Go_context(ctx, 2, ctx_ptr_pos, false);
|
|
|
|
|
|
|
+ void *context_ptr_val = get_Go_context(ctx, 2, proc_info->ctx_ptr_pos, false);
|
|
|
if (context_ptr_val == NULL)
|
|
if (context_ptr_val == NULL)
|
|
|
{
|
|
{
|
|
|
return 0;
|
|
return 0;
|
|
@@ -387,7 +421,7 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
|
|
|
cw_bpf_debug("uprobe/Transport_RoundTrip already tracked with the current context");
|
|
cw_bpf_debug("uprobe/Transport_RoundTrip already tracked with the current context");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ // return 0;
|
|
|
u32 map_id = 0;
|
|
u32 map_id = 0;
|
|
|
struct http_request_t *httpReq = bpf_map_lookup_elem(&http_client_uprobe_storage_map, &map_id);
|
|
struct http_request_t *httpReq = bpf_map_lookup_elem(&http_client_uprobe_storage_map, &map_id);
|
|
|
if (httpReq == NULL)
|
|
if (httpReq == NULL)
|
|
@@ -399,7 +433,7 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
|
|
|
__builtin_memset(httpReq, 0, sizeof(struct http_request_t));
|
|
__builtin_memset(httpReq, 0, sizeof(struct http_request_t));
|
|
|
httpReq->start_time = bpf_ktime_get_ns();
|
|
httpReq->start_time = bpf_ktime_get_ns();
|
|
|
|
|
|
|
|
- struct span_context *parent_span_ctx = get_parent_span_context(context_ptr_val);
|
|
|
|
|
|
|
+ /*struct span_context *parent_span_ctx = get_parent_span_context(context_ptr_val);
|
|
|
if (parent_span_ctx != NULL) {
|
|
if (parent_span_ctx != NULL) {
|
|
|
cw_bpf_debug("[Client] parent_span_ctx != NULL");
|
|
cw_bpf_debug("[Client] parent_span_ctx != NULL");
|
|
|
|
|
|
|
@@ -415,7 +449,6 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
|
|
|
// httpReq->sc = generate_span_context();
|
|
// httpReq->sc = generate_span_context();
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
-
|
|
|
|
|
struct apm_span_context *cw_psc = cw_get_parent_tracking_span();
|
|
struct apm_span_context *cw_psc = cw_get_parent_tracking_span();
|
|
|
if(cw_psc){
|
|
if(cw_psc){
|
|
|
// httpReq->apm_sc = *cw_sc;
|
|
// httpReq->apm_sc = *cw_sc;
|
|
@@ -432,26 +465,25 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
|
|
|
// generate_random_bytes(httpReq->sc.SpanID, SPAN_ID_SIZE);
|
|
// generate_random_bytes(httpReq->sc.SpanID, SPAN_ID_SIZE);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if (!get_go_string_from_user_ptr((void *)(req_ptr+method_ptr_pos), httpReq->method, sizeof(httpReq->method))) {
|
|
|
|
|
|
|
+ if (!get_go_string_from_user_ptr((void *)(req_ptr+proc_info->method_ptr_pos), httpReq->method, sizeof(httpReq->method))) {
|
|
|
cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get method from request");
|
|
cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get method from request");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// get path from Request.URL
|
|
// get path from Request.URL
|
|
|
void *url_ptr = 0;
|
|
void *url_ptr = 0;
|
|
|
- bpf_probe_read(&url_ptr, sizeof(url_ptr), (void *)(req_ptr+url_ptr_pos));
|
|
|
|
|
- if (!get_go_string_from_user_ptr((void *)(url_ptr+path_ptr_pos), httpReq->path, sizeof(httpReq->path))) {
|
|
|
|
|
|
|
+ bpf_probe_read(&url_ptr, sizeof(url_ptr), (void *)(req_ptr+proc_info->url_ptr_pos));
|
|
|
|
|
+ if (!get_go_string_from_user_ptr((void *)(url_ptr+proc_info->path_ptr_pos), httpReq->path, sizeof(httpReq->path))) {
|
|
|
cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get path from Request.URL");
|
|
cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get path from Request.URL");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// get host from Request
|
|
// get host from Request
|
|
|
- if (!get_go_string_from_user_ptr((void *)(req_ptr+request_host_pos), httpReq->host, sizeof(httpReq->host))) {
|
|
|
|
|
|
|
+ if (!get_go_string_from_user_ptr((void *)(req_ptr+proc_info->request_host_pos), httpReq->host, sizeof(httpReq->host))) {
|
|
|
cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get host from Request");
|
|
cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get host from Request");
|
|
|
}
|
|
}
|
|
|
// TODO set request_host_pos
|
|
// TODO set request_host_pos
|
|
|
- cw_bpf_debug("[Client] httpReq->host:%llu",request_host_pos);
|
|
|
|
|
|
|
+ cw_bpf_debug("[Client] httpReq->host:%llu",proc_info->request_host_pos);
|
|
|
// for (int i = 0; i < MAX_HOSTNAME_SIZE; ++i) {
|
|
// for (int i = 0; i < MAX_HOSTNAME_SIZE; ++i) {
|
|
|
// if (httpReq->host[i] == '\0') {
|
|
// if (httpReq->host[i] == '\0') {
|
|
|
// break;
|
|
// break;
|
|
@@ -472,10 +504,10 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
|
|
|
copy_byte_arrays(trace_conf->app_id, httpReq->apm_sc.app_id, APM_APP_ID_SIZE);
|
|
copy_byte_arrays(trace_conf->app_id, httpReq->apm_sc.app_id, APM_APP_ID_SIZE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- __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);
|
|
|
|
|
|
|
+ // __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) {
|
|
if (proc_info) {
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
// cw_bpf_debug("[Client] instance_id:%02x", proc_info->instance_id[i]);
|
|
// cw_bpf_debug("[Client] instance_id:%02x", proc_info->instance_id[i]);
|
|
@@ -487,13 +519,13 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
|
|
|
set_assumed_app_id_arrays(httpReq->host, httpReq->apm_sc.assumed_app_id, APM_ASSUMED_APP_ID_STRING_SIZE);
|
|
set_assumed_app_id_arrays(httpReq->host, httpReq->apm_sc.assumed_app_id, APM_ASSUMED_APP_ID_STRING_SIZE);
|
|
|
cw_save_current_tracking_span(&httpReq->apm_sc);
|
|
cw_save_current_tracking_span(&httpReq->apm_sc);
|
|
|
// get proto from Request
|
|
// get proto from Request
|
|
|
- if (!get_go_string_from_user_ptr((void *)(req_ptr+request_proto_pos), httpReq->proto, sizeof(httpReq->proto))) {
|
|
|
|
|
|
|
+ if (!get_go_string_from_user_ptr((void *)(req_ptr+proc_info->request_proto_pos), httpReq->proto, sizeof(httpReq->proto))) {
|
|
|
cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get proto from Request");
|
|
cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get proto from Request");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// get headers from Request
|
|
// get headers from Request
|
|
|
void *headers_ptr = 0;
|
|
void *headers_ptr = 0;
|
|
|
- bpf_probe_read(&headers_ptr, sizeof(headers_ptr), (void *)(req_ptr+headers_ptr_pos));
|
|
|
|
|
|
|
+ bpf_probe_read(&headers_ptr, sizeof(headers_ptr), (void *)(req_ptr+proc_info->headers_ptr_pos));
|
|
|
// long res = inject_header(headers_ptr, &httpReq->sc);
|
|
// long res = inject_header(headers_ptr, &httpReq->sc);
|
|
|
// long res = cw_inject_header(headers_ptr, &httpReq->apm_sc);
|
|
// long res = cw_inject_header(headers_ptr, &httpReq->apm_sc);
|
|
|
// if (res < 0) {
|
|
// if (res < 0) {
|
|
@@ -502,7 +534,7 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
|
|
|
long res2 = cw_inject_header2(headers_ptr, &httpReq->apm_sc);
|
|
long res2 = cw_inject_header2(headers_ptr, &httpReq->apm_sc);
|
|
|
if (res2 < 0) {
|
|
if (res2 < 0) {
|
|
|
cw_bpf_debug("uprobe_Transport_roundTrip: Failed to inject header");
|
|
cw_bpf_debug("uprobe_Transport_roundTrip: Failed to inject header");
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
|
|
// Write event
|
|
// Write event
|
|
|
// bpf_map_update_elem(&http_events, &key, httpReq, 0);
|
|
// bpf_map_update_elem(&http_events, &key, httpReq, 0);
|
|
@@ -517,7 +549,17 @@ int uprobe_Transport_roundTrip_Returns(struct pt_regs *ctx) {
|
|
|
cw_bpf_debug("[Uprobe HTTP Client] start Return----------");
|
|
cw_bpf_debug("[Uprobe HTTP Client] start Return----------");
|
|
|
clear_current_span_context();
|
|
clear_current_span_context();
|
|
|
u64 end_time = bpf_ktime_get_ns();
|
|
u64 end_time = bpf_ktime_get_ns();
|
|
|
- void *req_ctx_ptr = get_Go_context(ctx, 2, ctx_ptr_pos, false);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ __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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void *req_ctx_ptr = get_Go_context(ctx, 2, proc_info->ctx_ptr_pos, false);
|
|
|
void *key = get_consistent_key(ctx, req_ctx_ptr);
|
|
void *key = get_consistent_key(ctx, req_ctx_ptr);
|
|
|
|
|
|
|
|
struct http_request_t *http_req_span = bpf_map_lookup_elem(&http_events, &key);
|
|
struct http_request_t *http_req_span = bpf_map_lookup_elem(&http_events, &key);
|
|
@@ -530,7 +572,7 @@ int uprobe_Transport_roundTrip_Returns(struct pt_regs *ctx) {
|
|
|
// Getting the returned response
|
|
// Getting the returned response
|
|
|
void *resp_ptr = get_argument(ctx, 1);
|
|
void *resp_ptr = get_argument(ctx, 1);
|
|
|
// Get status code from response
|
|
// Get status code from response
|
|
|
- bpf_probe_read(&http_req_span->status_code, sizeof(http_req_span->status_code), (void *)(resp_ptr + status_code_pos));
|
|
|
|
|
|
|
+ bpf_probe_read(&http_req_span->status_code, sizeof(http_req_span->status_code), (void *)(resp_ptr + proc_info->status_code_pos));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
http_req_span->end_time = end_time;
|
|
http_req_span->end_time = end_time;
|