This week, we looked into the routing table. The whole routing table was pretty much built into the niche stack so we just did research to find exactly how it worked. In this entry, I will talk about the main functions of the routing table while David will talk about how they are called in his own blog entry.
First of all, all the routing table functions are in bsp/iniche/src/ip/iproute.c. What these functions do is manipulate (or search) through a routing table variable called rt_mib with the struct type RTMIB. These are the list of essential functions:
rt_lookup(ip_addr host): This function runs through the whole routing table through a for loop. It is looking for a match between the host ip address and an ip address in the routing table. It does a bit by bit comparison and it will have a pointer to the closest match. If an exact match is found, it will stop the for loop and return the pointer to the exact match. Otherwise, it will return either the closest match (closest subnet) or NULL.
add_route(ip_addr dest, ip_addr mask, ip_addr nexthop, int iface, int prot) : This function is supposed to add a route (or update an existing route) directing dest to nexthop. It will return a pointer to the table entry or NULL if there is an error. To work, this function first points to the interface and checks for errors. It will then loop through the whole table using a for loop (similar to rt_lookup). Inside this for loop, if the entry is found, it will update the entry and return the pointer to that entry (ending the function). If the entry is not found (and no empty slot has been previously discovered), it will check if the current spot is empty. If it is, it will make a pointer newrt point to the current entry. If the current slot is not empty, it will check if the priority of prot (from the function argument) is more than the priority of the protocol of the current table entry. If it is, it will point newrt to the entry and then check the priority of newrt against the table entry. It will then mark the entry depending on which pointer to the routing table is more prioritized by pointing newrt to the entry. It will then modify the entry, timestamp it, and return the modified entry.
del_route(ip_addr dest, ip_addr mask, int iface): This function will delete a routing table entry. First it will point ifp to the iface. Next it will go through the routing table using a for loop (like the other two functions) and try to find something with matching credentials to our function arguments.If there is a match, clear the struct (using memset) and clear the cache.
A side note to all of this is that the number of entries in the table (since it is static right now) is 16. This id defined in ipport.h under the varialbe RT_TABS
No comments:
Post a Comment