net/can: Add SO_RCVBUF option for can socket #12465
Merged
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.
Summary
If the CAN stack receiving packets fast, but the application layer reading packets slow. Then
conn->readahead
will continue to grow, leading to memory leaks. Finally CAN stack potentially starve out all IOB buffers.To prevent IOB buffers leaks, users can restrict CAN socket buffer length.
Impact
Rename mm/iob/iob_get_queue_size.c to mm/iob/iob_get_queue_info.c
Discard subsequent CAN frame, when the CAN socket is full.
Testing
CAN socket can cache x packets. x = (NET_MAX_RECV_BUFSIZE + IOB_BUF_SIZE - 1)/IOB_BUF_SIZE
Set NET_MAX_RECV_BUFSIZE = 1024 when make-menuconfig.
CAN Socket could cache 6 packets.
Create a demo program as follows:
`
int main(int argc, char **argv)
{
int fd;
int buf_size;
struct ifreq ifr_can;
struct sockaddr_can can_addr_can;
}
`
CAN stack potentially starve out all IOB buffers if do not set SO_RCVBUF option.