]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
6d2010ae | 2 | * Copyright (c) 2000-2011 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * Copyright (c) 1980, 1986, 1993 | |
30 | * The Regents of the University of California. All rights reserved. | |
31 | * | |
32 | * Redistribution and use in source and binary forms, with or without | |
33 | * modification, are permitted provided that the following conditions | |
34 | * are met: | |
35 | * 1. Redistributions of source code must retain the above copyright | |
36 | * notice, this list of conditions and the following disclaimer. | |
37 | * 2. Redistributions in binary form must reproduce the above copyright | |
38 | * notice, this list of conditions and the following disclaimer in the | |
39 | * documentation and/or other materials provided with the distribution. | |
40 | * 3. All advertising materials mentioning features or use of this software | |
41 | * must display the following acknowledgement: | |
42 | * This product includes software developed by the University of | |
43 | * California, Berkeley and its contributors. | |
44 | * 4. Neither the name of the University nor the names of its contributors | |
45 | * may be used to endorse or promote products derived from this software | |
46 | * without specific prior written permission. | |
47 | * | |
48 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
49 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
58 | * SUCH DAMAGE. | |
59 | * | |
60 | * @(#)route.h 8.3 (Berkeley) 4/19/94 | |
9bccf70c | 61 | * $FreeBSD: src/sys/net/route.h,v 1.36.2.1 2000/08/16 06:14:23 jayanth Exp $ |
1c79356b A |
62 | */ |
63 | ||
64 | #ifndef _NET_ROUTE_H_ | |
65 | #define _NET_ROUTE_H_ | |
9bccf70c | 66 | #include <sys/appleapiopts.h> |
b0d623f7 | 67 | #include <stdint.h> |
91447636 A |
68 | #include <sys/types.h> |
69 | #include <sys/socket.h> | |
1c79356b A |
70 | |
71 | /* | |
72 | * Kernel resident routing tables. | |
73 | * | |
74 | * The routing tables are initialized when interface addresses | |
75 | * are set by making entries for all directly connected interfaces. | |
76 | */ | |
77 | ||
78 | /* | |
79 | * A route consists of a destination address and a reference | |
80 | * to a routing entry. These are often held by protocols | |
81 | * in their control blocks, e.g. inpcb. | |
82 | */ | |
91447636 A |
83 | #ifdef PRIVATE |
84 | struct rtentry; | |
1c79356b | 85 | struct route { |
b0d623f7 A |
86 | /* |
87 | * N.B: struct route must begin with ro_rt and ro_flags | |
88 | * because the code does some casts of a 'struct route_in6 *' | |
89 | * to a 'struct route *'. | |
90 | */ | |
91 | struct rtentry *ro_rt; | |
92 | uint32_t ro_flags; /* route flags (see below) */ | |
93 | struct sockaddr ro_dst; | |
1c79356b | 94 | }; |
c910b4d9 A |
95 | |
96 | #define ROF_SRCIF_SELECTED 0x1 /* source interface was selected */ | |
97 | ||
6d2010ae A |
98 | /* |
99 | * Route reachability info (private) | |
100 | */ | |
101 | struct rt_reach_info { | |
102 | u_int32_t ri_refcnt; /* reference count */ | |
103 | u_int32_t ri_probes; /* total # of probes */ | |
104 | u_int64_t ri_snd_expire; /* transmit expiration (calendar) time */ | |
105 | u_int64_t ri_rcv_expire; /* receive expiration (calendar) time */ | |
106 | }; | |
9bccf70c A |
107 | #else |
108 | struct route; | |
91447636 | 109 | #endif /* PRIVATE */ |
1c79356b A |
110 | |
111 | /* | |
112 | * These numbers are used by reliable protocols for determining | |
113 | * retransmission behavior and are included in the routing structure. | |
114 | */ | |
115 | struct rt_metrics { | |
2d21ac55 A |
116 | u_int32_t rmx_locks; /* Kernel must leave these values alone */ |
117 | u_int32_t rmx_mtu; /* MTU for this path */ | |
118 | u_int32_t rmx_hopcount; /* max hops expected */ | |
119 | int32_t rmx_expire; /* lifetime for route, e.g. redirect */ | |
120 | u_int32_t rmx_recvpipe; /* inbound delay-bandwidth product */ | |
121 | u_int32_t rmx_sendpipe; /* outbound delay-bandwidth product */ | |
122 | u_int32_t rmx_ssthresh; /* outbound gateway buffer limit */ | |
123 | u_int32_t rmx_rtt; /* estimated round trip time */ | |
124 | u_int32_t rmx_rttvar; /* estimated rtt variance */ | |
125 | u_int32_t rmx_pksent; /* packets sent using this route */ | |
126 | u_int32_t rmx_filler[4]; /* will be used for T/TCP later */ | |
1c79356b A |
127 | }; |
128 | ||
129 | /* | |
130 | * rmx_rtt and rmx_rttvar are stored as microseconds; | |
1c79356b A |
131 | */ |
132 | #define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */ | |
1c79356b | 133 | |
d1ecb069 A |
134 | #ifdef KERNEL_PRIVATE |
135 | /* | |
136 | * New expiry value (in seconds) when dealing with interfaces which implement | |
137 | * the if_want_aggressive_drain behavior. Otherwise the event mechanism wouldn't | |
138 | * fire quick enough to cause any sort of significant gains in performance. | |
139 | */ | |
140 | #define RT_IF_IDLE_EXPIRE_TIMEOUT 30 | |
141 | #define RT_IF_IDLE_DRAIN_INTERVAL 10 | |
142 | #endif /* KERNEL_PRIVATE */ | |
143 | ||
1c79356b A |
144 | /* |
145 | * We distinguish between routes to hosts and routes to networks, | |
146 | * preferring the former if available. For each route we infer | |
147 | * the interface to use from the gateway address supplied when | |
148 | * the route was entered. Routes that forward packets through | |
149 | * gateways are marked so that the output routines know to address the | |
150 | * gateway rather than the ultimate destination. | |
151 | */ | |
b0d623f7 A |
152 | #ifdef KERNEL_PRIVATE |
153 | #include <kern/locks.h> | |
1c79356b A |
154 | #ifndef RNF_NORMAL |
155 | #include <net/radix.h> | |
156 | #endif | |
b0d623f7 A |
157 | /* |
158 | * Kernel routing entry structure (private). | |
159 | */ | |
1c79356b A |
160 | struct rtentry { |
161 | struct radix_node rt_nodes[2]; /* tree glue, and other values */ | |
162 | #define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key)) | |
163 | #define rt_mask(r) ((struct sockaddr *)((r)->rt_nodes->rn_mask)) | |
164 | struct sockaddr *rt_gateway; /* value */ | |
9bccf70c | 165 | int32_t rt_refcnt; /* # held references */ |
b0d623f7 | 166 | uint32_t rt_flags; /* up/down?, host/net */ |
1c79356b | 167 | struct ifnet *rt_ifp; /* the answer: interface to use */ |
b0d623f7 | 168 | struct ifaddr *rt_ifa; /* the answer: interface addr to use */ |
1c79356b | 169 | struct sockaddr *rt_genmask; /* for generation of cloned routes */ |
b0d623f7 | 170 | void *rt_llinfo; /* pointer to link level info cache */ |
6d2010ae A |
171 | void (*rt_llinfo_get_ri) /* llinfo get reachability info fn */ |
172 | (struct rtentry *, struct rt_reach_info *); | |
173 | void (*rt_llinfo_purge)(struct rtentry *); /* llinfo purge fn */ | |
b0d623f7 | 174 | void (*rt_llinfo_free)(void *); /* link level info free function */ |
1c79356b A |
175 | struct rt_metrics rt_rmx; /* metrics used by rx'ing protocols */ |
176 | struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */ | |
2d21ac55 | 177 | struct rtentry *rt_parent; /* cloning parent of this route */ |
b0d623f7 A |
178 | uint32_t generation_id; /* route generation id */ |
179 | /* | |
180 | * See bsd/net/route.c for synchronization notes. | |
181 | */ | |
182 | decl_lck_mtx_data(, rt_lock); /* lock for routing entry */ | |
6d2010ae | 183 | struct nstat_counts *rt_stats; |
d1ecb069 | 184 | void (*rt_if_ref_fn)(struct ifnet *, int); /* interface ref func */ |
6d2010ae A |
185 | |
186 | uint64_t rt_expire; /* expiration time in uptime seconds */ | |
187 | uint64_t base_calendartime; /* calendar time upon entry creation */ | |
188 | uint64_t base_uptime;/* uptime upon entry creation */ | |
1c79356b | 189 | }; |
6d2010ae A |
190 | |
191 | extern void rt_setexpire(struct rtentry *, uint64_t); | |
b0d623f7 | 192 | #endif /* KERNEL_PRIVATE */ |
1c79356b | 193 | |
b0d623f7 | 194 | #ifdef KERNEL_PRIVATE |
1c79356b | 195 | #define rt_use rt_rmx.rmx_pksent |
b0d623f7 | 196 | #endif /* KERNEL_PRIVATE */ |
1c79356b A |
197 | |
198 | #define RTF_UP 0x1 /* route usable */ | |
199 | #define RTF_GATEWAY 0x2 /* destination is a gateway */ | |
200 | #define RTF_HOST 0x4 /* host entry (net otherwise) */ | |
201 | #define RTF_REJECT 0x8 /* host or net unreachable */ | |
202 | #define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */ | |
203 | #define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */ | |
204 | #define RTF_DONE 0x40 /* message confirmed */ | |
9bccf70c | 205 | #define RTF_DELCLONE 0x80 /* delete cloned route */ |
1c79356b A |
206 | #define RTF_CLONING 0x100 /* generate new routes on use */ |
207 | #define RTF_XRESOLVE 0x200 /* external daemon resolves name */ | |
208 | #define RTF_LLINFO 0x400 /* generated by link layer (e.g. ARP) */ | |
209 | #define RTF_STATIC 0x800 /* manually added */ | |
210 | #define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */ | |
211 | #define RTF_PROTO2 0x4000 /* protocol specific routing flag */ | |
212 | #define RTF_PROTO1 0x8000 /* protocol specific routing flag */ | |
213 | ||
214 | #define RTF_PRCLONING 0x10000 /* protocol requires cloning */ | |
215 | #define RTF_WASCLONED 0x20000 /* route generated through cloning */ | |
216 | #define RTF_PROTO3 0x40000 /* protocol specific routing flag */ | |
91447636 | 217 | /* 0x80000 unused */ |
1c79356b | 218 | #define RTF_PINNED 0x100000 /* future use */ |
2d21ac55 | 219 | #define RTF_LOCAL 0x200000 /* route represents a local address */ |
1c79356b A |
220 | #define RTF_BROADCAST 0x400000 /* route represents a bcast address */ |
221 | #define RTF_MULTICAST 0x800000 /* route represents a mcast address */ | |
c910b4d9 | 222 | #define RTF_IFSCOPE 0x1000000 /* has valid interface scope */ |
b0d623f7 | 223 | #define RTF_CONDEMNED 0x2000000 /* defunct; no longer modifiable */ |
d1ecb069 A |
224 | #define RTF_IFREF 0x4000000 /* route holds a ref to interface */ |
225 | /* 0x8000000 and up unassigned */ | |
1c79356b A |
226 | |
227 | /* | |
228 | * Routing statistics. | |
229 | */ | |
230 | struct rtstat { | |
231 | short rts_badredirect; /* bogus redirect calls */ | |
232 | short rts_dynamic; /* routes created by redirects */ | |
233 | short rts_newgateway; /* routes modified by redirects */ | |
234 | short rts_unreach; /* lookups which failed */ | |
235 | short rts_wildcard; /* lookups satisfied by a wildcard */ | |
236 | }; | |
91447636 | 237 | |
1c79356b A |
238 | /* |
239 | * Structures for routing messages. | |
240 | */ | |
241 | struct rt_msghdr { | |
2d21ac55 A |
242 | u_short rtm_msglen; /* to skip over non-understood messages */ |
243 | u_char rtm_version; /* future binary compatibility */ | |
244 | u_char rtm_type; /* message type */ | |
245 | u_short rtm_index; /* index for associated ifp */ | |
246 | int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ | |
247 | int rtm_addrs; /* bitmask identifying sockaddrs in msg */ | |
248 | pid_t rtm_pid; /* identify sender */ | |
249 | int rtm_seq; /* for sender to identify action */ | |
250 | int rtm_errno; /* why failed */ | |
251 | int rtm_use; /* from rtentry */ | |
252 | u_int32_t rtm_inits; /* which metrics we are initializing */ | |
253 | struct rt_metrics rtm_rmx; /* metrics themselves */ | |
1c79356b A |
254 | }; |
255 | ||
91447636 | 256 | struct rt_msghdr2 { |
2d21ac55 A |
257 | u_short rtm_msglen; /* to skip over non-understood messages */ |
258 | u_char rtm_version; /* future binary compatibility */ | |
259 | u_char rtm_type; /* message type */ | |
260 | u_short rtm_index; /* index for associated ifp */ | |
261 | int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ | |
262 | int rtm_addrs; /* bitmask identifying sockaddrs in msg */ | |
263 | int32_t rtm_refcnt; /* reference count */ | |
264 | int rtm_parentflags; /* flags of the parent route */ | |
265 | int rtm_reserved; /* reserved field set to 0 */ | |
266 | int rtm_use; /* from rtentry */ | |
267 | u_int32_t rtm_inits; /* which metrics we are initializing */ | |
268 | struct rt_metrics rtm_rmx; /* metrics themselves */ | |
91447636 A |
269 | }; |
270 | ||
6d2010ae A |
271 | #ifdef PRIVATE |
272 | /* | |
273 | * Extended routing message header (private). | |
274 | */ | |
275 | struct rt_msghdr_ext { | |
276 | u_short rtm_msglen; /* to skip over non-understood messages */ | |
277 | u_char rtm_version; /* future binary compatibility */ | |
278 | u_char rtm_type; /* message type */ | |
279 | u_int32_t rtm_index; /* index for associated ifp */ | |
280 | u_int32_t rtm_flags; /* flags, incl. kern & message, e.g. DONE */ | |
281 | u_int32_t rtm_reserved; /* for future use */ | |
282 | u_int32_t rtm_addrs; /* bitmask identifying sockaddrs in msg */ | |
283 | pid_t rtm_pid; /* identify sender */ | |
284 | int rtm_seq; /* for sender to identify action */ | |
285 | int rtm_errno; /* why failed */ | |
286 | u_int32_t rtm_use; /* from rtentry */ | |
287 | u_int32_t rtm_inits; /* which metrics we are initializing */ | |
288 | struct rt_metrics rtm_rmx; /* metrics themselves */ | |
289 | struct rt_reach_info rtm_ri; /* route reachability info */ | |
290 | }; | |
291 | #endif /* PRIVATE */ | |
91447636 | 292 | |
1c79356b A |
293 | #define RTM_VERSION 5 /* Up the ante and ignore older versions */ |
294 | ||
295 | /* | |
296 | * Message types. | |
297 | */ | |
298 | #define RTM_ADD 0x1 /* Add Route */ | |
299 | #define RTM_DELETE 0x2 /* Delete Route */ | |
300 | #define RTM_CHANGE 0x3 /* Change Metrics or flags */ | |
301 | #define RTM_GET 0x4 /* Report Metrics */ | |
302 | #define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */ | |
303 | #define RTM_REDIRECT 0x6 /* Told to use different route */ | |
304 | #define RTM_MISS 0x7 /* Lookup failed on this address */ | |
305 | #define RTM_LOCK 0x8 /* fix specified metrics */ | |
306 | #define RTM_OLDADD 0x9 /* caused by SIOCADDRT */ | |
307 | #define RTM_OLDDEL 0xa /* caused by SIOCDELRT */ | |
308 | #define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */ | |
309 | #define RTM_NEWADDR 0xc /* address being added to iface */ | |
310 | #define RTM_DELADDR 0xd /* address being removed from iface */ | |
311 | #define RTM_IFINFO 0xe /* iface going up/down etc. */ | |
312 | #define RTM_NEWMADDR 0xf /* mcast group membership being added to if */ | |
313 | #define RTM_DELMADDR 0x10 /* mcast group membership being deleted */ | |
91447636 | 314 | #ifdef PRIVATE |
55e303ae | 315 | #define RTM_GET_SILENT 0x11 |
b0d623f7 | 316 | #endif /* PRIVATE */ |
91447636 A |
317 | #define RTM_IFINFO2 0x12 /* */ |
318 | #define RTM_NEWMADDR2 0x13 /* */ | |
319 | #define RTM_GET2 0x14 /* */ | |
6d2010ae A |
320 | #ifdef PRIVATE |
321 | #define RTM_GET_EXT 0x15 | |
322 | #endif /* PRIVATE */ | |
1c79356b A |
323 | |
324 | /* | |
325 | * Bitmask values for rtm_inits and rmx_locks. | |
326 | */ | |
327 | #define RTV_MTU 0x1 /* init or lock _mtu */ | |
328 | #define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */ | |
329 | #define RTV_EXPIRE 0x4 /* init or lock _expire */ | |
330 | #define RTV_RPIPE 0x8 /* init or lock _recvpipe */ | |
331 | #define RTV_SPIPE 0x10 /* init or lock _sendpipe */ | |
332 | #define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */ | |
333 | #define RTV_RTT 0x40 /* init or lock _rtt */ | |
334 | #define RTV_RTTVAR 0x80 /* init or lock _rttvar */ | |
335 | ||
336 | /* | |
337 | * Bitmask values for rtm_addrs. | |
338 | */ | |
339 | #define RTA_DST 0x1 /* destination sockaddr present */ | |
340 | #define RTA_GATEWAY 0x2 /* gateway sockaddr present */ | |
341 | #define RTA_NETMASK 0x4 /* netmask sockaddr present */ | |
342 | #define RTA_GENMASK 0x8 /* cloning mask sockaddr present */ | |
343 | #define RTA_IFP 0x10 /* interface name sockaddr present */ | |
344 | #define RTA_IFA 0x20 /* interface addr sockaddr present */ | |
345 | #define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */ | |
346 | #define RTA_BRD 0x80 /* for NEWADDR, broadcast or p-p dest addr */ | |
347 | ||
348 | /* | |
349 | * Index offsets for sockaddr array for alternate internal encoding. | |
350 | */ | |
351 | #define RTAX_DST 0 /* destination sockaddr present */ | |
352 | #define RTAX_GATEWAY 1 /* gateway sockaddr present */ | |
353 | #define RTAX_NETMASK 2 /* netmask sockaddr present */ | |
354 | #define RTAX_GENMASK 3 /* cloning mask sockaddr present */ | |
355 | #define RTAX_IFP 4 /* interface name sockaddr present */ | |
356 | #define RTAX_IFA 5 /* interface addr sockaddr present */ | |
357 | #define RTAX_AUTHOR 6 /* sockaddr for author of redirect */ | |
358 | #define RTAX_BRD 7 /* for NEWADDR, broadcast or p-p dest addr */ | |
359 | #define RTAX_MAX 8 /* size of array to allocate */ | |
360 | ||
361 | struct rt_addrinfo { | |
362 | int rti_addrs; | |
363 | struct sockaddr *rti_info[RTAX_MAX]; | |
364 | }; | |
365 | ||
366 | struct route_cb { | |
367 | int ip_count; | |
368 | int ip6_count; | |
369 | int ipx_count; | |
370 | int ns_count; | |
371 | int iso_count; | |
372 | int any_count; | |
373 | }; | |
374 | ||
b0d623f7 | 375 | #ifdef PRIVATE |
c910b4d9 A |
376 | /* |
377 | * For scoped routing; a zero interface scope value means nil/no scope. | |
378 | */ | |
379 | #define IFSCOPE_NONE 0 | |
b0d623f7 A |
380 | #endif /* PRIVATE */ |
381 | ||
382 | #ifdef KERNEL_PRIVATE | |
383 | /* | |
384 | * Generic call trace used by some subsystems (e.g. route, ifaddr) | |
385 | */ | |
386 | #define CTRACE_STACK_SIZE 8 /* depth of stack trace */ | |
387 | #define CTRACE_HIST_SIZE 4 /* refcnt history size */ | |
388 | typedef struct ctrace { | |
389 | void *th; /* thread ptr */ | |
390 | void *pc[CTRACE_STACK_SIZE]; /* PC stack trace */ | |
391 | } ctrace_t; | |
392 | ||
393 | extern void ctrace_record(ctrace_t *); | |
394 | ||
395 | #define RT_LOCK_ASSERT_HELD(_rt) \ | |
396 | lck_mtx_assert(&(_rt)->rt_lock, LCK_MTX_ASSERT_OWNED) | |
397 | ||
398 | #define RT_LOCK_ASSERT_NOTHELD(_rt) \ | |
399 | lck_mtx_assert(&(_rt)->rt_lock, LCK_MTX_ASSERT_NOTOWNED) | |
400 | ||
401 | #define RT_LOCK(_rt) do { \ | |
402 | if (!rte_debug) \ | |
403 | lck_mtx_lock(&(_rt)->rt_lock); \ | |
404 | else \ | |
405 | rt_lock(_rt, FALSE); \ | |
406 | } while (0) | |
407 | ||
408 | #define RT_LOCK_SPIN(_rt) do { \ | |
409 | if (!rte_debug) \ | |
410 | lck_mtx_lock_spin(&(_rt)->rt_lock); \ | |
411 | else \ | |
412 | rt_lock(_rt, TRUE); \ | |
413 | } while (0) | |
414 | ||
415 | #define RT_CONVERT_LOCK(_rt) do { \ | |
416 | RT_LOCK_ASSERT_HELD(_rt); \ | |
417 | lck_mtx_convert_spin(&(_rt)->rt_lock); \ | |
418 | } while (0) | |
419 | ||
420 | #define RT_UNLOCK(_rt) do { \ | |
421 | if (!rte_debug) \ | |
422 | lck_mtx_unlock(&(_rt)->rt_lock); \ | |
423 | else \ | |
424 | rt_unlock(_rt); \ | |
425 | } while (0) | |
426 | ||
427 | #define RT_ADDREF_LOCKED(_rt) do { \ | |
428 | if (!rte_debug) { \ | |
429 | RT_LOCK_ASSERT_HELD(_rt); \ | |
430 | if (++(_rt)->rt_refcnt == 0) \ | |
431 | panic("RT_ADDREF(%p) bad refcnt\n", _rt); \ | |
432 | } else { \ | |
433 | rtref(_rt); \ | |
434 | } \ | |
435 | } while (0) | |
436 | ||
437 | /* | |
438 | * Spin variant mutex is used here; caller is responsible for | |
439 | * converting any previously-held similar lock to full mutex. | |
440 | */ | |
441 | #define RT_ADDREF(_rt) do { \ | |
442 | RT_LOCK_SPIN(_rt); \ | |
443 | RT_ADDREF_LOCKED(_rt); \ | |
444 | RT_UNLOCK(_rt); \ | |
445 | } while (0) | |
446 | ||
447 | #define RT_REMREF_LOCKED(_rt) do { \ | |
448 | if (!rte_debug) { \ | |
449 | RT_LOCK_ASSERT_HELD(_rt); \ | |
450 | if ((_rt)->rt_refcnt == 0) \ | |
451 | panic("RT_REMREF(%p) bad refcnt\n", _rt); \ | |
452 | --(_rt)->rt_refcnt; \ | |
453 | } else { \ | |
454 | (void) rtunref(_rt); \ | |
455 | } \ | |
456 | } while (0) | |
457 | ||
458 | /* | |
459 | * Spin variant mutex is used here; caller is responsible for | |
460 | * converting any previously-held similar lock to full mutex. | |
461 | */ | |
462 | #define RT_REMREF(_rt) do { \ | |
463 | RT_LOCK_SPIN(_rt); \ | |
464 | RT_REMREF_LOCKED(_rt); \ | |
465 | RT_UNLOCK(_rt); \ | |
466 | } while (0) | |
467 | ||
468 | #define RTFREE(_rt) rtfree(_rt) | |
469 | #define RTFREE_LOCKED(_rt) rtfree_locked(_rt) | |
c910b4d9 | 470 | |
1c79356b A |
471 | extern struct route_cb route_cb; |
472 | extern struct radix_node_head *rt_tables[AF_MAX+1]; | |
b0d623f7 A |
473 | __private_extern__ lck_mtx_t *rnh_lock; |
474 | __private_extern__ int use_routegenid; | |
475 | __private_extern__ uint32_t route_generation; | |
476 | __private_extern__ int rttrash; | |
477 | __private_extern__ unsigned int rte_debug; | |
1c79356b A |
478 | |
479 | struct ifmultiaddr; | |
480 | struct proc; | |
481 | ||
2d21ac55 | 482 | extern void route_init(void) __attribute__((section("__TEXT, initcode"))); |
b0d623f7 | 483 | extern void routegenid_update(void); |
2d21ac55 A |
484 | extern void rt_ifmsg(struct ifnet *); |
485 | extern void rt_missmsg(int, struct rt_addrinfo *, int, int); | |
486 | extern void rt_newaddrmsg(int, struct ifaddr *, int, struct rtentry *); | |
487 | extern void rt_newmaddrmsg(int, struct ifmultiaddr *); | |
488 | extern int rt_setgate(struct rtentry *, struct sockaddr *, struct sockaddr *); | |
6d2010ae A |
489 | extern void set_primary_ifscope(int, unsigned int); |
490 | extern unsigned int get_primary_ifscope(int); | |
491 | extern boolean_t rt_primary_default(struct rtentry *, struct sockaddr *); | |
c910b4d9 A |
492 | extern struct rtentry *rt_lookup(boolean_t, struct sockaddr *, |
493 | struct sockaddr *, struct radix_node_head *, unsigned int); | |
2d21ac55 | 494 | extern void rtalloc(struct route *); |
6d2010ae | 495 | extern void rtalloc_scoped(struct route *, unsigned int); |
b0d623f7 | 496 | extern void rtalloc_ign(struct route *, uint32_t); |
b0d623f7 | 497 | extern void rtalloc_scoped_ign(struct route *, uint32_t, unsigned int); |
b0d623f7 | 498 | extern struct rtentry *rtalloc1(struct sockaddr *, int, uint32_t); |
b0d623f7 A |
499 | extern struct rtentry *rtalloc1_scoped(struct sockaddr *, int, uint32_t, |
500 | unsigned int); | |
c910b4d9 | 501 | extern struct rtentry *rtalloc1_scoped_locked(struct sockaddr *, int, |
b0d623f7 | 502 | uint32_t, unsigned int); |
2d21ac55 A |
503 | extern void rtfree(struct rtentry *); |
504 | extern void rtfree_locked(struct rtentry *); | |
505 | extern void rtref(struct rtentry *); | |
9bccf70c A |
506 | /* |
507 | * rtunref will decrement the refcount, rtfree will decrement and free if | |
508 | * the refcount has reached zero and the route is not up. | |
509 | * Unless you have good reason to do otherwise, use rtfree. | |
510 | */ | |
b0d623f7 | 511 | extern int rtunref(struct rtentry *); |
2d21ac55 A |
512 | extern void rtsetifa(struct rtentry *, struct ifaddr *); |
513 | extern int rtinit(struct ifaddr *, int, int); | |
514 | extern int rtinit_locked(struct ifaddr *, int, int); | |
b0d623f7 | 515 | extern int rtioctl(unsigned long, caddr_t, struct proc *); |
c910b4d9 | 516 | extern void rtredirect(struct ifnet *, struct sockaddr *, struct sockaddr *, |
2d21ac55 A |
517 | struct sockaddr *, int, struct sockaddr *, struct rtentry **); |
518 | extern int rtrequest(int, struct sockaddr *, | |
519 | struct sockaddr *, struct sockaddr *, int, struct rtentry **); | |
6d2010ae A |
520 | extern int rtrequest_scoped(int, struct sockaddr *, struct sockaddr *, |
521 | struct sockaddr *, int, struct rtentry **, unsigned int); | |
2d21ac55 A |
522 | extern int rtrequest_locked(int, struct sockaddr *, |
523 | struct sockaddr *, struct sockaddr *, int, struct rtentry **); | |
c910b4d9 A |
524 | extern int rtrequest_scoped_locked(int, struct sockaddr *, struct sockaddr *, |
525 | struct sockaddr *, int, struct rtentry **, unsigned int); | |
6d2010ae A |
526 | extern void sin_set_ifscope(struct sockaddr *, unsigned int); |
527 | extern unsigned int sin_get_ifscope(struct sockaddr *); | |
528 | extern unsigned int sin6_get_ifscope(struct sockaddr *); | |
b0d623f7 A |
529 | extern void rt_lock(struct rtentry *, boolean_t); |
530 | extern void rt_unlock(struct rtentry *); | |
6d2010ae | 531 | extern struct sockaddr *rtm_scrub_ifscope(int, int, struct sockaddr *, |
b0d623f7 | 532 | struct sockaddr *, struct sockaddr_storage *); |
d1ecb069 | 533 | extern u_int64_t rt_expiry(struct rtentry *, u_int64_t, u_int32_t); |
6d2010ae A |
534 | extern void rt_set_idleref(struct rtentry *); |
535 | extern void rt_clear_idleref(struct rtentry *); | |
d1ecb069 | 536 | extern void rt_aggdrain(int); |
6d2010ae A |
537 | extern boolean_t rt_validate(struct rtentry *); |
538 | ||
539 | #ifdef XNU_KERNEL_PRIVATE | |
540 | extern void route_copyin(struct route *src, struct route *dst, size_t length); | |
541 | extern void route_copyout(struct route *dst, const struct route *src, size_t length); | |
542 | #endif /* XNU_KERNEL_PRIVATE */ | |
543 | ||
b0d623f7 | 544 | #endif /* KERNEL_PRIVATE */ |
1c79356b A |
545 | |
546 | #endif |