xref: /freebsd/sys/netinet6/mld6_var.h (revision ba8d15d3a8b10be9f3a0cb86a60246f225a36736)
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 #ifndef _NETINET6_MLD6_VAR_H_
31 #define _NETINET6_MLD6_VAR_H_
32 
33 /*
34  * Multicast Listener Discovery (MLD)
35  * implementation-specific definitions.
36  */
37 
38 /*
39  * MLD per-group states.
40  */
41 #define MLD_NOT_MEMBER			0 /* Can garbage collect group */
42 #define MLD_SILENT_MEMBER		1 /* Do not perform MLD for group */
43 #define MLD_REPORTING_MEMBER		2 /* MLDv1 we are reporter */
44 #define MLD_IDLE_MEMBER			3 /* MLDv1 we reported last */
45 #define MLD_LAZY_MEMBER			4 /* MLDv1 other member reporting */
46 #define MLD_SLEEPING_MEMBER		5 /* MLDv1 start query response */
47 #define MLD_AWAKENING_MEMBER		6 /* MLDv1 group timer will start */
48 #define MLD_G_QUERY_PENDING_MEMBER	7 /* MLDv2 group query pending */
49 #define MLD_SG_QUERY_PENDING_MEMBER	8 /* MLDv2 source query pending */
50 #define MLD_LEAVING_MEMBER		9 /* MLDv2 dying gasp (pending last */
51 					  /* retransmission of INCLUDE {}) */
52 
53 /*
54  * MLD version tag.
55  */
56 #define MLD_VERSION_NONE		0 /* Invalid */
57 #define MLD_VERSION_1			1
58 #define MLD_VERSION_2			2 /* Default */
59 
60 /*
61  * MLDv2 protocol control variables.
62  */
63 #define MLD_RV_INIT		2	/* Robustness Variable */
64 #define MLD_RV_MIN		1
65 #define MLD_RV_MAX		7
66 
67 #define MLD_QI_INIT		125	/* Query Interval (s) */
68 #define MLD_QI_MIN		1
69 #define MLD_QI_MAX		255
70 
71 #define MLD_QRI_INIT		10	/* Query Response Interval (s) */
72 #define MLD_QRI_MIN		1
73 #define MLD_QRI_MAX		255
74 
75 #define MLD_URI_INIT		3	/* Unsolicited Report Interval (s) */
76 #define MLD_URI_MIN		0
77 #define MLD_URI_MAX		10
78 
79 #define MLD_MAX_GS_SOURCES		256 /* # of sources in rx GS query */
80 #define MLD_MAX_G_GS_PACKETS		8 /* # of packets to answer G/GS */
81 #define MLD_MAX_STATE_CHANGE_PACKETS	8 /* # of packets per state change */
82 #define MLD_MAX_RESPONSE_PACKETS	16 /* # of packets for general query */
83 #define MLD_MAX_RESPONSE_BURST		4 /* # of responses to send at once */
84 #define MLD_RESPONSE_BURST_INTERVAL	(PR_FASTHZ / 2)	/* 500ms */
85 
86 /*
87  * MLD-specific mbuf flags.
88  */
89 #define M_MLDV1		M_PROTO1	/* Packet is MLDv1 */
90 #define M_GROUPREC	M_PROTO3	/* mbuf chain is a group record */
91 
92 /*
93  * Leading space for MLDv2 reports inside MTU.
94  *
95  * NOTE: This differs from IGMPv3 significantly. KAME IPv6 requires
96  * that a fully formed mbuf chain *without* the Router Alert option
97  * is passed to ip6_output(), however we must account for it in the
98  * MTU if we need to split an MLDv2 report into several packets.
99  *
100  * We now put the MLDv2 report header in the initial mbuf containing
101  * the IPv6 header.
102  */
103 #define	MLD_MTUSPACE	(sizeof(struct ip6_hdr) + sizeof(struct mld_raopt) + \
104 			 sizeof(struct icmp6_hdr))
105 
106 /*
107  * Structure returned by net.inet6.mld.ifinfo.
108  */
109 struct mld_ifinfo {
110 	uint32_t mli_version;	/* MLDv1 Host Compatibility Mode */
111 	uint32_t mli_v1_timer;	/* MLDv1 Querier Present timer (s) */
112 	uint32_t mli_v2_timer;	/* MLDv2 General Query (interface) timer (s)*/
113 	uint32_t mli_flags;	/* MLD per-interface flags */
114 #define MLIF_SILENT	0x00000001	/* Do not use MLD on this ifp */
115 #define MLIF_USEALLOW	0x00000002	/* Use ALLOW/BLOCK for joins/leaves */
116 	uint32_t mli_rv;	/* MLDv2 Robustness Variable */
117 	uint32_t mli_qi;	/* MLDv2 Query Interval (s) */
118 	uint32_t mli_qri;	/* MLDv2 Query Response Interval (s) */
119 	uint32_t mli_uri;	/* MLDv2 Unsolicited Report Interval (s) */
120 };
121 
122 #ifdef _KERNEL
123 /*
124  * Per-link MLD state.
125  */
126 struct mld_ifsoftc {
127 	LIST_ENTRY(mld_ifsoftc) mli_link;
128 	struct ifnet *mli_ifp;	/* interface this instance belongs to */
129 	uint32_t mli_version;	/* MLDv1 Host Compatibility Mode */
130 	uint32_t mli_v1_timer;	/* MLDv1 Querier Present timer (s) */
131 	uint32_t mli_v2_timer;	/* MLDv2 General Query (interface) timer (s)*/
132 	uint32_t mli_flags;	/* MLD per-interface flags */
133 	uint32_t mli_rv;	/* MLDv2 Robustness Variable */
134 	uint32_t mli_qi;	/* MLDv2 Query Interval (s) */
135 	uint32_t mli_qri;	/* MLDv2 Query Response Interval (s) */
136 	uint32_t mli_uri;	/* MLDv2 Unsolicited Report Interval (s) */
137 	SLIST_HEAD(,in6_multi)	mli_relinmhead; /* released groups */
138 	struct mbufq	 mli_gq;	/* queue of general query responses */
139 };
140 
141 #define MLD_RANDOM_DELAY(X)		(arc4random() % (X) + 1)
142 #define MLD_MAX_STATE_CHANGES		24 /* Max pending changes per group */
143 
144 /*
145  * Subsystem lock macros.
146  * The MLD lock is only taken with MLD. Currently it is system-wide.
147  * VIMAGE: The lock could be pushed to per-VIMAGE granularity in future.
148  */
149 #define	MLD_LOCK_INIT()	mtx_init(&mld_mtx, "mld_mtx", NULL, MTX_DEF)
150 #define	MLD_LOCK_DESTROY()	mtx_destroy(&mld_mtx)
151 #define	MLD_LOCK()		mtx_lock(&mld_mtx)
152 #define	MLD_LOCK_ASSERT()	mtx_assert(&mld_mtx, MA_OWNED)
153 #define	MLD_UNLOCK()		mtx_unlock(&mld_mtx)
154 #define	MLD_UNLOCK_ASSERT()	mtx_assert(&mld_mtx, MA_NOTOWNED)
155 
156 /*
157  * Per-link MLD context.
158  */
159 #define MLD_IFINFO(ifp) \
160 	(((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->mld_ifinfo)
161 
162 int	mld_change_state(struct in6_multi *, const int);
163 struct mld_ifsoftc *
164 	mld_domifattach(struct ifnet *);
165 void	mld_domifdetach(struct ifnet *);
166 void	mld_fasttimo(void);
167 void	mld_ifdetach(struct ifnet *);
168 int	mld_input(struct mbuf *, int, int);
169 void	mld_slowtimo(void);
170 
171 #ifdef SYSCTL_DECL
172 SYSCTL_DECL(_net_inet6_mld);
173 #endif
174 
175 #endif /* _KERNEL */
176 
177 #endif /* _NETINET6_MLD6_VAR_H_ */
178