Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


The transition from FIN_WAIT_1 to FIN_WAIT_2 is performed by the central dispatcher function
tcp_rcv_state_processbecause there is no longer any need to take the fast path for existing connec-
tions. In the familiar case differentiation, a packet received with a set ACK flag triggers the transition to
FIN_WAIT_2 bytcp_set_state. All that is now required to place the TCP connection in the TIME_WAIT
state followed automatically by the CLOSED state is a FIN packet from the other party.

The status transitions of the other party that performs a passive close upon receipt of the first FIN packet
follow a similar pattern. Because the first FIN packet is received when the state is ESTABLISHED, han-
dling takes place in the slow path oftcp_rcv_establishedand involves sending an ACK to the other
party and changing the socket state to TCP_CLOSING.

The next state transition (to LAST_ACK) is performed by calling thecloselibrary function to invoke the
tcp_close_statefunction of the kernel. Only a further ACK packet from the other party is then needed
to terminate the connection. This packet is also handled by thetcp_rcv_state_processfunction, which
changes the socket state to CLOSED (by means oftcp_done), releases the memory space occupied by the
socket, and thus finally terminates the connection.

Only the possible transition from the FIN_WAIT_1 state is described above. As the
TCP finite-state machine illustrated in Figure 12-25 shows, two other alternatives are
implemented by the kernel but are far less frequently used than the path I describe,
reason enough not to bother with them here.

12.10 Application Layer


Sockets are used to apply theUnixmetaphor that ‘‘everything is a file‘‘ to network connections. The
interfaces between kernel and userspace sockets are implemented in the C standard library using the
socketcallsystem call.

socketcallacts as a multiplexer for various tasks performed by various procedure, for instance, opening
a socket or binding or sending data.

Linux adopts the concept of kernel sockets to make communication with sockets in userspace as simple
as possible. There is an instance of thesocketstructure and thesockstructure for every socket used
by a program. These serve as an interface downward(to the kernel) and upward (to userspace). Both
structures were referenced in the previous sections without defining them in detail, which is done now.

12.10.1 Socket Data Structures


Thesocketstructure, slightly simplified, is defined as follows:

<net.h>
struct socket {
socket_state state;
unsigned long flags;
const struct proto_ops *ops;
struct file *file;
struct sock *sk;
short type;
};
Free download pdf