1ad31211dSGarrett Wollman.\" 2ad31211dSGarrett Wollman.\" Copyright 1996 Massachusetts Institute of Technology 3ad31211dSGarrett Wollman.\" 4ad31211dSGarrett Wollman.\" Permission to use, copy, modify, and distribute this software and 5ad31211dSGarrett Wollman.\" its documentation for any purpose and without fee is hereby 6ad31211dSGarrett Wollman.\" granted, provided that both the above copyright notice and this 7ad31211dSGarrett Wollman.\" permission notice appear in all copies, that both the above 8ad31211dSGarrett Wollman.\" copyright notice and this permission notice appear in all 9ad31211dSGarrett Wollman.\" supporting documentation, and that the name of M.I.T. not be used 10ad31211dSGarrett Wollman.\" in advertising or publicity pertaining to distribution of the 11ad31211dSGarrett Wollman.\" software without specific, written prior permission. M.I.T. makes 12ad31211dSGarrett Wollman.\" no representations about the suitability of this software for any 13ad31211dSGarrett Wollman.\" purpose. It is provided "as is" without express or implied 14ad31211dSGarrett Wollman.\" warranty. 15ad31211dSGarrett Wollman.\" 16ad31211dSGarrett Wollman.\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 17ad31211dSGarrett Wollman.\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 18ad31211dSGarrett Wollman.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19ad31211dSGarrett Wollman.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 20ad31211dSGarrett Wollman.\" SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21ad31211dSGarrett Wollman.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22ad31211dSGarrett Wollman.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 23ad31211dSGarrett Wollman.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24ad31211dSGarrett Wollman.\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25ad31211dSGarrett Wollman.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26ad31211dSGarrett Wollman.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27ad31211dSGarrett Wollman.\" SUCH DAMAGE. 28ad31211dSGarrett Wollman.\" 297f3dea24SPeter Wemm.\" $FreeBSD$ 306e6b3f7cSQing Li.\" 31*d8115a86SGleb Smirnoff.Dd July 4, 2012 32ad31211dSGarrett Wollman.Dt RTALLOC 9 33aa12cea2SUlrich Spörlein.Os 34ad31211dSGarrett Wollman.Sh NAME 359aa3cab9SGleb Smirnoff.Nm rtalloc1_fib , 369aa3cab9SGleb Smirnoff.Nm rtalloc_ign_fib , 379aa3cab9SGleb Smirnoff.Nm rtalloc_fib 38ad31211dSGarrett Wollman.Nd look up a route in the kernel routing table 39ad31211dSGarrett Wollman.Sh SYNOPSIS 4032eef9aeSRuslan Ermilov.In sys/types.h 4132eef9aeSRuslan Ermilov.In sys/socket.h 4232eef9aeSRuslan Ermilov.In net/route.h 43ad31211dSGarrett Wollman.Ft "struct rtentry *" 449aa3cab9SGleb Smirnoff.Fn rtalloc1_fib "struct sockaddr *dst" "int report" "u_long flags" "u_int fibnum" 45729df1bbSGleb Smirnoff.Ft void 469aa3cab9SGleb Smirnoff.Fn rtalloc_fib "struct route *ro" "u_int fibnum" 479aa3cab9SGleb Smirnoff.Ft void 489aa3cab9SGleb Smirnoff.Fn rtalloc_ign_fib "struct route *ro" "u_long flags" "u_int fibnum" 499aa3cab9SGleb Smirnoff.Fn RTFREE_LOCKED "struct rt_entry *rt" 50729df1bbSGleb Smirnoff.Fn RTFREE "struct rt_entry *rt" 51bb978628SGleb Smirnoff.Fn RT_LOCK "struct rt_entry *rt" 52bb978628SGleb Smirnoff.Fn RT_UNLOCK "struct rt_entry *rt" 53bb978628SGleb Smirnoff.Fn RT_ADDREF "struct rt_entry *rt" 54bb978628SGleb Smirnoff.Fn RT_REMREF "struct rt_entry *rt" 55*d8115a86SGleb Smirnoff.Fn RO_RTFREE "struct route *ro" 569aa3cab9SGleb Smirnoff.Ft void 579aa3cab9SGleb Smirnoff.Fn rtfree "struct rt_entry *rt" 589aa3cab9SGleb Smirnoff.Ft "struct rtentry *" 599aa3cab9SGleb Smirnoff.Fn rtalloc1 "struct sockaddr *dst" "int report" "u_long flags" 609aa3cab9SGleb Smirnoff.Ft void 619aa3cab9SGleb Smirnoff.Fn rtalloc "struct route *ro" 629aa3cab9SGleb Smirnoff.Ft void 639aa3cab9SGleb Smirnoff.Fn rtalloc_ign "struct route *ro" "u_long flags" 649aa3cab9SGleb Smirnoff.Pp 659aa3cab9SGleb Smirnoff.Cd options RADIX_MPATH 66ad31211dSGarrett Wollman.Sh DESCRIPTION 67ad31211dSGarrett WollmanThe kernel uses a radix tree structure to manage routes for the 684c7b4d14SHiten Pandyanetworking subsystem. 699aa3cab9SGleb SmirnoffIf compiled with 709aa3cab9SGleb Smirnoff.Cd options RADIX_MPATH 719aa3cab9SGleb Smirnoffkernel may maintain several independent forwarding information databases (FIBs). 724c7b4d14SHiten PandyaThe 73ad31211dSGarrett Wollman.Fn rtalloc 749aa3cab9SGleb Smirnofffamily of routines is used by protocols to query these structures for a 75ad31211dSGarrett Wollmanroute corresponding to a particular end-node address, and to cause 76ad31211dSGarrett Wollmancertain protocol\- and interface-specific actions to take place. 77ad31211dSGarrett Wollman.Pp 789aa3cab9SGleb SmirnoffThe 799aa3cab9SGleb Smirnoff.Fn rtalloc1_fib 809aa3cab9SGleb Smirnofffunction is the most general form of 819aa3cab9SGleb Smirnoff.Fn rtalloc , 829aa3cab9SGleb Smirnoffand all of the other forms are implemented as calls to it. 839aa3cab9SGleb SmirnoffIt takes a 849aa3cab9SGleb Smirnoff.Fa "struct sockaddr *" 859aa3cab9SGleb Smirnoffdirectly as the 869aa3cab9SGleb Smirnoff.Fa dst 879aa3cab9SGleb Smirnoffargument. 889aa3cab9SGleb SmirnoffThe second argument, 899aa3cab9SGleb Smirnoff.Fa report , 909aa3cab9SGleb Smirnoffcontrols whether the routing sockets are notified when a lookup fails. 919aa3cab9SGleb SmirnoffThe third argument, 929aa3cab9SGleb Smirnoff.Fa flags , 939aa3cab9SGleb Smirnoffis a combination of 949aa3cab9SGleb Smirnoffthe following values: 959aa3cab9SGleb Smirnoff.Bl -item -offset indent 969aa3cab9SGleb Smirnoff.It 979aa3cab9SGleb Smirnoff.Dv RTF_RNH_LOCKED 989aa3cab9SGleb Smirnoffindicates that the radix tree lock is already held 999aa3cab9SGleb Smirnoff.El 100ad31211dSGarrett Wollman.Pp 1019aa3cab9SGleb SmirnoffThe last argument 1029aa3cab9SGleb Smirnoff.Fa fibnum 1039aa3cab9SGleb Smirnoffspecifies number of forwarding information database (FIB) on which 1049aa3cab9SGleb Smirnoffthe lookup should be performed. 1059aa3cab9SGleb SmirnoffIn case of success the 1069aa3cab9SGleb Smirnoff.Fn rtalloc1_fib 1079aa3cab9SGleb Smirnofffunction returns a pointer to a locked 1089aa3cab9SGleb Smirnoff.Vt "struct rtentry" 1099aa3cab9SGleb Smirnoffwith an additional reference. 1109aa3cab9SGleb Smirnoff.Pp 1119aa3cab9SGleb SmirnoffThe 1129aa3cab9SGleb Smirnoff.Fn rtalloc_fib 1139aa3cab9SGleb Smirnoffis the most simple variant. 1149aa3cab9SGleb SmirnoffIts main argument is 1150640e9e0SHiten Pandya.Fa ro , 116ad31211dSGarrett Wollmana pointer to a 1179aa3cab9SGleb Smirnoff.Fa "struct route" , 118ad31211dSGarrett Wollmanwhich is defined as follows: 119ad31211dSGarrett Wollman.Bd -literal -offset indent 120ad31211dSGarrett Wollmanstruct route { 121ad31211dSGarrett Wollman struct rtentry *ro_rt; 1229aa3cab9SGleb Smirnoff struct llentry *ro_lle; 1239aa3cab9SGleb Smirnoff struct sockaddr ro_dst; 124ad31211dSGarrett Wollman}; 125ad31211dSGarrett Wollman.Ed 126650c2669SGleb Smirnoff.Pp 127ad31211dSGarrett WollmanThus, this function can only be used for address families which are 128ad31211dSGarrett Wollmansmaller than the default 1299aa3cab9SGleb Smirnoff.Ft "struct sockaddr" . 130ad31211dSGarrett WollmanBefore calling 1319aa3cab9SGleb Smirnoff.Fn rtalloc_fib 132ad31211dSGarrett Wollmanfor the first time, callers should ensure that unused bits of the 1334c7b4d14SHiten Pandyastructure are set to zero. 1349aa3cab9SGleb SmirnoffThe second argument 1359aa3cab9SGleb Smirnoff.Fa fibnum 1369aa3cab9SGleb Smirnoffis FIB number. 1379aa3cab9SGleb SmirnoffIn case of success of the 1389aa3cab9SGleb Smirnoff.Fn rtalloc_fib 1399aa3cab9SGleb Smirnoffthe 1409aa3cab9SGleb Smirnoff.Fa ro_rt 1419aa3cab9SGleb Smirnoffpoints to a valid and unlocked 1429aa3cab9SGleb Smirnoff.Xr rtentry 9 , 1439aa3cab9SGleb Smirnoffwhich has an additional reference put on it, freeing which is 1449aa3cab9SGleb Smirnoffresponsibility of the caller. 1454c7b4d14SHiten PandyaOn subsequent calls, 1469aa3cab9SGleb Smirnoff.Fn rtalloc_fib 147ad31211dSGarrett Wollmanreturns without performing a lookup if 14809f84dd1SRuslan Ermilov.Fa ro->ro_rt 149ad31211dSGarrett Wollmanis non-null and the 150ad31211dSGarrett Wollman.Dv RTF_UP 1519aa3cab9SGleb Smirnoffflag is set in the rtentry's 1529aa3cab9SGleb Smirnoff.Fa rt_flags 153ad31211dSGarrett Wollmanfield. 154ad31211dSGarrett Wollman.Pp 155ad31211dSGarrett WollmanThe 1569aa3cab9SGleb Smirnoff.Fn rtalloc_ign_fib 1579aa3cab9SGleb Smirnofffunction is the same as the 1589aa3cab9SGleb Smirnoff.Fn rtalloc_fib , 1599aa3cab9SGleb Smirnoffbut there is additional 1600640e9e0SHiten Pandya.Fa flags 1619aa3cab9SGleb Smirnoffargument, which is same as in 1629aa3cab9SGleb Smirnoff.Fn rtalloc1_fib . 1639aa3cab9SGleb Smirnoff.Pp 1649aa3cab9SGleb SmirnoffThe 1659aa3cab9SGleb Smirnoff.Fn RTFREE_LOCKED 1669aa3cab9SGleb Smirnoffmacro is used to unref and possibly free a locked routing entry 1679aa3cab9SGleb Smirnoffwith one our reference, for example previously allocated by 1689aa3cab9SGleb Smirnoff.Fn rtalloc1_fib . 1699aa3cab9SGleb Smirnoff.Pp 1709aa3cab9SGleb SmirnoffThe 1719aa3cab9SGleb Smirnoff.Fn RTFREE 1729aa3cab9SGleb Smirnoffmacro is used to unref and possibly free an unlocked route entries with 1739aa3cab9SGleb Smirnoffone our reference, for example previously allocated by 1749aa3cab9SGleb Smirnoff.Fn rtalloc_fib 1759aa3cab9SGleb Smirnoffor 1769aa3cab9SGleb Smirnoff.Fn rtalloc_ign_fib . 1779aa3cab9SGleb Smirnoff.Pp 178729df1bbSGleb SmirnoffBoth 1799aa3cab9SGleb Smirnoff.Fn RTFREE_LOCKED 180729df1bbSGleb Smirnoffand 181729df1bbSGleb Smirnoff.Fn RTFREE 1829aa3cab9SGleb Smirnoffmacros decrement the reference count on the routing table entry, 1839aa3cab9SGleb Smirnoffand proceed with actual freeing if the reference count has reached zero. 184bb978628SGleb Smirnoff.Pp 185bb978628SGleb SmirnoffThe 186bb978628SGleb Smirnoff.Fn RT_LOCK 187bb978628SGleb Smirnoffmacro is used to lock a routing table entry. 1889aa3cab9SGleb Smirnoff.Pp 189bb978628SGleb SmirnoffThe 190bb978628SGleb Smirnoff.Fn RT_UNLOCK 191bb978628SGleb Smirnoffmacro is used to unlock a routing table entry. 192bb978628SGleb Smirnoff.Pp 193bb978628SGleb SmirnoffThe 194bb978628SGleb Smirnoff.Fn RT_ADDREF 195bb978628SGleb Smirnoffmacro increments the reference count on a previously locked route entry. 1969aa3cab9SGleb SmirnoffIt should be used whenever a reference to an 1979aa3cab9SGleb Smirnoff.Xr rtentry 9 1989aa3cab9SGleb Smirnoffis going to be stored outside the routing table. 1999aa3cab9SGleb Smirnoff.Pp 200bb978628SGleb SmirnoffThe 201bb978628SGleb Smirnoff.Fn RT_REMREF 202bb978628SGleb Smirnoffmacro decrements the reference count on a previously locked route entry. 2039aa3cab9SGleb SmirnoffIts usage is contrary to 2049aa3cab9SGleb Smirnoff.Fn RT_ADDREF . 2059aa3cab9SGleb Smirnoff.Pp 2069aa3cab9SGleb SmirnoffThe 207*d8115a86SGleb Smirnoff.Fn RO_RTFREE 208*d8115a86SGleb Smirnoffmacro is used to free route entry that is referenced by struct route. 209*d8115a86SGleb SmirnoffAt certain circumstances the latter may not hold a reference on rtentry, 210*d8115a86SGleb Smirnoffand 211*d8115a86SGleb Smirnoff.Fn RO_RTFREE 212*d8115a86SGleb Smirnofftreats such routes correctly. 213*d8115a86SGleb Smirnoff.Pp 214*d8115a86SGleb SmirnoffThe 2159aa3cab9SGleb Smirnoff.Fn rtfree 2169aa3cab9SGleb Smirnofffunction does the actual free of the routing table entry, and shouldn't 2179aa3cab9SGleb Smirnoffbe called directly by facilities, that just perform routing table lookups. 2189aa3cab9SGleb Smirnoff.Sh LEGACY INTERFACE 2199aa3cab9SGleb SmirnoffPrior to introduction of multiple routing tables functions did not 2209aa3cab9SGleb Smirnoffrequire the 2219aa3cab9SGleb Smirnoff.Fa "u_int fibnum" 2229aa3cab9SGleb Smirnoffargument. 2239aa3cab9SGleb SmirnoffLegacy 2249aa3cab9SGleb Smirnoff.Fn rtalloc1 , 2259aa3cab9SGleb Smirnoff.Fn rtalloc 2269aa3cab9SGleb Smirnoffand 2279aa3cab9SGleb Smirnoff.Fn rtalloc_ign 2289aa3cab9SGleb Smirnofffunctions are kept for compatibility, and are equivalent to 2299aa3cab9SGleb Smirnoffcalling new interface with 2309aa3cab9SGleb Smirnoff.Fa fibnum 2319aa3cab9SGleb Smirnoffargument equal to 2329aa3cab9SGleb Smirnoff.Va 0 , 2339aa3cab9SGleb Smirnoffwhich implies default forwarding table. 234ad31211dSGarrett Wollman.Sh RETURN VALUES 235ad31211dSGarrett WollmanThe 2369aa3cab9SGleb Smirnoff.Fn rtalloc1_fib 2379aa3cab9SGleb Smirnofffunction returns a pointer to a locked routing-table entry if it succeeds, 2384c7b4d14SHiten Pandyaotherwise a null pointer. 2399aa3cab9SGleb SmirnoffThe 2409aa3cab9SGleb Smirnoff.Fn rtalloc_fib 2419aa3cab9SGleb Smirnoffand 2429aa3cab9SGleb Smirnoff.Fn rtalloc_ign_fib 2439aa3cab9SGleb Smirnofffunctions do not return a value, but they fill in the 2449aa3cab9SGleb Smirnoff.Fa *ro_rt 2459aa3cab9SGleb Smirnoffmember of the 2469aa3cab9SGleb Smirnoff.Fa *ro 2479aa3cab9SGleb Smirnoffargument with a pointer to an unlocked routing-table entry if they 2489aa3cab9SGleb Smirnoffsucceed, otherwise a null pointer. 2499aa3cab9SGleb SmirnoffIn a case of success all functions put a reference on the 2509aa3cab9SGleb Smirnoffrouting-table entry, freeing of which is responsibility of the caller. 2514c7b4d14SHiten PandyaLack of a route should in most cases be 252ad31211dSGarrett Wollmantranslated to the 253ad31211dSGarrett Wollman.Xr errno 2 254ad31211dSGarrett Wollmanvalue 255ad31211dSGarrett Wollman.Er EHOSTUNREACH . 256ad31211dSGarrett Wollman.Sh SEE ALSO 25750853e53SGarrett Wollman.Xr route 4 , 25850853e53SGarrett Wollman.Xr rtentry 9 259ad31211dSGarrett Wollman.Sh HISTORY 260ad31211dSGarrett WollmanThe 2619aa3cab9SGleb Smirnoff.Nm rtalloc 262ad31211dSGarrett Wollmanfacility first appeared in 263ad31211dSGarrett Wollman.Bx 4.2 , 2644c7b4d14SHiten Pandyaalthough with much different internals. 2654c7b4d14SHiten PandyaThe 266ad31211dSGarrett Wollman.Fn rtalloc_ign 267ad31211dSGarrett Wollmanfunction and the 2680640e9e0SHiten Pandya.Fa flags 269ad31211dSGarrett Wollmanargument to 270ad31211dSGarrett Wollman.Fn rtalloc1 271ad31211dSGarrett Wollmanfirst appeared in 272ad31211dSGarrett Wollman.Fx 2.0 . 273bb978628SGleb SmirnoffRouting table locking was introduced in 274bb978628SGleb Smirnoff.Fx 5.2 . 2759aa3cab9SGleb SmirnoffMultiple routing tables were introduced in 2769aa3cab9SGleb Smirnoff.Fx 8.0 . 277aaf1f16eSPhilippe Charnier.Sh AUTHORS 2789aa3cab9SGleb SmirnoffThe original version of this manual page was written by 2799aa3cab9SGleb Smirnoff.An -nosplit 2809aa3cab9SGleb Smirnoff.An "Garrett Wollman" . 2819aa3cab9SGleb SmirnoffIt was significantly updated by 2829aa3cab9SGleb Smirnoff.An "Gleb Smirnoff" . 283