Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


❑ If the packet includes additional options (not normally the case), they are processed in
ip_forward_options.
❑ dst_outputpasses the packet to the send function selected during routing and held in
skb->dst->output. Normally,ip_output, which passes the packet to the network adapter that
matches the destination, is used for this purpose.^19 ip_outputis part of the send operation for
IP packets described in the next section.

12.8.5 Sending Packets


The kernel provides several functions that are used by higher protocol layers to send data via IP.
ip_queue_xmit, whose code flow diagram, shown in Figure 12-18, is the one most frequently used.

No route available yet? Determine route

ip_queue_xmit

ip_send_check

dst_output

skb->dst->output

Netfilter hook: NF_IP_LOCAL_out

Figure 12-18: Code flow diagram for
ip_queue_xmit.

The first task is to find a route for the packet. The kernel exploits the fact that all packets originating
from a socket have the same destination address so that the route doesn’t have to be determined afresh
each time. A pointer to the corresponding data structure discussed below is linked with the socket data
structure. When the first packet of a socket is sent, the kernel is required to find a new route (discussed
below).

Onceip_send_checkhas generated the checksum for the packet,^20 the kernel calls the netfilter hook
NF_IP_LOCAL_OUT.Thedst_outputfunction is then invoked; it is based on the destination-specific
skb->dst->outputfunction of the socket buffer found during routing. Normally, this isip_output,
which is the point where locally generated andforwarded packets are brought together.

Transitionto the Network Access Layer


Figure 12-19 shows the code flow diagram of theip_outputfunction that splits the route into two parts,
depending on whether a packet needs to be fragmented or not.

(^19) A different output routine is used when, for example, IP packets are tunneled inside IP packets. This is a very special application
that is rarely needed.
(^20) Generation of IP checksums is time-critical and can be highly optimized by modern processors. For this reason, the various archi-
tectures provide fast assembly language implementations of their own inip_fast_csum.

Free download pdf