Skip to content

feat: Clean map when destroy socket#691

Merged
cfc4n merged 2 commits into
gojue:masterfrom
Asphaltt:feat/destroy-sock
Dec 14, 2024
Merged

feat: Clean map when destroy socket#691
cfc4n merged 2 commits into
gojue:masterfrom
Asphaltt:feat/destroy-sock

Conversation

@Asphaltt
Copy link
Copy Markdown
Member

When a socket has been closed in kernel, the corresponding connection info in user space should be cleaned in order to avoid memory leaking.

Then, in user space, use another map to keep pid and fd for the socket with socket pointer in kernel space as key. It is because the tuple info in the socket is incorrect when destroy it.

e.g.

2024-12-13T13:23:10Z DBG AddConn success fd=5 pid=134386 tuple=192.168.241.133:35348-172.217.194.113:443
2024-12-13T13:23:10Z DBG DestroyConn success fd=5 pid=134386 tuple=192.168.241.133:35348-172.217.194.113:443
2024-12-13T13:23:16Z DBG AddConn success fd=4 pid=134404 tuple=192.168.241.1:65063-192.168.241.133:8080
2024-12-13T13:23:16Z DBG DestroyConn success fd=4 pid=134404 tuple=192.168.241.1:65063-192.168.241.133:8080

When a socket has been closed in kernel, the corresponding connection
info in user space should be cleaned in order to avoid memory leaking.

Then, in user space, use another map to keep pid and fd for the socket
with socket pointer in kernel space as key. It is because the tuple info
in the socket is incorrect when destroy it.

e.g.

```
2024-12-13T13:23:10Z DBG AddConn success fd=5 pid=134386 tuple=192.168.241.133:35348-172.217.194.113:443
2024-12-13T13:23:10Z DBG DestroyConn success fd=5 pid=134386 tuple=192.168.241.133:35348-172.217.194.113:443
2024-12-13T13:23:16Z DBG AddConn success fd=4 pid=134404 tuple=192.168.241.1:65063-192.168.241.133:8080
2024-12-13T13:23:16Z DBG DestroyConn success fd=4 pid=134404 tuple=192.168.241.1:65063-192.168.241.133:8080
```

Signed-off-by: Leon Hwang <hffilwlqm@gmail.com>
It's unnecessary to record excluding-tcp sockets' info.

So, when probe connect and accept, we only handle tcp socket by
filtering `sk->sk_protocol`.

Signed-off-by: Leon Hwang <hffilwlqm@gmail.com>
@Asphaltt Asphaltt changed the title WIP: feat: Clean map when destroy socket feat: Clean map when destroy socket Dec 13, 2024
@Asphaltt Asphaltt marked this pull request as ready for review December 13, 2024 14:53
@cfc4n cfc4n added the enhancement New feature or request label Dec 13, 2024
Copy link
Copy Markdown
Member

@cfc4n cfc4n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks.

@cfc4n cfc4n merged commit f0f1752 into gojue:master Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants