Socket buffer allocation

The allocation of a socket buffer is a bit tricky, since it needs at least three different functions:

  • First of all, the whole memory allocation should be done using the netdev_alloc_skb() function
  • Increase and align header room with the skb_reserve() function
  • Extend the used data area of the buffer (which will contain the packet) using the skb_put() function.

Let's have a look at the following diagram:

Socket buffers allocation process
  1. We allocate a buffer large enough to contain a packet along with the Ethernet header by means of the netdev_alloc_skb() function:
struct sk_buff *netdev_alloc_skb(struct net_device ...

Get Linux Device Drivers Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.