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