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