1route(7P)                          Protocols                         route(7P)
2
3
4

NAME

6       route - kernel packet forwarding database
7

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

DESCRIPTION

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

SEE ALSO

276       ioctl(2), setsockopt(3SOCKET), shutdown(3SOCKET), routing(7P)
277

NOTES

279       Some  of  the  metrics  might  not  be implemented and return zero. The
280       implemented metrics are set in rtm_inits.
281
282
283
284SunOS 5.11                        5 Feb 2009                         route(7P)
Impressum