feat: Clean map when destroy socket#691
Merged
Merged
Conversation
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>
9618fcb to
ff0807c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.