Chapter 21. Internet Protocol Version 4 (IPv4): Transmission
In this chapter, we discuss packet transmission at the L3 layer, which fits into the top-left corner of Figure 18-1 in Chapter 18. Transmission refers to packets leaving the local host for another; it can be initiated by the L4 layer or be invoked as the final stage of forwarding. As shown in Figure 18-1 in Chapter 18, the central function that delivers a packet is dst_output; the functions described in this chapter precede it and prepare packets for it. The tasks of the kernel at this stage include:
Looking up the next hop
The IP layer needs to know the outgoing device and the next router to use for the next hop. The route is found through the function ip_route_output_flow, called at the L3 or L4 layer. This chapter does not discuss routing, because that subject is big enough for its own discussion and is therefore covered in Part VII.
Initializing the IP header
Several fields, such as the packet ID, are filled in at this stage. If the packet is a forwarded one, a little work was done on the header earlier (such as updating the TTL, checksum, and options fields). But much more must be done at this point to enable transmission.
Processing options
The software has to honor options that require the addition of an address or timestamp to the header.
Fragmentation
If the IP packet is too big to be transmitted on the outgoing device, it must be fragmented (unless fragmentation is explicitly forbidden).
Checksum
The IP checksum has to be computed after all other work on the header is done. We will see that the IP layer may take care of the L4 checksum
as well as the L3 checksum
. In both cases, the checksum can be computed either in one shot or incrementally. While the checksum is required, the L3 layer doesn't always have to calculate it, because some devices' hardware does it (as denoted by the CHECKSUM_HW flag).
Checking with Netfilter
As shown in Figure 18-1 in Chapter 18, the Linux firewall system is given a chance to drop or mangle each packet at various stages of processing, including transmission.
Updating statistics
Depending on the result of the transmission (success or failure) and on actions such as fragmentation, the associated SNMP counters have to be updated.
Option processing and fragmentation are by far the most expensive tasks; fragmentation is addressed in Chapter 22, and options were addressed in Chapter 19. In the past there used to be two different functions for
transmission, one for packets that could be transmitted quickly because they didn't need fragmentation or IP option processing, and another that provided all the services. The kernel does not explicitly distinguish the two cases anymore.
 |