xref: /original-bsd/share/man/man4/route.4 (revision b4971bb3)
1.\" Copyright (c) 1990, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)route.4	8.1 (Berkeley) 06/09/93
7.\"
8.Dd
9.Dt ROUTE 4
10.Os
11.Sh NAME
12.Nm route
13.Nd kernel packet forwarding database
14.Sh SYNOPSIS
15.Fd #include <sys/socket.h>
16.Fd #include <net/if.h>
17.Fd #include <net/route.h>
18.Ft int
19.Fn socket PF_ROUTE SOCK_RAW "int family"
20.Sh DESCRIPTION
21.Tn UNIX
22provides some packet routing facilities.
23The kernel maintains a routing information database, which
24is used in selecting the appropriate network interface when
25transmitting packets.
26.Pp
27A user process (or possibly multiple co-operating processes)
28maintains this database by sending messages over a special kind
29of socket.
30This supplants fixed size
31.Xr ioctl 2 Ns 's
32used in earlier releases.
33Routing table changes may only be carried out by the super user.
34.Pp
35The operating system may spontaneously emit routing messages in response
36to external events, such as recipt of a re-direct, or failure to
37locate a suitable route for a request.
38The message types are described in greater detail below.
39.Pp
40Routing database entries come in two flavors: for a specific
41host, or for all hosts on a generic subnetwork (as specified
42by a bit mask and value under the mask.
43The effect of wildcard or default route may be achieved by using
44a mask of all zeros, and there may be hierarchical routes.
45.Pp
46When the system is booted and addresses are assigned
47to the network interfaces, each protocol family
48installs a routing table entry for each interface when it is ready for traffic.
49Normally the protocol specifies the route
50through each interface as a
51.Dq direct
52connection to the destination host
53or network.  If the route is direct, the transport layer of
54a protocol family usually requests the packet be sent to the
55same host specified in the packet.  Otherwise, the interface
56is requested to address the packet to the gateway listed in the routing entry
57(i.e. the packet is forwarded).
58.Pp
59When routing a packet,
60the kernel will first attempt to find a route to the destination host.
61Failing that, a search is made for a route to the network of the destination.
62Finally, any route to a default
63.Pq Dq wildcard
64gateway is chosen.
65If no entry is found, the destination is declared to be unreachable,
66and a routing\-miss message is generated if there are any
67listers on the routing control socket described below.
68.Pp
69A wildcard routing entry is specified with a zero
70destination address value.  Wildcard routes are used
71only when the system fails to find a route to the
72destination host and network.  The combination of wildcard
73routes and routing redirects can provide an economical
74mechanism for routing traffic.
75.Pp
76One opens the channel for passing routing control messasges
77by using the socket call shown in the synopsis above:
78.Pp
79The
80.Fa family
81paramter may be
82.Dv AF_UNSPEC
83which will provide
84routing information for all address families, or can be restricted
85to a specific address family by specifying which one is desired.
86There can be more than one routing socket open per system.
87.Pp
88Messages are formed by a header followed by a small
89number of sockadders (now variable length particularly
90in the
91.Tn ISO
92case), interpreted by position, and delimited
93by the new length entry in the sockaddr.
94An example of a message with four addresses might be an
95.Tn ISO
96redirect:
97Destination, Netmask, Gateway, and Author of the redirect.
98The interpretation of which address are present is given by a
99bit mask within the header, and the sequence is least significant
100to most significant bit within the vector.
101.Pp
102Any messages sent to the kernel are returned, and copies are sent
103to all interested listeners.  The kernel will provide the process
104id. for the sender, and the sender may use an additional sequence
105field to distinguish between outstanding messages.  However,
106message replies may be lost when kernel buffers are exhausted.
107.Pp
108The kernel may reject certain messages, and will indicate this
109by filling in the
110.Ar rtm_errno
111field.
112The routing code returns
113.Dv EEXIST
114if
115requested to duplicate an existing entry,
116.Dv ESRCH
117if
118requested to delete a non-existent entry,
119or
120.Dv ENOBUFS
121if insufficient resources were available
122to install a new route.
123In the current implementation, all routing process run locally,
124and the values for
125.Ar rtm_errno
126are available through the normal
127.Em errno
128mechanism, even if the routing reply message is lost.
129.Pp
130A process may avoid the expense of reading replies to
131its own messages by issuing a
132.Xr setsockopt 2
133call indicating that the
134.Dv SO_USELOOPBACK
135option
136at the
137.Dv SOL_SOCKET
138level is to be turned off.
139A process may ignore all messages from the routing socket
140by doing a
141.Xr shutdown 2
142system call for further input.
143.Pp
144If a route is in use when it is deleted,
145the routing entry will be marked down and removed from the routing table,
146but the resources associated with it will not
147be reclaimed until all references to it are released.
148User processes can obtain information about the routing
149entry to a specific destination by using a
150.Dv RTM_GET
151message,
152or by reading the
153.Pa /dev/kmem
154device, or by issuing a
155.Xr getkerninfo 2
156system call.
157.Pp
158Messages include:
159.Bd -literal
160#define	RTM_ADD		0x1    /* Add Route */
161#define	RTM_DELETE	0x2    /* Delete Route */
162#define	RTM_CHANGE	0x3    /* Change Metrics, Flags, or Gateway */
163#define	RTM_GET		0x4    /* Report Information */
164#define	RTM_LOOSING	0x5    /* Kernel Suspects Partitioning */
165#define	RTM_REDIRECT	0x6    /* Told to use different route */
166#define	RTM_MISS	0x7    /* Lookup failed on this address */
167#define	RTM_RESOLVE	0xb    /* request to resolve dst to LL addr */
168.Ed
169.Pp
170A message header consists of:
171.Bd -literal
172struct rt_msghdr {
173    u_short rmt_msglen;  /* to skip over non-understood messages */
174    u_char  rtm_version; /* future binary compatability */
175    u_char  rtm_type;    /* message type */
176    u_short rmt_index;   /* index for associated ifp */
177    pid_t   rmt_pid;     /* identify sender */
178    int     rtm_addrs;   /* bitmask identifying sockaddrs in msg */
179    int     rtm_seq;     /* for sender to identify action */
180    int     rtm_errno;   /* why failed */
181    int     rtm_flags;   /* flags, incl kern & message, e.g. DONE */
182    int     rtm_use;     /* from rtentry */
183    u_long  rtm_inits;   /* which values we are initializing */
184    struct  rt_metrics rtm_rmx;	/* metrics themselves */
185};
186.Ed
187.Pp
188where
189.Bd -literal
190struct rt_metrics {
191    u_long rmx_locks;     /* Kernel must leave these values alone */
192    u_long rmx_mtu;       /* MTU for this path */
193    u_long rmx_hopcount;  /* max hops expected */
194    u_long rmx_expire;    /* lifetime for route, e.g. redirect */
195    u_long rmx_recvpipe;  /* inbound delay-bandwith product */
196    u_long rmx_sendpipe;  /* outbound delay-bandwith product */
197    u_long rmx_ssthresh;  /* outbound gateway buffer limit */
198    u_long rmx_rtt;       /* estimated round trip time */
199    u_long rmx_rttvar;    /* estimated rtt variance */
200};
201.Ed
202.Pp
203Flags include the values:
204.Bd -literal
205#define	RTF_UP        0x1    /* route useable */
206#define	RTF_GATEWAY   0x2    /* destination is a gateway */
207#define	RTF_HOST      0x4    /* host entry (net otherwise) */
208#define	RTF_NORMAL    0x8    /* subnet mask is cannonical */
209#define	RTF_DYNAMIC   0x10   /* created dynamically (by redirect) */
210#define	RTF_MODIFIED  0x20   /* modified dynamically (by redirect) */
211#define	RTF_DONE      0x40   /* message confirmed */
212#define	RTF_MASK      0x80   /* subnet mask present */
213.Ed
214.Pp
215Specfiers for metric values in rmx_locks and rtm_inits are:
216.Bd -literal
217#define	RTV_SSTHRESH  0x1    /* init or lock _ssthresh */
218#define	RTV_RPIPE     0x2    /* init or lock _recvpipe */
219#define	RTV_SPIPE     0x4    /* init or lock _sendpipe */
220#define	RTV_HOPCOUNT  0x8    /* init or lock _hopcount */
221#define	RTV_RTT       0x10   /* init or lock _rtt */
222#define	RTV_RTTVAR    0x20   /* init or lock _rttvar */
223#define	RTV_MTU       0x40   /* init or lock _mtu */
224.Ed
225.Pp
226Specifiers for which addresses are present in the messages are:
227.Bd -literal
228#define RTA_DST       0x1    /* destination sockaddr present */
229#define RTA_GATEWAY   0x2    /* gateway sockaddr present */
230#define RTA_NETMASK   0x4    /* netmask sockaddr present */
231#define RTA_GENMASK   0x8    /* cloning mask sockaddr present */
232#define RTA_IFP       0x10   /* interface name sockaddr present */
233#define RTA_IFA       0x20   /* interface addr sockaddr present */
234#define RTA_AUTHOR    0x40   /* sockaddr for author of redirect */
235.Ed
236