Skip to content

EtherateMT Socket Overview

James Bensley edited this page Sep 11, 2017 · 4 revisions

A socket queue is defined by struct sk_buff_head, which includes a head and a tail pointer to sk_buff elements. All the queuing structures include an sk_buff_head representing the queue. For instance, struct sock includes a receive and send queue. Functions to manage the queues (skb_queue_head(), skb_queue_tail(), skb_dequeue(), skb_dequeue_tail()) operate on an sk_buff_head. In reality however, the sk_buff_head is included in the doubly linked list of sk_buffs (so it actually forms a ring). This means socket send and receive queues are ring buffers made from sk_buff’s.

sk->sk_rmem_alloc contains the count in bytes of packets in the socket receive queue. The default receive queue size in bytes is sk->sk_rcvbuf which can be read using getsockopt(SO_RCVBUF). This can also be read from /proc/sys/net/core/rmem_default. When receiving a packet sk_rmem_alloc is incremented by skb->truesize which it the size in bytes allocated for the data of the sk_buff plus the size of the sk_buff structure itself.

Equally the default transmit queue size is stored in /proc/sys/net/core/wmem_default and can be read with getsockopt(SO_SNDBUF). sk->sk_wmem_alloc contains the byte count of the transmit queue contents and sk->sndbuf stores the size of the send queue.

The maximum send and receive queue sizes are stored in /proc/sys/net/core/wmem_max and /proc/sys/net/core/rmem_max respectively. These maximums can be overridden by calling setsockopt(SO_RCVBUFFORCE) and setsockopt(SO_SNDBUFFORCE).

Note: The kernel doubles the SO_SNDBUF and SO_RCVBUF values (to allow space for bookkeeping overhead) when it is set using setsockopt(2), and this doubled value is returned by getsockopt(2).

One can change the default and max settings on the system using:

$ sudo sysctl -w net.core.wmem_default=8388608
$ sudo sysctl -w net.core.wmem_max=8388608

packet_release() which is called when the AF_PACKET socket is closed close(int socket_fd) creates a mutex lock brielfy with mutex_lock(&net->packet.sklist_lock); whilst the socket is deleted.