Gateways and Broadcasts
Most of the complexity in supporting broadcasts lies in gateways. If a gateway receives a directed broadcast for a network to which it is not connected, it simply forwards it using the usual mechanism. Otherwise, it must do some additional work.
6.1. Local Broadcasts
When a gateway receives a local broadcast datagram, there are several things it might have to do with it. The situation is unambiguous, but without due care it is possible to create infinite loops.
The appropriate action to take on receipt of a broadcast datagram depends on several things: the subnet it was received on, the destination network, and the addresses of the gateway.
-
The primary rule for avoiding loops is "never broadcast a datagram on the hardware network it was received on". It is not sufficient simply to avoid repeating datagram that a gateway has heard from itself; this still allows loops if there are several gateways on a hardware network.
-
If the datagram is received on the hardware network to which it is addressed, then it should not be forwarded. However, the gateway should consider itself to be a destination of the datagram (for example, it might be a routing table update.)
-
Otherwise, if the datagram is addressed to a hardware network to which the gateway is connected, it should be sent as a (data link layer) broadcast on that network. Again, the gateway should consider itself a destination of the datagram.
-
Otherwise, the gateway should use its normal routing procedure to choose a subsequent gateway, and send the datagram along to it.
6.2. Multi-subnet broadcasts
When a gateway receives a broadcast meant for all subnets of an IP network, it must use the Reverse Path Forwarding algorithm to decide what to do. The method is simple: the gateway should forward copies of the datagram along all connected links, if and only if the datagram arrived on the link which is part of the best route between the gateway and the source of the datagram. Otherwise, the datagram should be discarded.
This algorithm may be improved if some or all of the gateways exchange among themselves additional information; this can be done transparently from the point of view of other hosts and even other gateways. See [4, 3] for details.
6.3. Pseudo-Algol Routing Algorithm
This is a pseudo-Algol description of the routing algorithm a gateway should use. The algorithm is shown in figure 1. Some definitions are:
RouteLink(host)
A function taking a host address as a parameter and returning the first-hop link from the gateway to the host.
RouteHost(host)
As above but returns the first-hop host address.
ResolveAddress(host)
Returns the hardware address for an IP host.
IncomingLink
The link on which the packet arrived.
OutgoingLinkSet
The set of links on which the packet should be sent.
OutgoingHardwareHost
The hardware host address to send the packet to.
Destination.host
The host-part of the destination address.
Destination.subnet
The subnet-part of the destination address.
Destination.ipnet
The IP-network-part of the destination address.
BEGIN
IF Destination.ipnet IN AllLinks THEN
BEGIN
IF IsSubnetted(Destination.ipnet) THEN
BEGIN
IF Destination.subnet = BroadcastSubnet THEN
BEGIN /* use Reverse Path Forwarding algorithm */
IF IncomingLink = RouteLink(Source) THEN
BEGIN IF Destination.host = BroadcastHost THEN
OutgoingLinkSet <- AllLinks -
IncomingLink;
OutgoingHost <- BroadcastHost;
Examine packet for possible internal use;
END
ELSE /* duplicate from another gateway, discard */
Discard;
END
ELSE
IF Destination.subnet = IncomingLink.subnet THEN
BEGIN /* forwarding would cause a loop */
IF Destination.host = BroadcastHost THEN
Examine packet for possible internal use;
Discard;
END
ELSE BEGIN /* forward to (possibly local) subnet */
OutgoingLinkSet <- RouteLink(Destination);
OutgoingHost <- RouteHost(Destination);
END
END
ELSE BEGIN /* destined for one of our local networks */
IF Destination.ipnet = IncomingLink.ipnet THEN
BEGIN /* forwarding would cause a loop */
IF Destination.host = BroadcastHost THEN
Examine packet for possible internal use;
Discard;
END
ELSE BEGIN /* might be a broadcast */
OutgoingLinkSet <- RouteLink(Destination);
OutgoingHost <- RouteHost(Destination);
END
END
END
ELSE BEGIN /* forward to a non-local IP network */
OutgoingLinkSet <- RouteLink(Destination);
OutgoingHost <- RouteHost(Destination);
END
OutgoingHardwareHost <- ResolveAddress(OutgoingHost);
END
Figure 1: Pseudo-Algol algorithm for routing broadcasts by gateways