xref: /xnu-11215.61.5/bsd/net/route_private.h (revision 4f1223e81cd707a65cc109d0b8ad6653699da3c4)
1 /*
2  * Copyright (c) 2000-2022 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
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.
14  *
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
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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
61  * $FreeBSD: src/sys/net/route.h,v 1.36.2.1 2000/08/16 06:14:23 jayanth Exp $
62  */
63 
64 #ifndef _NET_ROUTE_PRIVATE_H_
65 #define _NET_ROUTE_PRIVATE_H_
66 #include <net/route.h>
67 #include <stdint.h>
68 #include <sys/types.h>
69 #include <sys/socket.h>
70 #include <uuid/uuid.h>
71 
72 struct route_old {
73 	void            *ro_rt;
74 	uint32_t        ro_flags;
75 	struct sockaddr ro_dst;
76 };
77 
78 #ifdef BSD_KERNEL_PRIVATE
79 #include <kern/locks.h>
80 #include <net/radix.h>
81 #include <sys/eventhandler.h>
82 #include <net/if_dl.h>
83 #include <netinet/in_private.h>
84 
85 extern boolean_t trigger_v6_defrtr_select;
86 /*
87  * Kernel resident routing tables.
88  *
89  * The routing tables are initialized when interface addresses
90  * are set by making entries for all directly connected interfaces.
91  */
92 
93 /* forward declarations */
94 struct ifnet_llreach_info;
95 struct rt_reach_info;
96 
97 /*
98  * IP route structure
99  *
100  * A route consists of a destination address and a reference
101  * to a routing entry.  These are often held by protocols
102  * in their control blocks, e.g. inpcb.
103  */
104 struct route {
105 	/*
106 	 * N.B: struct route must begin with ro_{rt, lle, srcia, flags}
107 	 * because the code does some casts of a 'struct route_in6 *'
108 	 * to a 'struct route *'.
109 	 */
110 	struct rtentry        *ro_rt;
111 	struct ifaddr         *ro_srcia;
112 	uint32_t              ro_flags;       /* route flags (see below) */
113 	struct sockaddr       ro_dst;
114 };
115 
116 #define ROF_SRCIF_SELECTED      0x0001  /* source interface was selected */
117 
118 #define ROUTE_UNUSABLE(_ro)                                             \
119 	((_ro)->ro_rt == NULL ||                                        \
120 	((_ro)->ro_rt->rt_flags & (RTF_UP|RTF_CONDEMNED)) != RTF_UP ||  \
121 	RT_GENID_OUTOFSYNC((_ro)->ro_rt))
122 
123 #define _ROUTE_RELEASE_COMMON(_ro, _rnh_locked) do {                    \
124 	if ((_ro)->ro_rt != NULL) {                                     \
125 	        RT_LOCK_ASSERT_NOTHELD((_ro)->ro_rt);                   \
126 	        if (_rnh_locked)                                        \
127 	                rtfree_locked((_ro)->ro_rt);                    \
128 	        else                                                    \
129 	                rtfree((_ro)->ro_rt);                           \
130 	        (_ro)->ro_rt = NULL;                                    \
131 	}                                                               \
132 	if ((_ro)->ro_srcia != NULL) {                                  \
133 	        ifa_remref((_ro)->ro_srcia);                            \
134 	        (_ro)->ro_srcia = NULL;                                 \
135 	        (_ro)->ro_flags &= ~ROF_SRCIF_SELECTED;                 \
136 	}                                                               \
137 } while (0)
138 
139 #define ROUTE_RELEASE_LOCKED(_ro)       _ROUTE_RELEASE_COMMON(_ro, TRUE)
140 #define ROUTE_RELEASE(_ro)              _ROUTE_RELEASE_COMMON(_ro, FALSE)
141 
142 /*
143  * We distinguish between routes to hosts and routes to networks,
144  * preferring the former if available.  For each route we infer
145  * the interface to use from the gateway address supplied when
146  * the route was entered.  Routes that forward packets through
147  * gateways are marked so that the output routines know to address the
148  * gateway rather than the ultimate destination.
149  */
150 
151 #define NRTT_HIST       10
152 /*
153  * Kernel routing entry structure.
154  */
155 struct rtentry {
156 	struct  radix_node rt_nodes[2]; /* tree glue, and other values */
157 #define rt_node(r)      &((r)->rt_nodes[0])
158 #define rt_key(r)       SA(rn_get_key(rt_node(r)))
159 #define rt_mask(r)      SA(rn_get_mask(rt_node(r)))
160 	/*
161 	 * See bsd/net/route.c for synchronization notes.
162 	 */
163 	decl_lck_mtx_data(, rt_lock);   /* lock for routing entry */
164 	uint32_t rt_refcnt;             /* # held references */
165 	uint32_t rt_flags;              /* up/down?, host/net */
166 	uint32_t rt_genid;              /* route generation id */
167 	struct sockaddr *rt_gateway;    /* value */
168 	struct ifnet *rt_ifp;           /* the answer: interface to use */
169 	struct ifaddr *rt_ifa;          /* the answer: interface addr to use */
170 	struct sockaddr *rt_genmask;    /* for generation of cloned routes */
171 	void *rt_llinfo;                /* pointer to link level info cache */
172 	void (*rt_llinfo_get_ri)        /* llinfo get reachability info fn */
173 	(struct rtentry *, struct rt_reach_info *);
174 	void (*rt_llinfo_get_iflri)     /* ifnet llinfo get reach. info fn */
175 	(struct rtentry *, struct ifnet_llreach_info *);
176 	void (*rt_llinfo_purge)(struct rtentry *); /* llinfo purge fn */
177 	void (*rt_llinfo_free)(void *); /* link level info free function */
178 	void (*rt_llinfo_refresh) (struct rtentry *); /* expedite llinfo refresh */
179 	struct rt_metrics rt_rmx;       /* metrics used by rx'ing protocols */
180 #define rt_use rt_rmx.rmx_pksent
181 	struct rtentry *rt_gwroute;     /* implied entry for gatewayed routes */
182 	struct rtentry *rt_parent;      /* cloning parent of this route */
183 	struct nstat_counts *rt_stats;  /* route stats */
184 	void (*rt_if_ref_fn)(struct ifnet *, int); /* interface ref func */
185 
186 	uint32_t *rt_tree_genid;        /* ptr to per-tree route_genid */
187 	uint64_t rt_expire;             /* expiration time in uptime seconds */
188 	uint64_t base_calendartime;     /* calendar time upon entry creation */
189 	uint64_t base_uptime;           /* uptime upon entry creation */
190 	u_int32_t rtt_hist[NRTT_HIST];  /* RTT history sample by TCP connections */
191 	u_int32_t rtt_min;              /* minimum RTT computed from history */
192 	u_int32_t rtt_expire_ts;        /* RTT history expire timestamp */
193 	u_int8_t rtt_index;             /* Index into RTT history */
194 	/* Event handler context for the rtentrt */
195 	struct eventhandler_lists_ctxt rt_evhdlr_ctxt;
196 };
197 
198 static inline struct rtentry *
199 __attribute__((always_inline)) __stateful_pure
rn_rtentry(struct radix_node * rn)200 rn_rtentry(struct radix_node *rn)
201 {
202 	return __container_of(rn, struct rtentry, rt_nodes[0]);
203 }
204 /* Backward compatibility. */
205 #define RT(r) rn_rtentry((r))
206 
207 #define rt_key_free(r) ({                                       \
208 	void *__r __single = rt_key(r);                         \
209 	kheap_free_addr(KHEAP_DATA_BUFFERS, __r);               \
210 })
211 
212 enum {
213 	ROUTE_STATUS_UPDATE = 1,
214 	ROUTE_ENTRY_REFRESH,
215 	ROUTE_ENTRY_DELETED,
216 	ROUTE_LLENTRY_RESOLVED,
217 	ROUTE_LLENTRY_UNREACH,
218 	ROUTE_LLENTRY_CHANGED,
219 	ROUTE_LLENTRY_STALE,
220 	ROUTE_LLENTRY_TIMEDOUT,
221 	ROUTE_LLENTRY_DELETED,
222 	ROUTE_LLENTRY_EXPIRED,
223 	ROUTE_LLENTRY_PROBED,
224 	ROUTE_EVHDLR_DEREGISTER,
225 };
226 
227 extern const char * route_event2str(int route_event);
228 
229 typedef void (*route_event_fn) (struct eventhandler_entry_arg,
230     struct sockaddr *, int, struct sockaddr *, int);
231 EVENTHANDLER_DECLARE(route_event, route_event_fn);
232 
233 /*
234  * Synchronize route entry's generation ID with the tree's.
235  */
236 #define RT_GENID_SYNC(_rt) do {                                         \
237 	if ((_rt)->rt_tree_genid != NULL)                               \
238 	        (_rt)->rt_genid = *(_rt)->rt_tree_genid;                \
239 } while (0)
240 
241 /*
242  * Indicates whether or not the route entry's generation ID is stale.
243  */
244 #define RT_GENID_OUTOFSYNC(_rt)                                         \
245 	((_rt)->rt_tree_genid != NULL &&                                \
246 	*(_rt)->rt_tree_genid != (_rt)->rt_genid)
247 
248 enum {
249 	ROUTE_OP_READ,
250 	ROUTE_OP_WRITE,
251 };
252 
253 extern int route_op_entitlement_check(struct socket *, kauth_cred_t, int, boolean_t);
254 #endif /* BSD_KERNEL_PRIVATE */
255 
256 struct kev_netevent_apnfallbk_data {
257 	pid_t           epid;           /* effective PID */
258 	uuid_t          euuid;          /* effective UUID */
259 };
260 
261 /*
262  * Route reachability info.
263  */
264 struct rt_reach_info {
265 	u_int32_t       ri_refcnt;      /* reference count */
266 	u_int32_t       ri_probes;      /* total # of probes */
267 	u_int64_t       ri_snd_expire;  /* tx expiration (calendar) time */
268 	u_int64_t       ri_rcv_expire;  /* rx expiration (calendar) time */
269 	int32_t         ri_rssi;        /* received signal strength */
270 	int32_t         ri_lqm;         /* link quality metric */
271 	int32_t         ri_npm;         /* node proximity metric */
272 };
273 
274 
275 /*
276  * Route address information with extra space for "tiny" socket addresses
277  * from the user space. A "tiny" socket address has the `sa_len' field
278  * smaller than the canonical sockaddr structure.
279  * To preserve the type and the bounds safety, such "tiny" addresses
280  * are copied to the `rtix_tiny_addr' field.
281  */
282 struct rt_addrinfo_ext {
283 	struct rt_addrinfo rtix_info;                    /* addr info containing sockaddr array */
284 	struct sockaddr    rtix_tiny_addr[RTAX_MAX];     /* storage for the "tiny" sockaddr addresss */
285 	uint8_t            rtix_next_tiny;               /* offset of the next "tiny" address */
286 };
287 
288 /*
289  * The following is used internally when parsing routing
290  * messages to avoid potential boundary issues when
291  * using shorter structures.
292  */
293 struct rt_msghdr_common {
294 	u_short rtm_msglen;     /* to skip over non-understood messages */
295 	u_char  rtm_version;    /* future binary compatibility */
296 	u_char  rtm_type;       /* message type */
297 	u_short rtm_index;      /* index for associated ifp */
298 	int     rtm_flags;      /* flags, incl. kern & message, e.g. DONE */
299 	int     rtm_addrs;      /* bitmask identifying sockaddrs in msg */
300 	pid_t   rtm_pid;        /* identify sender */
301 	int     rtm_seq;        /* for sender to identify action */
302 	int     rtm_errno;      /* why failed */
303 	int     rtm_use;        /* from rtentry */
304 };
305 
306 /*
307  * Extended routing message header (private).
308  */
309 struct rt_msghdr_ext {
310 	u_short rtm_msglen;     /* to skip over non-understood messages */
311 	u_char  rtm_version;    /* future binary compatibility */
312 	u_char  rtm_type;       /* message type */
313 	u_int32_t rtm_index;    /* index for associated ifp */
314 	u_int32_t rtm_flags;    /* flags, incl. kern & message, e.g. DONE */
315 	u_int32_t rtm_reserved; /* for future use */
316 	u_int32_t rtm_addrs;    /* bitmask identifying sockaddrs in msg */
317 	pid_t   rtm_pid;        /* identify sender */
318 	int     rtm_seq;        /* for sender to identify action */
319 	int     rtm_errno;      /* why failed */
320 	u_int32_t rtm_use;      /* from rtentry */
321 	u_int32_t rtm_inits;    /* which metrics we are initializing */
322 	struct rt_metrics rtm_rmx;      /* metrics themselves */
323 	struct rt_reach_info rtm_ri;    /* route reachability info */
324 };
325 
326 /*
327  * Message types.
328  */
329 #define RTM_GET_SILENT  0x11
330 #define RTM_GET_EXT     0x15
331 
332 /*
333  * Bitmask values for rtm_inits and rmx_locks.
334  */
335 #define RTV_REFRESH_HOST        0x100   /* init host route to expedite refresh */
336 
337 /*
338  * For scoped routing; a zero interface scope value means nil/no scope.
339  */
340 #define IFSCOPE_NONE    0
341 #define IFSCOPE_UNKNOWN IFSCOPE_NONE
342 
343 /*
344  * Routing statistics.
345  */
346 struct rtstat_64 {
347 	uint64_t        rts_badredirect;        /* bogus redirect calls */
348 	uint64_t        rts_dynamic;            /* routes created by redirects */
349 	uint64_t        rts_newgateway;         /* routes modified by redirects */
350 	uint64_t        rts_unreach;            /* lookups which failed */
351 	uint64_t        rts_wildcard;           /* lookups satisfied by a wildcard */
352 	uint64_t        rts_badrtgwroute;       /* route to gateway is not direct */
353 };
354 
355 #ifdef BSD_KERNEL_PRIVATE
356 /*
357  * Generic call trace used by some subsystems (e.g. route, ifaddr)
358  */
359 #define CTRACE_STACK_SIZE       8               /* depth of stack trace */
360 #define CTRACE_HIST_SIZE        4               /* refcnt history size */
361 typedef struct ctrace {
362 	void    *th;                            /* thread ptr */
363 	void    *pc[CTRACE_STACK_SIZE];         /* PC stack trace */
364 } ctrace_t;
365 
366 extern void ctrace_record(ctrace_t *);
367 
368 #define RT_LOCK_ASSERT_HELD(_rt)                                        \
369 	LCK_MTX_ASSERT(&(_rt)->rt_lock, LCK_MTX_ASSERT_OWNED)
370 
371 #define RT_LOCK_ASSERT_NOTHELD(_rt)                                     \
372 	LCK_MTX_ASSERT(&(_rt)->rt_lock, LCK_MTX_ASSERT_NOTOWNED)
373 
374 #define RT_LOCK(_rt) do {                                               \
375 	rt_lock(_rt, FALSE);                                            \
376 } while (0)
377 
378 #define RT_LOCK_SPIN(_rt) do {                                          \
379 	rt_lock(_rt, TRUE);                                             \
380 } while (0)
381 
382 #define RT_CONVERT_LOCK(_rt) do {                                       \
383 	RT_LOCK_ASSERT_HELD(_rt);                                       \
384 	lck_mtx_convert_spin(&(_rt)->rt_lock);                          \
385 } while (0)
386 
387 #define RT_UNLOCK(_rt) do {                                             \
388 	rt_unlock(_rt);                                                 \
389 } while (0)
390 
391 #define RT_ADDREF_LOCKED(_rt) do {                                      \
392 	rtref(_rt);                                                     \
393 } while (0)
394 
395 /*
396  * Spin variant mutex is used here; caller is responsible for
397  * converting any previously-held similar lock to full mutex.
398  */
399 #define RT_ADDREF(_rt) do {                                             \
400 	RT_LOCK_SPIN(_rt);                                              \
401 	RT_ADDREF_LOCKED(_rt);                                          \
402 	RT_UNLOCK(_rt);                                                 \
403 } while (0)
404 
405 #define RT_REMREF_LOCKED(_rt) do {                                      \
406 	(void) rtunref(_rt);                                            \
407 } while (0)
408 
409 /*
410  * Spin variant mutex is used here; caller is responsible for
411  * converting any previously-held similar lock to full mutex.
412  */
413 #define RT_REMREF(_rt) do {                                             \
414 	RT_LOCK_SPIN(_rt);                                              \
415 	RT_REMREF_LOCKED(_rt);                                          \
416 	RT_UNLOCK(_rt);                                                 \
417 } while (0)
418 
419 /*
420  * This macro calculates skew in wall clock, just in case the user changes the
421  * system time. This skew adjustment is required because we now keep the
422  * expiration times in uptime terms in the kernel, but the userland still
423  * expects expiration times in terms of calendar times.  This is used when
424  * reporting rt_expire, ln_expire, etc. values to user space.
425  */
426 #define NET_CALCULATE_CLOCKSKEW(cc, ic, cu, iu)                         \
427 	((cc.tv_sec - ic) - (cu - iu))
428 
429 extern unsigned int rt_verbose;
430 extern struct radix_node_head *rt_tables[AF_MAX + 1];
431 extern lck_mtx_t rnh_lock_data;
432 #define rnh_lock (&rnh_lock_data)
433 extern uint32_t route_genid_inet;       /* INET route generation count */
434 extern uint32_t route_genid_inet6;      /* INET6 route generation count */
435 extern int rttrash;
436 extern unsigned int rte_debug;
437 
438 struct ifmultiaddr;
439 struct proc;
440 
441 extern void route_init(void);
442 extern void routegenid_update(void);
443 extern void routegenid_inet_update(void);
444 extern void routegenid_inet6_update(void);
445 extern void rt_ifmsg(struct ifnet *);
446 extern void rt_missmsg(u_char, struct rt_addrinfo *, int, int);
447 extern void rt_newaddrmsg(u_char, struct ifaddr *, int, struct rtentry *);
448 extern void rt_newmaddrmsg(u_char, struct ifmultiaddr *);
449 extern int rt_setgate(struct rtentry *, struct sockaddr *, struct sockaddr *);
450 extern void set_primary_ifscope(int, unsigned int);
451 extern unsigned int get_primary_ifscope(int);
452 extern boolean_t rt_primary_default(struct rtentry *, struct sockaddr *);
453 extern struct rtentry *rt_lookup(boolean_t, struct sockaddr *,
454     struct sockaddr *, struct radix_node_head *, unsigned int);
455 extern struct rtentry *rt_lookup_coarse(boolean_t, struct sockaddr *,
456     struct sockaddr *, struct radix_node_head *);
457 extern void rtalloc(struct route *);
458 extern void rtalloc_scoped(struct route *, unsigned int);
459 extern void rtalloc_ign(struct route *, uint32_t);
460 extern void rtalloc_scoped_ign(struct route *, uint32_t, unsigned int);
461 extern struct rtentry *rtalloc1(struct sockaddr *, int, uint32_t);
462 extern struct rtentry *rtalloc1_scoped(struct sockaddr *, int, uint32_t,
463     unsigned int);
464 extern struct rtentry *rtalloc1_scoped_locked(struct sockaddr *, int,
465     uint32_t, unsigned int);
466 extern void rtfree_locked(struct rtentry *);
467 extern void rtfree(struct rtentry *);
468 extern void rtref(struct rtentry *);
469 /*
470  * rtunref will decrement the refcount, rtfree will decrement and free if
471  * the refcount has reached zero and the route is not up.
472  * Unless you have good reason to do otherwise, use rtfree.
473  */
474 extern int rtunref(struct rtentry *);
475 extern void rtsetifa(struct rtentry *, struct ifaddr *);
476 extern int rtinit(struct ifaddr *, uint8_t, int);
477 extern int rtinit_locked(struct ifaddr *, uint8_t, int);
478 extern int rtioctl(unsigned long req, caddr_t __sized_by(IOCPARM_LEN(req)), struct proc *);
479 extern void rtredirect(struct ifnet *, struct sockaddr *, struct sockaddr *,
480     struct sockaddr *, int, struct sockaddr *, struct rtentry **);
481 extern int rtrequest(int, struct sockaddr *,
482     struct sockaddr *, struct sockaddr *, int, struct rtentry **);
483 extern int rtrequest_scoped(int, struct sockaddr *, struct sockaddr *,
484     struct sockaddr *, int, struct rtentry **, unsigned int);
485 extern int rtrequest_locked(int, struct sockaddr *,
486     struct sockaddr *, struct sockaddr *, int, struct rtentry **);
487 extern int rtrequest_scoped_locked(int, struct sockaddr *, struct sockaddr *,
488     struct sockaddr *, int, struct rtentry **, unsigned int);
489 extern void sin_set_ifscope(struct sockaddr *, unsigned int);
490 extern unsigned int sin_get_ifscope(struct sockaddr *);
491 extern unsigned int sin6_get_ifscope(struct sockaddr *);
492 extern void rt_lock(struct rtentry *, boolean_t);
493 extern void rt_unlock(struct rtentry *);
494 extern struct sockaddr *rtm_scrub(int, int, struct sockaddr *,
495     struct sockaddr *, void *buf __sized_by(buflen), uint32_t buflen, kauth_cred_t *);
496 extern boolean_t rt_validate(struct rtentry *);
497 extern void rt_set_proxy(struct rtentry *, boolean_t);
498 extern void rt_set_gwroute(struct rtentry *, struct sockaddr *,
499     struct rtentry *);
500 extern void rt_revalidate_gwroute(struct rtentry *, struct rtentry *);
501 extern errno_t route_to_gwroute(const struct sockaddr *, struct rtentry *,
502     struct rtentry **);
503 extern void rt_setexpire(struct rtentry *, uint64_t);
504 extern void rt_str(struct rtentry *, char *ds __sized_by(dslen), uint32_t dslen, char *gs __sized_by(gslen), uint32_t gslen);
505 extern const char *rtm2str(int);
506 extern void route_clear(struct route *);
507 extern void route_copyin(struct route *, struct route *, size_t);
508 extern void route_copyout(struct route *, const struct route *, size_t);
509 extern boolean_t rt_ifa_is_dst(struct sockaddr *, struct ifaddr *);
510 extern struct sockaddr *sa_copy(struct sockaddr *, struct sockaddr_storage *,
511     unsigned int *);
512 
513 /*
514  * The following is used to enqueue work items for route events
515  * and also used to pass route event while walking the tree
516  */
517 struct route_event {
518 	struct rtentry *rt;
519 	/*
520 	 * There's no reference taken on gwrt.
521 	 * We only use it to check whether we should
522 	 * point to rt_gateway or the embedded rt_addr
523 	 * structure.
524 	 */
525 	struct rtentry *gwrt;
526 	union {
527 		union sockaddr_in_4_6 _rtev_ipaddr;
528 		char _rtev_addr_bytes[DLIL_SDLMAXLEN];
529 	} rt_addr;
530 	uint32_t route_event_code;
531 	eventhandler_tag evtag;
532 };
533 
534 #define rtev_ipaddr     rt_addr._rtev_ipaddr
535 #define rtev_addr_bytes rt_addr._rtev_addr_bytes
536 
537 extern void route_event_init(struct route_event *p_route_ev, struct rtentry *rt,
538     struct rtentry *gwrt, int route_ev_code);
539 extern int route_event_walktree(struct radix_node *rn, void *arg);
540 extern void route_event_enqueue_nwk_wq_entry(struct rtentry *, struct rtentry *,
541     uint32_t, eventhandler_tag, boolean_t);
542 
543 #endif /* BSD_KERNEL_PRIVATE */
544 #endif /* _NET_ROUTE_PRIVATE_H_ */
545