routing(6) TCP/IP 5.4.2 routing(6)
NAME
routing - network packet routing
SYNOPSIS
#include <net/route.h>
DESCRIPTION
The network facilities provide limited packet routing. A simple set
of data structures comprise a "routing table" used in selecting the
appropriate network interface when transmitting packets. This table
contains a single entry for each route to a specific network or host.
A user program, route(1M), allows the operator to configure this
database with the aid of two socket specific ioctl(2), commands,
SIOCADDRT and SIOCDELRT. The commands allow the addition and
deletion of a single routing table entry, respectively. Routing
table manipulations may be carried out only by the superuser.
A routing table entry has the following form, as defined in
net/route.h;
struct rtentry {
struct sockaddr rtdst;
struct sockaddr rtgateway;
short rtflags;
};
with rtflags defined from the following:
#define RTF_UP 0x1 /* route useable */
#define RTF_GATEWAY 0x2 /* destination is a gateway */
#define RTF_HOST 0x4 /* host entry (net otherwise) */
#define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */
#define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */
Routing table entries come in three flavors: for a specific host, for
all hosts on a specific network, and for any other destination not
matched by entries of the first two types (a wildcard route). When
an interface is started, it installs a routing table entry.
Normally, the interface specifies that the route coming through it is
a "direct" connection to the destination host or network. If the
route is direct, the transport layer of a protocol family usually
requests that the packet be sent to the same host specified in the
packet. Otherwise, the interface may be requested to address the
packet to an entity different from the eventual recipient (that is,
the packet is forwarded).
The routing code returns EEXIST if requested to duplicate an existing
entry, ESRCH if requested to delete a non-existent entry, ENOMEM if
insufficient resources were available to install a new route, or
ENETUNREACH if the gateway specified is not on the same network as
the host system.
The routing policy for transmitting packets is as follows:
Licensed material--property of copyright holder(s) 1
routing(6) TCP/IP 5.4.2 routing(6)
1) When a single host route exists, it is used. When multiple
host routes exist, the first route entry found is used.
2) When host routes don't exist, but a network route does, then
the network route is used. When multiple network routes
exist, the first route entry found is used.
3) When neither host nor network routes exist, but a wildcard
route exists, then the wildcard route is used.
4) When host, network, and wildcard routes don't exist, the
packet cannot be routed and is dropped.
A wildcard routing entry is specified with a zero destination address
value. Wildcard routes are used only when the system fails to find a
route to the destination host and network. The combination of
wildcard routes and routing redirects can provide an economical
mechanism for routing traffic.
SEE ALSO
ioctl(2), socket(2).
Licensed material--property of copyright holder(s) 2