Home |
Sockets, IP, and Port Addresses Blocking and Non-Blocking Sockets Routing Table |
Routing TableThe routing table code (not to be confused with router/gateway code) determines which interface to send a packet to and the IP address to actually send the packet to based upon the destination IP address. The IP address to actually send the packet to is the same address as the destination address if the two machines are on the same network. If they are not on the same network, the address to send the data to is an address of a gateway. The gateway will forward the packet. The remote address in the packet is always set to the final destination address. All of the routing information is stored in the routing table, rt_table. The table contains an IP address which is used to compare against the destination address, a mask to use for the comparison, a destination address to send the packet (used to specify the address of a gateway), the interface number to send to, and a time-to-live. There are four types of entries in the routing table. They are listed according to precedence (i.e. if an address matches a host entry and a network entry, it is sent to the host entry's interface; or if an address matches a network entry and a gateway address, it is sent to the network entry's interface):
An entry is a host entry if its mask is all FFs. An entry is a gateway if its rt_gw flag is set in rt_flags. An entry is a default gateway if its network address (rt_dest entry) is RT_DEFAULT. The entries are deleted by the timer task when time to live expires (rt_ttl entry in the routing table). This is done by the function rt_timer which is called by the timer task every second. If the time to live field is set to infinite (RT_INF), the entry is never deleted. When xn_set_ip is called after an interface has been opened with xn_interface_open or xn_attach, an entry for the interface is added to the routing table. If the interface is an ethernet interface, a network entry is added. If the interface is an RS232 interface, a host entry is added. Note that PPP and xn_rarp can also call xn_set_ip. These routes are added with an infinite time-to-live. Routes are also added to the routing table by the application calling xn_rt_add.
|