151369649SPedro F. Giffuni /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 4df8bae1dSRodney W. Grimes * Copyright (c) 1988 Stephen Deering. 5df8bae1dSRodney W. Grimes * Copyright (c) 1992, 1993 6df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 7df8bae1dSRodney W. Grimes * 8df8bae1dSRodney W. Grimes * This code is derived from software contributed to Berkeley by 9df8bae1dSRodney W. Grimes * Stephen Deering of Stanford University. 10df8bae1dSRodney W. Grimes * 11df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 12df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 13df8bae1dSRodney W. Grimes * are met: 14df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 15df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 16df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 17df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 18df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 19fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 20df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 21df8bae1dSRodney W. Grimes * without specific prior written permission. 22df8bae1dSRodney W. Grimes * 23df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33df8bae1dSRodney W. Grimes * SUCH DAMAGE. 34df8bae1dSRodney W. Grimes */ 35df8bae1dSRodney W. Grimes 36707f139eSPaul Richards #ifndef _NETINET_IGMP_VAR_H_ 37707f139eSPaul Richards #define _NETINET_IGMP_VAR_H_ 38707f139eSPaul Richards 39df8bae1dSRodney W. Grimes /* 40df8bae1dSRodney W. Grimes * Internet Group Management Protocol (IGMP), 41df8bae1dSRodney W. Grimes * implementation-specific definitions. 42df8bae1dSRodney W. Grimes * 43df8bae1dSRodney W. Grimes * Written by Steve Deering, Stanford, May 1988. 44df8bae1dSRodney W. Grimes * 4549fa849bSBill Fenner * MULTICAST Revision: 3.5.1.3 46df8bae1dSRodney W. Grimes */ 47df8bae1dSRodney W. Grimes 48d10910e6SBruce M Simpson /* 49d10910e6SBruce M Simpson * IGMPv3 protocol statistics. 50d10910e6SBruce M Simpson */ 51d10910e6SBruce M Simpson struct igmpstat { 52d10910e6SBruce M Simpson /* 53d10910e6SBruce M Simpson * Structure header (to insulate ABI changes). 54*b02c4e5cSMitchell Horne * XXX: unset inside the kernel, exported via sysctl_igmp_stat(). 55d10910e6SBruce M Simpson */ 56d10910e6SBruce M Simpson uint32_t igps_version; /* version of this structure */ 57d10910e6SBruce M Simpson uint32_t igps_len; /* length of this structure */ 58d10910e6SBruce M Simpson /* 59d10910e6SBruce M Simpson * Message statistics. 60d10910e6SBruce M Simpson */ 61d10910e6SBruce M Simpson uint64_t igps_rcv_total; /* total IGMP messages received */ 62d10910e6SBruce M Simpson uint64_t igps_rcv_tooshort; /* received with too few bytes */ 63d10910e6SBruce M Simpson uint64_t igps_rcv_badttl; /* received with ttl other than 1 */ 64d10910e6SBruce M Simpson uint64_t igps_rcv_badsum; /* received with bad checksum */ 65d10910e6SBruce M Simpson /* 66d10910e6SBruce M Simpson * Query statistics. 67d10910e6SBruce M Simpson */ 68d10910e6SBruce M Simpson uint64_t igps_rcv_v1v2_queries; /* received IGMPv1/IGMPv2 queries */ 69d10910e6SBruce M Simpson uint64_t igps_rcv_v3_queries; /* received IGMPv3 queries */ 70d10910e6SBruce M Simpson uint64_t igps_rcv_badqueries; /* received invalid queries */ 71d10910e6SBruce M Simpson uint64_t igps_rcv_gen_queries; /* received general queries */ 72d10910e6SBruce M Simpson uint64_t igps_rcv_group_queries;/* received group queries */ 73d10910e6SBruce M Simpson uint64_t igps_rcv_gsr_queries; /* received group-source queries */ 74d10910e6SBruce M Simpson uint64_t igps_drop_gsr_queries; /* dropped group-source queries */ 75d10910e6SBruce M Simpson /* 76d10910e6SBruce M Simpson * Report statistics. 77d10910e6SBruce M Simpson */ 78d10910e6SBruce M Simpson uint64_t igps_rcv_reports; /* received membership reports */ 79d10910e6SBruce M Simpson uint64_t igps_rcv_badreports; /* received invalid reports */ 80d10910e6SBruce M Simpson uint64_t igps_rcv_ourreports; /* received reports for our groups */ 81d10910e6SBruce M Simpson uint64_t igps_rcv_nora; /* received w/o Router Alert option */ 82d10910e6SBruce M Simpson uint64_t igps_snd_reports; /* sent membership reports */ 83d10910e6SBruce M Simpson /* 84d10910e6SBruce M Simpson * Padding for future additions. 85d10910e6SBruce M Simpson */ 86d10910e6SBruce M Simpson uint64_t __igps_pad[4]; 87d10910e6SBruce M Simpson }; 88d10910e6SBruce M Simpson #define IGPS_VERSION_3 3 /* as of FreeBSD 8.x */ 89d10910e6SBruce M Simpson #define IGPS_VERSION3_LEN 168 90d10910e6SBruce M Simpson #ifdef CTASSERT 910d159406SGleb Smirnoff CTASSERT(sizeof(struct igmpstat) == IGPS_VERSION3_LEN); 92d10910e6SBruce M Simpson #endif 93df8bae1dSRodney W. Grimes 940d159406SGleb Smirnoff /* 950d159406SGleb Smirnoff * Identifiers for IGMP sysctl nodes 960d159406SGleb Smirnoff */ 970d159406SGleb Smirnoff #define IGMPCTL_STATS 1 /* statistics (read-only) */ 98df8bae1dSRodney W. Grimes 990d159406SGleb Smirnoff #define IGMP_RANDOM_DELAY(X) (random() % (X) + 1) 100d10910e6SBruce M Simpson #define IGMP_MAX_STATE_CHANGES 24 /* Max pending changes per group */ 10149fa849bSBill Fenner 10249fa849bSBill Fenner /* 103d10910e6SBruce M Simpson * IGMP per-group states. 10471498f30SBruce M Simpson */ 105d10910e6SBruce M Simpson #define IGMP_NOT_MEMBER 0 /* Can garbage collect in_multi */ 106d10910e6SBruce M Simpson #define IGMP_SILENT_MEMBER 1 /* Do not perform IGMP for group */ 107d10910e6SBruce M Simpson #define IGMP_REPORTING_MEMBER 2 /* IGMPv1/2/3 we are reporter */ 108d10910e6SBruce M Simpson #define IGMP_IDLE_MEMBER 3 /* IGMPv1/2 we reported last */ 109d10910e6SBruce M Simpson #define IGMP_LAZY_MEMBER 4 /* IGMPv1/2 other member reporting */ 110d10910e6SBruce M Simpson #define IGMP_SLEEPING_MEMBER 5 /* IGMPv1/2 start query response */ 111d10910e6SBruce M Simpson #define IGMP_AWAKENING_MEMBER 6 /* IGMPv1/2 group timer will start */ 112d10910e6SBruce M Simpson #define IGMP_G_QUERY_PENDING_MEMBER 7 /* IGMPv3 group query pending */ 113d10910e6SBruce M Simpson #define IGMP_SG_QUERY_PENDING_MEMBER 8 /* IGMPv3 source query pending */ 114d10910e6SBruce M Simpson #define IGMP_LEAVING_MEMBER 9 /* IGMPv3 dying gasp (pending last */ 115d10910e6SBruce M Simpson /* retransmission of INCLUDE {}) */ 11671498f30SBruce M Simpson 11771498f30SBruce M Simpson /* 118d10910e6SBruce M Simpson * IGMP version tag. 11949fa849bSBill Fenner */ 120d10910e6SBruce M Simpson #define IGMP_VERSION_NONE 0 /* Invalid */ 121d10910e6SBruce M Simpson #define IGMP_VERSION_1 1 122d10910e6SBruce M Simpson #define IGMP_VERSION_2 2 123d10910e6SBruce M Simpson #define IGMP_VERSION_3 3 /* Default */ 12449fa849bSBill Fenner 12549fa849bSBill Fenner /* 126d10910e6SBruce M Simpson * IGMPv3 protocol control variables. 12749fa849bSBill Fenner */ 128d10910e6SBruce M Simpson #define IGMP_RV_INIT 2 /* Robustness Variable */ 129d10910e6SBruce M Simpson #define IGMP_RV_MIN 1 130d10910e6SBruce M Simpson #define IGMP_RV_MAX 7 131d10910e6SBruce M Simpson 132d10910e6SBruce M Simpson #define IGMP_QI_INIT 125 /* Query Interval (s) */ 133d10910e6SBruce M Simpson #define IGMP_QI_MIN 1 134d10910e6SBruce M Simpson #define IGMP_QI_MAX 255 135d10910e6SBruce M Simpson 136d10910e6SBruce M Simpson #define IGMP_QRI_INIT 10 /* Query Response Interval (s) */ 137d10910e6SBruce M Simpson #define IGMP_QRI_MIN 1 138d10910e6SBruce M Simpson #define IGMP_QRI_MAX 255 139d10910e6SBruce M Simpson 140d10910e6SBruce M Simpson #define IGMP_URI_INIT 3 /* Unsolicited Report Interval (s) */ 141d10910e6SBruce M Simpson #define IGMP_URI_MIN 0 142d10910e6SBruce M Simpson #define IGMP_URI_MAX 10 143d10910e6SBruce M Simpson 144d10910e6SBruce M Simpson #define IGMP_MAX_G_GS_PACKETS 8 /* # of packets to answer G/GS */ 145d10910e6SBruce M Simpson #define IGMP_MAX_STATE_CHANGE_PACKETS 8 /* # of packets per state change */ 146d10910e6SBruce M Simpson #define IGMP_MAX_RESPONSE_PACKETS 16 /* # of packets for general query */ 147d10910e6SBruce M Simpson #define IGMP_MAX_RESPONSE_BURST 4 /* # of responses to send at once */ 14849fa849bSBill Fenner 14971498f30SBruce M Simpson /* 150d10910e6SBruce M Simpson * IGMP-specific mbuf flags. 15171498f30SBruce M Simpson */ 152d10910e6SBruce M Simpson #define M_IGMPV2 M_PROTO1 /* Packet is IGMPv2 */ 153d10910e6SBruce M Simpson #define M_IGMPV3_HDR M_PROTO2 /* Packet has IGMPv3 headers */ 154d10910e6SBruce M Simpson #define M_GROUPREC M_PROTO3 /* mbuf chain is a group record */ 155d10910e6SBruce M Simpson #define M_IGMP_LOOP M_PROTO4 /* transmit on loif, not real ifp */ 15671498f30SBruce M Simpson 15771498f30SBruce M Simpson /* 158d10910e6SBruce M Simpson * Default amount of leading space for IGMPv3 to allocate at the 159d10910e6SBruce M Simpson * beginning of its mbuf packet chains, to avoid fragmentation and 160d10910e6SBruce M Simpson * unnecessary allocation of leading mbufs. 16171498f30SBruce M Simpson */ 162d10910e6SBruce M Simpson #define RAOPT_LEN 4 /* Length of IP Router Alert option */ 163d10910e6SBruce M Simpson #define IGMP_LEADINGSPACE \ 164d10910e6SBruce M Simpson (sizeof(struct ip) + RAOPT_LEN + sizeof(struct igmp_report)) 16571498f30SBruce M Simpson 16671498f30SBruce M Simpson /* 1670d159406SGleb Smirnoff * Structure returned by net.inet.igmp.ifinfo sysctl. 1680d159406SGleb Smirnoff */ 1690d159406SGleb Smirnoff struct igmp_ifinfo { 1700d159406SGleb Smirnoff uint32_t igi_version; /* IGMPv3 Host Compatibility Mode */ 1710d159406SGleb Smirnoff uint32_t igi_v1_timer; /* IGMPv1 Querier Present timer (s) */ 1720d159406SGleb Smirnoff uint32_t igi_v2_timer; /* IGMPv2 Querier Present timer (s) */ 1730d159406SGleb Smirnoff uint32_t igi_v3_timer; /* IGMPv3 General Query (interface) timer (s)*/ 1740d159406SGleb Smirnoff uint32_t igi_flags; /* IGMP per-interface flags */ 1750d159406SGleb Smirnoff #define IGIF_SILENT 0x00000001 /* Do not use IGMP on this ifp */ 1760d159406SGleb Smirnoff #define IGIF_LOOPBACK 0x00000002 /* Send IGMP reports to loopback */ 1770d159406SGleb Smirnoff uint32_t igi_rv; /* IGMPv3 Robustness Variable */ 1780d159406SGleb Smirnoff uint32_t igi_qi; /* IGMPv3 Query Interval (s) */ 1790d159406SGleb Smirnoff uint32_t igi_qri; /* IGMPv3 Query Response Interval (s) */ 1800d159406SGleb Smirnoff uint32_t igi_uri; /* IGMPv3 Unsolicited Report Interval (s) */ 1810d159406SGleb Smirnoff }; 1820d159406SGleb Smirnoff 1830d159406SGleb Smirnoff #ifdef _KERNEL 184*b02c4e5cSMitchell Horne #include <sys/counter.h> 185*b02c4e5cSMitchell Horne 186*b02c4e5cSMitchell Horne VNET_PCPUSTAT_DECLARE(struct igmpstat, igmpstat); 187*b02c4e5cSMitchell Horne #define IGMPSTAT_ADD(name, val) \ 188*b02c4e5cSMitchell Horne VNET_PCPUSTAT_ADD(struct igmpstat, igmpstat, name, (val)) 1890d159406SGleb Smirnoff #define IGMPSTAT_INC(name) IGMPSTAT_ADD(name, 1) 1900d159406SGleb Smirnoff 1910d159406SGleb Smirnoff /* 192d10910e6SBruce M Simpson * Subsystem lock macros. 193d10910e6SBruce M Simpson * The IGMP lock is only taken with IGMP. Currently it is system-wide. 194d10910e6SBruce M Simpson * VIMAGE: The lock could be pushed to per-VIMAGE granularity in future. 19571498f30SBruce M Simpson */ 196d10910e6SBruce M Simpson #define IGMP_LOCK_INIT() mtx_init(&igmp_mtx, "igmp_mtx", NULL, MTX_DEF) 197d10910e6SBruce M Simpson #define IGMP_LOCK_DESTROY() mtx_destroy(&igmp_mtx) 198d10910e6SBruce M Simpson #define IGMP_LOCK() mtx_lock(&igmp_mtx) 199d10910e6SBruce M Simpson #define IGMP_LOCK_ASSERT() mtx_assert(&igmp_mtx, MA_OWNED) 200d10910e6SBruce M Simpson #define IGMP_UNLOCK() mtx_unlock(&igmp_mtx) 201d10910e6SBruce M Simpson #define IGMP_UNLOCK_ASSERT() mtx_assert(&igmp_mtx, MA_NOTOWNED) 20271498f30SBruce M Simpson 2030d159406SGleb Smirnoff /* 2040d159406SGleb Smirnoff * Per-interface IGMP router version information. 2050d159406SGleb Smirnoff */ 2060d159406SGleb Smirnoff struct igmp_ifsoftc { 2070d159406SGleb Smirnoff LIST_ENTRY(igmp_ifsoftc) igi_link; 2080d159406SGleb Smirnoff struct ifnet *igi_ifp; /* pointer back to interface */ 2090d159406SGleb Smirnoff uint32_t igi_version; /* IGMPv3 Host Compatibility Mode */ 2100d159406SGleb Smirnoff uint32_t igi_v1_timer; /* IGMPv1 Querier Present timer (s) */ 2110d159406SGleb Smirnoff uint32_t igi_v2_timer; /* IGMPv2 Querier Present timer (s) */ 2120d159406SGleb Smirnoff uint32_t igi_v3_timer; /* IGMPv3 General Query (interface) timer (s)*/ 2130d159406SGleb Smirnoff uint32_t igi_flags; /* IGMP per-interface flags */ 2140d159406SGleb Smirnoff uint32_t igi_rv; /* IGMPv3 Robustness Variable */ 2150d159406SGleb Smirnoff uint32_t igi_qi; /* IGMPv3 Query Interval (s) */ 2160d159406SGleb Smirnoff uint32_t igi_qri; /* IGMPv3 Query Response Interval (s) */ 2170d159406SGleb Smirnoff uint32_t igi_uri; /* IGMPv3 Unsolicited Report Interval (s) */ 2180d159406SGleb Smirnoff struct mbufq igi_gq; /* general query responses queue */ 2190d159406SGleb Smirnoff }; 22071498f30SBruce M Simpson 221d10910e6SBruce M Simpson int igmp_change_state(struct in_multi *); 2220d159406SGleb Smirnoff struct igmp_ifsoftc * 223d10910e6SBruce M Simpson igmp_domifattach(struct ifnet *); 224d10910e6SBruce M Simpson void igmp_domifdetach(struct ifnet *); 225d10910e6SBruce M Simpson void igmp_ifdetach(struct ifnet *); 2268f5a8818SKevin Lo int igmp_input(struct mbuf **, int *, int); 2274022a21dSGarrett Wollman 2284022a21dSGarrett Wollman SYSCTL_DECL(_net_inet_igmp); 2294022a21dSGarrett Wollman 230d10910e6SBruce M Simpson #endif /* _KERNEL */ 231707f139eSPaul Richards #endif 232