Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


ReceivingPackets


The code flow diagram in Figure 12-30 shows the path taken — starting from the familiartcp_v4_rcv
function — when packets are received.

No

Yes

tcp_v4_rcv

tcp_v4_do_rcv

tcp_rcv_established

sk->sk_data_ready

sk->sk_data_ready

Packet easy to process? Slow Path

Fast Path

Figure 12-30: Receiving packets in TCP connections.

After control has been passed totcp_v4_do_rcv, a fast path is selected (if a connection already exists)
rather than entering the central dispatcher function — this is in contrast to other socket states but is logi-
cal because the transmission of data packets accounts for the lion’s share of work in any TCP connection
and should therefore be performed as quickly as possible. Once it has been established that the state of
the destination socket isTCP_ESTABLISHED,thetcp_rcv_establishedfunction is invoked to split the
control flow again. Packets that are easy to analyze are handled in thefast pathand those with unusual
options in theslow path.

Packets must fulfill one of the following criteria to be classified as easy to analyze:

❑ The packet must contain only an acknowledgment for the data last sent.
❑ The packet must contain the data expected next.

In addition,noneof the following flags must be set: SYN, URG, RST, or FIN.

This description of the ‘‘best case scenario‘‘ for packets is not Linux-specific but is also found in many
otherUnixvariants.^30 Almost all packets fall within these categories,^31 which is why it makes sense to
differentiate between a fast and a slow path.

Which operations are performed in the fast path? A few packet checks are carried out to find more
complex packets and return them to the slow path. Thereafter the packet length is analyzed to ascertain
whether the packet is an acknowledgment or a data packet. This is not difficult because ACK packets do
not contain data and must therefore be of exactly the same length as a TCP packet header.

(^30) This approach was developed by Van Jacobsen, a well-known network researcher, and is often referred to as theVJ mechanism.
(^31) Today’s transmission techniques are so sophisticated that very few errors occur. This was not the case in the early days of TCP.
Although more faults arise on global Internet connections than in local networks, most packets can still be handled in the fast path
owing to the low error rates.

Free download pdf