Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


though.dataandheadremain regular pointers, and allsk_buff_data_telements are now interpreted as
offsetsrelative to these pointers. A pointer to the start of the transport header is now computed as follows:

<skbuff.h>
static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
{
return skb->head + skb->transport_header;
}

It is valid to use this approach since 4 bytes are sufficient to describe memory regions of up to 4 GiB, and
a socket buffer that exceeds this size will never be encountered.

Since the internal representation of socket buffers is not supposed to be visible to the generic networking
code, several auxiliary functions as shown above are provided to access the elements ofstruct
sk_buff. They are all defined in<skbuff.h>, and the proper variant is automatically chosen at
compile time.

❑ skb_transport_header(const struct sk_buff *skb)obtains the address of the transport
header for a given socket buffer.
❑ skb_reset_transport_header(struct sk_buff *skb)resets the start of the transport header to
the start of the data section.
❑ skb_set_transport_header(struct sk_buff *skb, const int offset)sets the start of the
transport header given the offset to the data pointer.

The same set of functions is available for the MAC and network headers by replacingtransportwith
macornetwork, respectively.

12.6.2 Management Data of Socket Buffers


The socket buffer structure contains not only the above pointers, but also other elements that are used to
handle the associated data and to manage the socket buffer itself.

The less common elements are dicsussed in this chapter when they are needed. The most important
elements are listed below.

❑ tstampstores the time the packet arrived.
❑ devspecifies the network device on which the packet is processed.devmay change in the course
of processing the packet — for instance, when it will leave the computer on another device at
some point.
❑ The interface index number of the input device is always preserved iniif. Section 12.7.1
explains how to use this number.
❑ skis a link to thesocketinstance (see Section 12.10.1) of the socket used to process the packet.
❑ dstindicates the further route of the packet through the network implementation. A special
format is used (this is discussed in Section 12.8.5).
❑ nextandprevhold socket buffers in a doubly linked list. The standard list implementation of
the kernel isnotused here but is replaced by a manual version.
Free download pdf