|
|
@@ -11,7 +11,7 @@
|
|
|
|
|
|
// char __license[] SEC("license") = "Dual MIT/GPL";
|
|
|
|
|
|
-#define MAX_SIZE 100
|
|
|
+// #define MAX_SIZE 100
|
|
|
#define MAX_CONCURRENT 50
|
|
|
#define MAX_HEADERS 20
|
|
|
#define MAX_HEADER_STRING 50
|
|
|
@@ -46,8 +46,8 @@ struct {
|
|
|
} grpc_storage_map SEC(".maps");
|
|
|
|
|
|
struct hpack_header_field {
|
|
|
- struct go_string name;
|
|
|
- struct go_string value;
|
|
|
+ struct go_string_ot name;
|
|
|
+ struct go_string_ot value;
|
|
|
bool sensitive;
|
|
|
};
|
|
|
|
|
|
@@ -100,6 +100,7 @@ handleStream(struct pt_regs *ctx, void *stream_ptr, struct go_iface *go_context)
|
|
|
|
|
|
// Get parent context if exists
|
|
|
u32 stream_id = 0;
|
|
|
+ __u32 zero = 0;
|
|
|
long rc =
|
|
|
bpf_probe_read_user(&stream_id, sizeof(stream_id), (void *)(stream_ptr + stream_id_pos));
|
|
|
if (rc != 0) {
|
|
|
@@ -163,19 +164,18 @@ handleStream(struct pt_regs *ctx, void *stream_ptr, struct go_iface *go_context)
|
|
|
start_tracking_span(go_context->data, &grpcReq->sc);
|
|
|
|
|
|
//处理http请求之前,确认进程信息是否存在
|
|
|
+ __u64 id = bpf_get_current_pid_tgid();
|
|
|
+ __u32 pid = id >> 32;
|
|
|
struct ebpf_proc_info *proc_info = bpf_map_lookup_elem(&proc_info_map, &pid);
|
|
|
if (!proc_info) {
|
|
|
- cw_bpf_debug("[Trace End in l7][Response][HTTP]:no proc info. pid:%d \n",k.pid);
|
|
|
+ cw_bpf_debug("[Trace End in l7][Response][HTTP]:no proc info. pid:%d \n",pid);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- __u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
- __u32 pid = pid_tgid >> 32;
|
|
|
-
|
|
|
struct l7_request_key k = {};
|
|
|
k.pid = pid;
|
|
|
- k.fd = args->fd;
|
|
|
- k.is_tls = is_tls;
|
|
|
+ k.fd = 0;
|
|
|
+ k.is_tls = 0;
|
|
|
k.stream_id = -1;
|
|
|
|
|
|
struct l7_event *e = bpf_map_lookup_elem(&l7_event_heap, &zero);
|
|
|
@@ -251,13 +251,22 @@ int uprobe_server_handleStream(struct pt_regs *ctx) {
|
|
|
u64 stream_pos = 4;
|
|
|
void *stream_ptr = get_argument(ctx, stream_pos);
|
|
|
// Get key
|
|
|
+ __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)
|
|
|
+ {
|
|
|
+ cw_bpf_debug("[uprobe_HandlerFunc_ServeHTTP] no proc info");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
struct go_iface go_context = {0};
|
|
|
- get_Go_context(ctx, stream_pos, stream_ctx_pos, false, &go_context);
|
|
|
+ get_Go_context(ctx, stream_pos, proc_info->ctx_ptr_pos, false);
|
|
|
|
|
|
return handleStream(ctx, stream_ptr, &go_context);
|
|
|
}
|
|
|
|
|
|
-UPROBE_RETURN(server_handleStream, struct grpc_request_t, grpc_events)
|
|
|
+// UPROBE_RETURN(server_handleStream, struct grpc_request_t, grpc_events)
|
|
|
|
|
|
// This instrumentation attaches uprobe to the following function:
|
|
|
// func (s *Server) handleStream(t transport.ServerTransport, stream *transport.ServerStream)
|
|
|
@@ -308,6 +317,21 @@ int uprobe_server_handleStream2(struct pt_regs *ctx) {
|
|
|
SEC("uprobe/server_handleStream2")
|
|
|
int uprobe_server_handleStream2_Returns(struct pt_regs *ctx) {
|
|
|
u64 server_stream_pos = 4;
|
|
|
+ __u64 id = bpf_get_current_pid_tgid();
|
|
|
+ __u32 zero = 0;
|
|
|
+ __u32 fd = 0;
|
|
|
+ __u32 pid, tid;
|
|
|
+ __u32 http_status = 200;
|
|
|
+
|
|
|
+ pid = id >> 32;
|
|
|
+ tid = (__u32)id;
|
|
|
+
|
|
|
+ struct l7_request_key k = {};
|
|
|
+ k.pid = pid;
|
|
|
+ k.fd = fd;
|
|
|
+ k.is_tls = 0;
|
|
|
+ k.stream_id = -1;
|
|
|
+
|
|
|
void *server_stream_ptr = get_argument(ctx, server_stream_pos);
|
|
|
void *key = NULL;
|
|
|
if (server_stream_ptr == NULL) {
|
|
|
@@ -382,9 +406,9 @@ lookup:
|
|
|
e->trace_start = 0;
|
|
|
e->trace_end = 1;
|
|
|
e->trace_id = trace_id;
|
|
|
- e->payload_size = size;
|
|
|
+ e->payload_size = 0;
|
|
|
e->event_count = event_count;
|
|
|
- COPY_PAYLOAD(e->payload, size, payload);
|
|
|
+ // COPY_PAYLOAD(e->payload, size, payload);
|
|
|
bpf_map_delete_elem(&active_l7_requests, &k);
|
|
|
// 清除事件计数
|
|
|
bpf_map_delete_elem(&trace_event_count_heap, &trace_id);
|
|
|
@@ -392,16 +416,16 @@ lookup:
|
|
|
clear_parent_span_context_by_trace_key(start_trace_info->trace_key);
|
|
|
// 清除trace信息
|
|
|
cw_clear_trace(pid, tid, fd);
|
|
|
- cw_bpf_debug("socket accept bytes_sent cid.pid=%d, cid.fd=%d\n", cid.pid, cid.fd);
|
|
|
- struct accept_connection *accept_conn = bpf_map_lookup_elem(&active_accepts, &cid);
|
|
|
- if (accept_conn) {
|
|
|
- cw_bpf_debug("socket accept bytes_sent after cid.pid=%d, cid.fd=%d\n", cid.pid, cid.fd);
|
|
|
- cw_bpf_debug("rock enter the accept_conn function cid.pid=%d, cid.fd=%d\n", cid.pid, cid.fd);
|
|
|
- e->sport = accept_conn->sport;
|
|
|
- e->dport = accept_conn->dport;
|
|
|
- __builtin_memcpy(&e->saddr, &accept_conn->saddr, sizeof(e->saddr));
|
|
|
- __builtin_memcpy(&e->daddr, &accept_conn->daddr, sizeof(e->daddr));
|
|
|
- }
|
|
|
+ // cw_bpf_debug("socket accept bytes_sent cid.pid=%d, cid.fd=%d\n", cid.pid, cid.fd);
|
|
|
+ // struct accept_connection *accept_conn = bpf_map_lookup_elem(&active_accepts, &cid);
|
|
|
+ // if (accept_conn) {
|
|
|
+ // cw_bpf_debug("socket accept bytes_sent after cid.pid=%d, cid.fd=%d\n", cid.pid, cid.fd);
|
|
|
+ // cw_bpf_debug("rock enter the accept_conn function cid.pid=%d, cid.fd=%d\n", cid.pid, cid.fd);
|
|
|
+ // e->sport = accept_conn->sport;
|
|
|
+ // e->dport = accept_conn->dport;
|
|
|
+ // __builtin_memcpy(&e->saddr, &accept_conn->saddr, sizeof(e->saddr));
|
|
|
+ // __builtin_memcpy(&e->daddr, &accept_conn->daddr, sizeof(e->daddr));
|
|
|
+ // }
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -415,33 +439,33 @@ int uprobe_http2Server_operateHeader(struct pt_regs *ctx) {
|
|
|
void *frame_ptr = is_new_frame_pos ? arg4 : arg2;
|
|
|
struct go_slice header_fields = {};
|
|
|
bpf_probe_read(&header_fields, sizeof(header_fields), (void *)(frame_ptr + frame_fields_pos));
|
|
|
- char key[W3C_KEY_LENGTH] = "traceparent";
|
|
|
- for (s32 i = 0; i < MAX_HEADERS; i++) {
|
|
|
- if (i >= header_fields.len) {
|
|
|
- break;
|
|
|
- }
|
|
|
- struct hpack_header_field hf = {};
|
|
|
- long res =
|
|
|
- bpf_probe_read(&hf, sizeof(hf), (void *)(header_fields.array + (i * sizeof(hf))));
|
|
|
- if (hf.name.len == W3C_KEY_LENGTH && hf.value.len == W3C_VAL_LENGTH) {
|
|
|
- char current_key[W3C_KEY_LENGTH];
|
|
|
- bpf_probe_read(current_key, sizeof(current_key), hf.name.str);
|
|
|
- if (bpf_memcmp(key, current_key, sizeof(key))) {
|
|
|
- char val[W3C_VAL_LENGTH];
|
|
|
- bpf_probe_read(val, W3C_VAL_LENGTH, hf.value.str);
|
|
|
-
|
|
|
- // Get stream id
|
|
|
- void *headers_frame = NULL;
|
|
|
- bpf_probe_read(&headers_frame, sizeof(headers_frame), frame_ptr);
|
|
|
- u32 stream_id = 0;
|
|
|
- bpf_probe_read(
|
|
|
- &stream_id, sizeof(stream_id), (void *)(headers_frame + frame_stream_id_pod));
|
|
|
- struct grpc_request_t grpcReq = {};
|
|
|
- w3c_string_to_span_context(val, &grpcReq.psc);
|
|
|
- bpf_map_update_elem(&streamid_to_grpc_events, &stream_id, &grpcReq, 0);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // char key[W3C_KEY_LENGTH] = "traceparent";
|
|
|
+ // for (s32 i = 0; i < MAX_HEADERS; i++) {
|
|
|
+ // if (i >= header_fields.len) {
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // struct hpack_header_field hf = {};
|
|
|
+ // long res =
|
|
|
+ // bpf_probe_read(&hf, sizeof(hf), (void *)(header_fields.ptr + (i * sizeof(hf))));
|
|
|
+ // if (hf.name.len == W3C_KEY_LENGTH && hf.value.len == W3C_VAL_LENGTH) {
|
|
|
+ // char current_key[W3C_KEY_LENGTH];
|
|
|
+ // bpf_probe_read(current_key, sizeof(current_key), hf.name.str);
|
|
|
+ // if (bpf_memcmp(key, current_key, sizeof(key))) {
|
|
|
+ // char val[W3C_VAL_LENGTH];
|
|
|
+ // bpf_probe_read(val, W3C_VAL_LENGTH, hf.value.str);
|
|
|
+
|
|
|
+ // // Get stream id
|
|
|
+ // void *headers_frame = NULL;
|
|
|
+ // bpf_probe_read(&headers_frame, sizeof(headers_frame), frame_ptr);
|
|
|
+ // u32 stream_id = 0;
|
|
|
+ // bpf_probe_read(
|
|
|
+ // &stream_id, sizeof(stream_id), (void *)(headers_frame + frame_stream_id_pod));
|
|
|
+ // struct grpc_request_t grpcReq = {};
|
|
|
+ // w3c_string_to_span_context(val, &grpcReq.psc);
|
|
|
+ // bpf_map_update_elem(&streamid_to_grpc_events, &stream_id, &grpcReq, 0);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
|
|
|
return 0;
|
|
|
}
|