1996-10-08 20:45:06 +02:00
|
|
|
.\"
|
|
|
|
.\" Copyright 1996 Massachusetts Institute of Technology
|
|
|
|
.\"
|
|
|
|
.\" Permission to use, copy, modify, and distribute this software and
|
|
|
|
.\" its documentation for any purpose and without fee is hereby
|
|
|
|
.\" granted, provided that both the above copyright notice and this
|
|
|
|
.\" permission notice appear in all copies, that both the above
|
|
|
|
.\" copyright notice and this permission notice appear in all
|
|
|
|
.\" supporting documentation, and that the name of M.I.T. not be used
|
|
|
|
.\" in advertising or publicity pertaining to distribution of the
|
|
|
|
.\" software without specific, written prior permission. M.I.T. makes
|
|
|
|
.\" no representations about the suitability of this software for any
|
|
|
|
.\" purpose. It is provided "as is" without express or implied
|
|
|
|
.\" warranty.
|
2001-07-14 21:41:16 +02:00
|
|
|
.\"
|
1996-10-08 20:45:06 +02:00
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
|
|
|
|
.\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
|
|
|
|
.\" SHALL M.I.T. 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 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.
|
|
|
|
.\"
|
1999-08-28 02:22:10 +02:00
|
|
|
.\" $FreeBSD$
|
This main goals of this project are:
1. separating L2 tables (ARP, NDP) from the L3 routing tables
2. removing as much locking dependencies among these layers as
possible to allow for some parallelism in the search operations
3. simplify the logic in the routing code,
The most notable end result is the obsolescent of the route
cloning (RTF_CLONING) concept, which translated into code reduction
in both IPv4 ARP and IPv6 NDP related modules, and size reduction in
struct rtentry{}. The change in design obsoletes the semantics of
RTF_CLONING, RTF_WASCLONE and RTF_LLINFO routing flags. The userland
applications such as "arp" and "ndp" have been modified to reflect
those changes. The output from "netstat -r" shows only the routing
entries.
Quite a few developers have contributed to this project in the
past: Glebius Smirnoff, Luigi Rizzo, Alessandro Cerri, and
Andre Oppermann. And most recently:
- Kip Macy revised the locking code completely, thus completing
the last piece of the puzzle, Kip has also been conducting
active functional testing
- Sam Leffler has helped me improving/refactoring the code, and
provided valuable reviews
- Julian Elischer setup the perforce tree for me and has helped
me maintaining that branch before the svn conversion
2008-12-15 07:10:57 +01:00
|
|
|
.\"
|
2012-07-04 09:42:12 +02:00
|
|
|
.Dd July 4, 2012
|
1996-10-08 20:45:06 +02:00
|
|
|
.Dt RTALLOC 9
|
2010-04-14 21:08:06 +02:00
|
|
|
.Os
|
1996-10-08 20:45:06 +02:00
|
|
|
.Sh NAME
|
2011-12-14 15:52:50 +01:00
|
|
|
.Nm rtalloc1_fib ,
|
|
|
|
.Nm rtalloc_ign_fib ,
|
|
|
|
.Nm rtalloc_fib
|
1996-10-08 20:45:06 +02:00
|
|
|
.Nd look up a route in the kernel routing table
|
|
|
|
.Sh SYNOPSIS
|
2001-10-01 18:09:29 +02:00
|
|
|
.In sys/types.h
|
|
|
|
.In sys/socket.h
|
|
|
|
.In net/route.h
|
1996-10-08 20:45:06 +02:00
|
|
|
.Ft "struct rtentry *"
|
2011-12-14 15:52:50 +01:00
|
|
|
.Fn rtalloc1_fib "struct sockaddr *dst" "int report" "u_long flags" "u_int fibnum"
|
2004-10-07 12:14:23 +02:00
|
|
|
.Ft void
|
2011-12-14 15:52:50 +01:00
|
|
|
.Fn rtalloc_fib "struct route *ro" "u_int fibnum"
|
|
|
|
.Ft void
|
|
|
|
.Fn rtalloc_ign_fib "struct route *ro" "u_long flags" "u_int fibnum"
|
|
|
|
.Fn RTFREE_LOCKED "struct rt_entry *rt"
|
2004-10-07 12:14:23 +02:00
|
|
|
.Fn RTFREE "struct rt_entry *rt"
|
2004-10-11 22:48:36 +02:00
|
|
|
.Fn RT_LOCK "struct rt_entry *rt"
|
|
|
|
.Fn RT_UNLOCK "struct rt_entry *rt"
|
|
|
|
.Fn RT_ADDREF "struct rt_entry *rt"
|
|
|
|
.Fn RT_REMREF "struct rt_entry *rt"
|
2012-07-04 09:42:12 +02:00
|
|
|
.Fn RO_RTFREE "struct route *ro"
|
2011-12-14 15:52:50 +01:00
|
|
|
.Ft void
|
|
|
|
.Fn rtfree "struct rt_entry *rt"
|
|
|
|
.Ft "struct rtentry *"
|
|
|
|
.Fn rtalloc1 "struct sockaddr *dst" "int report" "u_long flags"
|
|
|
|
.Ft void
|
|
|
|
.Fn rtalloc "struct route *ro"
|
|
|
|
.Ft void
|
|
|
|
.Fn rtalloc_ign "struct route *ro" "u_long flags"
|
|
|
|
.Pp
|
|
|
|
.Cd options RADIX_MPATH
|
1996-10-08 20:45:06 +02:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The kernel uses a radix tree structure to manage routes for the
|
2003-10-23 04:15:46 +02:00
|
|
|
networking subsystem.
|
2011-12-14 15:52:50 +01:00
|
|
|
If compiled with
|
|
|
|
.Cd options RADIX_MPATH
|
|
|
|
kernel may maintain several independent forwarding information databases (FIBs).
|
2003-10-23 04:15:46 +02:00
|
|
|
The
|
1996-10-08 20:45:06 +02:00
|
|
|
.Fn rtalloc
|
2011-12-14 15:52:50 +01:00
|
|
|
family of routines is used by protocols to query these structures for a
|
1996-10-08 20:45:06 +02:00
|
|
|
route corresponding to a particular end-node address, and to cause
|
|
|
|
certain protocol\- and interface-specific actions to take place.
|
|
|
|
.Pp
|
2011-12-14 15:52:50 +01:00
|
|
|
The
|
|
|
|
.Fn rtalloc1_fib
|
|
|
|
function is the most general form of
|
|
|
|
.Fn rtalloc ,
|
|
|
|
and all of the other forms are implemented as calls to it.
|
|
|
|
It takes a
|
|
|
|
.Fa "struct sockaddr *"
|
|
|
|
directly as the
|
|
|
|
.Fa dst
|
|
|
|
argument.
|
|
|
|
The second argument,
|
|
|
|
.Fa report ,
|
|
|
|
controls whether the routing sockets are notified when a lookup fails.
|
|
|
|
The third argument,
|
|
|
|
.Fa flags ,
|
|
|
|
is a combination of
|
|
|
|
the following values:
|
|
|
|
.Bl -item -offset indent
|
|
|
|
.It
|
|
|
|
.Dv RTF_RNH_LOCKED
|
|
|
|
indicates that the radix tree lock is already held
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The last argument
|
|
|
|
.Fa fibnum
|
|
|
|
specifies number of forwarding information database (FIB) on which
|
|
|
|
the lookup should be performed.
|
|
|
|
In case of success the
|
|
|
|
.Fn rtalloc1_fib
|
|
|
|
function returns a pointer to a locked
|
|
|
|
.Vt "struct rtentry"
|
|
|
|
with an additional reference.
|
1996-10-08 20:45:06 +02:00
|
|
|
.Pp
|
2011-12-14 15:52:50 +01:00
|
|
|
The
|
|
|
|
.Fn rtalloc_fib
|
|
|
|
is the most simple variant.
|
|
|
|
Its main argument is
|
2003-05-31 16:07:25 +02:00
|
|
|
.Fa ro ,
|
1996-10-08 20:45:06 +02:00
|
|
|
a pointer to a
|
2011-12-14 15:52:50 +01:00
|
|
|
.Fa "struct route" ,
|
1996-10-08 20:45:06 +02:00
|
|
|
which is defined as follows:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
struct route {
|
|
|
|
struct rtentry *ro_rt;
|
2011-12-14 15:52:50 +01:00
|
|
|
struct llentry *ro_lle;
|
|
|
|
struct sockaddr ro_dst;
|
1996-10-08 20:45:06 +02:00
|
|
|
};
|
|
|
|
.Ed
|
2004-10-07 12:59:09 +02:00
|
|
|
.Pp
|
1996-10-08 20:45:06 +02:00
|
|
|
Thus, this function can only be used for address families which are
|
|
|
|
smaller than the default
|
2011-12-14 15:52:50 +01:00
|
|
|
.Ft "struct sockaddr" .
|
1996-10-08 20:45:06 +02:00
|
|
|
Before calling
|
2011-12-14 15:52:50 +01:00
|
|
|
.Fn rtalloc_fib
|
2001-07-14 21:41:16 +02:00
|
|
|
for the first time, callers should ensure that unused bits of the
|
2003-10-23 04:15:46 +02:00
|
|
|
structure are set to zero.
|
2011-12-14 15:52:50 +01:00
|
|
|
The second argument
|
|
|
|
.Fa fibnum
|
|
|
|
is FIB number.
|
|
|
|
In case of success of the
|
|
|
|
.Fn rtalloc_fib
|
|
|
|
the
|
|
|
|
.Fa ro_rt
|
|
|
|
points to a valid and unlocked
|
|
|
|
.Xr rtentry 9 ,
|
|
|
|
which has an additional reference put on it, freeing which is
|
|
|
|
responsibility of the caller.
|
2003-10-23 04:15:46 +02:00
|
|
|
On subsequent calls,
|
2011-12-14 15:52:50 +01:00
|
|
|
.Fn rtalloc_fib
|
1996-10-08 20:45:06 +02:00
|
|
|
returns without performing a lookup if
|
2003-06-02 17:02:06 +02:00
|
|
|
.Fa ro->ro_rt
|
1996-10-08 20:45:06 +02:00
|
|
|
is non-null and the
|
|
|
|
.Dv RTF_UP
|
2011-12-14 15:52:50 +01:00
|
|
|
flag is set in the rtentry's
|
|
|
|
.Fa rt_flags
|
1996-10-08 20:45:06 +02:00
|
|
|
field.
|
|
|
|
.Pp
|
|
|
|
The
|
2011-12-14 15:52:50 +01:00
|
|
|
.Fn rtalloc_ign_fib
|
|
|
|
function is the same as the
|
|
|
|
.Fn rtalloc_fib ,
|
|
|
|
but there is additional
|
2003-05-31 16:07:25 +02:00
|
|
|
.Fa flags
|
2011-12-14 15:52:50 +01:00
|
|
|
argument, which is same as in
|
|
|
|
.Fn rtalloc1_fib .
|
1996-10-08 20:45:06 +02:00
|
|
|
.Pp
|
|
|
|
The
|
2011-12-14 15:52:50 +01:00
|
|
|
.Fn RTFREE_LOCKED
|
|
|
|
macro is used to unref and possibly free a locked routing entry
|
|
|
|
with one our reference, for example previously allocated by
|
|
|
|
.Fn rtalloc1_fib .
|
2004-10-07 12:14:23 +02:00
|
|
|
.Pp
|
2004-10-07 12:59:09 +02:00
|
|
|
The
|
2004-10-07 12:14:23 +02:00
|
|
|
.Fn RTFREE
|
2011-12-14 15:52:50 +01:00
|
|
|
macro is used to unref and possibly free an unlocked route entries with
|
|
|
|
one our reference, for example previously allocated by
|
|
|
|
.Fn rtalloc_fib
|
2004-10-07 12:14:23 +02:00
|
|
|
or
|
2011-12-14 15:52:50 +01:00
|
|
|
.Fn rtalloc_ign_fib .
|
2004-10-11 22:48:36 +02:00
|
|
|
.Pp
|
2011-12-14 15:52:50 +01:00
|
|
|
Both
|
|
|
|
.Fn RTFREE_LOCKED
|
|
|
|
and
|
|
|
|
.Fn RTFREE
|
|
|
|
macros decrement the reference count on the routing table entry,
|
|
|
|
and proceed with actual freeing if the reference count has reached zero.
|
2004-10-11 22:48:36 +02:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn RT_LOCK
|
|
|
|
macro is used to lock a routing table entry.
|
2011-12-14 15:52:50 +01:00
|
|
|
.Pp
|
2004-10-11 22:48:36 +02:00
|
|
|
The
|
|
|
|
.Fn RT_UNLOCK
|
|
|
|
macro is used to unlock a routing table entry.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn RT_ADDREF
|
|
|
|
macro increments the reference count on a previously locked route entry.
|
2011-12-14 15:52:50 +01:00
|
|
|
It should be used whenever a reference to an
|
|
|
|
.Xr rtentry 9
|
|
|
|
is going to be stored outside the routing table.
|
|
|
|
.Pp
|
2004-10-11 22:48:36 +02:00
|
|
|
The
|
|
|
|
.Fn RT_REMREF
|
|
|
|
macro decrements the reference count on a previously locked route entry.
|
2011-12-14 15:52:50 +01:00
|
|
|
Its usage is contrary to
|
|
|
|
.Fn RT_ADDREF .
|
|
|
|
.Pp
|
2004-10-07 12:14:23 +02:00
|
|
|
The
|
2012-07-04 09:42:12 +02:00
|
|
|
.Fn RO_RTFREE
|
|
|
|
macro is used to free route entry that is referenced by struct route.
|
|
|
|
At certain circumstances the latter may not hold a reference on rtentry,
|
|
|
|
and
|
|
|
|
.Fn RO_RTFREE
|
|
|
|
treats such routes correctly.
|
|
|
|
.Pp
|
|
|
|
The
|
2004-10-07 12:14:23 +02:00
|
|
|
.Fn rtfree
|
2011-12-14 15:52:50 +01:00
|
|
|
function does the actual free of the routing table entry, and shouldn't
|
|
|
|
be called directly by facilities, that just perform routing table lookups.
|
|
|
|
.Sh LEGACY INTERFACE
|
|
|
|
Prior to introduction of multiple routing tables functions did not
|
|
|
|
require the
|
|
|
|
.Fa "u_int fibnum"
|
|
|
|
argument.
|
|
|
|
Legacy
|
|
|
|
.Fn rtalloc1 ,
|
|
|
|
.Fn rtalloc
|
|
|
|
and
|
|
|
|
.Fn rtalloc_ign
|
|
|
|
functions are kept for compatibility, and are equivalent to
|
|
|
|
calling new interface with
|
|
|
|
.Fa fibnum
|
|
|
|
argument equal to
|
|
|
|
.Va 0 ,
|
|
|
|
which implies default forwarding table.
|
|
|
|
.Sh RETURN VALUES
|
2003-10-23 04:15:46 +02:00
|
|
|
The
|
2011-12-14 15:52:50 +01:00
|
|
|
.Fn rtalloc1_fib
|
|
|
|
function returns a pointer to a locked routing-table entry if it succeeds,
|
2003-10-23 04:15:46 +02:00
|
|
|
otherwise a null pointer.
|
2011-12-14 15:52:50 +01:00
|
|
|
The
|
|
|
|
.Fn rtalloc_fib
|
|
|
|
and
|
|
|
|
.Fn rtalloc_ign_fib
|
|
|
|
functions do not return a value, but they fill in the
|
|
|
|
.Fa *ro_rt
|
|
|
|
member of the
|
|
|
|
.Fa *ro
|
|
|
|
argument with a pointer to an unlocked routing-table entry if they
|
|
|
|
succeed, otherwise a null pointer.
|
|
|
|
In a case of success all functions put a reference on the
|
|
|
|
routing-table entry, freeing of which is responsibility of the caller.
|
2003-10-23 04:15:46 +02:00
|
|
|
Lack of a route should in most cases be
|
1996-10-08 20:45:06 +02:00
|
|
|
translated to the
|
|
|
|
.Xr errno 2
|
|
|
|
value
|
|
|
|
.Er EHOSTUNREACH .
|
|
|
|
.Sh SEE ALSO
|
1996-10-08 22:25:39 +02:00
|
|
|
.Xr route 4 ,
|
|
|
|
.Xr rtentry 9
|
1996-10-08 20:45:06 +02:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
2011-12-14 15:52:50 +01:00
|
|
|
.Nm rtalloc
|
1996-10-08 20:45:06 +02:00
|
|
|
facility first appeared in
|
|
|
|
.Bx 4.2 ,
|
2003-10-23 04:15:46 +02:00
|
|
|
although with much different internals.
|
|
|
|
The
|
1996-10-08 20:45:06 +02:00
|
|
|
.Fn rtalloc_ign
|
|
|
|
function and the
|
2003-05-31 16:07:25 +02:00
|
|
|
.Fa flags
|
1996-10-08 20:45:06 +02:00
|
|
|
argument to
|
|
|
|
.Fn rtalloc1
|
|
|
|
first appeared in
|
|
|
|
.Fx 2.0 .
|
2004-10-11 22:48:36 +02:00
|
|
|
Routing table locking was introduced in
|
|
|
|
.Fx 5.2 .
|
2011-12-14 15:52:50 +01:00
|
|
|
Multiple routing tables were introduced in
|
|
|
|
.Fx 8.0 .
|
1998-03-12 08:31:21 +01:00
|
|
|
.Sh AUTHORS
|
2011-12-14 15:52:50 +01:00
|
|
|
The original version of this manual page was written by
|
|
|
|
.An -nosplit
|
|
|
|
.An "Garrett Wollman" .
|
|
|
|
It was significantly updated by
|
|
|
|
.An "Gleb Smirnoff" .
|