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