xref: /xnu-11215.41.3/bsd/netinet/in_var.h (revision 33de042d024d46de5ff4e89f2471de6608e37fa4)
1 /*
2  * Copyright (c) 2000-2024 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) 1985, 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  *	@(#)in_var.h	8.2 (Berkeley) 1/9/95
61  */
62 
63 #ifndef _NETINET_IN_VAR_H_
64 #define _NETINET_IN_VAR_H_
65 #include <sys/appleapiopts.h>
66 #include <sys/protosw.h>
67 
68 #include <sys/queue.h>
69 #include <sys/kern_event.h>
70 #include <net/if_var.h>
71 #include <net/net_kev.h>
72 #include <netinet/in.h>
73 
74 #ifdef BSD_KERNEL_PRIVATE
75 #include <net/route.h>
76 
77 /*
78  * Interface address, Internet version.  One of these structures
79  * is allocated for each Internet address on an interface.
80  * The ifaddr structure contains the protocol-independent part
81  * of the structure and is assumed to be first.
82  */
83 struct in_ifaddr {
84 	struct ifaddr ia_ifa;           /* protocol-independent info */
85 #define ia_ifp          ia_ifa.ifa_ifp
86 #define ia_flags        ia_ifa.ifa_flags
87 	/* ia_{,sub}net{,mask} in host order */
88 	u_int32_t ia_net;               /* network number of interface */
89 	u_int32_t ia_netmask;           /* mask of net part */
90 	u_int32_t ia_subnet;            /* subnet number, including net */
91 	u_int32_t ia_subnetmask;        /* mask of subnet part */
92 	struct in_addr ia_netbroadcast; /* to recognize net broadcasts */
93 	TAILQ_ENTRY(in_ifaddr) ia_link; /* tailq macro glue */
94 	struct sockaddr_in ia_addr;     /* reserve space for interface name */
95 	struct sockaddr_in ia_dstaddr;  /* reserve space for broadcast addr */
96 #define ia_broadaddr    ia_dstaddr
97 	struct sockaddr_in ia_sockmask; /* reserve space for general netmask */
98 	TAILQ_ENTRY(in_ifaddr) ia_hash; /* hash bucket entry */
99 };
100 
101 static inline const struct in_ifaddr *
102 __attribute__((overloadable)) __pure2
__ifatoia_const(const struct ifaddr * ifa)103 __ifatoia_const(const struct ifaddr *ifa)
104 {
105 	return __container_of(ifa, const struct in_ifaddr, ia_ifa);
106 }
107 static inline struct in_ifaddr *
108 __attribute__((overloadable)) __pure2
__ifatoia(struct ifaddr * ifa)109 __ifatoia(struct ifaddr *ifa)
110 {
111 	return __container_of(ifa, struct in_ifaddr, ia_ifa);
112 }
113 
114 #if __has_ptrcheck
115 #define ifatoia(ifa) (_Generic((ifa),                           \
116 	const struct ifaddr * __single         : __ifatoia_const,   \
117 	const struct ifaddr * __bidi_indexable : __ifatoia_const,   \
118 	const struct ifaddr * __indexable      : __ifatoia_const,   \
119 	      struct ifaddr * __single         : __ifatoia,         \
120 	      struct ifaddr * __bidi_indexable : __ifatoia,         \
121 	      struct ifaddr * __indexable      : __ifatoia)         \
122 	((ifa)))
123 #else /* !__has_ptrcheck */
124 #define ifatoia(ifa) (_Generic((ifa),                  \
125 	const struct ifaddr * : __ifatoia_const,           \
126 	      struct ifaddr * : __ifatoia)                 \
127 	((ifa)))
128 #endif /* !__has_ptrcheck */
129 
130 static inline const struct in_ifaddr *
131 __attribute__((overloadable)) __pure2
__iatoia_const(const struct in_ifaddr * ia)132 __iatoia_const(const struct in_ifaddr *ia)
133 {
134 	return ia;
135 }
136 static inline struct in_ifaddr *
137 __attribute__((overloadable)) __pure2
__iatoia(struct in_ifaddr * ia)138 __iatoia(struct in_ifaddr *ia)
139 {
140 	return ia;
141 }
142 #if __has_ptrcheck
143 #define IA(ifa_or_ia) (_Generic((ifa_or_ia),                        \
144 	const struct ifaddr    * __single          : __ifatoia_const,   \
145 	const struct ifaddr    * __bidi_indexable  : __ifatoia_const,   \
146 	const struct ifaddr    * __indexable       : __ifatoia_const,   \
147 	          struct ifaddr    * __single          : __ifatoia,         \
148 	          struct ifaddr    * __bidi_indexable  : __ifatoia,         \
149 	          struct ifaddr    * __indexable       : __ifatoia,         \
150 	const struct in_ifaddr * __single          : __iatoia_const,    \
151 	const struct in_ifaddr * __bidi_indexable  : __iatoia_const,    \
152 	const struct in_ifaddr * __indexable       : __iatoia_const,    \
153 	          struct in_ifaddr * __single          : __iatoia,          \
154 	          struct in_ifaddr * __bidi_indexable  : __iatoia,          \
155 	          struct in_ifaddr * __indexable       : __iatoia)          \
156 	((ifa_or_ia)))
157 #else /* !__has_ptrcheck */
158 #define IA(ifa_or_ia) (_Generic((ifa_or_ia),                        \
159 	const struct ifaddr    *                   : __ifatoia_const,   \
160 	      struct ifaddr    *                   : __ifatoia,         \
161 	const struct in_ifaddr *                   : __iatoia_const,    \
162 	      struct in_ifaddr *                   : __iatoia)          \
163 	((ifa_or_ia)))
164 #endif /* !__has_ptrcheck */
165 
166 #endif /* BSD_KERNEL_PRIVATE */
167 
168 struct in_aliasreq {
169 	char ifra_name[IFNAMSIZ];       /* if name, e.g. "en0" */
170 	struct sockaddr_in ifra_addr;
171 	struct sockaddr_in ifra_broadaddr;
172 #define ifra_dstaddr    ifra_broadaddr
173 	struct sockaddr_in ifra_mask;
174 };
175 
176 /*
177  * Event data, inet style.
178  */
179 struct kev_in_data {
180 	struct net_event_data link_data;
181 	struct in_addr ia_addr;         /* interface address */
182 	u_int32_t ia_net;               /* network number of interface */
183 	u_int32_t ia_netmask;           /* mask of net part */
184 	u_int32_t ia_subnet;            /* subnet number, including net */
185 	u_int32_t ia_subnetmask;        /* mask of subnet part */
186 	struct in_addr ia_netbroadcast; /* to recognize net broadcasts */
187 	struct in_addr ia_dstaddr;
188 };
189 
190 struct kev_in_collision {
191 	struct net_event_data link_data; /* link where ARP was received on */
192 	struct in_addr ia_ipaddr;       /* conflicting IP address */
193 	u_char hw_len;                  /* length of hardware address */
194 	u_char hw_addr[__counted_by(hw_len)];/* variable length hardware address */
195 };
196 
197 struct kev_in_arpfailure {
198 	struct net_event_data link_data; /* link where ARP is being sent */
199 };
200 
201 struct kev_in_arpalive {
202 	struct net_event_data link_data; /* link where ARP was received */
203 };
204 
205 #ifdef PRIVATE
206 /*
207  * Common structure for KEV_SOCKET_SUBCLASS
208  * Have to place here to avoid declaration dependencies.
209  */
210 struct kev_socket_event_data {
211 	union sockaddr_in_4_6 kev_sockname;
212 	union sockaddr_in_4_6 kev_peername;
213 };
214 
215 struct kev_socket_closed {
216 	struct kev_socket_event_data ev_data;
217 };
218 #endif /* PRIVATE */
219 
220 #ifdef __APPLE_API_PRIVATE
221 struct kev_in_portinuse {
222 	u_int16_t port;         /* conflicting port number in host order */
223 	u_int32_t req_pid;      /* PID port requestor */
224 	u_int32_t reserved[2];
225 };
226 #endif /* __APPLE_API_PRIVATE */
227 
228 #ifdef BSD_KERNEL_PRIVATE
229 extern void socket_post_kev_msg(uint32_t, struct kev_socket_event_data *,
230     uint32_t);
231 extern void socket_post_kev_msg_closed(struct socket *);
232 
233 #include <net/if.h>
234 #include <net/if_var.h>
235 #include <kern/locks.h>
236 #include <sys/tree.h>
237 /*
238  * Given a pointer to an in_ifaddr (ifaddr),
239  * return a pointer to the addr as a sockaddr_in.
240  */
241 #define IA_SIN(ia)    (&(IA((ia))->ia_addr))
242 #define IA_DSTSIN(ia) (&(IA((ia))->ia_dstaddr))
243 
244 #define IN_LNAOF(in, ifa) \
245 	(ntohl((in).s_addr) & ~(IA((ifa))->ia_subnetmask))
246 
247 /*
248  * Hash table for IPv4 addresses.
249  */
250 extern TAILQ_HEAD(in_ifaddrhead, in_ifaddr) in_ifaddrhead;
251 TAILQ_HEAD(in_ifaddrhashhead, in_ifaddr);
252 extern lck_rw_t in_ifaddr_rwlock;
253 
254 #define INADDR_HASH(x)  inaddr_hashlookup(x)
255 
256 extern  u_char  inetctlerrmap[PRC_NCMDS];
257 
258 /*
259  * Macro for finding the interface (ifnet structure) corresponding to one
260  * of our IP addresses.
261  */
262 #define INADDR_TO_IFP(addr, ifp)                                        \
263 	/* struct in_addr addr; */                                      \
264 	/* struct ifnet *ifp; */                                        \
265 {                                                                       \
266 	struct in_ifaddr *ia;                                           \
267                                                                         \
268 	lck_rw_lock_shared(&in_ifaddr_rwlock);                          \
269 	TAILQ_FOREACH(ia, INADDR_HASH((addr).s_addr), ia_hash) {        \
270 	        IFA_LOCK_SPIN(&ia->ia_ifa);                             \
271 	        if (IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) {     \
272 	                IFA_UNLOCK(&ia->ia_ifa);                        \
273 	                break;                                          \
274 	        }                                                       \
275 	        IFA_UNLOCK(&ia->ia_ifa);                                \
276 	}                                                               \
277 	(ifp) = (ia == NULL) ? NULL : ia->ia_ifp;                       \
278 	lck_rw_done(&in_ifaddr_rwlock);                                 \
279 }
280 
281 /*
282  * Macro for finding the internet address structure (in_ifaddr) corresponding
283  * to a given interface (ifnet structure).  Caller is responsible for freeing
284  * the reference.
285  */
286 #define IFP_TO_IA(ifp, ia)                                              \
287 	/* struct ifnet *ifp; */                                        \
288 	/* struct in_ifaddr *ia; */                                     \
289 {                                                                       \
290 	lck_rw_lock_shared(&in_ifaddr_rwlock);                          \
291 	for ((ia) = TAILQ_FIRST(&in_ifaddrhead);                        \
292 	    (ia) != NULL && (ia)->ia_ifp != (ifp);                      \
293 	    (ia) = TAILQ_NEXT((ia), ia_link))                           \
294 	        continue;                                               \
295 	if ((ia) != NULL)                                               \
296 	        ifa_addref(&(ia)->ia_ifa);                              \
297 	lck_rw_done(&in_ifaddr_rwlock);                                 \
298 }
299 
300 /*
301  * This information should be part of the ifnet structure but we don't wish
302  * to change that - as it might break a number of things
303  */
304 
305 /*
306  * Legacy IPv4 IGMP per-link structure.
307  */
308 struct router_info {
309 	struct ifnet *rti_ifp;
310 	int    rti_type; /* type of router which is querier on this interface */
311 	int    rti_time; /* # of slow timeouts since last old query */
312 	SLIST_ENTRY(router_info) rti_list;
313 };
314 
315 /*
316  * IPv4 multicast IGMP-layer source entry.
317  */
318 struct ip_msource {
319 	RB_ENTRY(ip_msource)    ims_link;       /* RB tree links */
320 	in_addr_t               ims_haddr;      /* host byte order */
321 	struct ims_st {
322 		uint16_t        ex;             /* # of exclusive members */
323 		uint16_t        in;             /* # of inclusive members */
324 	}                       ims_st[2];      /* state at t0, t1 */
325 	uint8_t                 ims_stp;        /* pending query */
326 };
327 
328 /*
329  * IPv4 multicast PCB-layer source entry.
330  */
331 struct in_msource {
332 	RB_ENTRY(ip_msource)    ims_link;       /* RB tree links */
333 	in_addr_t               ims_haddr;      /* host byte order */
334 	uint8_t                 imsl_st[2];     /* state before/at commit */
335 };
336 
337 RB_HEAD(ip_msource_tree, ip_msource);   /* define struct ip_msource_tree */
338 
339 RB_PROTOTYPE_SC_PREV(__private_extern__, ip_msource_tree, ip_msource,
340     ims_link, ip_msource_cmp);
341 
342 /*
343  * IPv4 multicast PCB-layer group filter descriptor.
344  */
345 struct in_mfilter {
346 	struct ip_msource_tree  imf_sources; /* source list for (S,G) */
347 	u_long                  imf_nsrc;    /* # of source entries */
348 	uint8_t                 imf_st[2];   /* state before/at commit */
349 };
350 
351 struct igmp_ifinfo;
352 
353 /*
354  * IPv4 group descriptor.
355  *
356  * For every entry on an ifnet's if_multiaddrs list which represents
357  * an IP multicast group, there is one of these structures.
358  *
359  * If any source filters are present, then a node will exist in the RB-tree
360  * to permit fast lookup by source whenever an operation takes place.
361  * This permits pre-order traversal when we issue reports.
362  * Source filter trees are kept separately from the socket layer to
363  * greatly simplify locking.
364  *
365  * When IGMPv3 is active, inm_timer is the response to group query timer.
366  * The state-change timer inm_sctimer is separate; whenever state changes
367  * for the group the state change record is generated and transmitted,
368  * and kept if retransmissions are necessary.
369  *
370  * The request count here is a count of requests for this address, not a
371  * count of pointers to this structure.
372  *
373  * FUTURE: inm_link is now only used when groups are being purged
374  * on a detaching ifnet.  It could be demoted to a SLIST_ENTRY.
375  */
376 struct in_multi {
377 	decl_lck_mtx_data(, inm_lock);
378 	u_int32_t inm_refcount;         /* reference count */
379 	u_int32_t inm_reqcnt;           /* request count for this address */
380 	u_int32_t inm_debug;            /* see ifa_debug flags */
381 	LIST_ENTRY(in_multi) inm_link;  /* queue macro glue */
382 	struct  in_addr inm_addr;       /* IP multicast address, convenience */
383 	struct  ifnet *inm_ifp;         /* back pointer to ifnet */
384 	struct  ifmultiaddr *inm_ifma;  /* back pointer to ifmultiaddr */
385 	u_int   inm_timer;              /* IGMPv1/v2 group / v3 query timer  */
386 	u_int   inm_state;              /* state of the membership */
387 	bool    inm_in_nrele;           /* if in nrele list */
388 
389 	/* New fields for IGMPv3 follow. */
390 	struct igmp_ifinfo      *inm_igi;       /* IGMP info */
391 	SLIST_ENTRY(in_multi)    inm_dtle;      /* detached waiting for rele */
392 	SLIST_ENTRY(in_multi)    inm_nrele;     /* to-be-released by IGMP */
393 	u_int32_t                inm_nrelecnt;  /* deferred release count */
394 	struct ip_msource_tree   inm_srcs;      /* tree of sources */
395 	u_long                   inm_nsrc;      /* # of tree entries */
396 
397 	struct ifqueue           inm_scq;       /* queue of pending
398 	                                         * state-change packets */
399 	struct timeval           inm_lastgsrtv; /* Time of last G-S-R query */
400 	uint16_t                 inm_sctimer;   /* state-change timer */
401 	uint16_t                 inm_scrv;      /* state-change rexmit count */
402 
403 	/*
404 	 * SSM state counters which track state at T0 (the time the last
405 	 * state-change report's RV timer went to zero) and T1
406 	 * (time of pending report, i.e. now).
407 	 * Used for computing IGMPv3 state-change reports. Several refcounts
408 	 * are maintained here to optimize for common use-cases.
409 	 */
410 	struct inm_st {
411 		uint16_t        iss_fmode;      /* IGMP filter mode */
412 		uint16_t        iss_asm;        /* # of ASM listeners */
413 		uint16_t        iss_ex;         /* # of exclusive members */
414 		uint16_t        iss_in;         /* # of inclusive members */
415 		uint16_t        iss_rec;        /* # of recorded sources */
416 	}                       inm_st[2];      /* state at t0, t1 */
417 
418 	void (*inm_trace)               /* callback fn for tracing refs */
419 	(struct in_multi *, int);
420 };
421 
422 #define INM_LOCK_ASSERT_HELD(_inm)                                      \
423 	LCK_MTX_ASSERT(&(_inm)->inm_lock, LCK_MTX_ASSERT_OWNED)
424 
425 #define INM_LOCK_ASSERT_NOTHELD(_inm)                                   \
426 	LCK_MTX_ASSERT(&(_inm)->inm_lock, LCK_MTX_ASSERT_NOTOWNED)
427 
428 #define INM_LOCK(_inm)                                                  \
429 	lck_mtx_lock(&(_inm)->inm_lock)
430 
431 #define INM_LOCK_SPIN(_inm)                                             \
432 	lck_mtx_lock_spin(&(_inm)->inm_lock)
433 
434 #define INM_CONVERT_LOCK(_inm) do {                                     \
435 	INM_LOCK_ASSERT_HELD(_inm);                                     \
436 	lck_mtx_convert_spin(&(_inm)->inm_lock);                        \
437 } while (0)
438 
439 #define INM_UNLOCK(_inm)                                                \
440 	lck_mtx_unlock(&(_inm)->inm_lock)
441 
442 #define INM_ADDREF(_inm)                                                \
443 	inm_addref(_inm, 0)
444 
445 #define INM_ADDREF_LOCKED(_inm)                                         \
446 	inm_addref(_inm, 1)
447 
448 #define INM_REMREF(_inm)                                                \
449 	inm_remref(_inm, 0)
450 
451 #define INM_REMREF_LOCKED(_inm)                                         \
452 	inm_remref(_inm, 1)
453 
454 #ifdef SYSCTL_DECL
455 SYSCTL_DECL(_net_inet_ip);
456 SYSCTL_DECL(_net_inet_raw);
457 #endif
458 
459 extern LIST_HEAD(in_multihead, in_multi) in_multihead;
460 
461 /*
462  * Structure used by macros below to remember position when stepping through
463  * all of the in_multi records.
464  */
465 struct in_multistep {
466 	struct in_multi *i_inm;
467 };
468 
469 /*
470  * Macro for looking up the in_multi record for a given IP multicast address
471  * on a given interface.  If no matching record is found, "inm" is set null.
472  *
473  * We do this differently compared other BSD implementations; instead of
474  * walking the if_multiaddrs list at the interface and returning the
475  * ifma_protospec value of a matching entry, we search the global list
476  * of in_multi records and find it that way.  Otherwise either the two
477  * structures (in_multi, ifmultiaddr) need to be ref counted both ways,
478  * which will make things too complicated, or they need to reside in the
479  * same protected domain, which they aren't.
480  *
481  * Must be called with in_multihead_lock held.
482  */
483 #define IN_LOOKUP_MULTI(addr, ifp, inm)                                 \
484 	/* struct in_addr *addr; */                                     \
485 	/* struct ifnet *ifp; */                                        \
486 	/* struct in_multi *inm; */                                     \
487 do {                                                                    \
488 	struct in_multistep _step;                                      \
489 	IN_FIRST_MULTI(_step, inm);                                     \
490 	while ((inm) != NULL) {                                         \
491 	        INM_LOCK_SPIN(inm);                                     \
492 	        if ((inm)->inm_ifp == (ifp) &&                          \
493 	            (inm)->inm_addr.s_addr == (addr)->s_addr) {         \
494 	                INM_ADDREF_LOCKED(inm);                         \
495 	                INM_UNLOCK(inm);                                \
496 	                break;                                          \
497 	        }                                                       \
498 	        INM_UNLOCK(inm);                                        \
499 	        IN_NEXT_MULTI(_step, inm);                              \
500 	}                                                               \
501 } while (0)
502 
503 /*
504  * Macro to step through all of the in_multi records, one at a time.
505  * The current position is remembered in "step", which the caller must
506  * provide.  IN_FIRST_MULTI(), below, must be called to initialize "step"
507  * and get the first record.  Both macros return a NULL "inm" when there
508  * are no remaining records.
509  *
510  * Must be called with in_multihead_lock held.
511  */
512 #define IN_NEXT_MULTI(step, inm)                                        \
513 	/* struct in_multistep  step; */                                \
514 	/* struct in_multi *inm; */                                     \
515 do {                                                                    \
516 	in_multihead_lock_assert(LCK_RW_ASSERT_HELD);                   \
517 	if (((inm) = (step).i_inm) != NULL)                             \
518 	        (step).i_inm = LIST_NEXT((step).i_inm, inm_link);       \
519 } while (0)
520 
521 #define IN_FIRST_MULTI(step, inm)                                       \
522 	/* struct in_multistep step; */                                 \
523 	/* struct in_multi *inm; */                                     \
524 do {                                                                    \
525 	in_multihead_lock_assert(LCK_RW_ASSERT_HELD);                   \
526 	(step).i_inm = LIST_FIRST(&in_multihead);                       \
527 	IN_NEXT_MULTI((step), (inm));                                   \
528 } while (0)
529 
530 extern lck_mtx_t *inet_domain_mutex;
531 extern struct domain *inetdomain;
532 
533 struct ip_moptions;
534 struct inpcb;
535 
536 /*
537  * Return values for imo_multi_filter().
538  */
539 #define MCAST_PASS              0       /* Pass */
540 #define MCAST_NOTGMEMBER        1       /* This host not a member of group */
541 #define MCAST_NOTSMEMBER        2       /* This host excluded source */
542 #define MCAST_MUTED             3       /* [deprecated] */
543 
544 /*
545  * Per-interface IPv4 structures.
546  */
547 struct in_ifextra {
548 	uint32_t                netsig_len;
549 	u_int8_t                netsig[IFNET_SIGNATURELEN];
550 };
551 #define IN_IFEXTRA(_ifp)        (_ifp->if_inetdata)
552 
553 extern u_int32_t ipv4_ll_arp_aware;
554 
555 extern int imo_multi_filter(const struct ip_moptions *,
556     const struct ifnet *, const struct sockaddr_in *,
557     const struct sockaddr_in *);
558 extern int imo_clone(struct inpcb *, struct inpcb *);
559 extern void inm_commit(struct in_multi *);
560 extern void inm_clear_recorded(struct in_multi *);
561 extern void inm_print(const struct in_multi *);
562 extern int inm_record_source(struct in_multi *inm, const in_addr_t);
563 extern void inm_release(struct in_multi *);
564 extern struct in_multi *in_addmulti(struct in_addr *, struct ifnet *);
565 extern void in_delmulti(struct in_multi *);
566 extern int in_leavegroup(struct in_multi *, struct in_mfilter *);
567 extern int in_multi_detach(struct in_multi *);
568 extern void inm_addref(struct in_multi *, int);
569 extern void inm_remref(struct in_multi *, int);
570 extern void inm_purge(struct in_multi *);
571 extern uint8_t ims_get_mode(const struct in_multi *,
572     const struct ip_msource *, uint8_t);
573 extern int in_control(struct socket *, u_long cmd, caddr_t __sized_by(IOCPARM_LEN(cmd)),
574     struct ifnet *, struct proc *);
575 extern int in_inithead(void **, int);
576 extern void in_rtqdrain(void);
577 extern struct radix_node *in_validate(struct radix_node *);
578 extern void ip_input(struct mbuf *);
579 extern void ip_input_process_list(struct mbuf *);
580 extern int in_ifadown(struct ifaddr *ifa, int);
581 extern void in_ifscrub(struct ifnet *, struct in_ifaddr *, int);
582 extern uint32_t inaddr_hashval(uint32_t);
583 extern struct in_ifaddrhashhead *inaddr_hashlookup(uint32_t);
584 extern void in_purgeaddrs(struct ifnet *);
585 extern void gre_input(struct mbuf *, int);
586 extern void imf_leave(struct in_mfilter *);
587 extern void imf_purge(struct in_mfilter *);
588 extern int inp_join_group(struct inpcb *, struct sockopt *);
589 extern int inp_leave_group(struct inpcb *, struct sockopt *);
590 extern void in_multihead_lock_exclusive(void);
591 extern void in_multihead_lock_shared(void);
592 extern void in_multihead_lock_assert(int);
593 extern void in_multihead_lock_done(void);
594 #endif /* BSD_KERNEL_PRIVATE */
595 /* INET6 stuff */
596 #include <netinet6/in6_var.h>
597 #endif /* _NETINET_IN_VAR_H_ */
598