1139823Simp/*-
21541Srgrimes * Copyright (c) 1985, 1986, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 4. Neither the name of the University nor the names of its contributors
141541Srgrimes *    may be used to endorse or promote products derived from this software
151541Srgrimes *    without specific prior written permission.
161541Srgrimes *
171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271541Srgrimes * SUCH DAMAGE.
281541Srgrimes *
2910939Swollman *	@(#)in_var.h	8.2 (Berkeley) 1/9/95
3050477Speter * $FreeBSD$
311541Srgrimes */
321541Srgrimes
332169Spaul#ifndef _NETINET_IN_VAR_H_
342169Spaul#define _NETINET_IN_VAR_H_
352169Spaul
367280Swollman#include <sys/queue.h>
3784102Sjlemon#include <sys/fnv_hash.h>
38189592Sbms#include <sys/tree.h>
397280Swollman
40189592Sbmsstruct igmp_ifinfo;
41189592Sbmsstruct in_multi;
42189592Sbmsstruct lltable;
43189592Sbms
441541Srgrimes/*
45189592Sbms * IPv4 per-interface state.
46189592Sbms */
47189592Sbmsstruct in_ifinfo {
48189592Sbms	struct lltable		*ii_llt;	/* ARP state */
49189592Sbms	struct igmp_ifinfo	*ii_igmp;	/* IGMP state */
50189592Sbms	struct in_multi		*ii_allhosts;	/* 224.0.0.1 membership */
51189592Sbms};
52189592Sbms
53189592Sbms/*
541541Srgrimes * Interface address, Internet version.  One of these structures
5521666Swollman * is allocated for each Internet address on an interface.
561541Srgrimes * The ifaddr structure contains the protocol-independent part
571541Srgrimes * of the structure and is assumed to be first.
581541Srgrimes */
591541Srgrimesstruct in_ifaddr {
601541Srgrimes	struct	ifaddr ia_ifa;		/* protocol-independent info */
611541Srgrimes#define	ia_ifp		ia_ifa.ifa_ifp
621541Srgrimes#define ia_flags	ia_ifa.ifa_flags
63226572Sglebius					/* ia_subnet{,mask} in host order */
64226572Sglebius	u_long	ia_subnet;		/* subnet address */
65226572Sglebius	u_long	ia_subnetmask;		/* mask of subnet */
6684102Sjlemon	LIST_ENTRY(in_ifaddr) ia_hash;	/* entry in bucket of inet addresses */
6784102Sjlemon	TAILQ_ENTRY(in_ifaddr) ia_link;	/* list of internet addresses */
681541Srgrimes	struct	sockaddr_in ia_addr;	/* reserve space for interface name */
691541Srgrimes	struct	sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */
701541Srgrimes#define	ia_broadaddr	ia_dstaddr
711541Srgrimes	struct	sockaddr_in ia_sockmask; /* reserve space for general netmask */
721541Srgrimes};
731541Srgrimes
741541Srgrimesstruct	in_aliasreq {
751541Srgrimes	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
761541Srgrimes	struct	sockaddr_in ifra_addr;
771541Srgrimes	struct	sockaddr_in ifra_broadaddr;
781541Srgrimes#define ifra_dstaddr ifra_broadaddr
791541Srgrimes	struct	sockaddr_in ifra_mask;
801541Srgrimes};
811541Srgrimes/*
821541Srgrimes * Given a pointer to an in_ifaddr (ifaddr),
831541Srgrimes * return a pointer to the addr as a sockaddr_in.
841541Srgrimes */
853865Sswallace#define IA_SIN(ia)    (&(((struct in_ifaddr *)(ia))->ia_addr))
863865Sswallace#define IA_DSTSIN(ia) (&(((struct in_ifaddr *)(ia))->ia_dstaddr))
871541Srgrimes
881541Srgrimes#define IN_LNAOF(in, ifa) \
891541Srgrimes	((ntohl((in).s_addr) & ~((struct in_ifaddr *)(ifa)->ia_subnetmask))
901541Srgrimes
918876Srgrimes
9255205Speter#ifdef	_KERNEL
937090Sbdeextern	u_char	inetctlerrmap[];
941541Srgrimes
95191120Skmacy#define LLTABLE(ifp)	\
96191120Skmacy	((struct in_ifinfo *)(ifp)->if_afdata[AF_INET])->ii_llt
97133874Srwatson/*
9884102Sjlemon * Hash table for IP addresses.
9984102Sjlemon */
100186048SbzTAILQ_HEAD(in_ifaddrhead, in_ifaddr);
101186048SbzLIST_HEAD(in_ifaddrhashhead, in_ifaddr);
10284102Sjlemon
103195699SrwatsonVNET_DECLARE(struct in_ifaddrhashhead *, in_ifaddrhashtbl);
104195699SrwatsonVNET_DECLARE(struct in_ifaddrhead, in_ifaddrhead);
105195699SrwatsonVNET_DECLARE(u_long, in_ifaddrhmask);		/* mask for hash table */
106195699Srwatson
107195727Srwatson#define	V_in_ifaddrhashtbl	VNET(in_ifaddrhashtbl)
108195727Srwatson#define	V_in_ifaddrhead		VNET(in_ifaddrhead)
109195727Srwatson#define	V_in_ifaddrhmask	VNET(in_ifaddrhmask)
110195699Srwatson
11184102Sjlemon#define INADDR_NHASH_LOG2       9
11284102Sjlemon#define INADDR_NHASH		(1 << INADDR_NHASH_LOG2)
11384102Sjlemon#define INADDR_HASHVAL(x)	fnv_32_buf((&(x)), sizeof(x), FNV1_32_INIT)
11484102Sjlemon#define INADDR_HASH(x) \
115181803Sbz	(&V_in_ifaddrhashtbl[INADDR_HASHVAL(x) & V_in_ifaddrhmask])
11684102Sjlemon
117194951Srwatsonextern	struct rwlock in_ifaddr_lock;
118194951Srwatson
119194951Srwatson#define	IN_IFADDR_LOCK_ASSERT()	rw_assert(&in_ifaddr_lock, RA_LOCKED)
120194951Srwatson#define	IN_IFADDR_RLOCK()	rw_rlock(&in_ifaddr_lock)
121194951Srwatson#define	IN_IFADDR_RLOCK_ASSERT()	rw_assert(&in_ifaddr_lock, RA_RLOCKED)
122194951Srwatson#define	IN_IFADDR_RUNLOCK()	rw_runlock(&in_ifaddr_lock)
123194951Srwatson#define	IN_IFADDR_WLOCK()	rw_wlock(&in_ifaddr_lock)
124194951Srwatson#define	IN_IFADDR_WLOCK_ASSERT()	rw_assert(&in_ifaddr_lock, RA_WLOCKED)
125194951Srwatson#define	IN_IFADDR_WUNLOCK()	rw_wunlock(&in_ifaddr_lock)
126194951Srwatson
127162615Sbms/*
128162625Sbms * Macro for finding the internet address structure (in_ifaddr)
129162615Sbms * corresponding to one of our IP addresses (in_addr).
130162615Sbms */
131162615Sbms#define INADDR_TO_IFADDR(addr, ia) \
132162615Sbms	/* struct in_addr addr; */ \
133162615Sbms	/* struct in_ifaddr *ia; */ \
134162615Sbmsdo { \
135162615Sbms\
136162615Sbms	LIST_FOREACH(ia, INADDR_HASH((addr).s_addr), ia_hash) \
137162615Sbms		if (IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) \
138162615Sbms			break; \
139162615Sbms} while (0)
14084102Sjlemon
1411541Srgrimes/*
1421541Srgrimes * Macro for finding the interface (ifnet structure) corresponding to one
1431541Srgrimes * of our IP addresses.
1441541Srgrimes */
1451541Srgrimes#define INADDR_TO_IFP(addr, ifp) \
1461541Srgrimes	/* struct in_addr addr; */ \
1471541Srgrimes	/* struct ifnet *ifp; */ \
1481541Srgrimes{ \
14979821Sru	struct in_ifaddr *ia; \
1501541Srgrimes\
151162615Sbms	INADDR_TO_IFADDR(addr, ia); \
1521541Srgrimes	(ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \
1531541Srgrimes}
1541541Srgrimes
1551541Srgrimes/*
1561541Srgrimes * Macro for finding the internet address structure (in_ifaddr) corresponding
1571541Srgrimes * to a given interface (ifnet structure).
1581541Srgrimes */
159194760Srwatson#define IFP_TO_IA(ifp, ia)						\
160194760Srwatson	/* struct ifnet *ifp; */					\
161194760Srwatson	/* struct in_ifaddr *ia; */					\
162238713Sglebiusdo {									\
163238713Sglebius	IN_IFADDR_RLOCK();						\
164194760Srwatson	for ((ia) = TAILQ_FIRST(&V_in_ifaddrhead);			\
165194760Srwatson	    (ia) != NULL && (ia)->ia_ifp != (ifp);			\
166194760Srwatson	    (ia) = TAILQ_NEXT((ia), ia_link))				\
167194760Srwatson		continue;						\
168194760Srwatson	if ((ia) != NULL)						\
169194760Srwatson		ifa_ref(&(ia)->ia_ifa);					\
170238713Sglebius	IN_IFADDR_RUNLOCK();						\
171238713Sglebius} while (0)
1721541Srgrimes#endif
1731541Srgrimes
1741541Srgrimes/*
175185088Szec * IP datagram reassembly.
176185088Szec */
177185088Szec#define	IPREASS_NHASH_LOG2	6
178185088Szec#define	IPREASS_NHASH		(1 << IPREASS_NHASH_LOG2)
179185088Szec#define	IPREASS_HMASK		(IPREASS_NHASH - 1)
180185088Szec#define	IPREASS_HASH(x,y) \
181185088Szec	(((((x) & 0xF) | ((((x) >> 8) & 0xF) << 4)) ^ (y)) & IPREASS_HMASK)
182185088Szec
183185088Szec/*
184189592Sbms * Legacy IPv4 IGMP per-link structure.
1852531Swollman */
1862531Swollmanstruct router_info {
18714622Sfenner	struct ifnet *rti_ifp;
18814622Sfenner	int    rti_type; /* type of router which is querier on this interface */
18914622Sfenner	int    rti_time; /* # of slow timeouts since last old query */
190119180Srwatson	SLIST_ENTRY(router_info) rti_list;
1912531Swollman};
1922531Swollman
1932531Swollman/*
194189592Sbms * Per-interface IGMP router version information.
1951541Srgrimes */
196189592Sbmsstruct igmp_ifinfo {
197189592Sbms	LIST_ENTRY(igmp_ifinfo) igi_link;
198189592Sbms	struct ifnet *igi_ifp;	/* interface this instance belongs to */
199189592Sbms	uint32_t igi_version;	/* IGMPv3 Host Compatibility Mode */
200189592Sbms	uint32_t igi_v1_timer;	/* IGMPv1 Querier Present timer (s) */
201189592Sbms	uint32_t igi_v2_timer;	/* IGMPv2 Querier Present timer (s) */
202189592Sbms	uint32_t igi_v3_timer;	/* IGMPv3 General Query (interface) timer (s)*/
203189592Sbms	uint32_t igi_flags;	/* IGMP per-interface flags */
204189592Sbms	uint32_t igi_rv;	/* IGMPv3 Robustness Variable */
205189592Sbms	uint32_t igi_qi;	/* IGMPv3 Query Interval (s) */
206189592Sbms	uint32_t igi_qri;	/* IGMPv3 Query Response Interval (s) */
207189592Sbms	uint32_t igi_uri;	/* IGMPv3 Unsolicited Report Interval (s) */
208189592Sbms	SLIST_HEAD(,in_multi)	igi_relinmhead; /* released groups */
209189592Sbms	struct ifqueue	 igi_gq;	/* queue of general query responses */
210189592Sbms};
211189592Sbms
212189592Sbms#define IGIF_SILENT	0x00000001	/* Do not use IGMP on this ifp */
213189592Sbms#define IGIF_LOOPBACK	0x00000002	/* Send IGMP reports to loopback */
214189592Sbms
215189592Sbms/*
216189592Sbms * IPv4 multicast IGMP-layer source entry.
217189592Sbms */
218189592Sbmsstruct ip_msource {
219189592Sbms	RB_ENTRY(ip_msource)	ims_link;	/* RB tree links */
220189592Sbms	in_addr_t		ims_haddr;	/* host byte order */
221189592Sbms	struct ims_st {
222189592Sbms		uint16_t	ex;		/* # of exclusive members */
223189592Sbms		uint16_t	in;		/* # of inclusive members */
224189592Sbms	}			ims_st[2];	/* state at t0, t1 */
225189592Sbms	uint8_t			ims_stp;	/* pending query */
226189592Sbms};
227189592Sbms
228189592Sbms/*
229189592Sbms * IPv4 multicast PCB-layer source entry.
230189592Sbms */
231189592Sbmsstruct in_msource {
232189592Sbms	RB_ENTRY(ip_msource)	ims_link;	/* RB tree links */
233189592Sbms	in_addr_t		ims_haddr;	/* host byte order */
234189592Sbms	uint8_t			imsl_st[2];	/* state before/at commit */
235189592Sbms};
236189592Sbms
237189592SbmsRB_HEAD(ip_msource_tree, ip_msource);	/* define struct ip_msource_tree */
238189592Sbms
239189592Sbmsstatic __inline int
240189592Sbmsip_msource_cmp(const struct ip_msource *a, const struct ip_msource *b)
241189592Sbms{
242189592Sbms
243189592Sbms	if (a->ims_haddr < b->ims_haddr)
244189592Sbms		return (-1);
245189592Sbms	if (a->ims_haddr == b->ims_haddr)
246189592Sbms		return (0);
247189592Sbms	return (1);
248189592Sbms}
249189592SbmsRB_PROTOTYPE(ip_msource_tree, ip_msource, ims_link, ip_msource_cmp);
250189592Sbms
251189592Sbms/*
252189592Sbms * IPv4 multicast PCB-layer group filter descriptor.
253189592Sbms */
254189592Sbmsstruct in_mfilter {
255189592Sbms	struct ip_msource_tree	imf_sources; /* source list for (S,G) */
256189592Sbms	u_long			imf_nsrc;    /* # of source entries */
257189592Sbms	uint8_t			imf_st[2];   /* state before/at commit */
258189592Sbms};
259189592Sbms
260189592Sbms/*
261189592Sbms * IPv4 group descriptor.
262189592Sbms *
263189592Sbms * For every entry on an ifnet's if_multiaddrs list which represents
264189592Sbms * an IP multicast group, there is one of these structures.
265189592Sbms *
266189592Sbms * If any source filters are present, then a node will exist in the RB-tree
267189592Sbms * to permit fast lookup by source whenever an operation takes place.
268189592Sbms * This permits pre-order traversal when we issue reports.
269189592Sbms * Source filter trees are kept separately from the socket layer to
270189592Sbms * greatly simplify locking.
271189592Sbms *
272189592Sbms * When IGMPv3 is active, inm_timer is the response to group query timer.
273189592Sbms * The state-change timer inm_sctimer is separate; whenever state changes
274189592Sbms * for the group the state change record is generated and transmitted,
275189592Sbms * and kept if retransmissions are necessary.
276189592Sbms *
277189592Sbms * FUTURE: inm_link is now only used when groups are being purged
278189592Sbms * on a detaching ifnet. It could be demoted to a SLIST_ENTRY, but
279189592Sbms * because it is at the very start of the struct, we can't do this
280189592Sbms * w/o breaking the ABI for ifmcstat.
281189592Sbms */
2821541Srgrimesstruct in_multi {
283189592Sbms	LIST_ENTRY(in_multi) inm_link;	/* to-be-released by in_ifdetach */
28421666Swollman	struct	in_addr inm_addr;	/* IP multicast address, convenience */
2851541Srgrimes	struct	ifnet *inm_ifp;		/* back pointer to ifnet */
28621666Swollman	struct	ifmultiaddr *inm_ifma;	/* back pointer to ifmultiaddr */
287189592Sbms	u_int	inm_timer;		/* IGMPv1/v2 group / v3 query timer */
288189592Sbms	u_int	inm_state;		/* state of the membership */
289189592Sbms	void	*inm_rti;		/* unused, legacy field */
290167729Sbms	u_int	inm_refcount;		/* reference count */
291189592Sbms
292189592Sbms	/* New fields for IGMPv3 follow. */
293189592Sbms	struct igmp_ifinfo	*inm_igi;	/* IGMP info */
294189592Sbms	SLIST_ENTRY(in_multi)	 inm_nrele;	/* to-be-released by IGMP */
295189592Sbms	struct ip_msource_tree	 inm_srcs;	/* tree of sources */
296189592Sbms	u_long			 inm_nsrc;	/* # of tree entries */
297189592Sbms
298189592Sbms	struct ifqueue		 inm_scq;	/* queue of pending
299189592Sbms						 * state-change packets */
300189592Sbms	struct timeval		 inm_lastgsrtv;	/* Time of last G-S-R query */
301189592Sbms	uint16_t		 inm_sctimer;	/* state-change timer */
302189592Sbms	uint16_t		 inm_scrv;	/* state-change rexmit count */
303189592Sbms
304189592Sbms	/*
305189592Sbms	 * SSM state counters which track state at T0 (the time the last
306189592Sbms	 * state-change report's RV timer went to zero) and T1
307189592Sbms	 * (time of pending report, i.e. now).
308189592Sbms	 * Used for computing IGMPv3 state-change reports. Several refcounts
309189592Sbms	 * are maintained here to optimize for common use-cases.
310189592Sbms	 */
311189592Sbms	struct inm_st {
312189592Sbms		uint16_t	iss_fmode;	/* IGMP filter mode */
313189592Sbms		uint16_t	iss_asm;	/* # of ASM listeners */
314189592Sbms		uint16_t	iss_ex;		/* # of exclusive members */
315189592Sbms		uint16_t	iss_in;		/* # of inclusive members */
316189592Sbms		uint16_t	iss_rec;	/* # of recorded sources */
317189592Sbms	}			inm_st[2];	/* state at t0, t1 */
3181541Srgrimes};
3191541Srgrimes
320170613Sbms/*
321189592Sbms * Helper function to derive the filter mode on a source entry
322189592Sbms * from its internal counters. Predicates are:
323189592Sbms *  A source is only excluded if all listeners exclude it.
324189592Sbms *  A source is only included if no listeners exclude it,
325189592Sbms *  and at least one listener includes it.
326189592Sbms * May be used by ifmcstat(8).
327170613Sbms */
328189592Sbmsstatic __inline uint8_t
329189592Sbmsims_get_mode(const struct in_multi *inm, const struct ip_msource *ims,
330189592Sbms    uint8_t t)
331189592Sbms{
332170613Sbms
333189592Sbms	t = !!t;
334189592Sbms	if (inm->inm_st[t].iss_ex > 0 &&
335189592Sbms	    inm->inm_st[t].iss_ex == ims->ims_st[t].ex)
336189592Sbms		return (MCAST_EXCLUDE);
337189592Sbms	else if (ims->ims_st[t].in > 0 && ims->ims_st[t].ex == 0)
338189592Sbms		return (MCAST_INCLUDE);
339189592Sbms	return (MCAST_UNDEFINED);
340189592Sbms}
341189592Sbms
34255205Speter#ifdef _KERNEL
34344078Sdfr
34444078Sdfr#ifdef SYSCTL_DECL
345136713SandreSYSCTL_DECL(_net_inet);
34644078SdfrSYSCTL_DECL(_net_inet_ip);
34744078SdfrSYSCTL_DECL(_net_inet_raw);
34844078Sdfr#endif
34944078Sdfr
3501541Srgrimes/*
351148682Srwatson * Lock macros for IPv4 layer multicast address lists.  IPv4 lock goes
352148682Srwatson * before link layer multicast locks in the lock order.  In most cases,
353148682Srwatson * consumers of IN_*_MULTI() macros should acquire the locks before
354148682Srwatson * calling them; users of the in_{add,del}multi() functions should not.
355148682Srwatson */
356148682Srwatsonextern struct mtx in_multi_mtx;
357148682Srwatson#define	IN_MULTI_LOCK()		mtx_lock(&in_multi_mtx)
358148682Srwatson#define	IN_MULTI_UNLOCK()	mtx_unlock(&in_multi_mtx)
359148682Srwatson#define	IN_MULTI_LOCK_ASSERT()	mtx_assert(&in_multi_mtx, MA_OWNED)
360189592Sbms#define	IN_MULTI_UNLOCK_ASSERT() mtx_assert(&in_multi_mtx, MA_NOTOWNED)
361148682Srwatson
362148682Srwatson/*
363189592Sbms * Function for looking up an in_multi record for an IPv4 multicast address
364189592Sbms * on a given interface. ifp must be valid. If no record found, return NULL.
365189592Sbms * The IN_MULTI_LOCK and IF_ADDR_LOCK on ifp must be held.
3661541Srgrimes */
367189592Sbmsstatic __inline struct in_multi *
368189592Sbmsinm_lookup_locked(struct ifnet *ifp, const struct in_addr ina)
369189592Sbms{
370189592Sbms	struct ifmultiaddr *ifma;
371189592Sbms	struct in_multi *inm;
3721541Srgrimes
373189592Sbms	IN_MULTI_LOCK_ASSERT();
374189592Sbms	IF_ADDR_LOCK_ASSERT(ifp);
375189592Sbms
376189592Sbms	inm = NULL;
377189592Sbms	TAILQ_FOREACH(ifma, &((ifp)->if_multiaddrs), ifma_link) {
378189592Sbms		if (ifma->ifma_addr->sa_family == AF_INET) {
379189592Sbms			inm = (struct in_multi *)ifma->ifma_protospec;
380189592Sbms			if (inm->inm_addr.s_addr == ina.s_addr)
381189592Sbms				break;
382189592Sbms			inm = NULL;
383189592Sbms		}
384189592Sbms	}
385189592Sbms	return (inm);
386189592Sbms}
387189592Sbms
3881541Srgrimes/*
389189592Sbms * Wrapper for inm_lookup_locked().
390189592Sbms * The IF_ADDR_LOCK will be taken on ifp and released on return.
3911541Srgrimes */
392189592Sbmsstatic __inline struct in_multi *
393189592Sbmsinm_lookup(struct ifnet *ifp, const struct in_addr ina)
394189592Sbms{
395189592Sbms	struct in_multi *inm;
3961541Srgrimes
397189592Sbms	IN_MULTI_LOCK_ASSERT();
398233200Sjhb	IF_ADDR_RLOCK(ifp);
399189592Sbms	inm = inm_lookup_locked(ifp, ina);
400233200Sjhb	IF_ADDR_RUNLOCK(ifp);
401189592Sbms
402189592Sbms	return (inm);
403189592Sbms}
404189592Sbms
405189592Sbms/* Acquire an in_multi record. */
406189592Sbmsstatic __inline void
407189592Sbmsinm_acquire_locked(struct in_multi *inm)
408189592Sbms{
409189592Sbms
410189592Sbms	IN_MULTI_LOCK_ASSERT();
411189592Sbms	++inm->inm_refcount;
412189592Sbms}
413189592Sbms
4141541Srgrimes/*
415189592Sbms * Return values for imo_multi_filter().
4161541Srgrimes */
417189592Sbms#define MCAST_PASS		0	/* Pass */
418189592Sbms#define MCAST_NOTGMEMBER	1	/* This host not a member of group */
419189592Sbms#define MCAST_NOTSMEMBER	2	/* This host excluded source */
420189592Sbms#define MCAST_MUTED		3	/* [deprecated] */
4211541Srgrimes
422178888Sjulianstruct	rtentry;
42336192Sdgstruct	route;
424170613Sbmsstruct	ip_moptions;
425242640Smelifarostruct radix_node_head;
426170613Sbms
427189592Sbmsint	imo_multi_filter(const struct ip_moptions *, const struct ifnet *,
428189592Sbms	    const struct sockaddr *, const struct sockaddr *);
429189592Sbmsvoid	inm_commit(struct in_multi *);
430189592Sbmsvoid	inm_clear_recorded(struct in_multi *);
431189592Sbmsvoid	inm_print(const struct in_multi *);
432189592Sbmsint	inm_record_source(struct in_multi *inm, const in_addr_t);
433189592Sbmsvoid	inm_release(struct in_multi *);
434189592Sbmsvoid	inm_release_locked(struct in_multi *);
435189592Sbmsstruct	in_multi *
436189592Sbms	in_addmulti(struct in_addr *, struct ifnet *);
43792723Salfredvoid	in_delmulti(struct in_multi *);
438189592Sbmsint	in_joingroup(struct ifnet *, const struct in_addr *,
439189592Sbms	    /*const*/ struct in_mfilter *, struct in_multi **);
440189592Sbmsint	in_joingroup_locked(struct ifnet *, const struct in_addr *,
441189592Sbms	    /*const*/ struct in_mfilter *, struct in_multi **);
442189592Sbmsint	in_leavegroup(struct in_multi *, /*const*/ struct in_mfilter *);
443189592Sbmsint	in_leavegroup_locked(struct in_multi *,
444189592Sbms	    /*const*/ struct in_mfilter *);
44592723Salfredint	in_control(struct socket *, u_long, caddr_t, struct ifnet *,
44693085Sbde	    struct thread *);
44792723Salfredvoid	in_rtqdrain(void);
44892723Salfredvoid	ip_input(struct mbuf *);
44992723Salfredint	in_ifadown(struct ifaddr *ifa, int);
450222143Sqinglivoid	in_ifscrub(struct ifnet *, struct in_ifaddr *, u_int);
451154518Sandrestruct	mbuf	*ip_fastforward(struct mbuf *);
452186119Sqinglivoid	*in_domifattach(struct ifnet *);
453186119Sqinglivoid	in_domifdetach(struct ifnet *, void *);
4542169Spaul
455186119Sqingli
456178888Sjulian/* XXX */
457178888Sjulianvoid	 in_rtalloc_ign(struct route *ro, u_long ignflags, u_int fibnum);
458178888Sjulianvoid	 in_rtalloc(struct route *ro, u_int fibnum);
459178888Sjulianstruct rtentry *in_rtalloc1(struct sockaddr *, int, u_long, u_int);
460178888Sjulianvoid	 in_rtredirect(struct sockaddr *, struct sockaddr *,
461178888Sjulian	    struct sockaddr *, int, struct sockaddr *, u_int);
462178888Sjulianint	 in_rtrequest(int, struct sockaddr *,
463178888Sjulian	    struct sockaddr *, struct sockaddr *, int, struct rtentry **, u_int);
464242640Smelifarovoid	in_setmatchfunc(struct radix_node_head *, int);
465178888Sjulian
466178888Sjulian#if 0
467178888Sjulianint	 in_rt_getifa(struct rt_addrinfo *, u_int fibnum);
468178888Sjulianint	 in_rtioctl(u_long, caddr_t, u_int);
469178888Sjulianint	 in_rtrequest1(int, struct rt_addrinfo *, struct rtentry **, u_int);
470178888Sjulian#endif
47155205Speter#endif /* _KERNEL */
47210939Swollman
47352904Sshin/* INET6 stuff */
47452904Sshin#include <netinet6/in6_var.h>
47552904Sshin
47610939Swollman#endif /* _NETINET_IN_VAR_H_ */
477