Quellcode durchsuchen

Fixed #TASK_QT-9810 修改bug。

roger.wang vor 1 Jahr
Ursprung
Commit
fc8a303efa
2 geänderte Dateien mit 42 neuen und 40 gelöschten Zeilen
  1. 3 3
      Makefile2
  2. 39 37
      ebpftracer/ebpf/l7/l7.c

+ 3 - 3
Makefile2

@@ -1,7 +1,7 @@
 FILTER=
 PARAMS=
 ifeq ($(debug),1)
-PARAMS+=debug=-D_DEBUG_MODE
+PARAMS+=debug=1
 endif
 
 ifdef pid
@@ -17,12 +17,12 @@ build:
 	CGO_ENABLED=1 go build -gcflags="all=-N -l" -buildvcs=false -o euspace
 c:
 	#docker exec -it 9d928d96d4d0 sh -c 'cd /opt/github/euspace/ebpftracer && sh build.sh${PARAMS}'
-	docker exec -it 0fec3217d6da sh -c 'cd /opt/github/euspace/ebpftracer && make all ${PARAMS}'
+	docker exec -it 3c1a4817a7ed sh -c 'cd /opt/github/euspace/ebpftracer && make all ${PARAMS}'
 c-build: c
 
 go-build:
 	#ssh [email protected] 'export https_proxy=http://10.0.22.50:4780 && source ~/.g/env && cd /opt/github/euspace && make -f Makefile2 build'
-	docker exec -it 0fec3217d6da bash -c 'cd /opt/github/euspace && source ~/.g/env && make -f Makefile2 build'
+	docker exec -it 3c1a4817a7ed bash -c 'cd /opt/github/euspace && source ~/.g/env && make -f Makefile2 build'
 go: go-build
 
 run:

+ 39 - 37
ebpftracer/ebpf/l7/l7.c

@@ -333,16 +333,8 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
     __u32 http_status ;
     pid = id >> 32;
     tid =  (__u32)id;
-    struct connection_id cid = {};
-    cid.pid = pid;
-    cid.fd = fd;
     __u64 total_size = size;
 
-    struct connection *conn = bpf_map_lookup_elem(&active_connections, &cid);
-    if (!conn) {
-        return 0;
-    }
-
     if (load_filter_pid() != 0 && pid != load_filter_pid()) {
         return 0;
     }
@@ -359,10 +351,6 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
         return 0;
     }
 
-    if (!is_tls) {
-        __sync_fetch_and_add(&conn->bytes_sent, total_size);
-    }
-
     struct l7_request *req = bpf_map_lookup_elem(&l7_request_heap, &zero);
     if (!req) {
         return 0;
@@ -373,8 +361,8 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
     req->ns = 0;
     req->payload_size = size;
     struct l7_request_key k = {};
-    k.pid = cid.pid;
-    k.fd = cid.fd;
+    k.pid = pid;
+    k.fd = fd;
     k.is_tls = is_tls;
     k.stream_id = -1;
 
@@ -455,6 +443,19 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
         return 0;
     }
 
+    struct connection_id cid = {};
+    cid.pid = pid;
+    cid.fd = fd;
+
+    struct connection *conn = bpf_map_lookup_elem(&active_connections, &cid);
+    if (!conn) {
+        return 0;
+    }
+
+    if (!is_tls) {
+        __sync_fetch_and_add(&conn->bytes_sent, total_size);
+    }
+
     if (is_http_request(payload)) {
 	    cw_bpf_debug("");
 	    cw_bpf_debug("-----[Kernel HTTP Enter]:pid:[%d]|CURRENT-GOID:[%llu]|FD:[%d]", tid, get_current_goroutine(), k.fd);
@@ -617,15 +618,15 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
 
 static inline __attribute__((__always_inline__))
 int trace_enter_read(__u64 id, __u32 pid, __u64 fd, char *buf, __u64 *ret, __u64 iovlen) {
-    struct connection_id cid = {};
-    cid.pid = pid;
-    cid.fd = fd;
-
-    struct connection *conn = bpf_map_lookup_elem(&active_connections, &cid);
-    if (!conn) {
-        return 0;
-    }
-
+    // struct connection_id cid = {};
+    // cid.pid = pid;
+    // cid.fd = fd;
+
+    // struct connection *conn = bpf_map_lookup_elem(&active_connections, &cid);
+    // if (!conn) {
+    //     // cw_bpf_debug("trace_enter_read no conn\n");
+    //     return 0;
+    // }
     struct read_args args = {};
     args.fd = fd;
     args.buf = buf;
@@ -647,17 +648,9 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
     if (!args) {
         return 0;
     }
-    struct connection_id cid = {};
-    cid.pid = pid;
-    cid.fd = args->fd;
-    struct connection *conn = bpf_map_lookup_elem(&active_connections, &cid);
-    if (!conn) {
-        bpf_map_delete_elem(&active_reads, &id);
-        return 0;
-    }
     struct l7_request_key k = {};
-    k.pid = cid.pid;
-    k.fd = cid.fd;
+    k.pid = pid;
+    k.fd = args->fd;
     k.is_tls = is_tls;
     k.stream_id = -1;
 
@@ -689,10 +682,6 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
         }
     }
 
-    if (!is_tls) {
-        __sync_fetch_and_add(&conn->bytes_received, total_size);
-    }
-
     struct l7_event *e = bpf_map_lookup_elem(&l7_event_heap, &zero);
     if (!e) {
         return 0;
@@ -777,6 +766,19 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
         return 0;
     }
 
+    struct connection_id cid = {};
+    cid.pid = pid;
+    cid.fd = args->fd;
+    struct connection *conn = bpf_map_lookup_elem(&active_connections, &cid);
+    if (args && !conn) {
+        bpf_map_delete_elem(&active_reads, &id);
+        return 0;
+    }
+
+    if (!is_tls) {
+        __sync_fetch_and_add(&conn->bytes_received, total_size);
+    }
+
     if (is_rabbitmq_consume(payload, ret)) {
         e->protocol = PROTOCOL_RABBITMQ;
         e->method = METHOD_CONSUME;