Linux Socket Buffer (SKB)

The socket buffer is the most commonly heard data structure in the Linux networking code. It forms the basis of how data packets are handled in the Linux network stack. The data structure can be viewed in the header file – skbuff.h. The structure – struct sk_buff contains numerous parameters. We look at some of the most common ones and also understand some of common MACROs for Socket buffers in the following few articles.

It is important to understand that “struct sk_buff” is a metadata structure. It contains control information and details of the packet rather than the packet itself. It provides a buffer memory with pointers to access the buffer memory which is placed elsewhere in memory. The skbuff structure is placed below for reference.

FIG Courtesy: https://linux-kernel-labs.github.io/refs/heads/master/labs/networking.html

Earlier, there was a struct skb_buff_head structure which was a doubly-linked list of sk_buff structures containing the *next and *prev pointers (seen in some older code). It is now removed from the sk_buff structure and made separate. The *prev and *next pointers point to previous and next sk_buff respectively.

The data packet pointers of the above structure can be pictured in the below format:

FIG Courtesy: https://docs.kernel.org/networking/skbuff.html

The parameters:

  1. head pointer – points to the head of the packet buffer
  2. data pointer – points to the start of data
  3. tail pointer – points to the end of relevant data for the data buffer
  4. end – points to the absolute end of allocated memory for the data buffer

The skb_shared_info holds information about fragmented packets and also holds the reference count for cloned SKBs.

Socket Buffer Manipulation APIs

Comments

  1. Pingback: Network device driver interfaced to a Hardware peripheral | Hitch Hiker's Guide to Learning

Leave a Reply

Your email address will not be published. Required fields are marked *