Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


to the start of the IP header. The same operations are repeated for the layers below until a finished packet
is ready to be sent across the network.

head

tail

data

end
TCP

head

tail

data

end
TCP

IP

Figure 12-7: Manipulation of the socket buffer in the transition
between protocol levels.

The procedure adopted to analyze packets is similar. The packet data are copied into a reserved memory
area in the kernel and remain there for the duration of the analysis phase. The socket buffer associated
with the packet is passed on from layer to layer, and the various pointers are successively supplied with
the correct values.

The kernel provides the standard functions listed in Table 12-1 for manipulating socket buffers.

Table 12-1: Operations on Socket Buffers

Function Meaning

alloc_skb Allocates a newsk_buffinstance.

skb_copy Creates a copy of the socket bufferandassociated data.

skb_clone Duplicates a socket buffer but uses the same packet data for the original and
the copy.

skb_tailroom Returns the size of the free space at the end of the data.

skb_headroom Returns the size of the free space at the start of the data.

skb_realloc_headroomCreates more free space at the start of the data. The existing data are retained.

Socket buffers require numerous pointers to represent the different components of the buffer’s contents.
Since low memory footprint and high processing speed are essential for the network layer and thus for
struct sk_buff, it is desirable to make the structure as small as possible. On 64-bit CPUs, a little trick
can be used to save some space. The definition ofsk_buff_data_tis changed to an integer variable:

<skbuff.h>
typedef unsigned int sk_buff_data_t;

Since integer variables require only half the memory of pointers (4 instead of 8 bytes) on such architec-
tures, the structure shrinks by 20 bytes.^8 The information contained in a socket buffer is still the same,

(^8) Since integers and pointers use an identical number of bits on 32-bit systems, the trick does not work for them.

Free download pdf