5331 want sockaddr(3SOCKET)
[illumos-gate.git] / usr / src / man / man7p / route.7p
blobba193fef11605f75c20754d33c127b1135663c46
1 '\" te
2 .\" Copyright (c) 1990, 1991, 1993 The Regents of the University of California. All rights reserved.
3 .\" Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
4 .\" 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display
5 .\" the following acknowledgement: This product includes software developed by the University of California, Berkeley and its contributors. 4. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without
6 .\" specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS
7 .\" OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
8 .\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 .\" Portions Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved.
10 .TH ROUTE 7P "Feb 5, 2009"
11 .SH NAME
12 route \- kernel packet forwarding database
13 .SH SYNOPSIS
14 .LP
15 .nf
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #include <net/if.h>
19 #include <net/route.h>
21 \fBint\fR \fBsocket\fR(\fB\fR\fIPF_ROUTE\fR, \fB\fR\fISOCK_RAW\fR, \fBint\fR \fIprotocol\fR);
22 .fi
24 .SH DESCRIPTION
25 .LP
26 UNIX provides some packet routing facilities. The kernel maintains a routing
27 information database, which is used in selecting the appropriate network
28 interface when transmitting packets.
29 .sp
30 .LP
31 A user process (or possibly multiple co-operating processes) maintains this
32 database by sending messages over a special kind of socket. This supplants
33 fixed size \fBioctl\fR(2)'s specified in \fBrouting\fR(7P). Routing table
34 changes can only be carried out by the superuser.
35 .sp
36 .LP
37 The operating system might spontaneously emit routing messages in response to
38 external events, such as receipt of a re-direct, or failure to locate a
39 suitable route for a request. The message types are described in greater detail
40 below.
41 .sp
42 .LP
43 Routing database entries come in two flavors: entries for a specific host, or
44 entries for all hosts on a generic subnetwork (as specified by a bit mask and
45 value under the mask). The effect of wildcard or default route can be achieved
46 by using a mask of all zeros, and there can be hierarchical routes.
47 .sp
48 .LP
49 When the system is booted and addresses are assigned to the network interfaces,
50 the internet protocol family installs a routing table entry for each interface
51 when it is ready for traffic. Normally the protocol specifies the route through
52 each interface as a \fIdirect\fR connection to the destination host or network.
53 If the route is direct, the transport layer of a protocol family usually
54 requests the packet be sent to the same host specified in the packet.
55 Otherwise, the interface is requested to address the packet to the gateway
56 listed in the routing entry, that is, the packet is forwarded.
57 .sp
58 .LP
59 When routing a packet, the kernel attempts to find the most specific route
60 matching the destination. If no entry is found, the destination is declared to
61 be unreachable, and a routing-miss message is generated if there are any
62 listeners on the routing control socket (described below). If there are two
63 different mask and value-under-the-mask pairs that match, the more specific is
64 the one with more bits in the mask. A route to a host is regarded as being
65 supplied with a mask of as many ones as there are bits in the destination.
66 .sp
67 .LP
68 A wildcard routing entry is specified with a zero destination address value,
69 and a mask of all zeroes. Wildcard routes are used when the system fails to
70 find other routes matching the destination. The combination of wildcard routes
71 and routing redirects can provide an economical mechanism for routing traffic.
72 .sp
73 .LP
74 One opens the channel for passing routing control messages by using the socket
75 call. There can be more than one routing socket open per system.
76 .sp
77 .LP
78 Messages are formed by a header followed by a small number of \fBsockaddrs\fR,
79 whose length depend on the address family. \fBsockaddrs\fR are interpreted by
80 position. An example of a type of message with three addresses might be a
81 \fBCIDR\fR prefix route: Destination, Netmask, and Gateway. The interpretation
82 of which addresses are present is given by a bit mask within the header, and
83 the sequence is least significant to most significant bit within the vector.
84 .sp
85 .LP
86 Any messages sent to the kernel are returned, and copies are sent to all
87 interested listeners. The kernel provides the process \fBID\fR of the sender,
88 and the sender can use an additional sequence field to distinguish between
89 outstanding messages. However, message replies can be lost when kernel buffers
90 are exhausted.
91 .sp
92 .LP
93 The \fIprotocol\fR parameter specifies which messages an application listening
94 on the routing socket is interested in seeing, based on the the address family
95 of the \fBsockaddrs\fR present. Currently, you can specify \fBAF_INET\fR and
96 \fBAF_INET6\fR to filter the messages seen by the listener, or alternatively,
97 you can specify \fBAF_UNSPEC\fR to indicate that the listener is interested in
98 all routing messages.
99 .sp
101 The kernel might reject certain messages, and indicates this by filling in the
102 \fBrtm_errno\fR field of the \fBrt_msghdr\fR struct (see below). The following
103 codes are returned:
105 .ne 2
107 \fB\fBEEXIST\fR\fR
109 .RS 11n
110 If requested to duplicate an existing entry
114 .ne 2
116 \fB\fBESRCH\fR\fR
118 .RS 11n
119 If requested to delete a non-existent entry
123 .ne 2
125 \fB\fBENOBUFS\fR\fR
127 .RS 11n
128 If insufficient resources were available to install a new route.
132 .ne 2
134 \fB\fBEPERM\fR\fR
136 .RS 11n
137 If the calling process does not have appropriate privileges to alter the
138 routing table.
143 In the current implementation, all routing processes run locally, and the
144 values for \fBrtm_errno\fR are available through the normal \fBerrno\fR
145 mechanism, even if the routing reply message is lost.
148 A process can avoid the expense of reading replies to its own messages by
149 issuing a \fBsetsockopt\fR(3SOCKET) call indicating that the
150 \fBSO_USELOOPBACK\fR option at the \fBSOL_SOCKET\fR level is to be turned off.
151 A process can ignore all messages from the routing socket by doing a
152 \fBshutdown\fR(3SOCKET) system call for further input.
155 By default, underlying IP interfaces in an IPMP group are not visible to
156 routing sockets. As such, routing sockets do not receive events related to
157 underlying IP interface in an IPMP group. For consistency, when an IP interface
158 is placed into an IPMP group, \fBRTM_DELADDR\fR messages are generated for each
159 \fBIFF_UP\fR address that is not migrated to the corresponding IPMP IP
160 interface and an \fBRTM_IFINFO\fR message is sent indicating the interface is
161 down. Similarly, when an underlying interface is removed from an IPMP group, an
162 \fBRTM_IFINFO\fR message is sent indicating the interface is again up and
163 \fBRTM_NEWADDR\fR messages are generated for each \fBIFF_UP\fR address found on
164 the interface.
167 The \fBRT_AWARE\fR socket option at the \fBSOL_ROUTE\fR level allows an
168 application to indicate its awareness of certain features, which control
169 routing socket behavior. The supported values are:
171 .ne 2
173 \fB\fBRTAW_DEFAULT\fR\fR
175 .RS 20n
176 Default awareness.
180 .ne 2
182 \fB\fBRTAW_UNDER_IPMP\fR\fR
184 .RS 20n
185 IPMP underlying interface awareness. When enabled, underlying IP interfaces in
186 an IPMP group remain visible to the routing socket and events related to them
187 continue to be generated.
192 An \fBRTM_ADD\fR request tied to an underlying IP interface in an IPMP group is
193 translated to an \fBRTM_ADD\fR request for its corresponding IPMP IP interface.
194 All routing socket requests other than \fBRTM_ADD\fR and \fBRTM_GET\fR  fail
195 when issued on an underlying IP interface in an IPMP group.
198 If a route is in use when it is deleted, the routing entry is marked down and
199 removed from the routing table, but the resources associated with it are not
200 reclaimed until all references to it are released.
203 The \fBRTM_IFINFO\fR, \fBRTM_NEWADDR\fR, and \fBRTM_ADD\fR messages associated
204 with interface configuration (setting the \fBIFF_UP\fR bit) are normally
205 delayed until after Duplicate Address Detection completes. Thus, applications
206 that configure interfaces and wish to wait until the interface is ready can
207 wait until \fBRTM_IFINFO\fR is returned and \fBSIOCGLIFFLAGS\fR shows that
208 \fBIFF_DUPLICATE\fR is not set.
209 .SS "Messages"
211 User processes can obtain information about the routing entry to a specific
212 destination by using a \fBRTM_GET\fR message.
215 Messages include:
217 .in +2
219 #define RTM_ADD      0x1   /* Add Route */
220 #define RTM_DELETE   0x2   /* Delete Route */
221 #define RTM_CHANGE   0x3   /* Change Metrics, Flags, or Gateway */
222 #define RTM_GET      0x4   /* Report Information */
223 #define RTM_LOSING   0x5   /* Kernel Suspects Partitioning */
224 #define RTM_REDIRECT 0x6   /* Told to use different route */
225 #define RTM_MISS     0x7   /* Lookup failed on this address */
226 #define RTM_LOCK     0x8   /* fix specified metrics */
227 #define RTM_OLDADD   0x9   /* caused by SIOCADDRT */
228 #define RTM_OLDDEL   0xa   /* caused by SIOCDELRT */
229 #define RTM_RESOLVE  0xb   /* request to resolve dst to LL addr */
230 #define RTM_NEWADDR  0xc   /* address being added to iface */
231 #define RTM_DELADDR  0xd   /* address being removed from iface */
232 #define RTM_IFINFO   0xe   /* iface going up/down etc. */
234 .in -2
238 A message header consists of:
240 .in +2
242 struct rt_msghdr {
243   ushort_t rtm_msglen;    /* to skip over non-understood messages */
244   uchar_t  rtm_version;   /* future binary compatibility */
245   uchar_t  rtm_type;      /* message type */
246   ushort_t rtm_index;     /* index for associated ifp */
247   pid_t   rtm_pid;        /* identify sender */
248   int     rtm_addrs;      /* bitmask identifying sockaddrs in msg */
249   int     rtm_seq;        /* for sender to identify action */
250   int     rtm_errno;      /* why failed */
251   int     rtm_flags;      /*  flags,  incl  kern  &  message, e.g., DONE */
252   int     rtm_use;        /* from rtentry */
253   uint_t  rtm_inits;      /* which values we are initializing */
255 struct  rt_metrics rtm_rmx;   /* metrics themselves */
256      };
258 .in -2
262 where
264 .in +2
266 struct rt_metrics {
267   uint32_t rmx_locks;      /* Kernel must leave  these  values alone */
268   uint32_t rmx_mtu;        /* MTU for this path */
269   uint32_t rmx_hopcount;   /* max hops expected */
270   uint32_t rmx_expire;     /* lifetime for route, e.g., redirect */
271   uint32_t rmx_recvpipe;   /* inbound delay-bandwidth  product */
272   uint32_t rmx_sendpipe;   /* outbound delay-bandwidth product */
273   uint32_t rmx_ssthresh;   /* outbound gateway buffer limit */
274   uint32_t rmx_rtt;        /* estimated round trip time */
275   uint32_t rmx_rttvar;     /* estimated rtt variance */
276   uint32_t rmx_pksent;     /* packets sent using this route */
277  };
279 /* Flags include the values */
282 #define RTF_UP         0x1     /* route usable */
283 #define RTF_GATEWAY    0x2     /* destination is a gateway */
284 #define RTF_HOST       0x4     /* host entry (net otherwise) */
285 #define RTF_REJECT     0x8     /* host or net unreachable */
286 #define RTF_DYNAMIC    0x10    /* created dynamically(by redirect) */
287 #define RTF_MODIFIED   0x20    /* modified dynamically(by redirect) */
288 #define RTF_DONE       0x40    /* message confirmed */
289 #define RTF_MASK       0x80    /* subnet mask present */
290 #define RTF_CLONING    0x100   /* generate new routes on use */
291 #define RTF_XRESOLVE   0x200   /* external daemon resolves name */
292 #define RTF_LLINFO     0x400   /* generated by ARP */
293 #define RTF_STATIC     0x800   /* manually added */
294 #define RTF_BLACKHOLE  0x1000  /* just discard pkts (during updates) */
295 #define RTF_PRIVATE    0x2000  /* do not advertise this route */
296 #define RTF_PROTO2     0x4000  /* protocol specific routing flag #2 */
297 #define RTF_PROTO1     0x8000  /* protocol specific routing flag #1 */
299 /* Specifiers for metric values in rmx_locks and rtm_inits are */
301 #define RTV_MTU        0x1     /* init or lock _mtu */
302 #define RTV_HOPCOUNT   0x2     /* init or lock _hopcount */
303 #define RTV_EXPIRE     0x4     /* init or lock _expire */
304 #define RTV_RPIPE      0x8     /* init or lock _recvpipe */
305 #define RTV_SPIPE      0x10    /* init or lock _sendpipe */
306 #define RTV_SSTHRESH   0x20    /* init or lock _ssthresh */
307 #define RTV_RTT        0x40    /* init or lock _rtt */
308 #define RTV_RTTVAR     0x80    /* init or lock _rttvar */
310 /* Specifiers for which addresses are present in  the  messages are */
312 #define RTA_DST        0x1     /* destination sockaddr present */
313 #define RTA_GATEWAY    0x2     /* gateway sockaddr present */
314 #define RTA_NETMASK    0x4     /* netmask sockaddr present */
315 #define RTA_GENMASK    0x8     /* cloning mask sockaddr present */
316 #define RTA_IFP        0x10    /* interface name sockaddr present */
317 #define RTA_IFA        0x20    /* interface addr sockaddr present */
318 #define RTA_AUTHOR     0x40    /* sockaddr for author of redirect */
319 #define RTA_BRD        0x80    /* for NEWADDR, broadcast or p-p dest addr */
321 .in -2
323 .SH SEE ALSO
325 \fBioctl\fR(2), \fBsetsockopt\fR(3SOCKET), \fBshutdown\fR(3SOCKET),
326 \fBsockaddr\fR(3SOCKET), \fBrouting\fR(7P)
327 .SH NOTES
329 Some of the metrics might not be implemented and return zero. The implemented
330 metrics are set in \fBrtm_inits\fR.