]> git.saurik.com Git - apple/xnu.git/blob - bsd/man/man4/route.4
xnu-792.25.20.tar.gz
[apple/xnu.git] / bsd / man / man4 / route.4
1 .\" $NetBSD: route.4,v 1.3 1994/11/30 16:22:31 jtc 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 Mac OS X provides some packet routing facilities.
50 The kernel maintains a routing information database, which
51 is used in selecting the appropriate network interface when
52 transmitting packets.
53 .Pp
54 A user process (or possibly multiple co-operating processes)
55 maintains this database by sending messages over a special kind
56 of socket.
57 This supplants fixed size
58 .Xr ioctl 2 Ns 's
59 used in earlier releases.
60 Routing table changes may only be carried out by the super user.
61 .Pp
62 The operating system may spontaneously emit routing messages in response
63 to external events, such as receipt of a re-direct, or failure to
64 locate a suitable route for a request.
65 The message types are described in greater detail below.
66 .Pp
67 Routing database entries come in two flavors: for a specific
68 host, or for all hosts on a generic subnetwork (as specified
69 by a bit mask and value under the mask.
70 The effect of wildcard or default route may be achieved by using
71 a mask of all zeros, and there may be hierarchical routes.
72 .Pp
73 When the system is booted and addresses are assigned
74 to the network interfaces, each protocol family
75 installs a routing table entry for each interface when it is ready for traffic.
76 Normally the protocol specifies the route
77 through each interface as a
78 .Dq direct
79 connection to the destination host
80 or network. If the route is direct, the transport layer of
81 a protocol family usually requests the packet be sent to the
82 same host specified in the packet. Otherwise, the interface
83 is requested to address the packet to the gateway listed in the routing entry
84 (i.e. the packet is forwarded).
85 .Pp
86 When routing a packet,
87 the kernel will attempt to find
88 the most specific route matching the destination.
89 (If there are two different mask and value-under-the-mask pairs
90 that match, the more specific is the one with more bits in the mask.
91 A route to a host is regarded as being supplied with a mask of
92 as many ones as there are bits in the destination).
93 If no entry is found, the destination is declared to be unreachable,
94 and a routing\-miss message is generated if there are any
95 listers on the routing control socket described below.
96 .Pp
97 A wildcard routing entry is specified with a zero
98 destination address value, and a mask of all zeroes.
99 Wildcard routes will be used
100 when the system fails to find other routes matching the
101 destination. The combination of wildcard
102 routes and routing redirects can provide an economical
103 mechanism for routing traffic.
104 .Pp
105 One opens the channel for passing routing control messages
106 by using the socket call shown in the synopsis above:
107 .Pp
108 The
109 .Fa family
110 parameter may be
111 .Dv AF_UNSPEC
112 which will provide
113 routing information for all address families, or can be restricted
114 to a specific address family by specifying which one is desired.
115 There can be more than one routing socket open per system.
116 .Pp
117 Messages are formed by a header followed by a small
118 number of sockadders (now variable length particularly
119 in the
120 .Tn ISO
121 case), interpreted by position, and delimited
122 by the new length entry in the sockaddr.
123 An example of a message with four addresses might be an
124 .Tn ISO
125 redirect:
126 Destination, Netmask, Gateway, and Author of the redirect.
127 The interpretation of which address are present is given by a
128 bit mask within the header, and the sequence is least significant
129 to most significant bit within the vector.
130 .Pp
131 Any messages sent to the kernel are returned, and copies are sent
132 to all interested listeners. The kernel will provide the process
133 id. for the sender, and the sender may use an additional sequence
134 field to distinguish between outstanding messages. However,
135 message replies may be lost when kernel buffers are exhausted.
136 .Pp
137 The kernel may reject certain messages, and will indicate this
138 by filling in the
139 .Ar rtm_errno
140 field.
141 The routing code returns
142 .Dv EEXIST
143 if
144 requested to duplicate an existing entry,
145 .Dv ESRCH
146 if
147 requested to delete a non-existent entry,
148 or
149 .Dv ENOBUFS
150 if insufficient resources were available
151 to install a new route.
152 In the current implementation, all routing process run locally,
153 and the values for
154 .Ar rtm_errno
155 are available through the normal
156 .Em errno
157 mechanism, even if the routing reply message is lost.
158 .Pp
159 A process may avoid the expense of reading replies to
160 its own messages by issuing a
161 .Xr setsockopt 2
162 call indicating that the
163 .Dv SO_USELOOPBACK
164 option
165 at the
166 .Dv SOL_SOCKET
167 level is to be turned off.
168 A process may ignore all messages from the routing socket
169 by doing a
170 .Xr shutdown 2
171 system call for further input.
172 .Pp
173 If a route is in use when it is deleted,
174 the routing entry will be marked down and removed from the routing table,
175 but the resources associated with it will not
176 be reclaimed until all references to it are released.
177 User processes can obtain information about the routing
178 entry to a specific destination by using a
179 .Dv RTM_GET
180 message,
181 or by reading the
182 .Pa /dev/kmem
183 device, or by issuing a
184 .Xr getkerninfo 2
185 system call.
186 .Pp
187 Messages include:
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_LOOSING 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 .Ed
198 .Pp
199 A message header consists of:
200 .Bd -literal
201 struct rt_msghdr {
202 u_short rmt_msglen; /* to skip over non-understood messages */
203 u_char rtm_version; /* future binary compatibility */
204 u_char rtm_type; /* message type */
205 u_short rmt_index; /* index for associated ifp */
206 pid_t rmt_pid; /* identify sender */
207 int rtm_addrs; /* bitmask identifying sockaddrs in msg */
208 int rtm_seq; /* for sender to identify action */
209 int rtm_errno; /* why failed */
210 int rtm_flags; /* flags, incl kern & message, e.g. DONE */
211 int rtm_use; /* from rtentry */
212 u_long rtm_inits; /* which values we are initializing */
213 struct rt_metrics rtm_rmx; /* metrics themselves */
214 };
215 .Ed
216 .Pp
217 where
218 .Bd -literal
219 struct rt_metrics {
220 u_long rmx_locks; /* Kernel must leave these values alone */
221 u_long rmx_mtu; /* MTU for this path */
222 u_long rmx_hopcount; /* max hops expected */
223 u_long rmx_expire; /* lifetime for route, e.g. redirect */
224 u_long rmx_recvpipe; /* inbound delay-bandwith product */
225 u_long rmx_sendpipe; /* outbound delay-bandwith product */
226 u_long rmx_ssthresh; /* outbound gateway buffer limit */
227 u_long rmx_rtt; /* estimated round trip time */
228 u_long rmx_rttvar; /* estimated rtt variance */
229 };
230 .Ed
231 .Pp
232 Flags include the values:
233 .Bd -literal
234 #define RTF_UP 0x1 /* route usable */
235 #define RTF_GATEWAY 0x2 /* destination is a gateway */
236 #define RTF_HOST 0x4 /* host entry (net otherwise) */
237 #define RTF_REJECT 0x8 /* host or net unreachable */
238 #define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */
239 #define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */
240 #define RTF_DONE 0x40 /* message confirmed */
241 #define RTF_MASK 0x80 /* subnet mask present */
242 #define RTF_CLONING 0x100 /* generate new routes on use */
243 #define RTF_XRESOLVE 0x200 /* external daemon resolves name */
244 #define RTF_LLINFO 0x400 /* generated by ARP or ESIS */
245 #define RTF_STATIC 0x800 /* manually added */
246 #define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */
247 #define RTF_PROTO2 0x4000 /* protocol specific routing flag #1 */
248 #define RTF_PROTO1 0x8000 /* protocol specific routing flag #2 */
249 .Ed
250 .Pp
251 Specifiers for metric values in rmx_locks and rtm_inits are:
252 .Bd -literal
253 #define RTV_SSTHRESH 0x1 /* init or lock _ssthresh */
254 #define RTV_RPIPE 0x2 /* init or lock _recvpipe */
255 #define RTV_SPIPE 0x4 /* init or lock _sendpipe */
256 #define RTV_HOPCOUNT 0x8 /* init or lock _hopcount */
257 #define RTV_RTT 0x10 /* init or lock _rtt */
258 #define RTV_RTTVAR 0x20 /* init or lock _rttvar */
259 #define RTV_MTU 0x40 /* init or lock _mtu */
260 .Ed
261 .Pp
262 Specifiers for which addresses are present in the messages are:
263 .Bd -literal
264 #define RTA_DST 0x1 /* destination sockaddr present */
265 #define RTA_GATEWAY 0x2 /* gateway sockaddr present */
266 #define RTA_NETMASK 0x4 /* netmask sockaddr present */
267 #define RTA_GENMASK 0x8 /* cloning mask sockaddr present */
268 #define RTA_IFP 0x10 /* interface name sockaddr present */
269 #define RTA_IFA 0x20 /* interface addr sockaddr present */
270 #define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */
271 .Ed