xref: /freebsd/sys/netinet/in_var.h (revision d10910e6cee0dca8be3d5a7fdbe404a15d9e7b52)
1c398230bSWarner Losh /*-
2df8bae1dSRodney W. Grimes  * Copyright (c) 1985, 1986, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
6df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
7df8bae1dSRodney W. Grimes  * are met:
8df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
9df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
10df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
11df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
12df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
13df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
14df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
15df8bae1dSRodney W. Grimes  *    without specific prior written permission.
16df8bae1dSRodney W. Grimes  *
17df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
28df8bae1dSRodney W. Grimes  *
292180b925SGarrett Wollman  *	@(#)in_var.h	8.2 (Berkeley) 1/9/95
30c3aac50fSPeter Wemm  * $FreeBSD$
31df8bae1dSRodney W. Grimes  */
32df8bae1dSRodney W. Grimes 
33707f139eSPaul Richards #ifndef _NETINET_IN_VAR_H_
34707f139eSPaul Richards #define _NETINET_IN_VAR_H_
35707f139eSPaul Richards 
36ffa5b11aSGarrett Wollman #include <sys/queue.h>
37ca925d9cSJonathan Lemon #include <sys/fnv_hash.h>
38d10910e6SBruce M Simpson #include <sys/tree.h>
39d10910e6SBruce M Simpson 
40d10910e6SBruce M Simpson struct igmp_ifinfo;
41d10910e6SBruce M Simpson struct in_multi;
42d10910e6SBruce M Simpson struct lltable;
43d10910e6SBruce M Simpson 
44d10910e6SBruce M Simpson /*
45d10910e6SBruce M Simpson  * IPv4 per-interface state.
46d10910e6SBruce M Simpson  */
47d10910e6SBruce M Simpson struct in_ifinfo {
48d10910e6SBruce M Simpson 	struct lltable		*ii_llt;	/* ARP state */
49d10910e6SBruce M Simpson 	struct igmp_ifinfo	*ii_igmp;	/* IGMP state */
50d10910e6SBruce M Simpson 	struct in_multi		*ii_allhosts;	/* 224.0.0.1 membership */
51d10910e6SBruce M Simpson };
52ffa5b11aSGarrett Wollman 
53df8bae1dSRodney W. Grimes /*
54df8bae1dSRodney W. Grimes  * Interface address, Internet version.  One of these structures
55477180fbSGarrett Wollman  * is allocated for each Internet address on an interface.
56df8bae1dSRodney W. Grimes  * The ifaddr structure contains the protocol-independent part
57df8bae1dSRodney W. Grimes  * of the structure and is assumed to be first.
58df8bae1dSRodney W. Grimes  */
59df8bae1dSRodney W. Grimes struct in_ifaddr {
60df8bae1dSRodney W. Grimes 	struct	ifaddr ia_ifa;		/* protocol-independent info */
61df8bae1dSRodney W. Grimes #define	ia_ifp		ia_ifa.ifa_ifp
62df8bae1dSRodney W. Grimes #define ia_flags	ia_ifa.ifa_flags
63df8bae1dSRodney W. Grimes 					/* ia_{,sub}net{,mask} in host order */
64df8bae1dSRodney W. Grimes 	u_long	ia_net;			/* network number of interface */
65df8bae1dSRodney W. Grimes 	u_long	ia_netmask;		/* mask of net part */
66df8bae1dSRodney W. Grimes 	u_long	ia_subnet;		/* subnet number, including net */
67df8bae1dSRodney W. Grimes 	u_long	ia_subnetmask;		/* mask of subnet part */
68df8bae1dSRodney W. Grimes 	struct	in_addr ia_netbroadcast; /* to recognize net broadcasts */
69ca925d9cSJonathan Lemon 	LIST_ENTRY(in_ifaddr) ia_hash;	/* entry in bucket of inet addresses */
70ca925d9cSJonathan Lemon 	TAILQ_ENTRY(in_ifaddr) ia_link;	/* list of internet addresses */
71df8bae1dSRodney W. Grimes 	struct	sockaddr_in ia_addr;	/* reserve space for interface name */
72df8bae1dSRodney W. Grimes 	struct	sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */
73df8bae1dSRodney W. Grimes #define	ia_broadaddr	ia_dstaddr
74df8bae1dSRodney W. Grimes 	struct	sockaddr_in ia_sockmask; /* reserve space for general netmask */
75df8bae1dSRodney W. Grimes };
76df8bae1dSRodney W. Grimes 
77df8bae1dSRodney W. Grimes struct	in_aliasreq {
78df8bae1dSRodney W. Grimes 	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
79df8bae1dSRodney W. Grimes 	struct	sockaddr_in ifra_addr;
80df8bae1dSRodney W. Grimes 	struct	sockaddr_in ifra_broadaddr;
81df8bae1dSRodney W. Grimes #define ifra_dstaddr ifra_broadaddr
82df8bae1dSRodney W. Grimes 	struct	sockaddr_in ifra_mask;
83df8bae1dSRodney W. Grimes };
84df8bae1dSRodney W. Grimes /*
85df8bae1dSRodney W. Grimes  * Given a pointer to an in_ifaddr (ifaddr),
86df8bae1dSRodney W. Grimes  * return a pointer to the addr as a sockaddr_in.
87df8bae1dSRodney W. Grimes  */
88df8bae1dSRodney W. Grimes #define IA_SIN(ia)    (&(((struct in_ifaddr *)(ia))->ia_addr))
891bc8a809SSteven Wallace #define IA_DSTSIN(ia) (&(((struct in_ifaddr *)(ia))->ia_dstaddr))
90df8bae1dSRodney W. Grimes 
91df8bae1dSRodney W. Grimes #define IN_LNAOF(in, ifa) \
92df8bae1dSRodney W. Grimes 	((ntohl((in).s_addr) & ~((struct in_ifaddr *)(ifa)->ia_subnetmask))
93df8bae1dSRodney W. Grimes 
94df8bae1dSRodney W. Grimes 
95664a31e4SPeter Wemm #ifdef	_KERNEL
96b5e8ce9fSBruce Evans extern	u_char	inetctlerrmap[];
97df8bae1dSRodney W. Grimes 
98df8bae1dSRodney W. Grimes /*
99ca925d9cSJonathan Lemon  * Hash table for IP addresses.
100ca925d9cSJonathan Lemon  */
1011b193af6SBjoern A. Zeeb TAILQ_HEAD(in_ifaddrhead, in_ifaddr);
1021b193af6SBjoern A. Zeeb LIST_HEAD(in_ifaddrhashhead, in_ifaddr);
1031b193af6SBjoern A. Zeeb #ifdef VIMAGE_GLOBALS
1041b193af6SBjoern A. Zeeb extern	struct in_ifaddrhashhead *in_ifaddrhashtbl;
1051b193af6SBjoern A. Zeeb extern	struct in_ifaddrhead in_ifaddrhead;
106ca925d9cSJonathan Lemon extern	u_long in_ifaddrhmask;			/* mask for hash table */
1071b193af6SBjoern A. Zeeb #endif
108ca925d9cSJonathan Lemon 
109ca925d9cSJonathan Lemon #define INADDR_NHASH_LOG2       9
110ca925d9cSJonathan Lemon #define INADDR_NHASH		(1 << INADDR_NHASH_LOG2)
111ca925d9cSJonathan Lemon #define INADDR_HASHVAL(x)	fnv_32_buf((&(x)), sizeof(x), FNV1_32_INIT)
112ca925d9cSJonathan Lemon #define INADDR_HASH(x) \
113603724d3SBjoern A. Zeeb 	(&V_in_ifaddrhashtbl[INADDR_HASHVAL(x) & V_in_ifaddrhmask])
114ca925d9cSJonathan Lemon 
11507ea6709SBruce M Simpson /*
116e2fd806bSBruce M Simpson  * Macro for finding the internet address structure (in_ifaddr)
11707ea6709SBruce M Simpson  * corresponding to one of our IP addresses (in_addr).
11807ea6709SBruce M Simpson  */
11907ea6709SBruce M Simpson #define INADDR_TO_IFADDR(addr, ia) \
12007ea6709SBruce M Simpson 	/* struct in_addr addr; */ \
12107ea6709SBruce M Simpson 	/* struct in_ifaddr *ia; */ \
12207ea6709SBruce M Simpson do { \
12307ea6709SBruce M Simpson \
12407ea6709SBruce M Simpson 	LIST_FOREACH(ia, INADDR_HASH((addr).s_addr), ia_hash) \
12507ea6709SBruce M Simpson 		if (IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) \
12607ea6709SBruce M Simpson 			break; \
12707ea6709SBruce M Simpson } while (0)
128ca925d9cSJonathan Lemon 
129ca925d9cSJonathan Lemon /*
130df8bae1dSRodney W. Grimes  * Macro for finding the interface (ifnet structure) corresponding to one
131df8bae1dSRodney W. Grimes  * of our IP addresses.
132df8bae1dSRodney W. Grimes  */
133df8bae1dSRodney W. Grimes #define INADDR_TO_IFP(addr, ifp) \
134df8bae1dSRodney W. Grimes 	/* struct in_addr addr; */ \
135df8bae1dSRodney W. Grimes 	/* struct ifnet *ifp; */ \
136df8bae1dSRodney W. Grimes { \
1379f81cc84SRuslan Ermilov 	struct in_ifaddr *ia; \
138df8bae1dSRodney W. Grimes \
13907ea6709SBruce M Simpson 	INADDR_TO_IFADDR(addr, ia); \
140df8bae1dSRodney W. Grimes 	(ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \
141df8bae1dSRodney W. Grimes }
142df8bae1dSRodney W. Grimes 
143df8bae1dSRodney W. Grimes /*
144df8bae1dSRodney W. Grimes  * Macro for finding the internet address structure (in_ifaddr) corresponding
145df8bae1dSRodney W. Grimes  * to a given interface (ifnet structure).
146df8bae1dSRodney W. Grimes  */
147df8bae1dSRodney W. Grimes #define IFP_TO_IA(ifp, ia) \
148df8bae1dSRodney W. Grimes 	/* struct ifnet *ifp; */ \
149df8bae1dSRodney W. Grimes 	/* struct in_ifaddr *ia; */ \
150df8bae1dSRodney W. Grimes { \
151603724d3SBjoern A. Zeeb 	for ((ia) = TAILQ_FIRST(&V_in_ifaddrhead); \
152df8bae1dSRodney W. Grimes 	    (ia) != NULL && (ia)->ia_ifp != (ifp); \
153ef9e85abSPoul-Henning Kamp 	    (ia) = TAILQ_NEXT((ia), ia_link)) \
154df8bae1dSRodney W. Grimes 		continue; \
155df8bae1dSRodney W. Grimes }
156df8bae1dSRodney W. Grimes #endif
157df8bae1dSRodney W. Grimes 
158df8bae1dSRodney W. Grimes /*
15944e33a07SMarko Zec  * IP datagram reassembly.
16044e33a07SMarko Zec  */
16144e33a07SMarko Zec #define	IPREASS_NHASH_LOG2	6
16244e33a07SMarko Zec #define	IPREASS_NHASH		(1 << IPREASS_NHASH_LOG2)
16344e33a07SMarko Zec #define	IPREASS_HMASK		(IPREASS_NHASH - 1)
16444e33a07SMarko Zec #define	IPREASS_HASH(x,y) \
16544e33a07SMarko Zec 	(((((x) & 0xF) | ((((x) >> 8) & 0xF) << 4)) ^ (y)) & IPREASS_HMASK)
16644e33a07SMarko Zec 
16744e33a07SMarko Zec /*
168d10910e6SBruce M Simpson  * Legacy IPv4 IGMP per-link structure.
169f0068c4aSGarrett Wollman  */
170f0068c4aSGarrett Wollman struct router_info {
17149fa849bSBill Fenner 	struct ifnet *rti_ifp;
17249fa849bSBill Fenner 	int    rti_type; /* type of router which is querier on this interface */
17349fa849bSBill Fenner 	int    rti_time; /* # of slow timeouts since last old query */
1746c4b2ad3SRobert Watson 	SLIST_ENTRY(router_info) rti_list;
175f0068c4aSGarrett Wollman };
176f0068c4aSGarrett Wollman 
177f0068c4aSGarrett Wollman /*
178d10910e6SBruce M Simpson  * Per-interface IGMP router version information.
179d10910e6SBruce M Simpson  */
180d10910e6SBruce M Simpson struct igmp_ifinfo {
181d10910e6SBruce M Simpson 	LIST_ENTRY(igmp_ifinfo) igi_link;
182d10910e6SBruce M Simpson 	struct ifnet *igi_ifp;	/* interface this instance belongs to */
183d10910e6SBruce M Simpson 	uint32_t igi_version;	/* IGMPv3 Host Compatibility Mode */
184d10910e6SBruce M Simpson 	uint32_t igi_v1_timer;	/* IGMPv1 Querier Present timer (s) */
185d10910e6SBruce M Simpson 	uint32_t igi_v2_timer;	/* IGMPv2 Querier Present timer (s) */
186d10910e6SBruce M Simpson 	uint32_t igi_v3_timer;	/* IGMPv3 General Query (interface) timer (s)*/
187d10910e6SBruce M Simpson 	uint32_t igi_flags;	/* IGMP per-interface flags */
188d10910e6SBruce M Simpson 	uint32_t igi_rv;	/* IGMPv3 Robustness Variable */
189d10910e6SBruce M Simpson 	uint32_t igi_qi;	/* IGMPv3 Query Interval (s) */
190d10910e6SBruce M Simpson 	uint32_t igi_qri;	/* IGMPv3 Query Response Interval (s) */
191d10910e6SBruce M Simpson 	uint32_t igi_uri;	/* IGMPv3 Unsolicited Report Interval (s) */
192d10910e6SBruce M Simpson 	SLIST_HEAD(,in_multi)	igi_relinmhead; /* released groups */
193d10910e6SBruce M Simpson 	struct ifqueue	 igi_gq;	/* queue of general query responses */
194d10910e6SBruce M Simpson };
195d10910e6SBruce M Simpson 
196d10910e6SBruce M Simpson #define IGIF_SILENT	0x00000001	/* Do not use IGMP on this ifp */
197d10910e6SBruce M Simpson #define IGIF_LOOPBACK	0x00000002	/* Send IGMP reports to loopback */
198d10910e6SBruce M Simpson 
199d10910e6SBruce M Simpson /*
200d10910e6SBruce M Simpson  * IPv4 multicast IGMP-layer source entry.
201d10910e6SBruce M Simpson  */
202d10910e6SBruce M Simpson struct ip_msource {
203d10910e6SBruce M Simpson 	RB_ENTRY(ip_msource)	ims_link;	/* RB tree links */
204d10910e6SBruce M Simpson 	in_addr_t		ims_haddr;	/* host byte order */
205d10910e6SBruce M Simpson 	struct ims_st {
206d10910e6SBruce M Simpson 		uint16_t	ex;		/* # of exclusive members */
207d10910e6SBruce M Simpson 		uint16_t	in;		/* # of inclusive members */
208d10910e6SBruce M Simpson 	}			ims_st[2];	/* state at t0, t1 */
209d10910e6SBruce M Simpson 	uint8_t			ims_stp;	/* pending query */
210d10910e6SBruce M Simpson };
211d10910e6SBruce M Simpson 
212d10910e6SBruce M Simpson /*
213d10910e6SBruce M Simpson  * IPv4 multicast PCB-layer source entry.
214d10910e6SBruce M Simpson  */
215d10910e6SBruce M Simpson struct in_msource {
216d10910e6SBruce M Simpson 	RB_ENTRY(ip_msource)	ims_link;	/* RB tree links */
217d10910e6SBruce M Simpson 	in_addr_t		ims_haddr;	/* host byte order */
218d10910e6SBruce M Simpson 	uint8_t			imsl_st[2];	/* state before/at commit */
219d10910e6SBruce M Simpson };
220d10910e6SBruce M Simpson 
221d10910e6SBruce M Simpson RB_HEAD(ip_msource_tree, ip_msource);	/* define struct ip_msource_tree */
222d10910e6SBruce M Simpson 
223d10910e6SBruce M Simpson static __inline int
224d10910e6SBruce M Simpson ip_msource_cmp(const struct ip_msource *a, const struct ip_msource *b)
225d10910e6SBruce M Simpson {
226d10910e6SBruce M Simpson 
227d10910e6SBruce M Simpson 	if (a->ims_haddr < b->ims_haddr)
228d10910e6SBruce M Simpson 		return (-1);
229d10910e6SBruce M Simpson 	if (a->ims_haddr == b->ims_haddr)
230d10910e6SBruce M Simpson 		return (0);
231d10910e6SBruce M Simpson 	return (1);
232d10910e6SBruce M Simpson }
233d10910e6SBruce M Simpson RB_PROTOTYPE(ip_msource_tree, ip_msource, ims_link, ip_msource_cmp);
234d10910e6SBruce M Simpson 
235d10910e6SBruce M Simpson /*
236d10910e6SBruce M Simpson  * IPv4 multicast PCB-layer group filter descriptor.
237d10910e6SBruce M Simpson  */
238d10910e6SBruce M Simpson struct in_mfilter {
239d10910e6SBruce M Simpson 	struct ip_msource_tree	imf_sources; /* source list for (S,G) */
240d10910e6SBruce M Simpson 	u_long			imf_nsrc;    /* # of source entries */
241d10910e6SBruce M Simpson 	uint8_t			imf_st[2];   /* state before/at commit */
242d10910e6SBruce M Simpson };
243d10910e6SBruce M Simpson 
244d10910e6SBruce M Simpson /*
245d10910e6SBruce M Simpson  * IPv4 group descriptor.
246d10910e6SBruce M Simpson  *
247d10910e6SBruce M Simpson  * For every entry on an ifnet's if_multiaddrs list which represents
248d10910e6SBruce M Simpson  * an IP multicast group, there is one of these structures.
249d10910e6SBruce M Simpson  *
250d10910e6SBruce M Simpson  * If any source filters are present, then a node will exist in the RB-tree
251d10910e6SBruce M Simpson  * to permit fast lookup by source whenever an operation takes place.
252d10910e6SBruce M Simpson  * This permits pre-order traversal when we issue reports.
253d10910e6SBruce M Simpson  * Source filter trees are kept separately from the socket layer to
254d10910e6SBruce M Simpson  * greatly simplify locking.
255d10910e6SBruce M Simpson  *
256d10910e6SBruce M Simpson  * When IGMPv3 is active, inm_timer is the response to group query timer.
257d10910e6SBruce M Simpson  * The state-change timer inm_sctimer is separate; whenever state changes
258d10910e6SBruce M Simpson  * for the group the state change record is generated and transmitted,
259d10910e6SBruce M Simpson  * and kept if retransmissions are necessary.
260d10910e6SBruce M Simpson  *
261d10910e6SBruce M Simpson  * FUTURE: inm_link is now only used when groups are being purged
262d10910e6SBruce M Simpson  * on a detaching ifnet. It could be demoted to a SLIST_ENTRY, but
263d10910e6SBruce M Simpson  * because it is at the very start of the struct, we can't do this
264d10910e6SBruce M Simpson  * w/o breaking the ABI for ifmcstat.
265df8bae1dSRodney W. Grimes  */
266df8bae1dSRodney W. Grimes struct in_multi {
267d10910e6SBruce M Simpson 	LIST_ENTRY(in_multi) inm_link;	/* to-be-released by in_ifdetach */
268477180fbSGarrett Wollman 	struct	in_addr inm_addr;	/* IP multicast address, convenience */
269df8bae1dSRodney W. Grimes 	struct	ifnet *inm_ifp;		/* back pointer to ifnet */
270477180fbSGarrett Wollman 	struct	ifmultiaddr *inm_ifma;	/* back pointer to ifmultiaddr */
271d10910e6SBruce M Simpson 	u_int	inm_timer;		/* IGMPv1/v2 group / v3 query timer */
272f0068c4aSGarrett Wollman 	u_int	inm_state;		/* state of the membership */
273d10910e6SBruce M Simpson 	void	*inm_rti;		/* unused, legacy field */
274ec002feeSBruce M Simpson 	u_int	inm_refcount;		/* reference count */
275d10910e6SBruce M Simpson 
276d10910e6SBruce M Simpson 	/* New fields for IGMPv3 follow. */
277d10910e6SBruce M Simpson 	struct igmp_ifinfo	*inm_igi;	/* IGMP info */
278d10910e6SBruce M Simpson 	SLIST_ENTRY(in_multi)	 inm_nrele;	/* to-be-released by IGMP */
279d10910e6SBruce M Simpson 	struct ip_msource_tree	 inm_srcs;	/* tree of sources */
280d10910e6SBruce M Simpson 	u_long			 inm_nsrc;	/* # of tree entries */
281d10910e6SBruce M Simpson 
282d10910e6SBruce M Simpson 	struct ifqueue		 inm_scq;	/* queue of pending
283d10910e6SBruce M Simpson 						 * state-change packets */
284d10910e6SBruce M Simpson 	struct timeval		 inm_lastgsrtv;	/* Time of last G-S-R query */
285d10910e6SBruce M Simpson 	uint16_t		 inm_sctimer;	/* state-change timer */
286d10910e6SBruce M Simpson 	uint16_t		 inm_scrv;	/* state-change rexmit count */
287d10910e6SBruce M Simpson 
288d10910e6SBruce M Simpson 	/*
289d10910e6SBruce M Simpson 	 * SSM state counters which track state at T0 (the time the last
290d10910e6SBruce M Simpson 	 * state-change report's RV timer went to zero) and T1
291d10910e6SBruce M Simpson 	 * (time of pending report, i.e. now).
292d10910e6SBruce M Simpson 	 * Used for computing IGMPv3 state-change reports. Several refcounts
293d10910e6SBruce M Simpson 	 * are maintained here to optimize for common use-cases.
294d10910e6SBruce M Simpson 	 */
295d10910e6SBruce M Simpson 	struct inm_st {
296d10910e6SBruce M Simpson 		uint16_t	iss_fmode;	/* IGMP filter mode */
297d10910e6SBruce M Simpson 		uint16_t	iss_asm;	/* # of ASM listeners */
298d10910e6SBruce M Simpson 		uint16_t	iss_ex;		/* # of exclusive members */
299d10910e6SBruce M Simpson 		uint16_t	iss_in;		/* # of inclusive members */
300d10910e6SBruce M Simpson 		uint16_t	iss_rec;	/* # of recorded sources */
301d10910e6SBruce M Simpson 	}			inm_st[2];	/* state at t0, t1 */
302df8bae1dSRodney W. Grimes };
303df8bae1dSRodney W. Grimes 
30471498f30SBruce M Simpson /*
305d10910e6SBruce M Simpson  * Helper function to derive the filter mode on a source entry
306d10910e6SBruce M Simpson  * from its internal counters. Predicates are:
307d10910e6SBruce M Simpson  *  A source is only excluded if all listeners exclude it.
308d10910e6SBruce M Simpson  *  A source is only included if no listeners exclude it,
309d10910e6SBruce M Simpson  *  and at least one listener includes it.
310d10910e6SBruce M Simpson  * May be used by ifmcstat(8).
31171498f30SBruce M Simpson  */
312d10910e6SBruce M Simpson static __inline uint8_t
313d10910e6SBruce M Simpson ims_get_mode(const struct in_multi *inm, const struct ip_msource *ims,
314d10910e6SBruce M Simpson     uint8_t t)
315d10910e6SBruce M Simpson {
316d10910e6SBruce M Simpson 
317d10910e6SBruce M Simpson 	t = !!t;
318d10910e6SBruce M Simpson 	if (inm->inm_st[t].iss_ex > 0 &&
319d10910e6SBruce M Simpson 	    inm->inm_st[t].iss_ex == ims->ims_st[t].ex)
320d10910e6SBruce M Simpson 		return (MCAST_EXCLUDE);
321d10910e6SBruce M Simpson 	else if (ims->ims_st[t].in > 0 && ims->ims_st[t].ex == 0)
322d10910e6SBruce M Simpson 		return (MCAST_INCLUDE);
323d10910e6SBruce M Simpson 	return (MCAST_UNDEFINED);
324d10910e6SBruce M Simpson }
32571498f30SBruce M Simpson 
326664a31e4SPeter Wemm #ifdef _KERNEL
327ce02431fSDoug Rabson 
328ce02431fSDoug Rabson #ifdef SYSCTL_DECL
329969bb53eSAndre Oppermann SYSCTL_DECL(_net_inet);
330ce02431fSDoug Rabson SYSCTL_DECL(_net_inet_ip);
331ce02431fSDoug Rabson SYSCTL_DECL(_net_inet_raw);
332ce02431fSDoug Rabson #endif
333ce02431fSDoug Rabson 
334d10910e6SBruce M Simpson LIST_HEAD(in_multihead, in_multi);	/* XXX unused */
3351b193af6SBjoern A. Zeeb #ifdef VIMAGE_GLOBALS
3361b193af6SBjoern A. Zeeb extern struct in_multihead in_multihead;
337d10910e6SBruce M Simpson #endif /* BURN_BRIDGES */
338477180fbSGarrett Wollman 
339df8bae1dSRodney W. Grimes /*
340dd5a318bSRobert Watson  * Lock macros for IPv4 layer multicast address lists.  IPv4 lock goes
341dd5a318bSRobert Watson  * before link layer multicast locks in the lock order.  In most cases,
342dd5a318bSRobert Watson  * consumers of IN_*_MULTI() macros should acquire the locks before
343dd5a318bSRobert Watson  * calling them; users of the in_{add,del}multi() functions should not.
344dd5a318bSRobert Watson  */
345dd5a318bSRobert Watson extern struct mtx in_multi_mtx;
346dd5a318bSRobert Watson #define	IN_MULTI_LOCK()		mtx_lock(&in_multi_mtx)
347dd5a318bSRobert Watson #define	IN_MULTI_UNLOCK()	mtx_unlock(&in_multi_mtx)
348dd5a318bSRobert Watson #define	IN_MULTI_LOCK_ASSERT()	mtx_assert(&in_multi_mtx, MA_OWNED)
349d10910e6SBruce M Simpson #define	IN_MULTI_UNLOCK_ASSERT() mtx_assert(&in_multi_mtx, MA_NOTOWNED)
350dd5a318bSRobert Watson 
351dd5a318bSRobert Watson /*
352d10910e6SBruce M Simpson  * Function for looking up an in_multi record for an IPv4 multicast address
353d10910e6SBruce M Simpson  * on a given interface. ifp must be valid. If no record found, return NULL.
354d10910e6SBruce M Simpson  * The IN_MULTI_LOCK and IF_ADDR_LOCK on ifp must be held.
355df8bae1dSRodney W. Grimes  */
356d10910e6SBruce M Simpson static __inline struct in_multi *
357d10910e6SBruce M Simpson inm_lookup_locked(struct ifnet *ifp, const struct in_addr ina)
358d10910e6SBruce M Simpson {
359d10910e6SBruce M Simpson 	struct ifmultiaddr *ifma;
360d10910e6SBruce M Simpson 	struct in_multi *inm;
361d10910e6SBruce M Simpson 
362d10910e6SBruce M Simpson 	IN_MULTI_LOCK_ASSERT();
363d10910e6SBruce M Simpson 	IF_ADDR_LOCK_ASSERT(ifp);
364d10910e6SBruce M Simpson 
365d10910e6SBruce M Simpson 	inm = NULL;
366d10910e6SBruce M Simpson 	TAILQ_FOREACH(ifma, &((ifp)->if_multiaddrs), ifma_link) {
367d10910e6SBruce M Simpson 		if (ifma->ifma_addr->sa_family == AF_INET) {
368d10910e6SBruce M Simpson 			inm = (struct in_multi *)ifma->ifma_protospec;
369d10910e6SBruce M Simpson 			if (inm->inm_addr.s_addr == ina.s_addr)
370d10910e6SBruce M Simpson 				break;
371d10910e6SBruce M Simpson 			inm = NULL;
372d10910e6SBruce M Simpson 		}
373d10910e6SBruce M Simpson 	}
374d10910e6SBruce M Simpson 	return (inm);
375d10910e6SBruce M Simpson }
376df8bae1dSRodney W. Grimes 
377df8bae1dSRodney W. Grimes /*
378d10910e6SBruce M Simpson  * Wrapper for inm_lookup_locked().
379d10910e6SBruce M Simpson  * The IF_ADDR_LOCK will be taken on ifp and released on return.
380df8bae1dSRodney W. Grimes  */
381d10910e6SBruce M Simpson static __inline struct in_multi *
382d10910e6SBruce M Simpson inm_lookup(struct ifnet *ifp, const struct in_addr ina)
383d10910e6SBruce M Simpson {
384d10910e6SBruce M Simpson 	struct in_multi *inm;
385d10910e6SBruce M Simpson 
386d10910e6SBruce M Simpson 	IN_MULTI_LOCK_ASSERT();
387d10910e6SBruce M Simpson 	IF_ADDR_LOCK(ifp);
388d10910e6SBruce M Simpson 	inm = inm_lookup_locked(ifp, ina);
389d10910e6SBruce M Simpson 	IF_ADDR_UNLOCK(ifp);
390d10910e6SBruce M Simpson 
391d10910e6SBruce M Simpson 	return (inm);
392d10910e6SBruce M Simpson }
393d10910e6SBruce M Simpson 
394d10910e6SBruce M Simpson /* Acquire an in_multi record. */
395d10910e6SBruce M Simpson static __inline void
396d10910e6SBruce M Simpson inm_acquire_locked(struct in_multi *inm)
397d10910e6SBruce M Simpson {
398d10910e6SBruce M Simpson 
399d10910e6SBruce M Simpson 	IN_MULTI_LOCK_ASSERT();
400d10910e6SBruce M Simpson 	++inm->inm_refcount;
401d10910e6SBruce M Simpson }
402df8bae1dSRodney W. Grimes 
403df8bae1dSRodney W. Grimes /*
404d10910e6SBruce M Simpson  * Return values for imo_multi_filter().
405df8bae1dSRodney W. Grimes  */
406d10910e6SBruce M Simpson #define MCAST_PASS		0	/* Pass */
407d10910e6SBruce M Simpson #define MCAST_NOTGMEMBER	1	/* This host not a member of group */
408d10910e6SBruce M Simpson #define MCAST_NOTSMEMBER	2	/* This host excluded source */
409d10910e6SBruce M Simpson #define MCAST_MUTED		3	/* [deprecated] */
410df8bae1dSRodney W. Grimes 
4118b07e49aSJulian Elischer struct	rtentry;
4121f91d8c5SDavid Greenman struct	route;
41371498f30SBruce M Simpson struct	ip_moptions;
41471498f30SBruce M Simpson 
415d10910e6SBruce M Simpson int	imo_multi_filter(const struct ip_moptions *, const struct ifnet *,
416d10910e6SBruce M Simpson 	    const struct sockaddr *, const struct sockaddr *);
417d10910e6SBruce M Simpson void	inm_commit(struct in_multi *);
418d10910e6SBruce M Simpson void	inm_clear_recorded(struct in_multi *);
419d10910e6SBruce M Simpson void	inm_print(const struct in_multi *);
420d10910e6SBruce M Simpson int	inm_record_source(struct in_multi *inm, const in_addr_t);
421d10910e6SBruce M Simpson void	inm_release(struct in_multi *);
422d10910e6SBruce M Simpson void	inm_release_locked(struct in_multi *);
423d10910e6SBruce M Simpson struct	in_multi *
424d10910e6SBruce M Simpson 	in_addmulti(struct in_addr *, struct ifnet *);
4254d77a549SAlfred Perlstein void	in_delmulti(struct in_multi *);
426d10910e6SBruce M Simpson int	in_joingroup(struct ifnet *, const struct in_addr *,
427d10910e6SBruce M Simpson 	    /*const*/ struct in_mfilter *, struct in_multi **);
428d10910e6SBruce M Simpson int	in_joingroup_locked(struct ifnet *, const struct in_addr *,
429d10910e6SBruce M Simpson 	    /*const*/ struct in_mfilter *, struct in_multi **);
430d10910e6SBruce M Simpson int	in_leavegroup(struct in_multi *, /*const*/ struct in_mfilter *);
431d10910e6SBruce M Simpson int	in_leavegroup_locked(struct in_multi *,
432d10910e6SBruce M Simpson 	    /*const*/ struct in_mfilter *);
4334d77a549SAlfred Perlstein int	in_control(struct socket *, u_long, caddr_t, struct ifnet *,
4344d77a549SAlfred Perlstein 	    struct thread *);
4354d77a549SAlfred Perlstein void	in_rtqdrain(void);
4364d77a549SAlfred Perlstein void	ip_input(struct mbuf *);
4374d77a549SAlfred Perlstein int	in_ifadown(struct ifaddr *ifa, int);
4384d77a549SAlfred Perlstein void	in_ifscrub(struct ifnet *, struct in_ifaddr *);
4395d691e6dSAndre Oppermann struct	mbuf	*ip_fastforward(struct mbuf *);
4406e6b3f7cSQing Li void	*in_domifattach(struct ifnet *);
4416e6b3f7cSQing Li void	in_domifdetach(struct ifnet *, void *);
4426e6b3f7cSQing Li 
443707f139eSPaul Richards 
4448b07e49aSJulian Elischer /* XXX */
4458b07e49aSJulian Elischer void	 in_rtalloc_ign(struct route *ro, u_long ignflags, u_int fibnum);
4468b07e49aSJulian Elischer void	 in_rtalloc(struct route *ro, u_int fibnum);
4478b07e49aSJulian Elischer struct rtentry *in_rtalloc1(struct sockaddr *, int, u_long, u_int);
4488b07e49aSJulian Elischer void	 in_rtredirect(struct sockaddr *, struct sockaddr *,
4498b07e49aSJulian Elischer 	    struct sockaddr *, int, struct sockaddr *, u_int);
4508b07e49aSJulian Elischer int	 in_rtrequest(int, struct sockaddr *,
4518b07e49aSJulian Elischer 	    struct sockaddr *, struct sockaddr *, int, struct rtentry **, u_int);
4528b07e49aSJulian Elischer 
4538b07e49aSJulian Elischer #if 0
4548b07e49aSJulian Elischer int	 in_rt_getifa(struct rt_addrinfo *, u_int fibnum);
4558b07e49aSJulian Elischer int	 in_rtioctl(u_long, caddr_t, u_int);
4568b07e49aSJulian Elischer int	 in_rtrequest1(int, struct rt_addrinfo *, struct rtentry **, u_int);
4578b07e49aSJulian Elischer #endif
458664a31e4SPeter Wemm #endif /* _KERNEL */
4592180b925SGarrett Wollman 
46076429de4SYoshinobu Inoue /* INET6 stuff */
46176429de4SYoshinobu Inoue #include <netinet6/in6_var.h>
46276429de4SYoshinobu Inoue 
4632180b925SGarrett Wollman #endif /* _NETINET_IN_VAR_H_ */
464