The previous article (here) discussed a few of the commonly used Socket Buff (SKB) APIs to modify the socket buffer allocated. The below APIs are also used to access different regions of the buffer or to act on the buffer in a desired manner and more widely seen.
- skb_headroom – Check the headroom available
- skb_tailroom – check the tailroom available
- dev_alloc_skb – allocate an SKB buffer, set a usage count of 1 and map dev parameter to skb->dev
- internally invokes netdev_alloc_skb
- kfree_skb – free an SKB and its data. The drop reason is mentioned as SKB_DROP_REASON_NOT_SPECIFIED
- dev_kfree_skb – a variant of kfree_skb used by device drivers. Internally, it invokes consume_skb which drops one reference count to SKB and frees the buffer if reference count is zero.
- skb_clone – create a copy of the skb_buff structure. The data buffer pointers are maintained the same. Only the metadata portion is copied and the reference count for the SKB packet is increased by 1.
- skb_copy – copy the entire metadata and data buffer portion. The new SKB created will have its own reference count.
- Certain APIs that use elements in the sk_buff structure to point to different network headers in the packet
- transport_header – value which is an offset from skb->head which points to the transport header.
- The API – skb_transport_header points to the transport header
- network_header – value which is an offset from skb->head which points to the network header.
- The API – skb_network_header points to the network header
- mac_header – value which is an offset from skb->head which points to the MAC header
- The API – skb_mac_header points to the MAC header
- transport_header – value which is an offset from skb->head which points to the transport header.
- skb_get – increases the reference count of the SKB
- consume_skb – frees the SKB. It decrements the reference count and only frees the SKB when the reference count for the SKB reaches zero.
There are quite a few APIs that operate on an SKB. The above list only provides some of the most commonly seen and queried APIs. To look at the different APIs – refer the skbuff.h header file (skbuff.h for 6.12)
Pingback: Socket Buffer(SKB) Manipulation APIs | Hitch Hiker's Guide to Learning