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: stable/10/sys/netinet/in_var.h 309340 2016-11-30 22:20:23Z vangyzen $
311541Srgrimes */
321541Srgrimes
332169Spaul#ifndef _NETINET_IN_VAR_H_
342169Spaul#define _NETINET_IN_VAR_H_
352169Spaul
36309340Svangyzen#include <sys/callout.h>
377280Swollman#include <sys/queue.h>
3884102Sjlemon#include <sys/fnv_hash.h>
39189592Sbms#include <sys/tree.h>
407280Swollman
41189592Sbmsstruct igmp_ifinfo;
42189592Sbmsstruct in_multi;
43189592Sbmsstruct lltable;
44189592Sbms
451541Srgrimes/*
46189592Sbms * IPv4 per-interface state.
47189592Sbms */
48189592Sbmsstruct in_ifinfo {
49189592Sbms	struct lltable		*ii_llt;	/* ARP state */
50189592Sbms	struct igmp_ifinfo	*ii_igmp;	/* IGMP state */
51189592Sbms	struct in_multi		*ii_allhosts;	/* 224.0.0.1 membership */
52189592Sbms};
53189592Sbms
54189592Sbms/*
551541Srgrimes * Interface address, Internet version.  One of these structures
5621666Swollman * is allocated for each Internet address on an interface.
571541Srgrimes * The ifaddr structure contains the protocol-independent part
581541Srgrimes * of the structure and is assumed to be first.
591541Srgrimes */
601541Srgrimesstruct in_ifaddr {
611541Srgrimes	struct	ifaddr ia_ifa;		/* protocol-independent info */
621541Srgrimes#define	ia_ifp		ia_ifa.ifa_ifp
631541Srgrimes#define ia_flags	ia_ifa.ifa_flags
64226401Sglebius					/* ia_subnet{,mask} in host order */
65226401Sglebius	u_long	ia_subnet;		/* subnet address */
66226401Sglebius	u_long	ia_subnetmask;		/* mask of subnet */
6784102Sjlemon	LIST_ENTRY(in_ifaddr) ia_hash;	/* entry in bucket of inet addresses */
6884102Sjlemon	TAILQ_ENTRY(in_ifaddr) ia_link;	/* list of internet addresses */
691541Srgrimes	struct	sockaddr_in ia_addr;	/* reserve space for interface name */
701541Srgrimes	struct	sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */
711541Srgrimes#define	ia_broadaddr	ia_dstaddr
721541Srgrimes	struct	sockaddr_in ia_sockmask; /* reserve space for general netmask */
73309340Svangyzen	struct	callout ia_garp_timer;	/* timer for retransmitting GARPs */
74309340Svangyzen	int	ia_garp_count;		/* count of retransmitted GARPs */
751541Srgrimes};
761541Srgrimes
771541Srgrimesstruct	in_aliasreq {
781541Srgrimes	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
791541Srgrimes	struct	sockaddr_in ifra_addr;
801541Srgrimes	struct	sockaddr_in ifra_broadaddr;
811541Srgrimes#define ifra_dstaddr ifra_broadaddr
821541Srgrimes	struct	sockaddr_in ifra_mask;
83228571Sglebius	int	ifra_vhid;
841541Srgrimes};
851541Srgrimes/*
861541Srgrimes * Given a pointer to an in_ifaddr (ifaddr),
871541Srgrimes * return a pointer to the addr as a sockaddr_in.
881541Srgrimes */
893865Sswallace#define IA_SIN(ia)    (&(((struct in_ifaddr *)(ia))->ia_addr))
903865Sswallace#define IA_DSTSIN(ia) (&(((struct in_ifaddr *)(ia))->ia_dstaddr))
91229815Sglebius#define IA_MASKSIN(ia) (&(((struct in_ifaddr *)(ia))->ia_sockmask))
921541Srgrimes
931541Srgrimes#define IN_LNAOF(in, ifa) \
941541Srgrimes	((ntohl((in).s_addr) & ~((struct in_ifaddr *)(ifa)->ia_subnetmask))
951541Srgrimes
968876Srgrimes
9755205Speter#ifdef	_KERNEL
987090Sbdeextern	u_char	inetctlerrmap[];
991541Srgrimes
100191120Skmacy#define LLTABLE(ifp)	\
101191120Skmacy	((struct in_ifinfo *)(ifp)->if_afdata[AF_INET])->ii_llt
102133874Srwatson/*
10384102Sjlemon * Hash table for IP addresses.
10484102Sjlemon */
105186048SbzTAILQ_HEAD(in_ifaddrhead, in_ifaddr);
106186048SbzLIST_HEAD(in_ifaddrhashhead, in_ifaddr);
10784102Sjlemon
108195699SrwatsonVNET_DECLARE(struct in_ifaddrhashhead *, in_ifaddrhashtbl);
109195699SrwatsonVNET_DECLARE(struct in_ifaddrhead, in_ifaddrhead);
110195699SrwatsonVNET_DECLARE(u_long, in_ifaddrhmask);		/* mask for hash table */
111195699Srwatson
112195727Srwatson#define	V_in_ifaddrhashtbl	VNET(in_ifaddrhashtbl)
113195727Srwatson#define	V_in_ifaddrhead		VNET(in_ifaddrhead)
114195727Srwatson#define	V_in_ifaddrhmask	VNET(in_ifaddrhmask)
115195699Srwatson
11684102Sjlemon#define INADDR_NHASH_LOG2       9
11784102Sjlemon#define INADDR_NHASH		(1 << INADDR_NHASH_LOG2)
11884102Sjlemon#define INADDR_HASHVAL(x)	fnv_32_buf((&(x)), sizeof(x), FNV1_32_INIT)
11984102Sjlemon#define INADDR_HASH(x) \
120181803Sbz	(&V_in_ifaddrhashtbl[INADDR_HASHVAL(x) & V_in_ifaddrhmask])
12184102Sjlemon
122250300Sandreextern	struct rwlock in_ifaddr_lock;
123194951Srwatson
124194951Srwatson#define	IN_IFADDR_LOCK_ASSERT()	rw_assert(&in_ifaddr_lock, RA_LOCKED)
125194951Srwatson#define	IN_IFADDR_RLOCK()	rw_rlock(&in_ifaddr_lock)
126194951Srwatson#define	IN_IFADDR_RLOCK_ASSERT()	rw_assert(&in_ifaddr_lock, RA_RLOCKED)
127194951Srwatson#define	IN_IFADDR_RUNLOCK()	rw_runlock(&in_ifaddr_lock)
128194951Srwatson#define	IN_IFADDR_WLOCK()	rw_wlock(&in_ifaddr_lock)
129194951Srwatson#define	IN_IFADDR_WLOCK_ASSERT()	rw_assert(&in_ifaddr_lock, RA_WLOCKED)
130194951Srwatson#define	IN_IFADDR_WUNLOCK()	rw_wunlock(&in_ifaddr_lock)
131194951Srwatson
132162615Sbms/*
133162625Sbms * Macro for finding the internet address structure (in_ifaddr)
134162615Sbms * corresponding to one of our IP addresses (in_addr).
135162615Sbms */
136162615Sbms#define INADDR_TO_IFADDR(addr, ia) \
137162615Sbms	/* struct in_addr addr; */ \
138162615Sbms	/* struct in_ifaddr *ia; */ \
139162615Sbmsdo { \
140162615Sbms\
141162615Sbms	LIST_FOREACH(ia, INADDR_HASH((addr).s_addr), ia_hash) \
142162615Sbms		if (IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) \
143162615Sbms			break; \
144162615Sbms} while (0)
14584102Sjlemon
1461541Srgrimes/*
1471541Srgrimes * Macro for finding the interface (ifnet structure) corresponding to one
1481541Srgrimes * of our IP addresses.
1491541Srgrimes */
1501541Srgrimes#define INADDR_TO_IFP(addr, ifp) \
1511541Srgrimes	/* struct in_addr addr; */ \
1521541Srgrimes	/* struct ifnet *ifp; */ \
1531541Srgrimes{ \
15479821Sru	struct in_ifaddr *ia; \
1551541Srgrimes\
156162615Sbms	INADDR_TO_IFADDR(addr, ia); \
1571541Srgrimes	(ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \
1581541Srgrimes}
1591541Srgrimes
1601541Srgrimes/*
1611541Srgrimes * Macro for finding the internet address structure (in_ifaddr) corresponding
1621541Srgrimes * to a given interface (ifnet structure).
1631541Srgrimes */
164194760Srwatson#define IFP_TO_IA(ifp, ia)						\
165194760Srwatson	/* struct ifnet *ifp; */					\
166194760Srwatson	/* struct in_ifaddr *ia; */					\
167238572Sglebiusdo {									\
168238572Sglebius	IN_IFADDR_RLOCK();						\
169194760Srwatson	for ((ia) = TAILQ_FIRST(&V_in_ifaddrhead);			\
170194760Srwatson	    (ia) != NULL && (ia)->ia_ifp != (ifp);			\
171194760Srwatson	    (ia) = TAILQ_NEXT((ia), ia_link))				\
172194760Srwatson		continue;						\
173194760Srwatson	if ((ia) != NULL)						\
174194760Srwatson		ifa_ref(&(ia)->ia_ifa);					\
175238572Sglebius	IN_IFADDR_RUNLOCK();						\
176238572Sglebius} while (0)
1771541Srgrimes#endif
1781541Srgrimes
1791541Srgrimes/*
180185088Szec * IP datagram reassembly.
181185088Szec */
182185088Szec#define	IPREASS_NHASH_LOG2	6
183185088Szec#define	IPREASS_NHASH		(1 << IPREASS_NHASH_LOG2)
184185088Szec#define	IPREASS_HMASK		(IPREASS_NHASH - 1)
185185088Szec#define	IPREASS_HASH(x,y) \
186185088Szec	(((((x) & 0xF) | ((((x) >> 8) & 0xF) << 4)) ^ (y)) & IPREASS_HMASK)
187185088Szec
188185088Szec/*
189189592Sbms * Legacy IPv4 IGMP per-link structure.
1902531Swollman */
1912531Swollmanstruct router_info {
19214622Sfenner	struct ifnet *rti_ifp;
19314622Sfenner	int    rti_type; /* type of router which is querier on this interface */
19414622Sfenner	int    rti_time; /* # of slow timeouts since last old query */
195119180Srwatson	SLIST_ENTRY(router_info) rti_list;
1962531Swollman};
1972531Swollman
1982531Swollman/*
199189592Sbms * Per-interface IGMP router version information.
2001541Srgrimes */
201189592Sbmsstruct igmp_ifinfo {
202189592Sbms	LIST_ENTRY(igmp_ifinfo) igi_link;
203189592Sbms	struct ifnet *igi_ifp;	/* interface this instance belongs to */
204189592Sbms	uint32_t igi_version;	/* IGMPv3 Host Compatibility Mode */
205189592Sbms	uint32_t igi_v1_timer;	/* IGMPv1 Querier Present timer (s) */
206189592Sbms	uint32_t igi_v2_timer;	/* IGMPv2 Querier Present timer (s) */
207189592Sbms	uint32_t igi_v3_timer;	/* IGMPv3 General Query (interface) timer (s)*/
208189592Sbms	uint32_t igi_flags;	/* IGMP per-interface flags */
209189592Sbms	uint32_t igi_rv;	/* IGMPv3 Robustness Variable */
210189592Sbms	uint32_t igi_qi;	/* IGMPv3 Query Interval (s) */
211189592Sbms	uint32_t igi_qri;	/* IGMPv3 Query Response Interval (s) */
212189592Sbms	uint32_t igi_uri;	/* IGMPv3 Unsolicited Report Interval (s) */
213189592Sbms	SLIST_HEAD(,in_multi)	igi_relinmhead; /* released groups */
214189592Sbms	struct ifqueue	 igi_gq;	/* queue of general query responses */
215189592Sbms};
216189592Sbms
217189592Sbms#define IGIF_SILENT	0x00000001	/* Do not use IGMP on this ifp */
218189592Sbms#define IGIF_LOOPBACK	0x00000002	/* Send IGMP reports to loopback */
219189592Sbms
220189592Sbms/*
221189592Sbms * IPv4 multicast IGMP-layer source entry.
222189592Sbms */
223189592Sbmsstruct ip_msource {
224189592Sbms	RB_ENTRY(ip_msource)	ims_link;	/* RB tree links */
225189592Sbms	in_addr_t		ims_haddr;	/* host byte order */
226189592Sbms	struct ims_st {
227189592Sbms		uint16_t	ex;		/* # of exclusive members */
228189592Sbms		uint16_t	in;		/* # of inclusive members */
229189592Sbms	}			ims_st[2];	/* state at t0, t1 */
230189592Sbms	uint8_t			ims_stp;	/* pending query */
231189592Sbms};
232189592Sbms
233189592Sbms/*
234189592Sbms * IPv4 multicast PCB-layer source entry.
235189592Sbms */
236189592Sbmsstruct in_msource {
237189592Sbms	RB_ENTRY(ip_msource)	ims_link;	/* RB tree links */
238189592Sbms	in_addr_t		ims_haddr;	/* host byte order */
239189592Sbms	uint8_t			imsl_st[2];	/* state before/at commit */
240189592Sbms};
241189592Sbms
242189592SbmsRB_HEAD(ip_msource_tree, ip_msource);	/* define struct ip_msource_tree */
243189592Sbms
244189592Sbmsstatic __inline int
245189592Sbmsip_msource_cmp(const struct ip_msource *a, const struct ip_msource *b)
246189592Sbms{
247189592Sbms
248189592Sbms	if (a->ims_haddr < b->ims_haddr)
249189592Sbms		return (-1);
250189592Sbms	if (a->ims_haddr == b->ims_haddr)
251189592Sbms		return (0);
252189592Sbms	return (1);
253189592Sbms}
254189592SbmsRB_PROTOTYPE(ip_msource_tree, ip_msource, ims_link, ip_msource_cmp);
255189592Sbms
256189592Sbms/*
257189592Sbms * IPv4 multicast PCB-layer group filter descriptor.
258189592Sbms */
259189592Sbmsstruct in_mfilter {
260189592Sbms	struct ip_msource_tree	imf_sources; /* source list for (S,G) */
261189592Sbms	u_long			imf_nsrc;    /* # of source entries */
262189592Sbms	uint8_t			imf_st[2];   /* state before/at commit */
263189592Sbms};
264189592Sbms
265189592Sbms/*
266189592Sbms * IPv4 group descriptor.
267189592Sbms *
268189592Sbms * For every entry on an ifnet's if_multiaddrs list which represents
269189592Sbms * an IP multicast group, there is one of these structures.
270189592Sbms *
271189592Sbms * If any source filters are present, then a node will exist in the RB-tree
272189592Sbms * to permit fast lookup by source whenever an operation takes place.
273189592Sbms * This permits pre-order traversal when we issue reports.
274189592Sbms * Source filter trees are kept separately from the socket layer to
275189592Sbms * greatly simplify locking.
276189592Sbms *
277189592Sbms * When IGMPv3 is active, inm_timer is the response to group query timer.
278189592Sbms * The state-change timer inm_sctimer is separate; whenever state changes
279189592Sbms * for the group the state change record is generated and transmitted,
280189592Sbms * and kept if retransmissions are necessary.
281189592Sbms *
282189592Sbms * FUTURE: inm_link is now only used when groups are being purged
283189592Sbms * on a detaching ifnet. It could be demoted to a SLIST_ENTRY, but
284189592Sbms * because it is at the very start of the struct, we can't do this
285189592Sbms * w/o breaking the ABI for ifmcstat.
286189592Sbms */
2871541Srgrimesstruct in_multi {
288189592Sbms	LIST_ENTRY(in_multi) inm_link;	/* to-be-released by in_ifdetach */
28921666Swollman	struct	in_addr inm_addr;	/* IP multicast address, convenience */
2901541Srgrimes	struct	ifnet *inm_ifp;		/* back pointer to ifnet */
29121666Swollman	struct	ifmultiaddr *inm_ifma;	/* back pointer to ifmultiaddr */
292189592Sbms	u_int	inm_timer;		/* IGMPv1/v2 group / v3 query timer */
293189592Sbms	u_int	inm_state;		/* state of the membership */
294189592Sbms	void	*inm_rti;		/* unused, legacy field */
295167729Sbms	u_int	inm_refcount;		/* reference count */
296189592Sbms
297189592Sbms	/* New fields for IGMPv3 follow. */
298189592Sbms	struct igmp_ifinfo	*inm_igi;	/* IGMP info */
299189592Sbms	SLIST_ENTRY(in_multi)	 inm_nrele;	/* to-be-released by IGMP */
300189592Sbms	struct ip_msource_tree	 inm_srcs;	/* tree of sources */
301189592Sbms	u_long			 inm_nsrc;	/* # of tree entries */
302189592Sbms
303189592Sbms	struct ifqueue		 inm_scq;	/* queue of pending
304189592Sbms						 * state-change packets */
305189592Sbms	struct timeval		 inm_lastgsrtv;	/* Time of last G-S-R query */
306189592Sbms	uint16_t		 inm_sctimer;	/* state-change timer */
307189592Sbms	uint16_t		 inm_scrv;	/* state-change rexmit count */
308189592Sbms
309189592Sbms	/*
310189592Sbms	 * SSM state counters which track state at T0 (the time the last
311189592Sbms	 * state-change report's RV timer went to zero) and T1
312189592Sbms	 * (time of pending report, i.e. now).
313189592Sbms	 * Used for computing IGMPv3 state-change reports. Several refcounts
314189592Sbms	 * are maintained here to optimize for common use-cases.
315189592Sbms	 */
316189592Sbms	struct inm_st {
317189592Sbms		uint16_t	iss_fmode;	/* IGMP filter mode */
318189592Sbms		uint16_t	iss_asm;	/* # of ASM listeners */
319189592Sbms		uint16_t	iss_ex;		/* # of exclusive members */
320189592Sbms		uint16_t	iss_in;		/* # of inclusive members */
321189592Sbms		uint16_t	iss_rec;	/* # of recorded sources */
322189592Sbms	}			inm_st[2];	/* state at t0, t1 */
3231541Srgrimes};
3241541Srgrimes
325170613Sbms/*
326189592Sbms * Helper function to derive the filter mode on a source entry
327189592Sbms * from its internal counters. Predicates are:
328189592Sbms *  A source is only excluded if all listeners exclude it.
329189592Sbms *  A source is only included if no listeners exclude it,
330189592Sbms *  and at least one listener includes it.
331189592Sbms * May be used by ifmcstat(8).
332170613Sbms */
333189592Sbmsstatic __inline uint8_t
334189592Sbmsims_get_mode(const struct in_multi *inm, const struct ip_msource *ims,
335189592Sbms    uint8_t t)
336189592Sbms{
337170613Sbms
338189592Sbms	t = !!t;
339189592Sbms	if (inm->inm_st[t].iss_ex > 0 &&
340189592Sbms	    inm->inm_st[t].iss_ex == ims->ims_st[t].ex)
341189592Sbms		return (MCAST_EXCLUDE);
342189592Sbms	else if (ims->ims_st[t].in > 0 && ims->ims_st[t].ex == 0)
343189592Sbms		return (MCAST_INCLUDE);
344189592Sbms	return (MCAST_UNDEFINED);
345189592Sbms}
346189592Sbms
34755205Speter#ifdef _KERNEL
34844078Sdfr
34944078Sdfr#ifdef SYSCTL_DECL
350136713SandreSYSCTL_DECL(_net_inet);
35144078SdfrSYSCTL_DECL(_net_inet_ip);
35244078SdfrSYSCTL_DECL(_net_inet_raw);
35344078Sdfr#endif
35444078Sdfr
3551541Srgrimes/*
356148682Srwatson * Lock macros for IPv4 layer multicast address lists.  IPv4 lock goes
357148682Srwatson * before link layer multicast locks in the lock order.  In most cases,
358148682Srwatson * consumers of IN_*_MULTI() macros should acquire the locks before
359148682Srwatson * calling them; users of the in_{add,del}multi() functions should not.
360148682Srwatson */
361148682Srwatsonextern struct mtx in_multi_mtx;
362148682Srwatson#define	IN_MULTI_LOCK()		mtx_lock(&in_multi_mtx)
363148682Srwatson#define	IN_MULTI_UNLOCK()	mtx_unlock(&in_multi_mtx)
364148682Srwatson#define	IN_MULTI_LOCK_ASSERT()	mtx_assert(&in_multi_mtx, MA_OWNED)
365189592Sbms#define	IN_MULTI_UNLOCK_ASSERT() mtx_assert(&in_multi_mtx, MA_NOTOWNED)
366148682Srwatson
367148682Srwatson/*
368189592Sbms * Function for looking up an in_multi record for an IPv4 multicast address
369189592Sbms * on a given interface. ifp must be valid. If no record found, return NULL.
370189592Sbms * The IN_MULTI_LOCK and IF_ADDR_LOCK on ifp must be held.
3711541Srgrimes */
372189592Sbmsstatic __inline struct in_multi *
373189592Sbmsinm_lookup_locked(struct ifnet *ifp, const struct in_addr ina)
374189592Sbms{
375189592Sbms	struct ifmultiaddr *ifma;
376189592Sbms	struct in_multi *inm;
3771541Srgrimes
378189592Sbms	IN_MULTI_LOCK_ASSERT();
379189592Sbms	IF_ADDR_LOCK_ASSERT(ifp);
380189592Sbms
381189592Sbms	inm = NULL;
382189592Sbms	TAILQ_FOREACH(ifma, &((ifp)->if_multiaddrs), ifma_link) {
383189592Sbms		if (ifma->ifma_addr->sa_family == AF_INET) {
384189592Sbms			inm = (struct in_multi *)ifma->ifma_protospec;
385189592Sbms			if (inm->inm_addr.s_addr == ina.s_addr)
386189592Sbms				break;
387189592Sbms			inm = NULL;
388189592Sbms		}
389189592Sbms	}
390189592Sbms	return (inm);
391189592Sbms}
392189592Sbms
3931541Srgrimes/*
394189592Sbms * Wrapper for inm_lookup_locked().
395189592Sbms * The IF_ADDR_LOCK will be taken on ifp and released on return.
3961541Srgrimes */
397189592Sbmsstatic __inline struct in_multi *
398189592Sbmsinm_lookup(struct ifnet *ifp, const struct in_addr ina)
399189592Sbms{
400189592Sbms	struct in_multi *inm;
4011541Srgrimes
402189592Sbms	IN_MULTI_LOCK_ASSERT();
403229621Sjhb	IF_ADDR_RLOCK(ifp);
404189592Sbms	inm = inm_lookup_locked(ifp, ina);
405229621Sjhb	IF_ADDR_RUNLOCK(ifp);
406189592Sbms
407189592Sbms	return (inm);
408189592Sbms}
409189592Sbms
410189592Sbms/* Acquire an in_multi record. */
411189592Sbmsstatic __inline void
412189592Sbmsinm_acquire_locked(struct in_multi *inm)
413189592Sbms{
414189592Sbms
415189592Sbms	IN_MULTI_LOCK_ASSERT();
416189592Sbms	++inm->inm_refcount;
417189592Sbms}
418189592Sbms
4191541Srgrimes/*
420189592Sbms * Return values for imo_multi_filter().
4211541Srgrimes */
422189592Sbms#define MCAST_PASS		0	/* Pass */
423189592Sbms#define MCAST_NOTGMEMBER	1	/* This host not a member of group */
424189592Sbms#define MCAST_NOTSMEMBER	2	/* This host excluded source */
425189592Sbms#define MCAST_MUTED		3	/* [deprecated] */
4261541Srgrimes
427178888Sjulianstruct	rtentry;
42836192Sdgstruct	route;
429170613Sbmsstruct	ip_moptions;
430241406Smelifarostruct radix_node_head;
431170613Sbms
432189592Sbmsint	imo_multi_filter(const struct ip_moptions *, const struct ifnet *,
433189592Sbms	    const struct sockaddr *, const struct sockaddr *);
434189592Sbmsvoid	inm_commit(struct in_multi *);
435189592Sbmsvoid	inm_clear_recorded(struct in_multi *);
436189592Sbmsvoid	inm_print(const struct in_multi *);
437189592Sbmsint	inm_record_source(struct in_multi *inm, const in_addr_t);
438189592Sbmsvoid	inm_release(struct in_multi *);
439189592Sbmsvoid	inm_release_locked(struct in_multi *);
440189592Sbmsstruct	in_multi *
441189592Sbms	in_addmulti(struct in_addr *, struct ifnet *);
44292723Salfredvoid	in_delmulti(struct in_multi *);
443189592Sbmsint	in_joingroup(struct ifnet *, const struct in_addr *,
444189592Sbms	    /*const*/ struct in_mfilter *, struct in_multi **);
445189592Sbmsint	in_joingroup_locked(struct ifnet *, const struct in_addr *,
446189592Sbms	    /*const*/ struct in_mfilter *, struct in_multi **);
447189592Sbmsint	in_leavegroup(struct in_multi *, /*const*/ struct in_mfilter *);
448189592Sbmsint	in_leavegroup_locked(struct in_multi *,
449189592Sbms	    /*const*/ struct in_mfilter *);
45092723Salfredint	in_control(struct socket *, u_long, caddr_t, struct ifnet *,
45193085Sbde	    struct thread *);
45292723Salfredvoid	in_rtqdrain(void);
453228571Sglebiusint	in_addprefix(struct in_ifaddr *, int);
454228571Sglebiusint	in_scrubprefix(struct in_ifaddr *, u_int);
45592723Salfredvoid	ip_input(struct mbuf *);
45692723Salfredint	in_ifadown(struct ifaddr *ifa, int);
457222143Sqinglivoid	in_ifscrub(struct ifnet *, struct in_ifaddr *, u_int);
458295896Sgnnstruct	mbuf	*ip_fastforward(struct mbuf *);
459186119Sqinglivoid	*in_domifattach(struct ifnet *);
460186119Sqinglivoid	in_domifdetach(struct ifnet *, void *);
4612169Spaul
462186119Sqingli
463178888Sjulian/* XXX */
464178888Sjulianvoid	 in_rtalloc_ign(struct route *ro, u_long ignflags, u_int fibnum);
465178888Sjulianvoid	 in_rtalloc(struct route *ro, u_int fibnum);
466178888Sjulianstruct rtentry *in_rtalloc1(struct sockaddr *, int, u_long, u_int);
467178888Sjulianvoid	 in_rtredirect(struct sockaddr *, struct sockaddr *,
468178888Sjulian	    struct sockaddr *, int, struct sockaddr *, u_int);
469178888Sjulianint	 in_rtrequest(int, struct sockaddr *,
470178888Sjulian	    struct sockaddr *, struct sockaddr *, int, struct rtentry **, u_int);
471241406Smelifarovoid	in_setmatchfunc(struct radix_node_head *, int);
472178888Sjulian
473178888Sjulian#if 0
474178888Sjulianint	 in_rt_getifa(struct rt_addrinfo *, u_int fibnum);
475178888Sjulianint	 in_rtioctl(u_long, caddr_t, u_int);
476178888Sjulianint	 in_rtrequest1(int, struct rt_addrinfo *, struct rtentry **, u_int);
477178888Sjulian#endif
47855205Speter#endif /* _KERNEL */
47910939Swollman
48052904Sshin/* INET6 stuff */
48152904Sshin#include <netinet6/in6_var.h>
48252904Sshin
48310939Swollman#endif /* _NETINET_IN_VAR_H_ */
484