Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


ReceivingTCP Data


All TCP actions (connection setup and shutdown, data transmission) are performed by sending data
packets with specific properties and various flags. Before discussing state transitions, I must first establish
how the TCP data are passed to the transport layer and at what point the information in the header is
analyzed.

tcp_v4_rcvis the entry point into the TCP layer once a packet has been processed by the IP layer. The
code flow diagram fortcp_v4_rcvis shown in Figure 12-27.

No socket?

Realize TCP state automaton

tcp_v4_rcv

_ _inet_lookup

_ _inet_lookup_established

inet_lookup_listener

tcp_v4_do_rcv

Figure 12-27: Code flow diagram fortcp_v4_rcv.

Each TCP socket of the system is included in one of three hash tables that accept sockets in the following
states:

❑ Sockets that are fully connected.
❑ Sockets that are waiting for a connection (in thelistenstate).
❑ Sockets that are in the process of establishing a connection (using the three-way handshake dis-
cussed below).

After performing various checks on the packet data and copying information from the header into the
control block of the socket buffer, the kernel delegates the work of finding a socket that is waiting for the
packet to the__inet_lookupfunction. The only task of this function is to invoke two further functions
to scan various hash tables.__inet_lookup_establishedattempts to return a connected socket. If no
appropriate structure is found, theinet_lookup_listenerfunction is invoked to check all listening
sockets.

In both cases, the functions combine different elements of the respective connection (IP addresses of the
client and server, port addresses and the kernel-internal index of the network interface) by means of hash
functions to find an instance of the abovementionedsocktype. When searching for a listening socket, a
score method is applied to find the best candidate among several sockets working with wildcards. This
topic is not discussed because the results simply reflect what would intuitively be regarded as the best
candidate.

In contrast to UDP, work does not end but begins when the appropriatesockstructure for the connec-
tion is found. Depending on connection state, it is necessary to perform a state transition as shown in
Free download pdf