1139823Simp/*-a
21541Srgrimes * Copyright (c) 1988 Stephen Deering.
31541Srgrimes * Copyright (c) 1992, 1993
41541Srgrimes *	The Regents of the University of California.  All rights reserved.
51541Srgrimes *
61541Srgrimes * This code is derived from software contributed to Berkeley by
71541Srgrimes * Stephen Deering of Stanford University.
81541Srgrimes *
91541Srgrimes * Redistribution and use in source and binary forms, with or without
101541Srgrimes * modification, are permitted provided that the following conditions
111541Srgrimes * are met:
121541Srgrimes * 1. Redistributions of source code must retain the above copyright
131541Srgrimes *    notice, this list of conditions and the following disclaimer.
141541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
151541Srgrimes *    notice, this list of conditions and the following disclaimer in the
161541Srgrimes *    documentation and/or other materials provided with the distribution.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
3344511Swollman *	from: @(#)igmp_var.h	8.1 (Berkeley) 7/19/93
3450477Speter * $FreeBSD$
351541Srgrimes */
361541Srgrimes
372169Spaul#ifndef _NETINET_IGMP_VAR_H_
382169Spaul#define _NETINET_IGMP_VAR_H_
392169Spaul
401541Srgrimes/*
411541Srgrimes * Internet Group Management Protocol (IGMP),
421541Srgrimes * implementation-specific definitions.
431541Srgrimes *
441541Srgrimes * Written by Steve Deering, Stanford, May 1988.
451541Srgrimes *
4614622Sfenner * MULTICAST Revision: 3.5.1.3
471541Srgrimes */
481541Srgrimes
49189592Sbms#ifndef BURN_BRIDGES
50189592Sbms/*
51189592Sbms * Pre-IGMPV3 igmpstat structure.
52189592Sbms */
53189592Sbmsstruct oigmpstat {
54189592Sbms	u_int igps_rcv_total;		/* total IGMP messages received */
55189592Sbms	u_int igps_rcv_tooshort;	/* received with too few bytes */
56189592Sbms	u_int igps_rcv_badsum;		/* received with bad checksum */
57189592Sbms	u_int igps_rcv_queries;		/* received membership queries */
58189592Sbms	u_int igps_rcv_badqueries;	/* received invalid queries */
59189592Sbms	u_int igps_rcv_reports;		/* received membership reports */
60189592Sbms	u_int igps_rcv_badreports;	/* received invalid reports */
61189592Sbms	u_int igps_rcv_ourreports;	/* received reports for our groups */
62189592Sbms	u_int igps_snd_reports;		/* sent membership reports */
63189592Sbms	u_int igps_rcv_toolong;		/* received with too many bytes */
64189592Sbms};
65189592Sbms#endif
66189592Sbms
67189592Sbms/*
68189592Sbms * IGMPv3 protocol statistics.
69189592Sbms */
701541Srgrimesstruct igmpstat {
71189592Sbms	/*
72189592Sbms	 * Structure header (to insulate ABI changes).
73189592Sbms	 */
74189592Sbms	uint32_t igps_version;		/* version of this structure */
75189592Sbms	uint32_t igps_len;		/* length of this structure */
76189592Sbms	/*
77189592Sbms	 * Message statistics.
78189592Sbms	 */
79189592Sbms	uint64_t igps_rcv_total;	/* total IGMP messages received */
80189592Sbms	uint64_t igps_rcv_tooshort;	/* received with too few bytes */
81189592Sbms	uint64_t igps_rcv_badttl;	/* received with ttl other than 1 */
82189592Sbms	uint64_t igps_rcv_badsum;	/* received with bad checksum */
83189592Sbms	/*
84189592Sbms	 * Query statistics.
85189592Sbms	 */
86189592Sbms	uint64_t igps_rcv_v1v2_queries;	/* received IGMPv1/IGMPv2 queries */
87189592Sbms	uint64_t igps_rcv_v3_queries;	/* received IGMPv3 queries */
88189592Sbms	uint64_t igps_rcv_badqueries;	/* received invalid queries */
89189592Sbms	uint64_t igps_rcv_gen_queries;	/* received general queries */
90189592Sbms	uint64_t igps_rcv_group_queries;/* received group queries */
91189592Sbms	uint64_t igps_rcv_gsr_queries;	/* received group-source queries */
92189592Sbms	uint64_t igps_drop_gsr_queries;	/* dropped group-source queries */
93189592Sbms	/*
94189592Sbms	 * Report statistics.
95189592Sbms	 */
96189592Sbms	uint64_t igps_rcv_reports;	/* received membership reports */
97189592Sbms	uint64_t igps_rcv_badreports;	/* received invalid reports */
98189592Sbms	uint64_t igps_rcv_ourreports;	/* received reports for our groups */
99189592Sbms	uint64_t igps_rcv_nora;		/* received w/o Router Alert option */
100189592Sbms	uint64_t igps_snd_reports;	/* sent membership reports */
101189592Sbms	/*
102189592Sbms	 * Padding for future additions.
103189592Sbms	 */
104189592Sbms	uint64_t __igps_pad[4];
1051541Srgrimes};
106189592Sbms#define IGPS_VERSION_3	3		/* as of FreeBSD 8.x */
107189592Sbms#define IGPS_VERSION3_LEN		168
1081541Srgrimes
109190965Srwatson#ifdef _KERNEL
110190965Srwatson#define	IGMPSTAT_ADD(name, val)		V_igmpstat.name += (val)
111190965Srwatson#define	IGMPSTAT_INC(name)		IGMPSTAT_ADD(name, 1)
112190965Srwatson#endif
113190965Srwatson
114189592Sbms#ifdef CTASSERT
115189592SbmsCTASSERT(sizeof(struct igmpstat) == 168);
116189592Sbms#endif
117189592Sbms
11855205Speter#ifdef _KERNEL
1192531Swollman#define IGMP_RANDOM_DELAY(X) (random() % (X) + 1)
1201541Srgrimes
121189592Sbms#define IGMP_MAX_STATE_CHANGES		24 /* Max pending changes per group */
12214622Sfenner
12314622Sfenner/*
124189592Sbms * IGMP per-group states.
125170613Sbms */
126189592Sbms#define IGMP_NOT_MEMBER			0 /* Can garbage collect in_multi */
127189592Sbms#define IGMP_SILENT_MEMBER		1 /* Do not perform IGMP for group */
128189592Sbms#define IGMP_REPORTING_MEMBER		2 /* IGMPv1/2/3 we are reporter */
129189592Sbms#define IGMP_IDLE_MEMBER		3 /* IGMPv1/2 we reported last */
130189592Sbms#define IGMP_LAZY_MEMBER		4 /* IGMPv1/2 other member reporting */
131189592Sbms#define IGMP_SLEEPING_MEMBER		5 /* IGMPv1/2 start query response */
132189592Sbms#define IGMP_AWAKENING_MEMBER		6 /* IGMPv1/2 group timer will start */
133189592Sbms#define IGMP_G_QUERY_PENDING_MEMBER	7 /* IGMPv3 group query pending */
134189592Sbms#define IGMP_SG_QUERY_PENDING_MEMBER	8 /* IGMPv3 source query pending */
135189592Sbms#define IGMP_LEAVING_MEMBER		9 /* IGMPv3 dying gasp (pending last */
136189592Sbms					  /* retransmission of INCLUDE {}) */
137170613Sbms
138170613Sbms/*
139189592Sbms * IGMP version tag.
14014622Sfenner */
141189592Sbms#define IGMP_VERSION_NONE		0 /* Invalid */
142189592Sbms#define IGMP_VERSION_1			1
143189592Sbms#define IGMP_VERSION_2			2
144189592Sbms#define IGMP_VERSION_3			3 /* Default */
14514622Sfenner
14614622Sfenner/*
147189592Sbms * IGMPv3 protocol control variables.
14814622Sfenner */
149189592Sbms#define IGMP_RV_INIT		2	/* Robustness Variable */
150189592Sbms#define IGMP_RV_MIN		1
151189592Sbms#define IGMP_RV_MAX		7
15214622Sfenner
153189592Sbms#define IGMP_QI_INIT		125	/* Query Interval (s) */
154189592Sbms#define IGMP_QI_MIN		1
155189592Sbms#define IGMP_QI_MAX		255
156189592Sbms
157189592Sbms#define IGMP_QRI_INIT		10	/* Query Response Interval (s) */
158189592Sbms#define IGMP_QRI_MIN		1
159189592Sbms#define IGMP_QRI_MAX		255
160189592Sbms
161189592Sbms#define IGMP_URI_INIT		3	/* Unsolicited Report Interval (s) */
162189592Sbms#define IGMP_URI_MIN		0
163189592Sbms#define IGMP_URI_MAX		10
164189592Sbms
165189592Sbms#define IGMP_MAX_G_GS_PACKETS		8 /* # of packets to answer G/GS */
166189592Sbms#define IGMP_MAX_STATE_CHANGE_PACKETS	8 /* # of packets per state change */
167189592Sbms#define IGMP_MAX_RESPONSE_PACKETS	16 /* # of packets for general query */
168189592Sbms#define IGMP_MAX_RESPONSE_BURST		4 /* # of responses to send at once */
169189592Sbms#define IGMP_RESPONSE_BURST_INTERVAL	(PR_FASTHZ / 2)	/* 500ms */
170189592Sbms
171170613Sbms/*
172189592Sbms * IGMP-specific mbuf flags.
173170613Sbms */
174189592Sbms#define M_IGMPV2	M_PROTO1	/* Packet is IGMPv2 */
175189592Sbms#define M_IGMPV3_HDR	M_PROTO2	/* Packet has IGMPv3 headers */
176189592Sbms#define M_GROUPREC	M_PROTO3	/* mbuf chain is a group record */
177189592Sbms#define M_IGMP_LOOP	M_PROTO4	/* transmit on loif, not real ifp */
178170613Sbms
179170613Sbms/*
180189592Sbms * Default amount of leading space for IGMPv3 to allocate at the
181189592Sbms * beginning of its mbuf packet chains, to avoid fragmentation and
182189592Sbms * unnecessary allocation of leading mbufs.
183170613Sbms */
184189592Sbms#define RAOPT_LEN	4		/* Length of IP Router Alert option */
185189592Sbms#define	IGMP_LEADINGSPACE		\
186189592Sbms	(sizeof(struct ip) + RAOPT_LEN + sizeof(struct igmp_report))
187170613Sbms
188170613Sbms/*
189189592Sbms * Subsystem lock macros.
190189592Sbms * The IGMP lock is only taken with IGMP. Currently it is system-wide.
191189592Sbms * VIMAGE: The lock could be pushed to per-VIMAGE granularity in future.
192170613Sbms */
193189592Sbms#define	IGMP_LOCK_INIT()	mtx_init(&igmp_mtx, "igmp_mtx", NULL, MTX_DEF)
194189592Sbms#define	IGMP_LOCK_DESTROY()	mtx_destroy(&igmp_mtx)
195189592Sbms#define	IGMP_LOCK()		mtx_lock(&igmp_mtx)
196189592Sbms#define	IGMP_LOCK_ASSERT()	mtx_assert(&igmp_mtx, MA_OWNED)
197189592Sbms#define	IGMP_UNLOCK()		mtx_unlock(&igmp_mtx)
198189592Sbms#define	IGMP_UNLOCK_ASSERT()	mtx_assert(&igmp_mtx, MA_NOTOWNED)
199170613Sbms
200189592Sbmsstruct igmp_ifinfo;
201170613Sbms
202189592Sbmsint	igmp_change_state(struct in_multi *);
203189592Sbmsvoid	igmp_fasttimo(void);
204189592Sbmsstruct igmp_ifinfo *
205189592Sbms	igmp_domifattach(struct ifnet *);
206189592Sbmsvoid	igmp_domifdetach(struct ifnet *);
207189592Sbmsvoid	igmp_ifdetach(struct ifnet *);
20892723Salfredvoid	igmp_input(struct mbuf *, int);
20992723Salfredvoid	igmp_slowtimo(void);
21044511Swollman
21144511SwollmanSYSCTL_DECL(_net_inet_igmp);
21244511Swollman
213189592Sbms#endif /* _KERNEL */
2142169Spaul
2156472Swollman/*
2166472Swollman * Names for IGMP sysctl objects
2176472Swollman */
2186472Swollman#define IGMPCTL_STATS		1	/* statistics (read-only) */
2196472Swollman#define IGMPCTL_MAXID		2
2206472Swollman
2216472Swollman#define IGMPCTL_NAMES { \
2226472Swollman	{ 0, 0 }, \
223170613Sbms	{ "stats", CTLTYPE_STRUCT } \
2246472Swollman}
2252169Spaul#endif
226