master
  1/*-
  2 * SPDX-License-Identifier: BSD-3-Clause
  3 *
  4 * Copyright (c) 1988 Stephen Deering.
  5 * Copyright (c) 1992, 1993
  6 *	The Regents of the University of California.  All rights reserved.
  7 *
  8 * This code is derived from software contributed to Berkeley by
  9 * Stephen Deering of Stanford University.
 10 *
 11 * Redistribution and use in source and binary forms, with or without
 12 * modification, are permitted provided that the following conditions
 13 * are met:
 14 * 1. Redistributions of source code must retain the above copyright
 15 *    notice, this list of conditions and the following disclaimer.
 16 * 2. Redistributions in binary form must reproduce the above copyright
 17 *    notice, this list of conditions and the following disclaimer in the
 18 *    documentation and/or other materials provided with the distribution.
 19 * 3. Neither the name of the University nor the names of its contributors
 20 *    may be used to endorse or promote products derived from this software
 21 *    without specific prior written permission.
 22 *
 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 26 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 33 * SUCH DAMAGE.
 34 *
 35 *	from: @(#)igmp_var.h	8.1 (Berkeley) 7/19/93
 36 */
 37
 38#ifndef _NETINET_IGMP_VAR_H_
 39#define _NETINET_IGMP_VAR_H_
 40
 41/*
 42 * Internet Group Management Protocol (IGMP),
 43 * implementation-specific definitions.
 44 *
 45 * Written by Steve Deering, Stanford, May 1988.
 46 *
 47 * MULTICAST Revision: 3.5.1.3
 48 */
 49
 50/*
 51 * IGMPv3 protocol statistics.
 52 */
 53struct igmpstat {
 54	/*
 55	 * Structure header (to insulate ABI changes).
 56	 * XXX: unset inside the kernel, exported via sysctl_igmp_stat().
 57	 */
 58	uint32_t igps_version;		/* version of this structure */
 59	uint32_t igps_len;		/* length of this structure */
 60	/*
 61	 * Message statistics.
 62	 */
 63	uint64_t igps_rcv_total;	/* total IGMP messages received */
 64	uint64_t igps_rcv_tooshort;	/* received with too few bytes */
 65	uint64_t igps_rcv_badttl;	/* received with ttl other than 1 */
 66	uint64_t igps_rcv_badsum;	/* received with bad checksum */
 67	/*
 68	 * Query statistics.
 69	 */
 70	uint64_t igps_rcv_v1v2_queries;	/* received IGMPv1/IGMPv2 queries */
 71	uint64_t igps_rcv_v3_queries;	/* received IGMPv3 queries */
 72	uint64_t igps_rcv_badqueries;	/* received invalid queries */
 73	uint64_t igps_rcv_gen_queries;	/* received general queries */
 74	uint64_t igps_rcv_group_queries;/* received group queries */
 75	uint64_t igps_rcv_gsr_queries;	/* received group-source queries */
 76	uint64_t igps_drop_gsr_queries;	/* dropped group-source queries */
 77	/*
 78	 * Report statistics.
 79	 */
 80	uint64_t igps_rcv_reports;	/* received membership reports */
 81	uint64_t igps_rcv_badreports;	/* received invalid reports */
 82	uint64_t igps_rcv_ourreports;	/* received reports for our groups */
 83	uint64_t igps_rcv_nora;		/* received w/o Router Alert option */
 84	uint64_t igps_snd_reports;	/* sent membership reports */
 85	/*
 86	 * Padding for future additions.
 87	 */
 88	uint64_t __igps_pad[4];
 89};
 90#define IGPS_VERSION_3	3		/* as of FreeBSD 8.x */
 91#define IGPS_VERSION3_LEN		168
 92#ifdef CTASSERT
 93CTASSERT(sizeof(struct igmpstat) == IGPS_VERSION3_LEN);
 94#endif
 95
 96/*
 97 * Identifiers for IGMP sysctl nodes
 98 */
 99#define IGMPCTL_STATS		1	/* statistics (read-only) */
