Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


Together with the set ACK flag of the packet, this indicates to the client that the first packet has been
received. No extra packet need be generated to acknowledge receipt of a data packet. Acknowledgment
can be given in any packet in which the ACK flag is set and theackfield is filled.

Packets sent to establish the connection do not contain data; only the TCP header is relevant. The length
stored in thelenfield of the header is therefore 0.

The mechanisms described are not specific to the Linux kernel but must be implemented by all operating
systems wishing to communicate via TCP. The sections below deal more extensively with the kernel-
specific implementation of the operations described.

PassiveConnectionEstablishment
Active connection setup does not originate from the kernel itself but is triggered by receipt of a SYN
packet with a connection request. The starting point is therefore thetcp_v4_rcvfunction, which, as
described above, finds a listening socket and transfers control totcp_v4_do_rcv, whose code flow dia-
gram (for this specific scenario) is shown in Figure 12-28.


tcp_v4_rcv

tcp_v4_do_rcv

tcp_v4_hnd_req

tcp_rcv_state_process

Figure 12-28: Code flow diagram for
tcp_v4_rcv_passive.

tcp_v4_hnd_reqis invoked to perform the various initialization tasks required in the network layer to
establish a new connection. The actual state transition takes place intcp_rcv_state_process,which
consists of a longcasestatement to differentiate between the possible socket states and to invoke the
appropriate transition function.

Possible socket states are defined in anenumlist:

include/net/tcp_states.h
enum {
TCP_ESTABLISHED = 1,
TCP_SYN_SENT,
TCP_SYN_RECV,
TCP_FIN_WAIT1,
TCP_FIN_WAIT2,
TCP_TIME_WAIT,
TCP_CLOSE,
TCP_CLOSE_WAIT,
TCP_LAST_ACK,
TCP_LISTEN,
TCP_CLOSING, /* Now a valid state */

TCP_MAX_STATES /* Leave at the end! */
};
Free download pdf