Page 298 - DCAP403_Operating System
P. 298
Unit 13: Case Study: Linux
Figure 13.15: The Socket Buffer (sk_buff) Notes
sk_buff
next
prev
dev
head
data
tail
end
Packet
truesize len
to be
transmitted
Data: Points at the current start of the protocol data. This pointer varies depending on the
protocol layer that currently owns the sk_buff.
Tail: Points at the current end of the protocol data. Again, this pointer varies depending on the
owning protocol layer,
End: Points at the end of the data area in memory. This is fixed when the sk_buff is allocated.
There are two length fields len and truesize, which describe the length of the current protocol
packet and the total size of the data buffer respectively. The sk_buff handling code provides
standard mechanisms for adding and removing protocol headers and tails to the application
data. These safely manipulate the data, tail and len fields in the sk_buff:
Push: This moves the data pointer towards the start of the data area and increments the len fi eld.
This is used when adding data or protocol headers to the start of the data to be transmitted,
Pull: This moves the data pointer away from the start, towards the end of the data area and
decrements the len field. This is used when removing data or protocol headers from the start of
the data that has been received.
Put: This moves the tail pointer towards the end of the data area and increments the len fi eld.
This is used when adding data or protocol information to the end of the data to be transmitted,
Trim: This moves the tail pointer towards the start of the data area and decrements the len fi eld.
This is used when removing data or protocol tails from the received packet.
The sk_buff data structure also contains pointers that are used as it is stored in doubly linked
circular lists of sk_buff’s during processing. There are generic sk_buff routines for adding sk_
buffs to the front and back of these lists and for removing them.
LOVELY PROFESSIONAL UNIVERSITY 291