3.7 Basic Forwarding Algorithm
This section provides an overview of the forwarding algorithm performed by the router when it is clear that the packet is not destined for the router itself and should be delivered to a remote network. The algorithm uses the following data structures:
Packet: the IP packet being forwarded. Each packet has fields described in Chapter 2. In particular, the forwarding algorithm uses such fields as Destination Address and Time-To-Live (TTL).
Interface: the network attachment description. Various characteristics are associated with each interface, including the following, which are considered interesting from the forwarding perspective:
TypeCan be point-to-point, point-to-multipoint, or broadcast, depending on the type of encapsulation. For example, PPP and High-Level Data Link Control (HDLC) interfaces are point-to-point; Frame Relay and X.25 interfaces are point-to-multipoint; Ethernet and Token Ring interfaces are broadcast.
StateOperational statusup or downof the interface. The state of the interface is determined by the status of the physical and the data link layer protocols.
IP statusFlag specifying whether IP processing is enabled on the interface.
IP unnumberedFlag indicating that the interfacepoint-to-pointis configured as unnumbered.
Reference interfaceInterface whose IP address should be used when the packets are generated for the unnumbered interface.
IP addressAddress assigned to the interface.
Address maskMask configured together with the IP address to specify the border between the network and hosts parts of the address.
Routing tableCollection of routing entries (routes). The following parameters are associated with each entry:
Network prefixIP prefixin the form of the prefix value and its length, or a network address and a route maskthat describes a collection of destinations. For example, 192.0.0.0/8, or 192.0.0.0 255.0.0.0, describes all IP hosts that are assigned IP addresses starting with 192, such as 18.104.22.168 or 22.214.171.124.
Default candidateFlag indicating that the route should be considered a candidate for becoming the default route
PathsCollection of next-hop structures, each corresponding to a distinct path to the destination through the network. The following parameters are associated with each path, and at least one of the two must be present.
Outbound interfaceThe interface that should be used to forward packets to the collection of destinations described by the route. If the path does not specify the interface, the route is considered recursive.
Intermediate addressIf the path specifies the interface, this is the next-hop address that should be used to find out the data link layer details. If the path does not specify the interface, this is the address that should be used for the next iteration of the recursive routing table lookup operation.
The following algorithm is an outline of functionality performed by the routers. The packet is assumed to have passed initial checks: the sanity check (basic IP header validity verification), the inbound packet filtering policy, the TTL field check, and so on. These checks and the forwarding algorithm are discussed in more detail in Chapter 5.
Set the next-hop address to the destination address in the packet.
Perform recursive routing table lookup operation as follows.
Find the route for the current next-hop address in the routing table.
If a route is found and it specifies the intermediate address, set the next-hop address to the address in the route.
If the route is found and it does not specify the interface, loop back to step 2.a.
If the recursive route lookup did not succeedno matching route was found or a route could not be resolvedsend an ICMP "Destination Unreachable, Host Unreachable" message to the packet originator, using the source IP address in the packet as the destination IP address in the ICMP message, and drop the packet.
Otherwise, if the current value of the next-hop address equals the prefix value of the found route, set the next-hop address back to the destination IP address in the packet.
Pass the packet to the packet-delivery function. Provide the interface in the route and the current next-hop address as the arguments.
The algorithm is pretty simple. First, the routing table is searched for a route that can be used to route to the destination IP address in the packet. (The routing table lookup algorithm is discussed later.) If a route is found and it specifies only an interfacedescribes a directly connected networkthe packet is sent out of the specified interface, using the destination IP address in the packet as the next-hop address. If the route specifies both the address and the interfacethis is how IGP routes are installedthe packet is sent out of the interface to the next-hop router corresponding to the address in the route. If the route is recursiveonly the intermediate address is specifiedthe intermediate address becomes the current next-hop route, and a routing table lookup operation is performed again.
The check in step 4 needs more explanation. That check is required when the routing table contains information similar to that shown in the following example:
10.0.0.0 is accessible via 126.96.36.199 188.8.131.52 is directly connected to the interface Ethernet 1
The recursive route to network 10.0.0.0 specifies a subnet address (184.108.40.206) as the intermediate address. Without the check, the subnet address would be used as the next-hop address. The check makes sure that the destination address in the packet is used as the next-hop address in this situation.
The packet-delivery procedure is initiated by the forwarding algorithm and receives the packet, the outbound interface, and the next-hop IP address as the arguments from it. Following is the outline of the steps taken by the packet-delivery process.
If the interface state is down or IP processing is not enabled on the interface, send an ICMP "Destination Unreachable, Host Unreachable" message to the source host, and stop processing the packet.
A route in the routing table can reference an interface in down state while the routing table is convergingit takes time to remove invalid routesor because a static route through an interface was configured to be never removed from the routing table (see Chapter 6).
If the interface type is point-to-point, pass the packet directly to the packet encapsulation procedure specific to the interface. There is no need to look up data link layer details for point-to-point interfaces. They are either not necessary (such as HDLC or PPP encapsulation) or statically configured for the interface, such as, a point-to-point Frame Relay interface.
Otherwise, if the interface type is point-to-multipoint, perform the following steps.
Search the map table associated with the interface, using the next-hop address as the search parameter.
If no map for the next-hop address is found, log an encapsulation failure, send an ICMP "Destination Unreachable, Host Unreachable" message to the source host, and stop processing the packet,
Otherwise, pass the packet to the packet encapsulation procedure specific to the interface, and pass the located map table entry as a parameter; it will be used to construct the data link layer frame for the packet.
Otherwise, if the interface type is broadcast, perform the following steps.
Search the ARP cache for the MAC address corresponding to the next-hop address and outbound interface.
If no ARP entry is found, log an encapsulation failure, send an ARP request message for the next-hop address, send an ICMP "Destination Unreachable, Host Unreachable" message to the source host, and drop the packet.
Note that the router does not wait for the ARP reply message to come in and does not queue the packet.
Otherwise, pass the packet to the packet encapsulation procedure specific to the interface, providing the found ARP entry as a parameter; it will be used to construct the data link layer frame for the packet.
As you can see, the data link parameters vary by type of interface. Point-to-point interfaces require very little additional work. Point-to-multipoint links, such as Frame Relay or X.25, require the DLCI or X.121, which should be used to reach a specific next-hop router. The mapping between the next-hop addresses and the data link layer details is usually configured manually by the administrator (see Chapter 5 for details). Broadcast interfaces require knowledge of the next-hop router's MAC address that is discovered using ARP. Also note that the interface MTU check and the IP packet fragmentation functionality are performed by the packet encapsulation function.