Initial import from FreeBSD RELENG_4:
[dragonfly.git] / share / man / man4 / route.4
1 .\" Copyright (c) 1990, 1991, 1993
2 .\"     The Regents of the University of California.  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       8.6 (Berkeley) 4/19/94
33 .\" $FreeBSD: src/share/man/man4/route.4,v 1.9.2.6 2002/03/17 09:12:44 schweikh Exp $
34 .\"
35 .Dd January 18, 2002
36 .Dt ROUTE 4
37 .Os
38 .Sh NAME
39 .Nm route
40 .Nd kernel packet forwarding database
41 .Sh SYNOPSIS
42 .In sys/types.h
43 .In sys/time.h
44 .In sys/socket.h
45 .In net/if.h
46 .In net/route.h
47 .Ft int
48 .Fn socket PF_ROUTE SOCK_RAW "int family"
49 .Sh DESCRIPTION
50 .Fx
51 provides some packet routing facilities.
52 The kernel maintains a routing information database, which
53 is used in selecting the appropriate network interface when
54 transmitting packets.
55 .Pp
56 A user process (or possibly multiple co-operating processes)
57 maintains this database by sending messages over a special kind
58 of socket.
59 This supplants fixed size
60 .Xr ioctl 2 Ns 's
61 used in earlier releases.
62 Routing table changes may only be carried out by the super user.
63 .Pp
64 The operating system may spontaneously emit routing messages in response
65 to external events, such as receipt of a re-direct, or failure to
66 locate a suitable route for a request.
67 The message types are described in greater detail below.
68 .Pp
69 Routing database entries come in two flavors: for a specific
70 host, or for all hosts on a generic subnetwork (as specified
71 by a bit mask and value under the mask.
72 The effect of wildcard or default route may be achieved by using
73 a mask of all zeros, and there may be hierarchical routes.
74 .Pp
75 When the system is booted and addresses are assigned
76 to the network interfaces, each protocol family
77 installs a routing table entry for each interface when it is ready for traffic.
78 Normally the protocol specifies the route
79 through each interface as a
80 .Dq direct
81 connection to the destination host
82 or network.  If the route is direct, the transport layer of
83 a protocol family usually requests the packet be sent to the
84 same host specified in the packet.  Otherwise, the interface
85 is requested to address the packet to the gateway listed in the routing entry
86 (i.e. the packet is forwarded).
87 .Pp
88 When routing a packet,
89 the kernel will attempt to find
90 the most specific route matching the destination.
91 (If there are two different mask and value-under-the-mask pairs
92 that match, the more specific is the one with more bits in the mask.
93 A route to a host is regarded as being supplied with a mask of
94 as many ones as there are bits in the destination).
95 If no entry is found, the destination is declared to be unreachable,
96 and a routing\-miss message is generated if there are any
97 listeners on the routing control socket described below.
98 .Pp
99 A wildcard routing entry is specified with a zero
100 destination address value, and a mask of all zeroes.
101 Wildcard routes will be used
102 when the system fails to find other routes matching the
103 destination.  The combination of wildcard
104 routes and routing redirects can provide an economical
105 mechanism for routing traffic.
106 .Pp
107 One opens the channel for passing routing control messages
108 by using the socket call shown in the synopsis above:
109 .Pp
110 The
111 .Fa family
112 parameter may be
113 .Dv AF_UNSPEC
114 which will provide
115 routing information for all address families, or can be restricted
116 to a specific address family by specifying which one is desired.
117 There can be more than one routing socket open per system.
118 .Pp
119 Messages are formed by a header followed by a small
120 number of sockaddrs (now variable length particularly
121 in the
122 .Tn ISO
123 case), interpreted by position, and delimited
124 by the new length entry in the sockaddr.
125 An example of a message with four addresses might be an
126 .Tn ISO
127 redirect:
128 Destination, Netmask, Gateway, and Author of the redirect.
129 The interpretation of which address are present is given by a
130 bit mask within the header, and the sequence is least significant
131 to most significant bit within the vector.
132 .Pp
133 Any messages sent to the kernel are returned, and copies are sent
134 to all interested listeners.  The kernel will provide the process
135 ID for the sender, and the sender may use an additional sequence
136 field to distinguish between outstanding messages.  However,
137 message replies may be lost when kernel buffers are exhausted.
138 .Pp
139 The kernel may reject certain messages, and will indicate this
140 by filling in the
141 .Ar rtm_errno
142 field.
143 The routing code returns
144 .Er EEXIST
145 if
146 requested to duplicate an existing entry,
147 .Er ESRCH
148 if
149 requested to delete a non-existent entry,
150 or
151 .Er ENOBUFS
152 if insufficient resources were available
153 to install a new route.
154 In the current implementation, all routing processes run locally,
155 and the values for
156 .Ar rtm_errno
157 are available through the normal
158 .Em errno
159 mechanism, even if the routing reply message is lost.
160 .Pp
161 A process may avoid the expense of reading replies to
162 its own messages by issuing a
163 .Xr setsockopt 2
164 call indicating that the
165 .Dv SO_USELOOPBACK
166 option
167 at the
168 .Dv SOL_SOCKET
169 level is to be turned off.
170 A process may ignore all messages from the routing socket
171 by doing a
172 .Xr shutdown 2
173 system call for further input.
174 .Pp
175 If a route is in use when it is deleted,
176 the routing entry will be marked down and removed from the routing table,
177 but the resources associated with it will not
178 be reclaimed until all references to it are released.
179 User processes can obtain information about the routing
180 entry to a specific destination by using a
181 .Dv RTM_GET
182 message, or by calling
183 .Xr sysctl 3 .
184 .Pp
185 Messages 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_LOSING      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_LOCK        0x8    /* fix specified metrics */
195 #define RTM_RESOLVE     0xb    /* request to resolve dst to LL addr */
196 #define RTM_NEWADDR     0xc    /* address being added to iface */
197 #define RTM_DELADDR     0xd    /* address being removed from iface */
198 #define RTM_IFINFO      0xe    /* iface going up/down etc. */
199 #define RTM_NEWMADDR    0xf    /* mcast group membership being added to if */
200 #define RTM_DELMADDR    0x10   /* mcast group membership being deleted */
201 #define RTM_IFANNOUNCE  0x11   /* iface arrival/departure */
202 .Ed
203 .Pp
204 A message header consists of one of the following:
205 .Bd -literal
206 struct rt_msghdr {
207     u_short rtm_msglen;         /* to skip over non-understood messages */
208     u_char  rtm_version;        /* future binary compatibility */
209     u_char  rtm_type;           /* message type */
210     u_short rtm_index;          /* index for associated ifp */
211     int     rtm_flags;          /* flags, incl. kern & message, e.g. DONE */
212     int     rtm_addrs;          /* bitmask identifying sockaddrs in msg */
213     pid_t   rtm_pid;            /* identify sender */
214     int     rtm_seq;            /* for sender to identify action */
215     int     rtm_errno;          /* why failed */
216     int     rtm_use;            /* from rtentry */
217     u_long  rtm_inits;          /* which metrics we are initializing */
218     struct  rt_metrics rtm_rmx; /* metrics themselves */
219 };
220
221 struct if_msghdr {
222     u_short ifm_msglen;         /* to skip over non-understood messages */
223     u_char  ifm_version;        /* future binary compatibility */
224     u_char  ifm_type;           /* message type */
225     int     ifm_addrs;          /* like rtm_addrs */
226     int     ifm_flags;          /* value of if_flags */
227     u_short ifm_index;          /* index for associated ifp */
228     struct  if_data ifm_data;   /* statistics and other data about if */
229 };
230
231 struct ifa_msghdr {
232     u_short ifam_msglen;        /* to skip over non-understood messages */
233     u_char  ifam_version;       /* future binary compatibility */
234     u_char  ifam_type;          /* message type */
235     int     ifam_addrs;         /* like rtm_addrs */
236     int     ifam_flags;         /* value of ifa_flags */
237     u_short ifam_index;         /* index for associated ifp */
238     int     ifam_metric;        /* value of ifa_metric */
239 };
240
241 struct ifma_msghdr {
242     u_short ifmam_msglen;       /* to skip over non-understood messages */
243     u_char  ifmam_version;      /* future binary compatibility */
244     u_char  ifmam_type;         /* message type */
245     int     ifmam_addrs;        /* like rtm_addrs */
246     int     ifmam_flags;        /* value of ifa_flags */
247     u_short ifmam_index;        /* index for associated ifp */
248 };
249
250 struct if_announcemsghdr {
251         u_short ifan_msglen;    /* to skip over non-understood messages */
252         u_char  ifan_version;   /* future binary compatibility */
253         u_char  ifan_type;      /* message type */
254         u_short ifan_index;     /* index for associated ifp */
255         char    ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
256         u_short ifan_what;      /* what type of announcement */
257 };
258 .Ed
259 .Pp
260 The
261 .Dv RTM_IFINFO
262 message uses a
263 .Ar if_msghdr
264 header, the
265 .Dv RTM_NEWADDR
266 and
267 .Dv RTM_DELADDR
268 messages use a
269 .Ar ifa_msghdr
270 header, the
271 .Dv RTM_NEWMADDR
272 and
273 .Dv RTM_DELMADDR
274 messages use a
275 .Vt ifma_msghdr
276 header, the
277 .Dv RTM_IFANNOUNCE
278 message uses a
279 .Vt if_announcemsghdr
280 header,
281 and all other messages use the
282 .Ar rt_msghdr
283 header.
284 .Pp
285 The
286 .Dq Li "struct rt_metrics"
287 and the flag bits are as defined in
288 .Xr rtentry 9 .
289 .Pp
290 Specifiers for metric values in rmx_locks and rtm_inits are:
291 .Bd -literal
292 #define RTV_MTU       0x1    /* init or lock _mtu */
293 #define RTV_HOPCOUNT  0x2    /* init or lock _hopcount */
294 #define RTV_EXPIRE    0x4    /* init or lock _expire */
295 #define RTV_RPIPE     0x8    /* init or lock _recvpipe */
296 #define RTV_SPIPE     0x10   /* init or lock _sendpipe */
297 #define RTV_SSTHRESH  0x20   /* init or lock _ssthresh */
298 #define RTV_RTT       0x40   /* init or lock _rtt */
299 #define RTV_RTTVAR    0x80   /* init or lock _rttvar */
300 .Ed
301 .Pp
302 Specifiers for which addresses are present in the messages are:
303 .Bd -literal
304 #define RTA_DST       0x1    /* destination sockaddr present */
305 #define RTA_GATEWAY   0x2    /* gateway sockaddr present */
306 #define RTA_NETMASK   0x4    /* netmask sockaddr present */
307 #define RTA_GENMASK   0x8    /* cloning mask sockaddr present */
308 #define RTA_IFP       0x10   /* interface name sockaddr present */
309 #define RTA_IFA       0x20   /* interface addr sockaddr present */
310 #define RTA_AUTHOR    0x40   /* sockaddr for author of redirect */
311 #define RTA_BRD       0x80   /* for NEWADDR, broadcast or p-p dest addr */
312 .Ed
313 .Sh SEE ALSO
314 .Xr sysctl 3 ,
315 .Xr route 8 ,
316 .Xr rtentry 9
317 .Sh HISTORY
318 A
319 .Dv PF_ROUTE
320 protocol family first appeared in
321 .Bx 4.3 reno .