Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


Note, however, that two data structures are used to represent sockets in the kernel.sockis the interface
to the network access layer, andsocketis the link to userspace. These rather lengthy structures are
discussed in detail in the next section, which examines the part of the application layer anchored in the
kernel. At the moment, we are interested only in the methods of thesockstructure needed to forward
data to the next higher layer. These must allow data received to be placed on a socket-specific wait queue
and must also inform the receiving processthat new data have arrived. Currently, thesockstructure can
be reduced to the following abbreviated version:

include/net/sock.h
/* Short version */
struct sock {
wait_queue_head_t *sk_sleep;
struct sk_buff_head sk_receive_queue;

/* Callback */
void (*sk_data_ready)(struct sock *sk, int bytes);
}

Control is transferred toudp_queue_rcv_skbonceudp_rcvhas found the appropriatesockinstance and
immediately afterward tosock_queue_rcv_skb, where 2 important actions are performed to complete
data delivery to the application layer.

❑ Processes waiting for data delivery via the socket sleep on thesleepwait queue.
❑ Invokingskb_queue_tailinserts the socket buffer with the packet data at the end of the
receive_queuelist whose head is held in the socket-specificsockstructure.
❑ The function pointed to bydata_ready(typically,sock_def_readableif thesockinstance
is initialized with the standard functionsock_init_data) is invoked to inform the socket
that new data has arrived. It wakes all processes sleeping onsleepwhile waiting for data
to arrive.

12.9.2 TCP


TCP provides many more functions than UDP. Consequently, its implementation in the kernel is much
more difficult and comprehensive, and a whole book could easily be dedicated to the specific problems
involved. The connection-oriented communication model used by TCPto support the secure transmis-
sion of data streams not only requires greater administrative overhead in the kernel, but also calls for
further operations such as explicit connection setup following from negotiations between computers.
The handling (and prevention) of specific scenarios as well as optimization to boost transmission perfor-
mance account for a large part of TCP implementation in the kernel; all their subtleties and oddities are
not discussed here.

Let’s look at the three major components of the TCP protocol (connection establishment, connection
termination, and the orderly transmission of data streams) by first describing the procedure required by
the standard before going on to examine the implementation.

A TCP connection is always in a clearly defined state. These include thelistenandestablishedstates men-
tioned above. There are also other states and clearly defined rules for the possible transitions between
them, as shown in Figure 12-25.
At first glance, the diagram is a little confusing, not to say off-putting. However, the information it con-
tains almost fully describes the behavior of a TCP implementation. Basically, the kernel could distinguish
Free download pdf