1331722Seadler/*-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/*
50189592Sbms * IGMPv3 protocol statistics.
51189592Sbms */
521541Srgrimesstruct igmpstat {
53189592Sbms	/*
54189592Sbms	 * Structure header (to insulate ABI changes).
55189592Sbms	 */
56189592Sbms	uint32_t igps_version;		/* version of this structure */
57189592Sbms	uint32_t igps_len;		/* length of this structure */
58189592Sbms	/*
59189592Sbms	 * Message statistics.
60189592Sbms	 */
61189592Sbms	uint64_t igps_rcv_total;	/* total IGMP messages received */
62189592Sbms	uint64_t igps_rcv_tooshort;	/* received with too few bytes */
63189592Sbms	uint64_t igps_rcv_badttl;	/* received with ttl other than 1 */
64189592Sbms	uint64_t igps_rcv_badsum;	/* received with bad checksum */
65189592Sbms	/*
66189592Sbms	 * Query statistics.
67189592Sbms	 */
68189592Sbms	uint64_t igps_rcv_v1v2_queries;	/* received IGMPv1/IGMPv2 queries */
69189592Sbms	uint64_t igps_rcv_v3_queries;	/* received IGMPv3 queries */
70189592Sbms	uint64_t igps_rcv_badqueries;	/* received invalid queries */
71189592Sbms	uint64_t igps_rcv_gen_queries;	/* received general queries */
72189592Sbms	uint64_t igps_rcv_group_queries;/* received group queries */
73189592Sbms	uint64_t igps_rcv_gsr_queries;	/* received group-source queries */
74189592Sbms	uint64_t igps_drop_gsr_queries;	/* dropped group-source queries */
75189592Sbms	/*
76189592Sbms	 * Report statistics.
77189592Sbms	 */
78189592Sbms	uint64_t igps_rcv_reports;	/* received membership reports */
79189592Sbms	uint64_t igps_rcv_badreports;	/* received invalid reports */
80189592Sbms	uint64_t igps_rcv_ourreports;	/* received reports for our groups */
81189592Sbms	uint64_t igps_rcv_nora;		/* received w/o Router Alert option */
82189592Sbms	uint64_t igps_snd_reports;	/* sent membership reports */
83189592Sbms	/*
84189592Sbms	 * Padding for future additions.
85189592Sbms	 */
86189592Sbms	uint64_t __igps_pad[4];
871541Srgrimes};
88189592Sbms#define IGPS_VERSION_3	3		/* as of FreeBSD 8.x */
89189592Sbms#define IGPS_VERSION3_LEN		168
90189592Sbms#ifdef CTASSERT
91279026SglebiusCTASSERT(sizeof(struct igmpstat) == IGPS_VERSION3_LEN);
92189592Sbms#endif
93189592Sbms
94279026Sglebius/*
95279026Sglebius * Identifiers for IGMP sysctl nodes
96279026Sglebius */
97279026Sglebius#define IGMPCTL_STATS		1	/* statistics (read-only) */
98279026Sglebius
992531Swollman#define IGMP_RANDOM_DELAY(X) (random() % (X) + 1)
100189592Sbms#define IGMP_MAX_STATE_CHANGES		24 /* Max pending changes per group */
10114622Sfenner
10214622Sfenner/*
103189592Sbms * IGMP per-group states.
104170613Sbms */
105189592Sbms#define IGMP_NOT_MEMBER			0 /* Can garbage collect in_multi */
106189592Sbms#define IGMP_SILENT_MEMBER		1 /* Do not perform IGMP for group */
107189592Sbms#define IGMP_REPORTING_MEMBER		2 /* IGMPv1/2/3 we are reporter */
108189592Sbms#define IGMP_IDLE_MEMBER		3 /* IGMPv1/2 we reported last */
109189592Sbms#define IGMP_LAZY_MEMBER		4 /* IGMPv1/2 other member reporting */
110189592Sbms#define IGMP_SLEEPING_MEMBER		5 /* IGMPv1/2 start query response */
111189592Sbms#define IGMP_AWAKENING_MEMBER		6 /* IGMPv1/2 group timer will start */
112189592Sbms#define IGMP_G_QUERY_PENDING_MEMBER	7 /* IGMPv3 group query pending */
113189592Sbms#define IGMP_SG_QUERY_PENDING_MEMBER	8 /* IGMPv3 source query pending */
114189592Sbms#define IGMP_LEAVING_MEMBER		9 /* IGMPv3 dying gasp (pending last */
115189592Sbms					  /* retransmission of INCLUDE {}) */
116170613Sbms
117170613Sbms/*
118189592Sbms * IGMP version tag.
11914622Sfenner */
120189592Sbms#define IGMP_VERSION_NONE		0 /* Invalid */
121189592Sbms#define IGMP_VERSION_1			1
122189592Sbms#define IGMP_VERSION_2			2
123189592Sbms#define IGMP_VERSION_3			3 /* Default */
12414622Sfenner
12514622Sfenner/*
126189592Sbms * IGMPv3 protocol control variables.
12714622Sfenner */
128189592Sbms#define IGMP_RV_INIT		2	/* Robustness Variable */
129189592Sbms#define IGMP_RV_MIN		1
130189592Sbms#define IGMP_RV_MAX		7
13114622Sfenner
132189592Sbms#define IGMP_QI_INIT		125	/* Query Interval (s) */
133189592Sbms#define IGMP_QI_MIN		1
134189592Sbms#define IGMP_QI_MAX		255
135189592Sbms
136189592Sbms#define IGMP_QRI_INIT		10	/* Query Response Interval (s) */
137189592Sbms#define IGMP_QRI_MIN		1
138189592Sbms#define IGMP_QRI_MAX		255
139189592Sbms
140189592Sbms#define IGMP_URI_INIT		3	/* Unsolicited Report Interval (s) */
141189592Sbms#define IGMP_URI_MIN		0
142189592Sbms#define IGMP_URI_MAX		10
143189592Sbms
144189592Sbms#define IGMP_MAX_G_GS_PACKETS		8 /* # of packets to answer G/GS */
145189592Sbms#define IGMP_MAX_STATE_CHANGE_PACKETS	8 /* # of packets per state change */
146189592Sbms#define IGMP_MAX_RESPONSE_PACKETS	16 /* # of packets for general query */
147189592Sbms#define IGMP_MAX_RESPONSE_BURST		4 /* # of responses to send at once */
148189592Sbms#define IGMP_RESPONSE_BURST_INTERVAL	(PR_FASTHZ / 2)	/* 500ms */
149189592Sbms
150170613Sbms/*
151189592Sbms * IGMP-specific mbuf flags.
152170613Sbms */
153189592Sbms#define M_IGMPV2	M_PROTO1	/* Packet is IGMPv2 */
154189592Sbms#define M_IGMPV3_HDR	M_PROTO2	/* Packet has IGMPv3 headers */
155189592Sbms#define M_GROUPREC	M_PROTO3	/* mbuf chain is a group record */
156189592Sbms#define M_IGMP_LOOP	M_PROTO4	/* transmit on loif, not real ifp */
157170613Sbms
158170613Sbms/*
159189592Sbms * Default amount of leading space for IGMPv3 to allocate at the
160189592Sbms * beginning of its mbuf packet chains, to avoid fragmentation and
161189592Sbms * unnecessary allocation of leading mbufs.
162170613Sbms */
163189592Sbms#define RAOPT_LEN	4		/* Length of IP Router Alert option */
164189592Sbms#define	IGMP_LEADINGSPACE		\
165189592Sbms	(sizeof(struct ip) + RAOPT_LEN + sizeof(struct igmp_report))
166170613Sbms
167170613Sbms/*
168279026Sglebius * Structure returned by net.inet.igmp.ifinfo sysctl.
169279026Sglebius */
170279026Sglebiusstruct igmp_ifinfo {
171279026Sglebius	uint32_t igi_version;	/* IGMPv3 Host Compatibility Mode */
172279026Sglebius	uint32_t igi_v1_timer;	/* IGMPv1 Querier Present timer (s) */
173279026Sglebius	uint32_t igi_v2_timer;	/* IGMPv2 Querier Present timer (s) */
174279026Sglebius	uint32_t igi_v3_timer;	/* IGMPv3 General Query (interface) timer (s)*/
175279026Sglebius	uint32_t igi_flags;	/* IGMP per-interface flags */
176279026Sglebius#define IGIF_SILENT	0x00000001	/* Do not use IGMP on this ifp */
177279026Sglebius#define IGIF_LOOPBACK	0x00000002	/* Send IGMP reports to loopback */
178279026Sglebius	uint32_t igi_rv;	/* IGMPv3 Robustness Variable */
179279026Sglebius	uint32_t igi_qi;	/* IGMPv3 Query Interval (s) */
180279026Sglebius	uint32_t igi_qri;	/* IGMPv3 Query Response Interval (s) */
181279026Sglebius	uint32_t igi_uri;	/* IGMPv3 Unsolicited Report Interval (s) */
182279026Sglebius};
183279026Sglebius
184279026Sglebius#ifdef _KERNEL
185279026Sglebius#define	IGMPSTAT_ADD(name, val)		V_igmpstat.name += (val)
186279026Sglebius#define	IGMPSTAT_INC(name)		IGMPSTAT_ADD(name, 1)
187279026Sglebius
188279026Sglebius/*
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
200279026Sglebius/*
201279026Sglebius * Per-interface IGMP router version information.
202279026Sglebius */
203279026Sglebiusstruct igmp_ifsoftc {
204279026Sglebius	LIST_ENTRY(igmp_ifsoftc) igi_link;
205279026Sglebius	struct ifnet *igi_ifp;	/* pointer back to interface */
206279026Sglebius	uint32_t igi_version;	/* IGMPv3 Host Compatibility Mode */
207279026Sglebius	uint32_t igi_v1_timer;	/* IGMPv1 Querier Present timer (s) */
208279026Sglebius	uint32_t igi_v2_timer;	/* IGMPv2 Querier Present timer (s) */
209279026Sglebius	uint32_t igi_v3_timer;	/* IGMPv3 General Query (interface) timer (s)*/
210279026Sglebius	uint32_t igi_flags;	/* IGMP per-interface flags */
211279026Sglebius	uint32_t igi_rv;	/* IGMPv3 Robustness Variable */
212279026Sglebius	uint32_t igi_qi;	/* IGMPv3 Query Interval (s) */
213279026Sglebius	uint32_t igi_qri;	/* IGMPv3 Query Response Interval (s) */
214279026Sglebius	uint32_t igi_uri;	/* IGMPv3 Unsolicited Report Interval (s) */
215279026Sglebius	SLIST_HEAD(,in_multi)	igi_relinmhead; /* released groups */
216279026Sglebius	struct mbufq	igi_gq;		/* general query responses queue */
217279026Sglebius};
218170613Sbms
219189592Sbmsint	igmp_change_state(struct in_multi *);
220189592Sbmsvoid	igmp_fasttimo(void);
221279026Sglebiusstruct igmp_ifsoftc *
222189592Sbms	igmp_domifattach(struct ifnet *);
223189592Sbmsvoid	igmp_domifdetach(struct ifnet *);
224189592Sbmsvoid	igmp_ifdetach(struct ifnet *);
225269699Skevloint	igmp_input(struct mbuf **, int *, int);
22692723Salfredvoid	igmp_slowtimo(void);
22744511Swollman
22844511SwollmanSYSCTL_DECL(_net_inet_igmp);
22944511Swollman
230189592Sbms#endif /* _KERNEL */
2312169Spaul#endif
232