1 Protocols route(7P)
2
3
4
5 NAME
6 route - kernel packet forwarding database
7
8 SYNOPSIS
9 #include <sys/types.h>
10 #include <sys/socket.h>
11 #include <net/if.h>
12 #include <net/route.h>
13
14 int socket(PF_ROUTE, SOCK_RAW, int protocol);
15
16
17 DESCRIPTION
18 UNIX provides some packet routing facilities. The kernel
19 maintains a routing information database, which is used in
20 selecting the appropriate network interface when transmit-
21 ting packets.
22
23
24 A user process (or possibly multiple co-operating processes)
25 maintains this database by sending messages over a special
26 kind of socket. This supplants fixed size ioctl(2)'s speci-
27 fied in routing(7P). Routing table changes may only be car-
28 ried out by the superuser.
29
30
31 The operating system may spontaneously emit routing messages
32 in response to external events, such as receipt of a re-
33 direct, or failure to locate a suitable route for a request.
34 The message types are described in greater detail below.
35
36
37 Routing database entries come in two flavors: entries for a
38 specific host, or entries for all hosts on a generic subnet-
39 work (as specified by a bit mask and value under the mask).
40 The effect of wildcard or default route may be achieved by
41 using a mask of all zeros, and there may be hierarchical
42 routes.
43
44
45 When the system is booted and addresses are assigned to the
46 network interfaces, the internet protocol family installs a
47 routing table entry for each interface when it is ready for
48 traffic. Normally the protocol specifies the route through
49 each interface as a direct connection to the destination
50 host or network. If the route is direct, the transport
51 layer of a protocol family usually requests the packet be
52 sent to the same host specified in the packet. Otherwise,
53 the interface is requested to address the packet to the
54 gateway listed in the routing entry, that is, the packet is
55 forwarded.
56
57
58
59
60 SunOS 5.11 Last change: 25 July 2006 1
61
62
63
64
65
66
67 Protocols route(7P)
68
69
70
71 When routing a packet, the kernel attempts to find the most
72 specific route matching the destination. If no entry is
73 found, the destination is declared to be unreachable, and a
74 routing-miss message is generated if there are any listeners
75 on the routing control socket (described below). If there
76 are two different mask and value-under-the-mask pairs that
77 match, the more specific is the one with more bits in the
78 mask. A route to a host is regarded as being supplied with a
79 mask of as many ones as there are bits in the destination.
80
81
82 A wildcard routing entry is specified with a zero destina-
83 tion address value, and a mask of all zeroes. Wildcard
84 routes are used when the system fails to find other routes
85 matching the destination. The combination of wildcard routes
86 and routing redirects can provide an economical mechanism
87 for routing traffic.
88
89
90 One opens the channel for passing routing control messages
91 by using the socket call shown in the section above. There
92 can be more than one routing socket open per system.
93
94
95 Messages are formed by a header followed by a small number
96 of sockaddrs, whose length depend on the address family.
97 sockaddrs are interpreted by position. An example of a type
98 of message with three addresses might be a CIDR prefix
99 route: Destination, Netmask, and Gateway. The interpretation
100 of which addresses are present is given by a bit mask within
101 the header, and the sequence is least significant to most
102 significant bit within the vector.
103
104
105 Any messages sent to the kernel are returned, and copies are
106 sent to all interested listeners. The kernel provides the
107 process ID of the sender, and the sender may use an addi-
108 tional sequence field to distinguish between outstanding
109 messages. However, message replies may be lost when kernel
110 buffers are exhausted.
111
112
113 The protocol parameter specifies which messages an applica-
114 tion listening on the routing socket is interested in see-
115 ing, based on the the address family of the sockaddrs
116 present. Currently, you can specify AF_INET and AF_INET6 to
117 filter the messages seen by the listener, or alternatively,
118 you can specify AF_UNSPEC to indicate that the listener is
119 interested in all routing messages.
120
121
122
123
124
125
126 SunOS 5.11 Last change: 25 July 2006 2
127
128
129
130
131
132
133 Protocols route(7P)
134
135
136
137 The kernel may reject certain messages, and will indicate
138 this by filling in the rtm_errno field of the rt_msghdr
139 struct (see below). The following codes may be returned:
140
141 EEXIST If requested to duplicate an existing entry
142
143
144 ESRCH If requested to delete a non-existent entry
145
146
147 ENOBUFS If insufficient resources were available to
148 install a new route.
149
150
151 EPERM If the calling process does not have appropriate
152 privileges to alter the routing table.
153
154
155
156 In the current implementation, all routing processes run
157 locally, and the values for rtm_errno are available through
158 the normal errno mechanism, even if the routing reply mes-
159 sage is lost.
160
161
162 A process may avoid the expense of reading replies to its
163 own messages by issuing a setsockopt(3SOCKET) call indicat-
164 ing that the SO_USELOOPBACK option at the SOL_SOCKET level
165 is to be turned off. A process may ignore all messages from
166 the routing socket by doing a shutdown(3SOCKET) system call
167 for further input.
168
169
170 By default, underlying IP interfaces in an IPMP group are
171 not visible to routing sockets. As such, routing sockets
172 will not receive events related to underlying IP interfaces
173 in an IPMP group. For consistency, when an IP interface is
174 placed into an IPMP group, *RTM_DELADDR* messages will be
175 generated for each of the *IFF_UP* addresses that are not
176 migrated to the corresponding IPMP IP interface, and an
177 *RTM_IFINFO* message will be sent indicating that the
178 interface is now down. Similarly, when an underlying
179 interface is removed from an IPMP group, an *RTM_IFINFO*
180 message will be sent indicating that the interface is again
181 up, and *RTM_NEWADDR* messages will be generated for each
182 *IFF_UP* address found on the interface.
183
184
185 The *RT_AWARE* socket option at the *SOL_ROUTE* level allows
186 an application to indicate its awareness of certain
187 features, which controls routing socket behavior. The
188 supported values are:
189
190 *RTAW_DEFAULT* Default awareness.
191
192 *RTAW_UNDER_IPMP* IPMP underlying interface awareness.
193 When this is enabled, underlying IP
194 interfaces in an IPMP group will remain
195 visible to the routing socket and
196 events related to them will continue to
197 be generated.
198
199
200 An *RTM_ADD* request tied to an underlying IP interface in
201 an IPMP group will be translated to an *RTM_ADD* request for
202 its corresponding IPMP IP interface. All routing socket
203 requests other than *RTM_ADD* and *RTM_GET* will fail when
204 issued on an underlying IP interface in an IPMP group.
205
206
207 If a route is in use when it is deleted, the routing entry
208 is marked down and removed from the routing table, but the
209 resources associated with it are not reclaimed until all
210 references to it are released.
211
212
213 The RTM_IFINFO, RTM_NEWADDR, and RTM_ADD messages associated
214 with interface configuration (setting the IFF_UP bit) are
215 normally delayed until after Duplicate Address Detection
216 completes. Thus, applications that configure interfaces and
217 wish to wait until the interface is ready can wait until
218 RTM_IFINFO is returned and SIOCGLIFFLAGS shows that
219 IFF_DUPLICATE is not set.
220
221 Messages
222 User processes can obtain information about the routing
223 entry to a specific destination by using a RTM_GET message.
224
225
226
227
228
229 SunOS 5.11 Last change: 25 July 2006 3
230
231
232
233
234
235
236 Protocols route(7P)
237
238
239
240 Messages include:
241
242 #define RTM_ADD 0x1 /* Add Route */
243 #define RTM_DELETE 0x2 /* Delete Route */
244 #define RTM_CHANGE 0x3 /* Change Metrics, Flags, or Gateway */
245 #define RTM_GET 0x4 /* Report Information */
246 #define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */
247 #define RTM_REDIRECT 0x6 /* Told to use different route */
248 #define RTM_MISS 0x7 /* Lookup failed on this address */
249 #define RTM_LOCK 0x8 /* fix specified metrics */
250 #define RTM_OLDADD 0x9 /* caused by SIOCADDRT */
251 #define RTM_OLDDEL 0xa /* caused by SIOCDELRT */
252 #define RTM_RESOLVE 0xb /* request to resolve dst to LL addr */
253 #define RTM_NEWADDR 0xc /* address being added to iface */
254 #define RTM_DELADDR 0xd /* address being removed from iface */
255 #define RTM_IFINFO 0xe /* iface going up/down etc. */
256
257
258
259 A message header consists of:
260
261 struct rt_msghdr {
262 ushort_t rtm_msglen; /* to skip over non-understood messages */
263 uchar_t rtm_version; /* future binary compatibility */
264 uchar_t rtm_type; /* message type */
265 ushort_t rtm_index; /* index for associated ifp */
266 pid_t rtm_pid; /* identify sender */
267 int rtm_addrs; /* bitmask identifying sockaddrs in msg */
268 int rtm_seq; /* for sender to identify action */
269 int rtm_errno; /* why failed */
270 int rtm_flags; /* flags, incl kern & message, e.g., DONE */
271 int rtm_use; /* from rtentry */
272 uint_t rtm_inits; /* which values we are initializing */
273
274 struct rt_metrics rtm_rmx; /* metrics themselves */
275 };
276
277
278
279 where
280
281 struct rt_metrics {
282 uint32_t rmx_locks; /* Kernel must leave these values alone */
283 uint32_t rmx_mtu; /* MTU for this path */
284 uint32_t rmx_hopcount; /* max hops expected */
285 uint32_t rmx_expire; /* lifetime for route, e.g., redirect */
286 uint32_t rmx_recvpipe; /* inbound delay-bandwidth product */
287 uint32_t rmx_sendpipe; /* outbound delay-bandwidth product */
288 uint32_t rmx_ssthresh; /* outbound gateway buffer limit */
289 uint32_t rmx_rtt; /* estimated round trip time */
290 uint32_t rmx_rttvar; /* estimated rtt variance */
291 uint32_t rmx_pksent; /* packets sent using this route */
292
293
294
295 SunOS 5.11 Last change: 25 July 2006 4
296
297
298
299
300
301
302 Protocols route(7P)
303
304
305
306 };
307
308 /* Flags include the values */
309
310
311 #define RTF_UP 0x1 /* route usable */
312 #define RTF_GATEWAY 0x2 /* destination is a gateway */
313 #define RTF_HOST 0x4 /* host entry (net otherwise) */
314 #define RTF_REJECT 0x8 /* host or net unreachable */
315 #define RTF_DYNAMIC 0x10 /* created dynamically(by redirect) */
316 #define RTF_MODIFIED 0x20 /* modified dynamically(by redirect) */
317 #define RTF_DONE 0x40 /* message confirmed */
318 #define RTF_MASK 0x80 /* subnet mask present */
319 #define RTF_CLONING 0x100 /* generate new routes on use */
320 #define RTF_XRESOLVE 0x200 /* external daemon resolves name */
321 #define RTF_LLINFO 0x400 /* generated by ARP */
322 #define RTF_STATIC 0x800 /* manually added */
323 #define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */
324 #define RTF_PRIVATE 0x2000 /* do not advertise this route */
325 #define RTF_PROTO2 0x4000 /* protocol specific routing flag #2 */
326 #define RTF_PROTO1 0x8000 /* protocol specific routing flag #1 */
327
328 /* Specifiers for metric values in rmx_locks and rtm_inits are */
329
330 #define RTV_MTU 0x1 /* init or lock _mtu */
331 #define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */
332 #define RTV_EXPIRE 0x4 /* init or lock _expire */
333 #define RTV_RPIPE 0x8 /* init or lock _recvpipe */
334 #define RTV_SPIPE 0x10 /* init or lock _sendpipe */
335 #define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */
336 #define RTV_RTT 0x40 /* init or lock _rtt */
337 #define RTV_RTTVAR 0x80 /* init or lock _rttvar */
338
339 /* Specifiers for which addresses are present in the messages are */
340
341 #define RTA_DST 0x1 /* destination sockaddr present */
342 #define RTA_GATEWAY 0x2 /* gateway sockaddr present */
343 #define RTA_NETMASK 0x4 /* netmask sockaddr present */
344 #define RTA_GENMASK 0x8 /* cloning mask sockaddr present */
345 #define RTA_IFP 0x10 /* interface name sockaddr present */
346 #define RTA_IFA 0x20 /* interface addr sockaddr present */
347 #define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */
348 #define RTA_BRD 0x80 /* for NEWADDR, broadcast or p-p dest addr */
349
350
351 SEE ALSO
352 ioctl(2), setsockopt(3SOCKET), shutdown(3SOCKET),
353 routing(7P)
354
355 NOTES
356 Some of the metrics may not be implemented and return zero.
357 The implemented metrics are set in rtm_inits.
358
359
360
361 SunOS 5.11 Last change: 25 July 2006 5
362
363
364