1/*-
2 * Copyright (c) 2009 Bruce Simpson.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote
13 *    products derived from this software without specific prior written
14 *    permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD$
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 */
46struct 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 */
67struct 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
74struct 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