|
@@ -145,7 +145,6 @@ struct l7_request {
|
|
|
__u64 payload_size;
|
|
__u64 payload_size;
|
|
|
char payload[MAX_PAYLOAD_SIZE];
|
|
char payload[MAX_PAYLOAD_SIZE];
|
|
|
};
|
|
};
|
|
|
-
|
|
|
|
|
struct {
|
|
struct {
|
|
|
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
|
|
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
|
|
|
__type(key, int);
|
|
__type(key, int);
|
|
@@ -160,6 +159,37 @@ struct {
|
|
|
__uint(max_entries, 32768);
|
|
__uint(max_entries, 32768);
|
|
|
} active_l7_requests SEC(".maps");
|
|
} active_l7_requests SEC(".maps");
|
|
|
|
|
|
|
|
|
|
+struct l7_request_dm_ctx {
|
|
|
|
|
+// __u8 request_type;
|
|
|
|
|
+ __u64 req_start_at_ns;
|
|
|
|
|
+
|
|
|
|
|
+// char db_name[128] ;
|
|
|
|
|
+// __s32 srv_encoding ;
|
|
|
|
|
+
|
|
|
|
|
+ __u64 query_sql_payload_size;
|
|
|
|
|
+ char query_sql_payload[MAX_PAYLOAD_SIZE];
|
|
|
|
|
+
|
|
|
|
|
+ __u32 status;
|
|
|
|
|
+// __s32 svr_err_code;
|
|
|
|
|
+// __u64 svr_err_msg_size;
|
|
|
|
|
+// char svr_err_msg[MAX_PAYLOAD_SIZE];
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+struct {
|
|
|
|
|
+ __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
|
|
|
|
|
+ __type(key, int);
|
|
|
|
|
+ __type(value, struct l7_request_dm_ctx);
|
|
|
|
|
+ __uint(max_entries, 1);
|
|
|
|
|
+} l7_request_dm_ctx_heap SEC(".maps");
|
|
|
|
|
+
|
|
|
|
|
+struct {
|
|
|
|
|
+ __uint(type, BPF_MAP_TYPE_LRU_HASH);
|
|
|
|
|
+ __uint(key_size, sizeof(struct l7_request_key));
|
|
|
|
|
+ __uint(value_size, sizeof(struct l7_request_dm_ctx));
|
|
|
|
|
+ __uint(max_entries, 32768);
|
|
|
|
|
+} active_l7_requests_dm_ctx SEC(".maps");
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
struct {
|
|
struct {
|
|
|
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
|
|
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
|
|
|
__type(key, int);
|
|
__type(key, int);
|
|
@@ -414,8 +444,38 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
|
|
|
}
|
|
}
|
|
|
req->protocol = PROTOCOL_MYSQL;
|
|
req->protocol = PROTOCOL_MYSQL;
|
|
|
} else if (is_dm_query(payload, size,&req->request_type)) {
|
|
} else if (is_dm_query(payload, size,&req->request_type)) {
|
|
|
- bpf_printk("[Enter][DM]:req->request_type:%d\n",req->request_type);
|
|
|
|
|
- req->protocol = PROTOCOL_DM;
|
|
|
|
|
|
|
+ bpf_printk("[Request][DM] start -------->");
|
|
|
|
|
+ req->protocol = PROTOCOL_DM;
|
|
|
|
|
+
|
|
|
|
|
+ struct l7_request_dm_ctx *dm_ctx ;
|
|
|
|
|
+ dm_ctx = bpf_map_lookup_elem(&active_l7_requests_dm_ctx, &k);
|
|
|
|
|
+ if (!dm_ctx) {
|
|
|
|
|
+ dm_ctx = bpf_map_lookup_elem(&l7_request_dm_ctx_heap, &zero);
|
|
|
|
|
+ if (!dm_ctx) {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ dm_ctx->req_start_at_ns = 0 ;
|
|
|
|
|
+ dm_ctx->status = 0;
|
|
|
|
|
+ bpf_map_update_elem(&active_l7_requests_dm_ctx, &k, dm_ctx, BPF_NOEXIST);
|
|
|
|
|
+ bpf_printk("[Request][DM] init active_l7_requests_dm_ctx,request_type <0x%x> [%d]",req->request_type,req->request_type);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (req->request_type == DM_QUERY) {
|
|
|
|
|
+
|
|
|
|
|
+ dm_ctx->req_start_at_ns=bpf_ktime_get_ns();
|
|
|
|
|
+ req->ns = dm_ctx->req_start_at_ns ;
|
|
|
|
|
+
|
|
|
|
|
+ dm_ctx->query_sql_payload_size = size;
|
|
|
|
|
+ COPY_PAYLOAD(dm_ctx->query_sql_payload, size, payload);
|
|
|
|
|
+ bpf_map_update_elem(&active_l7_requests_dm_ctx, &k, dm_ctx, BPF_ANY);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(req->request_type == DM_STMT_EXECUTE) {
|
|
|
|
|
+ bpf_map_update_elem(&active_l7_requests, &k, req, BPF_ANY);
|
|
|
|
|
+ return 0 ;
|
|
|
|
|
+ }
|
|
|
|
|
+ bpf_printk("[Request][DM] is request ,request_type <0x%x> [%d]",req->request_type,req->request_type);
|
|
|
|
|
+ bpf_printk("[Request][DM] end <--------");
|
|
|
} else if (is_mongo_query(payload, size)) {
|
|
} else if (is_mongo_query(payload, size)) {
|
|
|
req->protocol = PROTOCOL_MONGO;
|
|
req->protocol = PROTOCOL_MONGO;
|
|
|
} else if (is_rabbitmq_produce(payload, size)) {
|
|
} else if (is_rabbitmq_produce(payload, size)) {
|
|
@@ -729,12 +789,152 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
|
|
|
e->method = METHOD_STATEMENT_PREPARE;
|
|
e->method = METHOD_STATEMENT_PREPARE;
|
|
|
}
|
|
}
|
|
|
} else if (e->protocol == PROTOCOL_DM) {
|
|
} else if (e->protocol == PROTOCOL_DM) {
|
|
|
|
|
+
|
|
|
|
|
+ bpf_printk("[Response][DM] start -------->");
|
|
|
|
|
+
|
|
|
|
|
+ struct l7_request_dm_ctx *dm_ctx = bpf_map_lookup_elem(&active_l7_requests_dm_ctx, &k);
|
|
|
|
|
+ if (!dm_ctx) {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ //获取server端的字符集类型(用来编码数据库名称,暂时不用)
|
|
|
|
|
+// if(req->request_type == DM_VERSION_CLI) {
|
|
|
|
|
+// __u8 srv_encode_buf[4];
|
|
|
|
|
+// bpf_read(payload+DM_SVR_ENCODING_OFFSET, srv_encode_buf);
|
|
|
|
|
+//
|
|
|
|
|
+// bpf_printk(" srv_encode_buf:[0x%x]",srv_encode_buf[0]);
|
|
|
|
|
+// bpf_printk(" srv_encode_buf:[0x%x]",srv_encode_buf[1]);
|
|
|
|
|
+// bpf_printk(" srv_encode_buf:[0x%x]",srv_encode_buf[2]);
|
|
|
|
|
+// bpf_printk(" srv_encode_buf:[0x%x]",srv_encode_buf[3]);
|
|
|
|
|
+// dm_ctx->srv_encoding = (__s32)(srv_encode_buf[0]& 0xff) | ((__s32)srv_encode_buf[1]&0xff) << 8 | ((__s32)srv_encode_buf[2]&0xff) << 16 | ((__s32)srv_encode_buf[3]&0xff) << 24 ;
|
|
|
|
|
+// bpf_printk(" srv_encode_buf:[%d]",dm_ctx->srv_encoding);
|
|
|
|
|
+// bpf_map_update_elem(&active_l7_requests_dm_ctx, &k, dm_ctx, BPF_ANY);
|
|
|
|
|
+// return 0;
|
|
|
|
|
+// }
|
|
|
|
|
+ //获取数据库名称(暂时不用)
|
|
|
|
|
+// if(req->request_type == DM_DO_LOGIN ) {
|
|
|
|
|
+//// //todo 拷贝payload 不进行处理,留给用户空间处理
|
|
|
|
|
+//// //pack_type == DM_LOGIN_ACK
|
|
|
|
|
+// if (ret == DM_HEADER_SIZE) {
|
|
|
|
|
+// bpf_map_update_elem(&active_l7_requests, &k, req, BPF_ANY);
|
|
|
|
|
+// return 0;
|
|
|
|
|
+// }
|
|
|
|
|
+//// //获取数据库名称
|
|
|
|
|
+// // bpf_read(buf+DM_PAYLOAD_OFFSET, svr_encode_buf);
|
|
|
|
|
+// __u8 tmp_1[4];
|
|
|
|
|
+// // __u32 tmp_offset = DM_PAYLOAD_OFFSET ;
|
|
|
|
|
+// __u32 tmp_offset = 0 ;
|
|
|
|
|
+// //1
|
|
|
|
|
+// bpf_read(payload+tmp_offset, tmp_1);
|
|
|
|
|
+// __s32 tmp_len = (__s32)(tmp_1[0]& 0xff) | ((__s32)tmp_1[1]&0xff) << 8 | ((__s32)tmp_1[2]&0xff) << 16 | ((__s32)tmp_1[3]&0xff) << 24 ;
|
|
|
|
|
+// tmp_offset = tmp_offset + 4 ;
|
|
|
|
|
+// tmp_offset = tmp_offset+tmp_len ;
|
|
|
|
|
+// bpf_printk("===== DM_LOGIN_ACK ----1 tmp_len:%d",tmp_len);
|
|
|
|
|
+//
|
|
|
|
|
+// //2
|
|
|
|
|
+// bpf_read(payload+tmp_offset,tmp_1);
|
|
|
|
|
+// tmp_len = (__s32)(tmp_1[0]& 0xff) | ((__s32)tmp_1[1]&0xff) << 8 | ((__s32)tmp_1[2]&0xff) << 16 | ((__s32)tmp_1[3]&0xff) << 24 ;
|
|
|
|
|
+// tmp_offset = tmp_offset + 4 ;
|
|
|
|
|
+// tmp_offset = tmp_offset+tmp_len ;
|
|
|
|
|
+// bpf_printk("===== DM_LOGIN_ACK ----2 tmp_len:%d",tmp_len);
|
|
|
|
|
+// //3
|
|
|
|
|
+// bpf_read(payload+tmp_offset,tmp_1);
|
|
|
|
|
+// tmp_len = (__s32)(tmp_1[0]& 0xff) | ((__s32)tmp_1[1]&0xff) << 8 | ((__s32)tmp_1[2]&0xff) << 16 | ((__s32)tmp_1[3]&0xff) << 24 ;
|
|
|
|
|
+// tmp_offset = tmp_offset + 4 ;
|
|
|
|
|
+// tmp_offset = tmp_offset+tmp_len ;
|
|
|
|
|
+// bpf_printk("===== DM_LOGIN_ACK ----3 tmp_len:%d",tmp_len);
|
|
|
|
|
+// //4
|
|
|
|
|
+// bpf_read(payload+tmp_offset,tmp_1);
|
|
|
|
|
+// tmp_len = (__s32)(tmp_1[0]& 0xff) | ((__s32)tmp_1[1]&0xff) << 8 | ((__s32)tmp_1[2]&0xff) << 16 | ((__s32)tmp_1[3]&0xff) << 24 ;
|
|
|
|
|
+// tmp_offset = tmp_offset + 4 ;
|
|
|
|
|
+// tmp_offset = tmp_offset+tmp_len ;
|
|
|
|
|
+// bpf_printk("===== DM_LOGIN_ACK ----4 tmp_len:%d",tmp_len);
|
|
|
|
|
+// //5
|
|
|
|
|
+// bpf_read(payload+tmp_offset,tmp_1);
|
|
|
|
|
+// tmp_len = (__s32)(tmp_1[0]& 0xff) | ((__s32)tmp_1[1]&0xff) << 8 | ((__s32)tmp_1[2]&0xff) << 16 | ((__s32)tmp_1[3]&0xff) << 24 ;
|
|
|
|
|
+// tmp_offset = tmp_offset + 4 ;
|
|
|
|
|
+// tmp_offset = tmp_offset+tmp_len ;
|
|
|
|
|
+// bpf_printk("===== DM_LOGIN_ACK ----5 tmp_len:%d",tmp_len);
|
|
|
|
|
+// //6
|
|
|
|
|
+// bpf_read(payload+tmp_offset,tmp_1);
|
|
|
|
|
+// tmp_len = (__s32)(tmp_1[0]& 0xff) | ((__s32)tmp_1[1]&0xff) << 8 | ((__s32)tmp_1[2]&0xff) << 16 | ((__s32)tmp_1[3]&0xff) << 24 ;
|
|
|
|
|
+// tmp_offset = tmp_offset + 4 ;
|
|
|
|
|
+// tmp_offset = tmp_offset+tmp_len ;
|
|
|
|
|
+// bpf_printk("===== DM_LOGIN_ACK ----6 tmp_len:%d",tmp_len);
|
|
|
|
|
+// //7
|
|
|
|
|
+// bpf_read(payload+tmp_offset,tmp_1);
|
|
|
|
|
+// tmp_len = (__s32)(tmp_1[0]& 0xff) | ((__s32)tmp_1[1]&0xff) << 8 | ((__s32)tmp_1[2]&0xff) << 16 | ((__s32)tmp_1[3]&0xff) << 24 ;
|
|
|
|
|
+// tmp_offset = tmp_offset + 4 ;
|
|
|
|
|
+// tmp_offset = tmp_offset+tmp_len ;
|
|
|
|
|
+// bpf_printk("===== DM_LOGIN_ACK ----7 tmp_len:%d",tmp_len);
|
|
|
|
|
+// //8
|
|
|
|
|
+// bpf_read(payload+tmp_offset,tmp_1);
|
|
|
|
|
+// tmp_len = (__s32)(tmp_1[0]& 0xff) | ((__s32)tmp_1[1]&0xff) << 8 | ((__s32)tmp_1[2]&0xff) << 16 | ((__s32)tmp_1[3]&0xff) << 24 ;
|
|
|
|
|
+// tmp_offset = tmp_offset + 4 ;
|
|
|
|
|
+// tmp_offset = tmp_offset+tmp_len ;
|
|
|
|
|
+// bpf_printk("===== DM_LOGIN_ACK ----8 tmp_len:%d",tmp_len);
|
|
|
|
|
+//
|
|
|
|
|
+// //9
|
|
|
|
|
+// tmp_offset = tmp_offset + 4 ;
|
|
|
|
|
+// //10
|
|
|
|
|
+// tmp_offset = tmp_offset + 4 ;
|
|
|
|
|
+// //11
|
|
|
|
|
+// tmp_offset = tmp_offset + 4 ;
|
|
|
|
|
+// //12
|
|
|
|
|
+// bpf_read(payload+tmp_offset,tmp_1);
|
|
|
|
|
+// tmp_len = (__s32)(tmp_1[0]& 0xff) | ((__s32)tmp_1[1]&0xff) << 8 | ((__s32)tmp_1[2]&0xff) << 16 | ((__s32)tmp_1[3]&0xff) << 24 ;
|
|
|
|
|
+// tmp_offset = tmp_offset + 4 ;
|
|
|
|
|
+// tmp_offset = tmp_offset+tmp_len ;
|
|
|
|
|
+// bpf_printk("===== DM_LOGIN_ACK ----12 tmp_len:%d",tmp_len);
|
|
|
|
|
+// //13
|
|
|
|
|
+// bpf_read(payload+tmp_offset,tmp_1);
|
|
|
|
|
+// tmp_offset = tmp_offset + 4 ;
|
|
|
|
|
+// tmp_len = (__s32)(tmp_1[0]& 0xff) | ((__s32)tmp_1[1]&0xff) << 8 | ((__s32)tmp_1[2]&0xff) << 16 | ((__s32)tmp_1[3]&0xff) << 24 ;
|
|
|
|
|
+// bpf_printk("===== DM_LOGIN_ACK ----13 tmp_len:%d",tmp_len);
|
|
|
|
|
+//
|
|
|
|
|
+// bpf_printk("===== DM_LOGIN_ACK dbName tmp_offset:%d",tmp_offset);
|
|
|
|
|
+// if(tmp_len>0){
|
|
|
|
|
+//// char dbNameBuff[7] ;
|
|
|
|
|
+// char dbNameBuff[128] ;
|
|
|
|
|
+// if(tmp_len > 128){
|
|
|
|
|
+// tmp_len = 128;
|
|
|
|
|
+// }
|
|
|
|
|
+// bpf_read(payload+tmp_offset,dbNameBuff);
|
|
|
|
|
+// dbNameBuff[tmp_len-1]='\0';
|
|
|
|
|
+//// bpf_printk("===== DM-resp DM_LOGIN_ACK dbName[0]:%c",dbNameBuff[0]);
|
|
|
|
|
+//// bpf_printk("===== DM-resp DM_LOGIN_ACK dbName[1]:%c",dbNameBuff[1]);
|
|
|
|
|
+//// bpf_printk("===== DM-resp DM_LOGIN_ACK dbName[2]:%c",dbNameBuff[2]);
|
|
|
|
|
+//// bpf_printk("===== DM-resp DM_LOGIN_ACK dbName[3]:%c",dbNameBuff[3]);
|
|
|
|
|
+//// bpf_printk("===== DM-resp DM_LOGIN_ACK dbName[4]:%c",dbNameBuff[4]);
|
|
|
|
|
+//// bpf_printk("===== DM-resp DM_LOGIN_ACK dbName[5]:%c",dbNameBuff[5]);
|
|
|
|
|
+// bpf_printk("===== DM_LOGIN_ACK dbName:%s",dbNameBuff);
|
|
|
|
|
+//
|
|
|
|
|
+// __u32 dn_name_size = (__u32)tmp_len + 1 ;
|
|
|
|
|
+// COPY_PAYLOAD(dm_ctx->db_name,dn_name_size, dbNameBuff);
|
|
|
|
|
+// bpf_printk("===== DM_LOGIN_ACK strcpy(db_name,dbNameBuff):%s",dm_ctx->db_name);
|
|
|
|
|
+// bpf_map_update_elem(&active_l7_requests_dm_ctx, &k, dm_ctx, BPF_ANY);
|
|
|
|
|
+// }
|
|
|
|
|
+// return 0;
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
__u64 trace_id = get_apm_trace_id(pid, tid);
|
|
__u64 trace_id = get_apm_trace_id(pid, tid);
|
|
|
e->trace_id = trace_id;
|
|
e->trace_id = trace_id;
|
|
|
- bpf_printk("[DM] trace_id:%llu", trace_id);
|
|
|
|
|
- bpf_printk("[Response][DM] ---------start");
|
|
|
|
|
- response = is_dm_response(payload, ret, req->request_type, &e->statement_id, &e->status);
|
|
|
|
|
- bpf_printk("[Response][DM]end ---------- %d\n",e->status);
|
|
|
|
|
|
|
+// bpf_printk("[Response][DM] trace_id:%llu", trace_id);
|
|
|
|
|
+
|
|
|
|
|
+ response = is_dm_response(payload, ret, req->request_type, &dm_ctx->status);
|
|
|
|
|
+// bpf_printk("[Response][DM] is_dm_response status ---------- %d",dm_ctx->status);
|
|
|
|
|
+
|
|
|
|
|
+ if(response) {
|
|
|
|
|
+ req->ns = dm_ctx->req_start_at_ns;
|
|
|
|
|
+ e->status = dm_ctx->status;
|
|
|
|
|
+ e->payload_size = dm_ctx->query_sql_payload_size;
|
|
|
|
|
+ COPY_PAYLOAD(e->payload, dm_ctx->query_sql_payload_size, dm_ctx->query_sql_payload);
|
|
|
|
|
+ bpf_map_delete_elem(&active_l7_requests_dm_ctx, &k);
|
|
|
|
|
+ bpf_printk("[Response][DM] is response ,delete active_l7_requests_dm_ctx -- req->request_type<0x%x> , e->payload_size:[%d]",req->request_type,e->payload_size);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ bpf_printk("[Response][DM] not response req->request_type <0x%x>",req->request_type);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ bpf_printk("[Response][DM] end <---------\n");
|
|
|
} else if (e->protocol == PROTOCOL_MONGO) {
|
|
} else if (e->protocol == PROTOCOL_MONGO) {
|
|
|
response = is_mongo_response(payload, ret, req->partial);
|
|
response = is_mongo_response(payload, ret, req->partial);
|
|
|
if (response == 2) { // partial
|
|
if (response == 2) { // partial
|