xref: /freebsd/sys/netinet6/mld6.h (revision 315ee00f)
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 
31 #ifndef _NETINET6_MLD6_H_
32 #define _NETINET6_MLD6_H_
33 
34 /*
35  * Multicast Listener Discovery (MLD) definitions.
36  */
37 
38 /* Minimum length of any MLD protocol message. */
39 #define MLD_MINLEN	sizeof(struct icmp6_hdr)
40 
41 /*
42  * MLD v2 query format.
43  * See <netinet/icmp6.h> for struct mld_hdr
44  * (MLDv1 query and host report format).
45  */
46 struct mldv2_query {
47 	struct icmp6_hdr	mld_icmp6_hdr;	/* ICMPv6 header */
48 	struct in6_addr		mld_addr;	/* address being queried */
49 	uint8_t		mld_misc;	/* reserved/suppress/robustness   */
50 	uint8_t		mld_qqi;	/* querier's query interval       */
51 	uint16_t	mld_numsrc;	/* number of sources              */
52 	/* followed by 1..numsrc source addresses */
53 } __packed;
54 #define MLD_V2_QUERY_MINLEN		sizeof(struct mldv2_query)
55 #define MLD_MRC_EXP(x)			((ntohs((x)) >> 12) & 0x0007)
56 #define MLD_MRC_MANT(x)			(ntohs((x)) & 0x0fff)
57 #define MLD_QQIC_EXP(x)			(((x) >> 4) & 0x07)
58 #define MLD_QQIC_MANT(x)		((x) & 0x0f)
59 #define MLD_QRESV(x)			(((x) >> 4) & 0x0f)
60 #define MLD_SFLAG(x)			(((x) >> 3) & 0x01)
61 #define MLD_QRV(x)			((x) & 0x07)
62 
63 /*
64  * MLDv2 host membership report header.
65  * mld_type: MLDV2_LISTENER_REPORT
66  */
67 struct mldv2_report {
68 	struct icmp6_hdr	mld_icmp6_hdr;
69 	/* followed by 1..numgrps records */
70 } __packed;
71 /* overlaid on struct icmp6_hdr. */
72 #define mld_numrecs	mld_icmp6_hdr.icmp6_data16[1]
73 
74 struct mldv2_record {
75 	uint8_t			mr_type;	/* record type */
76 	uint8_t			mr_datalen;	/* length of auxiliary data */
77 	uint16_t		mr_numsrc;	/* number of sources */
78 	struct in6_addr		mr_addr;	/* address being reported */
79 	/* followed by 1..numsrc source addresses */
80 } __packed;
81 #define MLD_V2_REPORT_MAXRECS		65535
82 
83 /*
84  * MLDv2 report modes.
85  */
86 #define MLD_DO_NOTHING			0	/* don't send a record */
87 #define MLD_MODE_IS_INCLUDE		1	/* MODE_IN */
88 #define MLD_MODE_IS_EXCLUDE		2	/* MODE_EX */
89 #define MLD_CHANGE_TO_INCLUDE_MODE	3	/* TO_IN */
90 #define MLD_CHANGE_TO_EXCLUDE_MODE	4	/* TO_EX */
91 #define MLD_ALLOW_NEW_SOURCES		5	/* ALLOW_NEW */
92 #define MLD_BLOCK_OLD_SOURCES		6	/* BLOCK_OLD */
93 
94 /*
95  * MLDv2 query types.
96  */
97 #define MLD_V2_GENERAL_QUERY		1
98 #define MLD_V2_GROUP_QUERY		2
99 #define MLD_V2_GROUP_SOURCE_QUERY	3
100 
101 /*
102  * Maximum report interval for MLDv1 host membership reports.
103  */
104 #define MLD_V1_MAX_RI			10
105 
106 /*
107  * MLD_TIMER_SCALE denotes that the MLD code field specifies
108  * time in milliseconds.
109  */
110 #define MLD_TIMER_SCALE			1000
111 
112 #endif /* _NETINET6_MLD6_H_ */
113