|
@@ -85,6 +85,13 @@ struct connection {
|
|
|
__u64 new_read_time;
|
|
__u64 new_read_time;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+struct accept_connection {
|
|
|
|
|
+ __u16 sport;
|
|
|
|
|
+ __u16 dport;
|
|
|
|
|
+ __u8 saddr[16];
|
|
|
|
|
+ __u8 daddr[16];
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
struct {
|
|
struct {
|
|
|
__uint(type, BPF_MAP_TYPE_LRU_HASH);
|
|
__uint(type, BPF_MAP_TYPE_LRU_HASH);
|
|
|
__uint(key_size, sizeof(struct connection_id));
|
|
__uint(key_size, sizeof(struct connection_id));
|
|
@@ -95,7 +102,7 @@ struct {
|
|
|
struct {
|
|
struct {
|
|
|
__uint(type, BPF_MAP_TYPE_LRU_HASH);
|
|
__uint(type, BPF_MAP_TYPE_LRU_HASH);
|
|
|
__uint(key_size, sizeof(struct connection_id));
|
|
__uint(key_size, sizeof(struct connection_id));
|
|
|
- __uint(value_size, sizeof(struct connection));
|
|
|
|
|
|
|
+ __uint(value_size, sizeof(struct accept_connection));
|
|
|
__uint(max_entries, MAX_CONNECTIONS);
|
|
__uint(max_entries, MAX_CONNECTIONS);
|
|
|
} active_accepts SEC(".maps");
|
|
} active_accepts SEC(".maps");
|
|
|
|
|
|
|
@@ -275,19 +282,19 @@ int sys_enter_close(void *ctx) {
|
|
|
bpf_map_delete_elem(&active_connections, &cid);
|
|
bpf_map_delete_elem(&active_connections, &cid);
|
|
|
}
|
|
}
|
|
|
cw_bpf_debug("socket accept socket sys_enter_close accept_Connection before cid.pid=%d, cid.fd=%d\n", cid.pid, cid.fd);
|
|
cw_bpf_debug("socket accept socket sys_enter_close accept_Connection before cid.pid=%d, cid.fd=%d\n", cid.pid, cid.fd);
|
|
|
- struct connection *acceptConn = bpf_map_lookup_elem(&active_accepts, &cid);
|
|
|
|
|
|
|
+ struct accept_connection *acceptConn = bpf_map_lookup_elem(&active_accepts, &cid);
|
|
|
if (acceptConn) {
|
|
if (acceptConn) {
|
|
|
- struct tcp_event e = {};
|
|
|
|
|
- e.type = EVENT_TYPE_ACCEPT_CLOSE;
|
|
|
|
|
- e.pid = cid.pid;
|
|
|
|
|
- e.fd = cid.fd;
|
|
|
|
|
- e.bytes_sent = acceptConn->bytes_sent;
|
|
|
|
|
- e.bytes_received = acceptConn->bytes_received;
|
|
|
|
|
- e.timestamp = acceptConn->timestamp;
|
|
|
|
|
- bpf_perf_event_output(ctx, &tcp_accept_events, BPF_F_CURRENT_CPU, &e, sizeof(e));
|
|
|
|
|
|
|
+ // struct tcp_event e = {};
|
|
|
|
|
+ // e.type = EVENT_TYPE_ACCEPT_CLOSE;
|
|
|
|
|
+ // e.pid = cid.pid;
|
|
|
|
|
+ // e.fd = cid.fd;
|
|
|
|
|
+ // e.bytes_sent = acceptConn->bytes_sent;
|
|
|
|
|
+ // e.bytes_received = acceptConn->bytes_received;
|
|
|
|
|
+ // e.timestamp = acceptConn->timestamp;
|
|
|
|
|
+ // bpf_perf_event_output(ctx, &tcp_accept_events, BPF_F_CURRENT_CPU, &e, sizeof(e));
|
|
|
bpf_map_delete_elem(&active_accepts, &cid);
|
|
bpf_map_delete_elem(&active_accepts, &cid);
|
|
|
- cw_bpf_debug("socket accept socket sys_enter_close accept_Connection cid.pid=%d, cid.fd=%d\n", cid.pid, cid.fd);
|
|
|
|
|
- cw_bpf_debug("socket accept socket sys_enter_close accept_Connection cid.bytes_sent=%d, cid.bytes_received=%d\n", e.bytes_sent, e.bytes_received);
|
|
|
|
|
|
|
+ // cw_bpf_debug("socket accept socket sys_enter_close accept_Connection cid.pid=%d, cid.fd=%d\n", cid.pid, cid.fd);
|
|
|
|
|
+ // cw_bpf_debug("socket accept socket sys_enter_close accept_Connection cid.bytes_sent=%d, cid.bytes_received=%d\n", e.bytes_sent, e.bytes_received);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//TODO 2,增加active_accept 对应的判断,类比234行操作,新增EVENT_TYPE_accept_conn_CLOSE类型
|
|
//TODO 2,增加active_accept 对应的判断,类比234行操作,新增EVENT_TYPE_accept_conn_CLOSE类型
|
|
@@ -453,8 +460,11 @@ int tracepoint__sys_exit_accept4(struct sys_exit_accept4_ctx *ctx) {
|
|
|
cid.pid = pid_tgid >> 32;
|
|
cid.pid = pid_tgid >> 32;
|
|
|
cid.fd = fd;
|
|
cid.fd = fd;
|
|
|
|
|
|
|
|
- struct connection conn = {};
|
|
|
|
|
- conn.timestamp = bpf_ktime_get_ns();
|
|
|
|
|
|
|
+ struct accept_connection conn = {};
|
|
|
|
|
+ conn.sport = tuple.sport;
|
|
|
|
|
+ conn.dport = tuple.dport;
|
|
|
|
|
+ __builtin_memcpy(&conn.saddr, &saddr, sizeof(conn.saddr));
|
|
|
|
|
+ __builtin_memcpy(&conn.daddr, &daddr, sizeof(conn.daddr));
|
|
|
cw_bpf_debug("socket accept update active_accepts before cid.pid=%d, cid.fd=%lld\n", cid.pid, cid.fd);
|
|
cw_bpf_debug("socket accept update active_accepts before cid.pid=%d, cid.fd=%lld\n", cid.pid, cid.fd);
|
|
|
bpf_map_update_elem(&active_accepts, &cid, &conn, BPF_ANY);
|
|
bpf_map_update_elem(&active_accepts, &cid, &conn, BPF_ANY);
|
|
|
cw_bpf_debug("socket accept update active_accepts after cid.pid=%d, cid.fd=%lld\n", cid.pid, cid.fd);
|
|
cw_bpf_debug("socket accept update active_accepts after cid.pid=%d, cid.fd=%lld\n", cid.pid, cid.fd);
|