Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


tcp_v4_conn_requestis invoked if the socket state isTCP_LISTEN.^29 The function concerns itself with
many details and subtleties of TCP that are not described here. What is important is the acknowledgment
packet sent at the end of the function. It containsnot only the set ACK flag and the sequence number
of the received packet but also a newly generated sequence number and a SYN flag as required by the
three-way handshake procedure. This concludes the first phase of connection setup.

The next step at the client is reception of the ACK packet that arrives at thetcp_rcv_state_process
function via the usual path. The socket state is nowTCP_SYN_RECV, which is handled by a separate branch
ofcasedifferentiation. The main task of the kernel is to change the socket state toTCP_ESTABLISHEDto
indicate that a connection has now been set up.

Active ConnectionEstablishment


Active connection setup is initiated by invoking theopenlibrary function by means of a userspace appli-
cation that issues thesocketcallsystem call to arrive at the kernel functiontcp_v4_connect,whose
code flow diagram is shown on the upper part of Figure 12-29.

tcp_v4_connect

ip_route_connect

tcp_connect

Set socket status to SYN_SENT

tcp_transmit_skb

tcp_rcv_state_process

tcp_rcv_synsent_state_process

tcp_send_ack

inet_csk_reset_xmit_timer

Set socket status to ESTABILISHED

Figure 12-29: Code flow diagram for active connection establishment.

The function starts by looking for an IP route to the destination host using the framework described
above. After the TCP header has been generated and the relevant values have been set in a socket buffer,
the socket state changes fromCLOSEDtoSYN_SENT.tcp_connect, then sends a SYN packet to the IP layer
and therefore to the client. In addition, a timer is created in the kernel to ensure that packet sending is
repeated if no acknowledgment is received within a certain period.

(^29) A function pointer to an address family-specific data structure is used because the dispatcher supports both IPv4 and IPv6. As the
implementation of the finite-state machine is the samefor IPv4 and IPv6, a large amount of code can be saved.

Free download pdf