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