xref: /freebsd/sys/netinet6/mld6.h (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2009 Bruce Simpson.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote
15  *    products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * $FreeBSD$
31  */
32 
33 #ifndef _NETINET6_MLD6_H_
34 #define _NETINET6_MLD6_H_
35 
36 /*
37  * Multicast Listener Discovery (MLD) definitions.
38  */
39 
40 /* Minimum length of any MLD protocol message. */
41 #define MLD_MINLEN	sizeof(struct icmp6_hdr)
42 
43 /*
44  * MLD v2 query format.
45  * See <netinet/icmp6.h> for struct mld_hdr
46  * (MLDv1 query and host report format).
47  */
48 struct mldv2_query {
49 	struct icmp6_hdr	mld_icmp6_hdr;	/* ICMPv6 header */
50 	struct in6_addr		mld_addr;	/* address being queried */
51 	uint8_t		mld_misc;	/* reserved/suppress/robustness   */
52 	uint8_t		mld_qqi;	/* querier's query interval       */
53 	uint16_t	mld_numsrc;	/* number of sources              */
54 	/* followed by 1..numsrc source addresses */
55 } __packed;
56 #define MLD_V2_QUERY_MINLEN		sizeof(struct mldv2_query)
57 #define MLD_MRC_EXP(x)			((ntohs((x)) >> 12) & 0x0007)
58 #define MLD_MRC_MANT(x)			(ntohs((x)) & 0x0fff)
59 #define MLD_QQIC_EXP(x)			(((x) >> 4) & 0x07)
60 #define MLD_QQIC_MANT(x)		((x) & 0x0f)
61 #define MLD_QRESV(x)			(((x) >> 4) & 0x0f)
62 #define MLD_SFLAG(x)			(((x) >> 3) & 0x01)
63 #define MLD_QRV(x)			((x) & 0x07)
64 
65 /*
66  * MLDv2 host membership report header.
67  * mld_type: MLDV2_LISTENER_REPORT
68  */
69 struct mldv2_report {
70 	struct icmp6_hdr	mld_icmp6_hdr;
71 	/* followed by 1..numgrps records */
72 } __packed;
73 /* overlaid on struct icmp6_hdr. */
74 #define mld_numrecs	mld_icmp6_hdr.icmp6_data16[1]
75 
76 struct mldv2_record {
77 	uint8_t			mr_type;	/* record type */
78 	uint8_t			mr_datalen;	/* length of auxiliary data */
79 	uint16_t		mr_numsrc;	/* number of sources */
80 	struct in6_addr		mr_addr;	/* address being reported */
81 	/* followed by 1..numsrc source addresses */
82 } __packed;
83 #define MLD_V2_REPORT_MAXRECS		65535
84 
85 /*
86  * MLDv2 report modes.
87  */
88 #define MLD_DO_NOTHING			0	/* don't send a record */
89 #define MLD_MODE_IS_INCLUDE		1	/* MODE_IN */
90 #define MLD_MODE_IS_EXCLUDE		2	/* MODE_EX */
91 #define MLD_CHANGE_TO_INCLUDE_MODE	3	/* TO_IN */
92 #define MLD_CHANGE_TO_EXCLUDE_MODE	4	/* TO_EX */
93 #define MLD_ALLOW_NEW_SOURCES		5	/* ALLOW_NEW */
94 #define MLD_BLOCK_OLD_SOURCES		6	/* BLOCK_OLD */
95 
96 /*
97  * MLDv2 query types.
98  */
99 #define MLD_V2_GENERAL_QUERY		1
100 #define MLD_V2_GROUP_QUERY		2
101 #define MLD_V2_GROUP_SOURCE_QUERY	3
102 
103 /*
104  * Maximum report interval for MLDv1 host membership reports.
105  */
106 #define MLD_V1_MAX_RI			10
107 
108 /*
109  * MLD_TIMER_SCALE denotes that the MLD code field specifies
110  * time in milliseconds.
111  */
112 #define MLD_TIMER_SCALE			1000
113 
114 #endif /* _NETINET6_MLD6_H_ */
115