The SKB structure buffer for data is manipulated using various support APIs. Some of the APIs are described below with a pictorial representation of how the operation takes place.
- alloc_skb followed by skb_reserve and later followed by skb_put

- From the above picture, after alloc_skb function is invoked, the head, data and tail pointers are all pointing to the start of the data buffer.
- When skb_reserve API call is invoked to reserve headroom for various headers, the tailroom pointer moves down along with the data pointer
- when skb_put API call is invoked, the tailroom shrinks further giving space to the data region.
- Now, the head pointer points to the start of the buffer(start of headroom)
- The data pointer points to the start of the data region
- The tail pointer points to the start of the tailroom region
- The end pointer points to the absolute end of the allocated SKB buffer
- The length of the data region is also saved in the length element of the structure
- skb_push API operation

- When some header is to be appended at the start of the Data packet, the skb_push API is utilised to achieve that result.
- when skb_push API is used, the headroom shrinks and the data pointer is moved up to include the new header as part of the data region
- The data packet length is updated to correspond to the new length of the data packet
- skb_put API operation

- When some information has to be appended at the bottom of the data packet (for e.g. CRC), the skb_put operation is used.
- The skb_put operation, provides space from the top of the tailroom
- The tailroom shrinks and the tail pointer is moved down.
- data packet length is updated to correspond to the new length of the data packet
- skb_trim API operation

- When some information has to be removed from the bottom of the data packet (for e.g. CRC), the skb_trim operation is used.
- The skb_trim operation
- The tailroom grows and the tail pointer is moved up.
- data packet length is updated to correspond to the new length of the data packet
Pingback: Linux Socket Buffer (SKB) | Hitch Hiker's Guide to Learning