100
101#define IGMP_RANDOM_DELAY(X) (random() % (X) + 1)
102#define IGMP_MAX_STATE_CHANGES		24 /* Max pending changes per group */
103
104/*
105 * IGMP per-group states.
106 */
107#define IGMP_NOT_MEMBER			0 /* Can garbage collect in_multi */
108#define IGMP_SILENT_MEMBER		1 /* Do not perform IGMP for group */
109#define IGMP_REPORTING_MEMBER		2 /* IGMPv1/2/3 we are reporter */
110#define IGMP_IDLE_MEMBER		3 /* IGMPv1/2 we reported last */
111#define IGMP_LAZY_MEMBER		4 /* IGMPv1/2 other member reporting */
112#define IGMP_SLEEPING_MEMBER		5 /* IGMPv1/2 start query response */
113#define IGMP_AWAKENING_MEMBER		6 /* IGMPv1/2 group timer will start */
114#define IGMP_G_QUERY_PENDING_MEMBER	7 /* IGMPv3 group query pending */
115#define IGMP_SG_QUERY_PENDING_MEMBER	8 /* IGMPv3 source query pending */
116#define IGMP_LEAVING_MEMBER		9 /* IGMPv3 dying gasp (pending last */
117					  /* retransmission of INCLUDE {}) */
118
119/*
120 * IGMP version tag.
121 */
122#define IGMP_VERSION_NONE		0 /* Invalid */
123#define IGMP_VERSION_1			1
124#define IGMP_VERSION_2			2
125#define IGMP_VERSION_3			3 /* Default */
126
127/*
128 * IGMPv3 protocol control variables.
129 */
130#define IGMP_RV_INIT		2	/* Robustness Variable */
131#define IGMP_RV_MIN		1
132#define IGMP_RV_MAX		7
133
134#define IGMP_QI_INIT		125	/* Query Interval (s) */
135#define IGMP_QI_MIN		1
136#define IGMP_QI_MAX		255
137
138#define IGMP_QRI_INIT		10	/* Query Response Interval (s) */
139#define IGMP_QRI_MIN		1
140#define IGMP_QRI_MAX		255
141
142#define IGMP_URI_INIT		3	/* Unsolicited Report Interval (s) */
143#define IGMP_URI_MIN		0
144#define IGMP_URI_MAX		10
145
146#define IGMP_MAX_G_GS_PACKETS		8 /* # of packets to answer G/GS */
147#define IGMP_MAX_STATE_CHANGE_PACKETS	8 /* # of packets per state change */
148#define IGMP_MAX_RESPONSE_PACKETS	16 /* # of packets for general query */
149#define IGMP_MAX_RESPONSE_BURST		4 /* # of responses to send at once */
150
151/*
152 * IGMP-specific mbuf flags.
153 */
154#define M_IGMPV2	M_PROTO1	/* Packet is IGMPv2 */
155#define M_IGMPV3_HDR	M_PROTO2	/* Packet has IGMPv3 headers */
156#define M_GROUPREC	M_PROTO3	/* mbuf chain is a group record */
157#define M_IGMP_LOOP	M_PROTO4	/* transmit on loif, not real ifp */
158
159/*
160 * Default amount of leading space for IGMPv3 to allocate at the
161 * beginning of its mbuf packet chains, to avoid fragmentation and
162 * unnecessary allocation of leading mbufs.
163 */
164#define RAOPT_LEN	4		/* Length of IP Router Alert option */
165#define	IGMP_LEADINGSPACE		\
166	(sizeof(struct ip) + RAOPT_LEN + sizeof(struct igmp_report))
167
168/*
169 * Structure returned by net.inet.igmp.ifinfo sysctl.
170 */
171struct igmp_ifinfo {
172	uint32_t igi_version;	/* IGMPv3 Host Compatibility Mode */
173	uint32_t igi_v1_timer;	/* IGMPv1 Querier Present timer (s) */
174	uint32_t igi_v2_timer;	/* IGMPv2 Querier Present timer (s) */
175	uint32_t igi_v3_timer;	/* IGMPv3 General Query (interface) timer (s)*/
176	uint32_t igi_flags;	/* IGMP per-interface flags */
177#define IGIF_SILENT	0x00000001	/* Do not use IGMP on this ifp */
178#define IGIF_LOOPBACK	0x00000002	/* Send IGMP reports to loopback */
179	uint32_t igi_rv;	/* IGMPv3 Robustness Variable */
180	uint32_t igi_qi;	/* IGMPv3 Query Interval (s) */
181	uint32_t igi_qri;	/* IGMPv3 Query Response Interval (s) */
182	uint32_t igi_uri;	/* IGMPv3 Unsolicited Report Interval (s) */
183};
184
185#ifdef _KERNEL
186#include <sys/counter.h>
187
188VNET_PCPUSTAT_DECLARE(struct igmpstat, igmpstat);
189#define	IGMPSTAT_ADD(name, val)	\
190    VNET_PCPUSTAT_ADD(struct igmpstat, igmpstat, name, (val))
191#define	IGMPSTAT_INC(name)	IGMPSTAT_ADD(name, 1)
192
193/*
194 * Subsystem lock macros.
195 * The IGMP lock is only taken with IGMP. Currently it is system-wide.
196 * VIMAGE: The lock could be pushed to per-VIMAGE granularity in future.
197 */
198#define	IGMP_LOCK_INIT()	mtx_init(&igmp_mtx, "igmp_mtx", NULL, MTX_DEF)
199#define	IGMP_LOCK_DESTROY()	mtx_destroy(&igmp_mtx)
200#define	IGMP_LOCK()		mtx_lock(&igmp_mtx)
201#define	IGMP_LOCK_ASSERT()	mtx_assert(&igmp_mtx, MA_OWNED)
202#define	IGMP_UNLOCK()		mtx_unlock(&igmp_mtx)
203#define	IGMP_UNLOCK_ASSERT()	mtx_assert(&igmp_mtx, MA_NOTOWNED)
204
205/*
206 * Per-interface IGMP router version information.
207 */
208struct igmp_ifsoftc {
209	LIST_ENTRY(igmp_ifsoftc) igi_link;
210	struct ifnet *igi_ifp;	/* pointer back to interface */
211	uint32_t igi_version;	/* IGMPv3 Host Compatibility Mode */
212	uint32_t igi_v1_timer;	/* IGMPv1 Querier Present timer (s) */
213	uint32_t igi_v2_timer;	/* IGMPv2 Querier Present timer (s) */
214	uint32_t igi_v3_timer;	/* IGMPv3 General Query (interface) timer (s)*/
215	uint32_t igi_flags;	/* IGMP per-interface flags */
216	uint32_t igi_rv;	/* IGMPv3 Robustness Variable */
217	uint32_t igi_qi;	/* IGMPv3 Query Interval (s) */
218	uint32_t igi_qri;	/* IGMPv3 Query Response Interval (s) */
219	uint32_t igi_uri;	/* IGMPv3 Unsolicited Report Interval (s) */
220	struct mbufq	igi_gq;		/* general query responses queue */
221};
222
223int	igmp_change_state(struct in_multi *);
224struct igmp_ifsoftc *
225	igmp_domifattach(struct ifnet *);
226void	igmp_domifdetach(struct ifnet *);
227void	igmp_ifdetach(struct ifnet *);
228int	igmp_input(struct mbuf **, int *, int);
229
230SYSCTL_DECL(_net_inet_igmp);
231
232#endif /* _KERNEL */
233#endif