Parcourir la source

Feature #TASK_QT-31498 cwother影响es数据发送

Carl il y a 5 mois
Parent
commit
c65d58f6f6

+ 1 - 0
dist/aarch64/package_dir/bin/agentctl

@@ -136,6 +136,7 @@ startAgent() {
     export DISABLE_STACK_TRACING=true
     export RUN_IN_OMNIAGENT=true
 #    export SEND_NET_DATA=true
+#    export ENABLE_ES=true
     export SEND=1
     local params="--listen=0.0.0.0:8123"
 #    if [ -f "/etc/chaosd/pki/ca.crt" ] && [ -f "/etc/chaosd/pki/chaosd.crt" ] && [ -f "/etc/chaosd/pki/chaosd.key" ]; then

+ 1 - 0
dist/x86_64/package_dir/bin/agentctl

@@ -136,6 +136,7 @@ startAgent() {
     export DISABLE_STACK_TRACING=true
     export RUN_IN_OMNIAGENT=true
 #    export SEND_NET_DATA=true
+#    export ENABLE_ES=true
     export SEND=1
     local params="--listen=0.0.0.0:8123"
 #    if [ -f "/etc/chaosd/pki/ca.crt" ] && [ -f "/etc/chaosd/pki/chaosd.crt" ] && [ -f "/etc/chaosd/pki/chaosd.key" ]; then

+ 27 - 13
ebpftracer/ebpf/utrace/go/net/client.probe.bpf.c

@@ -659,20 +659,34 @@ int uprobe_writeSubset(struct pt_regs *ctx) {
 				bpf_probe_read(sys_storage->sys_val, sizeof(sys_storage->sys_val), proc_info->sysvc);
 				
 				// 检查 sysvc 是否有值(第一个字符不是 '\0')
-				if (sys_storage->sys_val[0] != '\0' && len < (size - CW_SYS_HEADER_VAL_LENGTH - CW_SYS_HEADER_KEY_LENGTH - 4)) {
-					// Initialize sys_str with "cwother: "
-					__builtin_memcpy(sys_storage->sys_str, "cwother: ", CW_SYS_HEADER_KEY_LENGTH + 2);
-					__builtin_memcpy(&sys_storage->sys_str[CW_SYS_HEADER_KEY_LENGTH + 2], sys_storage->sys_val, sizeof(sys_storage->sys_val));
-					__builtin_memcpy(&sys_storage->sys_str[CW_SYS_HEADER_KEY_LENGTH + 2 + CW_SYS_HEADER_VAL_LENGTH], "\r\n", 2);
-					
-					if (bpf_probe_write_user(buf_ptr + (len & 0x0ffff), sys_storage->sys_str, sizeof(sys_storage->sys_str))) {
-						cw_bpf_debug("uprobe_writeSubset: Failed to write cwother header in buffer");
-						goto done;
+				if (sys_storage->sys_val[0] != '\0') {
+					u32 sys_val_len = CW_SYS_HEADER_VAL_LENGTH;
+					#pragma unroll
+					for (int i = 0; i < CW_SYS_HEADER_VAL_LENGTH; i++) {
+						char c = sys_storage->sys_val[i];
+						if (c == '\0') {
+							sys_val_len = i;
+							break;
+						}
 					}
-					len += CW_SYS_HEADER_KEY_LENGTH + 2 + CW_SYS_HEADER_VAL_LENGTH + 2;
-					if (bpf_probe_write_user((void *) (io_writer_ptr + proc_info->io_writer_n_pos), &len, sizeof(len))) {
-						cw_bpf_debug("uprobe_writeSubset: Failed to change io writer n for cwother");
-						goto done;
+
+					// 检查缓冲区空间
+					u32 total_header_len = CW_SYS_HEADER_KEY_LENGTH + 2 + sys_val_len + 2; // "cwother: " + sys_val + "\r\n"
+					if (len + total_header_len <= size) {
+						// Initialize sys_str with "cwother: "
+						__builtin_memcpy(sys_storage->sys_str, "cwother: ", CW_SYS_HEADER_KEY_LENGTH + 2);
+						__builtin_memcpy(&sys_storage->sys_str[CW_SYS_HEADER_KEY_LENGTH + 2], sys_storage->sys_val, CW_SYS_HEADER_VAL_LENGTH);
+						__builtin_memcpy(&sys_storage->sys_str[CW_SYS_HEADER_KEY_LENGTH + 2 + sys_val_len], "\r\n", 2);
+
+						if (bpf_probe_write_user(buf_ptr + (len & 0x0ffff), sys_storage->sys_str, total_header_len)) {
+							cw_bpf_debug("uprobe_writeSubset: Failed to write cwother header in buffer");
+							goto done;
+						}
+						len += total_header_len;
+						if (bpf_probe_write_user((void *) (io_writer_ptr + proc_info->io_writer_n_pos), &len, sizeof(len))) {
+							cw_bpf_debug("uprobe_writeSubset: Failed to change io writer n for cwother");
+							goto done;
+						}
 					}
 				}
 			}