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