Переглянути джерело

Fixed #JiraBug28023 修复内存对齐问题

Carl 1 рік тому
батько
коміт
f43c4560cf
2 змінених файлів з 21 додано та 8 видалено
  1. 3 1
      ebpftracer/ebpf/tcp/state.c
  2. 18 7
      utils/modelse/bpf_struct.go

+ 3 - 1
ebpftracer/ebpf/tcp/state.c

@@ -76,6 +76,7 @@ struct {
     __uint(max_entries, MAX_CONNECTIONS);
 } connection_id_by_socket SEC(".maps");
 
+/* struct connection 保持与go符号对齐  utils/modelse/bpf_struct.go:229*/
 struct connection {
     __u64 timestamp;
     __u64 bytes_sent;
@@ -87,7 +88,8 @@ struct connection {
     __u16 dport;
     __u8 saddr[16];
     __u8 daddr[16];
-};
+} __attribute__((packed));
+/* struct connection 保持与go符号对齐  utils/modelse/bpf_struct.go:229*/
 
 struct accept_connection {
     __u16 sport;

+ 18 - 7
utils/modelse/bpf_struct.go

@@ -223,14 +223,25 @@ struct connection {
     __u64 first_read_time;
     __u64 first_write_time;
     __u64 new_read_time;
-};
+    __u16 sport;
+    __u16 dport;
+    __u8 saddr[16];
+    __u8 daddr[16];
+} __attribute__((packed));
 */
 
+/* 保持与c符号对齐 */
 type Connection struct {
-	Timestamp      uint64
-	BytesSent      uint64
-	BytesReceived  uint64
-	FirstReadTime  uint64
-	FirstWriteTime uint64
-	NewReadTime    uint64
+	Timestamp      uint64    // __u64
+	BytesSent      uint64    // __u64
+	BytesReceived  uint64    // __u64
+	FirstReadTime  uint64    // __u64
+	FirstWriteTime uint64    // __u64
+	NewReadTime    uint64    // __u64
+	Sport          uint16    // __u16
+	Dport          uint16    // __u16
+	Saddr          [16]uint8 // __u8[16]
+	Daddr          [16]uint8 // __u8[16]
 }
+
+/* 保持与c符号对齐 */