next up previous
Next: 10 ICMP Up: Simulation Environment Overview 15-441 Previous: 8.2 The IP address


9 Routing Sockets

Figure 4: An example of how a user process could add a route to the kernel's routing table.
\begin{figure}\hrule {\scriptsize\begin{verbatim}int s;
char buf[1024];
str...
...msglen) < 0) {
perror(''Write'');
exit(1);
}\end{verbatim}}\hrule\end{figure}

Routing sockets are created with domain AF_ROUTE and type SOCK_RAW. This type of socket is used with the following system calls: Socket(), Close(), Write(), and Setsockopt(). A routing socket is a special type of socket that is not specific to any particular network protocol, but allows ``privileged'' user processes to write information into the kernel. User processes use this type of socket to add and remove information from the routing table. This is done by filling in the rt_msghdr structure and passing it to Write(). The rt_msghdr structure is defined in $PDIR/include/route.h. Figure 9 shows example code for modifying the route table.

The following values of the rtm_type field of the rt_msghdr structure are supported:

These constants are defined in $PDIR/include/route.h.

To look up a route within the kernel, call rt_lookup_dest() (defined in $PDIR/include/rtable.h). This function will return the address of the gateway to which a packet with the given destination address should be sent. It also returns the index of the interface over which the packet should be sent. Note that the current implementation of the simulator supports only host routes, there is no support for network masks or prefix matching. If there is no host route available in the routing table, the function returns the default gateway. The default gateway route is defined as a route that has a destination address of 0.0.0.0. It can be inserted into the routing table in the same way as host routes.


next up previous
Next: 10 ICMP Up: Simulation Environment Overview 15-441 Previous: 8.2 The IP address