1 | /** @file
|
---|
2 | Multicast Listener Discovery support routines.
|
---|
3 |
|
---|
4 | Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
---|
5 |
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include "Ip6Impl.h"
|
---|
11 |
|
---|
12 | /**
|
---|
13 | Create a IP6_MLD_GROUP list entry node and record to IP6 service binding data.
|
---|
14 |
|
---|
15 | @param[in, out] IpSb Points to IP6 service binding instance.
|
---|
16 | @param[in] MulticastAddr The IPv6 multicast address to be recorded.
|
---|
17 | @param[in] DelayTimer The maximum allowed delay before sending a responding
|
---|
18 | report, in units of milliseconds.
|
---|
19 | @return The created IP6_ML_GROUP list entry or NULL.
|
---|
20 |
|
---|
21 | **/
|
---|
22 | IP6_MLD_GROUP *
|
---|
23 | Ip6CreateMldEntry (
|
---|
24 | IN OUT IP6_SERVICE *IpSb,
|
---|
25 | IN EFI_IPv6_ADDRESS *MulticastAddr,
|
---|
26 | IN UINT32 DelayTimer
|
---|
27 | )
|
---|
28 | {
|
---|
29 | IP6_MLD_GROUP *Entry;
|
---|
30 |
|
---|
31 | NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
|
---|
32 | ASSERT (MulticastAddr != NULL && IP6_IS_MULTICAST (MulticastAddr));
|
---|
33 |
|
---|
34 | Entry = AllocatePool (sizeof (IP6_MLD_GROUP));
|
---|
35 | if (Entry != NULL) {
|
---|
36 | Entry->RefCnt = 1;
|
---|
37 | Entry->DelayTimer = DelayTimer;
|
---|
38 | Entry->SendByUs = FALSE;
|
---|
39 | IP6_COPY_ADDRESS (&Entry->Address, MulticastAddr);
|
---|
40 | InsertTailList (&IpSb->MldCtrl.Groups, &Entry->Link);
|
---|
41 | }
|
---|
42 |
|
---|
43 | return Entry;
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | Search a IP6_MLD_GROUP list entry node from a list array.
|
---|
48 |
|
---|
49 | @param[in] IpSb Points to IP6 service binding instance.
|
---|
50 | @param[in] MulticastAddr The IPv6 multicast address to be searched.
|
---|
51 |
|
---|
52 | @return The found IP6_ML_GROUP list entry or NULL.
|
---|
53 |
|
---|
54 | **/
|
---|
55 | IP6_MLD_GROUP *
|
---|
56 | Ip6FindMldEntry (
|
---|
57 | IN IP6_SERVICE *IpSb,
|
---|
58 | IN EFI_IPv6_ADDRESS *MulticastAddr
|
---|
59 | )
|
---|
60 | {
|
---|
61 | LIST_ENTRY *Entry;
|
---|
62 | IP6_MLD_GROUP *Group;
|
---|
63 |
|
---|
64 | NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
|
---|
65 | ASSERT (MulticastAddr != NULL && IP6_IS_MULTICAST (MulticastAddr));
|
---|
66 |
|
---|
67 | NET_LIST_FOR_EACH (Entry, &IpSb->MldCtrl.Groups) {
|
---|
68 | Group = NET_LIST_USER_STRUCT (Entry, IP6_MLD_GROUP, Link);
|
---|
69 | if (EFI_IP6_EQUAL (MulticastAddr, &Group->Address)) {
|
---|
70 | return Group;
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | return NULL;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | Count the number of IP6 multicast groups that are mapped to the
|
---|
79 | same MAC address. Several IP6 multicast address may be mapped to
|
---|
80 | the same MAC address.
|
---|
81 |
|
---|
82 | @param[in] MldCtrl The MLD control block to search in.
|
---|
83 | @param[in] Mac The MAC address to search.
|
---|
84 |
|
---|
85 | @return The number of the IP6 multicast group that mapped to the same
|
---|
86 | multicast group Mac.
|
---|
87 |
|
---|
88 | **/
|
---|
89 | INTN
|
---|
90 | Ip6FindMac (
|
---|
91 | IN IP6_MLD_SERVICE_DATA *MldCtrl,
|
---|
92 | IN EFI_MAC_ADDRESS *Mac
|
---|
93 | )
|
---|
94 | {
|
---|
95 | LIST_ENTRY *Entry;
|
---|
96 | IP6_MLD_GROUP *Group;
|
---|
97 | INTN Count;
|
---|
98 |
|
---|
99 | Count = 0;
|
---|
100 |
|
---|
101 | NET_LIST_FOR_EACH (Entry, &MldCtrl->Groups) {
|
---|
102 | Group = NET_LIST_USER_STRUCT (Entry, IP6_MLD_GROUP, Link);
|
---|
103 |
|
---|
104 | if (NET_MAC_EQUAL (&Group->Mac, Mac, sizeof (EFI_MAC_ADDRESS))) {
|
---|
105 | Count++;
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | return Count;
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | Generate MLD report message and send it out to MulticastAddr.
|
---|
114 |
|
---|
115 | @param[in] IpSb The IP service to send the packet.
|
---|
116 | @param[in] Interface The IP interface to send the packet.
|
---|
117 | If NULL, a system interface will be selected.
|
---|
118 | @param[in] MulticastAddr The specific IPv6 multicast address to which
|
---|
119 | the message sender is listening.
|
---|
120 |
|
---|
121 | @retval EFI_OUT_OF_RESOURCES There are not sufficient resources to complete the
|
---|
122 | operation.
|
---|
123 | @retval EFI_SUCCESS The MLD report message was successfully sent out.
|
---|
124 |
|
---|
125 | **/
|
---|
126 | EFI_STATUS
|
---|
127 | Ip6SendMldReport (
|
---|
128 | IN IP6_SERVICE *IpSb,
|
---|
129 | IN IP6_INTERFACE *Interface OPTIONAL,
|
---|
130 | IN EFI_IPv6_ADDRESS *MulticastAddr
|
---|
131 | )
|
---|
132 | {
|
---|
133 | IP6_MLD_HEAD *MldHead;
|
---|
134 | NET_BUF *Packet;
|
---|
135 | EFI_IP6_HEADER Head;
|
---|
136 | UINT16 PayloadLen;
|
---|
137 | UINTN OptionLen;
|
---|
138 | UINT8 *Options;
|
---|
139 | EFI_STATUS Status;
|
---|
140 | UINT16 HeadChecksum;
|
---|
141 | UINT16 PseudoChecksum;
|
---|
142 |
|
---|
143 | NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
|
---|
144 | ASSERT (MulticastAddr != NULL && IP6_IS_MULTICAST (MulticastAddr));
|
---|
145 |
|
---|
146 | //
|
---|
147 | // Generate the packet to be sent
|
---|
148 | // IPv6 basic header + Hop by Hop option + MLD message
|
---|
149 | //
|
---|
150 |
|
---|
151 | OptionLen = 0;
|
---|
152 | Status = Ip6FillHopByHop (NULL, &OptionLen, IP6_ICMP);
|
---|
153 | ASSERT (Status == EFI_BUFFER_TOO_SMALL);
|
---|
154 |
|
---|
155 | PayloadLen = (UINT16) (OptionLen + sizeof (IP6_MLD_HEAD));
|
---|
156 | Packet = NetbufAlloc (sizeof (EFI_IP6_HEADER) + (UINT32) PayloadLen);
|
---|
157 | if (Packet == NULL) {
|
---|
158 | return EFI_OUT_OF_RESOURCES;
|
---|
159 | }
|
---|
160 |
|
---|
161 | //
|
---|
162 | // Create the basic IPv6 header.
|
---|
163 | // RFC3590: Use link-local address as source address if it is available,
|
---|
164 | // otherwise use the unspecified address.
|
---|
165 | //
|
---|
166 | Head.FlowLabelL = 0;
|
---|
167 | Head.FlowLabelH = 0;
|
---|
168 | Head.PayloadLength = HTONS (PayloadLen);
|
---|
169 | Head.NextHeader = IP6_HOP_BY_HOP;
|
---|
170 | Head.HopLimit = 1;
|
---|
171 | IP6_COPY_ADDRESS (&Head.DestinationAddress, MulticastAddr);
|
---|
172 |
|
---|
173 | //
|
---|
174 | // If Link-Local address is not ready, we use unspecified address.
|
---|
175 | //
|
---|
176 | IP6_COPY_ADDRESS (&Head.SourceAddress, &IpSb->LinkLocalAddr);
|
---|
177 |
|
---|
178 | NetbufReserve (Packet, sizeof (EFI_IP6_HEADER));
|
---|
179 |
|
---|
180 | //
|
---|
181 | // Fill a IPv6 Router Alert option in a Hop-by-Hop Options Header
|
---|
182 | //
|
---|
183 | Options = NetbufAllocSpace (Packet, (UINT32) OptionLen, FALSE);
|
---|
184 | ASSERT (Options != NULL);
|
---|
185 | Status = Ip6FillHopByHop (Options, &OptionLen, IP6_ICMP);
|
---|
186 | if (EFI_ERROR (Status)) {
|
---|
187 | NetbufFree (Packet);
|
---|
188 | Packet = NULL;
|
---|
189 | return Status;
|
---|
190 | }
|
---|
191 |
|
---|
192 | //
|
---|
193 | // Fill in MLD message - Report
|
---|
194 | //
|
---|
195 | MldHead = (IP6_MLD_HEAD *) NetbufAllocSpace (Packet, sizeof (IP6_MLD_HEAD), FALSE);
|
---|
196 | ASSERT (MldHead != NULL);
|
---|
197 | ZeroMem (MldHead, sizeof (IP6_MLD_HEAD));
|
---|
198 | MldHead->Head.Type = ICMP_V6_LISTENER_REPORT;
|
---|
199 | MldHead->Head.Code = 0;
|
---|
200 | IP6_COPY_ADDRESS (&MldHead->Group, MulticastAddr);
|
---|
201 |
|
---|
202 | HeadChecksum = NetblockChecksum ((UINT8 *) MldHead, sizeof (IP6_MLD_HEAD));
|
---|
203 | PseudoChecksum = NetIp6PseudoHeadChecksum (
|
---|
204 | &Head.SourceAddress,
|
---|
205 | &Head.DestinationAddress,
|
---|
206 | IP6_ICMP,
|
---|
207 | sizeof (IP6_MLD_HEAD)
|
---|
208 | );
|
---|
209 |
|
---|
210 | MldHead->Head.Checksum = (UINT16) ~NetAddChecksum (HeadChecksum, PseudoChecksum);
|
---|
211 |
|
---|
212 | //
|
---|
213 | // Transmit the packet
|
---|
214 | //
|
---|
215 | return Ip6Output (IpSb, Interface, NULL, Packet, &Head, NULL, 0, Ip6SysPacketSent, NULL);
|
---|
216 | }
|
---|
217 |
|
---|
218 | /**
|
---|
219 | Generate MLD Done message and send it out to MulticastAddr.
|
---|
220 |
|
---|
221 | @param[in] IpSb The IP service to send the packet.
|
---|
222 | @param[in] MulticastAddr The specific IPv6 multicast address to which
|
---|
223 | the message sender is ceasing to listen.
|
---|
224 |
|
---|
225 | @retval EFI_OUT_OF_RESOURCES There are not sufficient resources to complete the
|
---|
226 | operation.
|
---|
227 | @retval EFI_SUCCESS The MLD report message was successfully sent out.
|
---|
228 |
|
---|
229 | **/
|
---|
230 | EFI_STATUS
|
---|
231 | Ip6SendMldDone (
|
---|
232 | IN IP6_SERVICE *IpSb,
|
---|
233 | IN EFI_IPv6_ADDRESS *MulticastAddr
|
---|
234 | )
|
---|
235 | {
|
---|
236 | IP6_MLD_HEAD *MldHead;
|
---|
237 | NET_BUF *Packet;
|
---|
238 | EFI_IP6_HEADER Head;
|
---|
239 | UINT16 PayloadLen;
|
---|
240 | UINTN OptionLen;
|
---|
241 | UINT8 *Options;
|
---|
242 | EFI_STATUS Status;
|
---|
243 | EFI_IPv6_ADDRESS Destination;
|
---|
244 | UINT16 HeadChecksum;
|
---|
245 | UINT16 PseudoChecksum;
|
---|
246 |
|
---|
247 | NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
|
---|
248 | ASSERT (MulticastAddr != NULL && IP6_IS_MULTICAST (MulticastAddr));
|
---|
249 |
|
---|
250 | //
|
---|
251 | // Generate the packet to be sent
|
---|
252 | // IPv6 basic header + Hop by Hop option + MLD message
|
---|
253 | //
|
---|
254 |
|
---|
255 | OptionLen = 0;
|
---|
256 | Status = Ip6FillHopByHop (NULL, &OptionLen, IP6_ICMP);
|
---|
257 | ASSERT (Status == EFI_BUFFER_TOO_SMALL);
|
---|
258 |
|
---|
259 | PayloadLen = (UINT16) (OptionLen + sizeof (IP6_MLD_HEAD));
|
---|
260 | Packet = NetbufAlloc (sizeof (EFI_IP6_HEADER) + (UINT32) PayloadLen);
|
---|
261 | if (Packet == NULL) {
|
---|
262 | return EFI_OUT_OF_RESOURCES;
|
---|
263 | }
|
---|
264 |
|
---|
265 | //
|
---|
266 | // Create the basic IPv6 header.
|
---|
267 | //
|
---|
268 | Head.FlowLabelL = 0;
|
---|
269 | Head.FlowLabelH = 0;
|
---|
270 | Head.PayloadLength = HTONS (PayloadLen);
|
---|
271 | Head.NextHeader = IP6_HOP_BY_HOP;
|
---|
272 | Head.HopLimit = 1;
|
---|
273 |
|
---|
274 | //
|
---|
275 | // If Link-Local address is not ready, we use unspecified address.
|
---|
276 | //
|
---|
277 | IP6_COPY_ADDRESS (&Head.SourceAddress, &IpSb->LinkLocalAddr);
|
---|
278 |
|
---|
279 | Ip6SetToAllNodeMulticast (TRUE, IP6_LINK_LOCAL_SCOPE, &Destination);
|
---|
280 | IP6_COPY_ADDRESS (&Head.DestinationAddress, &Destination);
|
---|
281 |
|
---|
282 | NetbufReserve (Packet, sizeof (EFI_IP6_HEADER));
|
---|
283 |
|
---|
284 | //
|
---|
285 | // Fill a IPv6 Router Alert option in a Hop-by-Hop Options Header
|
---|
286 | //
|
---|
287 | Options = NetbufAllocSpace (Packet, (UINT32) OptionLen, FALSE);
|
---|
288 | ASSERT (Options != NULL);
|
---|
289 | Status = Ip6FillHopByHop (Options, &OptionLen, IP6_ICMP);
|
---|
290 | if (EFI_ERROR (Status)) {
|
---|
291 | NetbufFree (Packet);
|
---|
292 | Packet = NULL;
|
---|
293 | return Status;
|
---|
294 | }
|
---|
295 |
|
---|
296 | //
|
---|
297 | // Fill in MLD message - Done
|
---|
298 | //
|
---|
299 | MldHead = (IP6_MLD_HEAD *) NetbufAllocSpace (Packet, sizeof (IP6_MLD_HEAD), FALSE);
|
---|
300 | ASSERT (MldHead != NULL);
|
---|
301 | ZeroMem (MldHead, sizeof (IP6_MLD_HEAD));
|
---|
302 | MldHead->Head.Type = ICMP_V6_LISTENER_DONE;
|
---|
303 | MldHead->Head.Code = 0;
|
---|
304 | IP6_COPY_ADDRESS (&MldHead->Group, MulticastAddr);
|
---|
305 |
|
---|
306 | HeadChecksum = NetblockChecksum ((UINT8 *) MldHead, sizeof (IP6_MLD_HEAD));
|
---|
307 | PseudoChecksum = NetIp6PseudoHeadChecksum (
|
---|
308 | &Head.SourceAddress,
|
---|
309 | &Head.DestinationAddress,
|
---|
310 | IP6_ICMP,
|
---|
311 | sizeof (IP6_MLD_HEAD)
|
---|
312 | );
|
---|
313 |
|
---|
314 | MldHead->Head.Checksum = (UINT16) ~NetAddChecksum (HeadChecksum, PseudoChecksum);
|
---|
315 |
|
---|
316 | //
|
---|
317 | // Transmit the packet
|
---|
318 | //
|
---|
319 | return Ip6Output (IpSb, NULL, NULL, Packet, &Head, NULL, 0, Ip6SysPacketSent, NULL);
|
---|
320 | }
|
---|
321 |
|
---|
322 | /**
|
---|
323 | Init the MLD data of the IP6 service instance. Configure
|
---|
324 | MNP to receive ALL SYSTEM multicast.
|
---|
325 |
|
---|
326 | @param[in] IpSb The IP6 service whose MLD is to be initialized.
|
---|
327 |
|
---|
328 | @retval EFI_OUT_OF_RESOURCES There are not sufficient resourcet to complete the
|
---|
329 | operation.
|
---|
330 | @retval EFI_SUCCESS The MLD module successfully initialized.
|
---|
331 |
|
---|
332 | **/
|
---|
333 | EFI_STATUS
|
---|
334 | Ip6InitMld (
|
---|
335 | IN IP6_SERVICE *IpSb
|
---|
336 | )
|
---|
337 | {
|
---|
338 | EFI_IPv6_ADDRESS AllNodes;
|
---|
339 | IP6_MLD_GROUP *Group;
|
---|
340 | EFI_STATUS Status;
|
---|
341 |
|
---|
342 | //
|
---|
343 | // Join the link-scope all-nodes multicast address (FF02::1).
|
---|
344 | // This address is started in Idle Listener state and never transitions to
|
---|
345 | // another state, and never sends a Report or Done for that address.
|
---|
346 | //
|
---|
347 |
|
---|
348 | Ip6SetToAllNodeMulticast (FALSE, IP6_LINK_LOCAL_SCOPE, &AllNodes);
|
---|
349 |
|
---|
350 | Group = Ip6CreateMldEntry (IpSb, &AllNodes, (UINT32) IP6_INFINIT_LIFETIME);
|
---|
351 | if (Group == NULL) {
|
---|
352 | return EFI_OUT_OF_RESOURCES;
|
---|
353 | }
|
---|
354 |
|
---|
355 | Status = Ip6GetMulticastMac (IpSb->Mnp, &AllNodes, &Group->Mac);
|
---|
356 | if (EFI_ERROR (Status)) {
|
---|
357 | goto ERROR;
|
---|
358 | }
|
---|
359 |
|
---|
360 | //
|
---|
361 | // Configure MNP to receive all-nodes multicast
|
---|
362 | //
|
---|
363 | Status = IpSb->Mnp->Groups (IpSb->Mnp, TRUE, &Group->Mac);
|
---|
364 | if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
|
---|
365 | goto ERROR;
|
---|
366 | }
|
---|
367 |
|
---|
368 | return EFI_SUCCESS;
|
---|
369 |
|
---|
370 | ERROR:
|
---|
371 | RemoveEntryList (&Group->Link);
|
---|
372 | FreePool (Group);
|
---|
373 | return Status;
|
---|
374 | }
|
---|
375 |
|
---|
376 | /**
|
---|
377 | Add a group address to the array of group addresses.
|
---|
378 | The caller should make sure that no duplicated address
|
---|
379 | existed in the array.
|
---|
380 |
|
---|
381 | @param[in, out] IpInstance Points to an IP6_PROTOCOL instance.
|
---|
382 | @param[in] Group The IP6 multicast address to add.
|
---|
383 |
|
---|
384 | @retval EFI_OUT_OF_RESOURCES There are not sufficient resources to complete
|
---|
385 | the operation.
|
---|
386 | @retval EFI_SUCESS The address is added to the group address array.
|
---|
387 |
|
---|
388 | **/
|
---|
389 | EFI_STATUS
|
---|
390 | Ip6CombineGroups (
|
---|
391 | IN OUT IP6_PROTOCOL *IpInstance,
|
---|
392 | IN EFI_IPv6_ADDRESS *Group
|
---|
393 | )
|
---|
394 | {
|
---|
395 | EFI_IPv6_ADDRESS *GroupList;
|
---|
396 |
|
---|
397 | NET_CHECK_SIGNATURE (IpInstance, IP6_PROTOCOL_SIGNATURE);
|
---|
398 | ASSERT (Group != NULL && IP6_IS_MULTICAST (Group));
|
---|
399 |
|
---|
400 | IpInstance->GroupCount++;
|
---|
401 |
|
---|
402 | GroupList = AllocatePool (IpInstance->GroupCount * sizeof (EFI_IPv6_ADDRESS));
|
---|
403 | if (GroupList == NULL) {
|
---|
404 | return EFI_OUT_OF_RESOURCES;
|
---|
405 | }
|
---|
406 |
|
---|
407 | if (IpInstance->GroupCount > 1) {
|
---|
408 | ASSERT (IpInstance->GroupList != NULL);
|
---|
409 |
|
---|
410 | CopyMem (
|
---|
411 | GroupList,
|
---|
412 | IpInstance->GroupList,
|
---|
413 | (IpInstance->GroupCount - 1) * sizeof (EFI_IPv6_ADDRESS)
|
---|
414 | );
|
---|
415 |
|
---|
416 | FreePool (IpInstance->GroupList);
|
---|
417 | }
|
---|
418 |
|
---|
419 | IP6_COPY_ADDRESS (GroupList + (IpInstance->GroupCount - 1), Group);
|
---|
420 |
|
---|
421 | IpInstance->GroupList = GroupList;
|
---|
422 |
|
---|
423 | return EFI_SUCCESS;
|
---|
424 | }
|
---|
425 |
|
---|
426 | /**
|
---|
427 | Remove a group address from the array of group addresses.
|
---|
428 | Although the function doesn't assume the byte order of Group,
|
---|
429 | the network byte order is used by the caller.
|
---|
430 |
|
---|
431 | @param[in, out] IpInstance Points to an IP6_PROTOCOL instance.
|
---|
432 | @param[in] Group The IP6 multicast address to remove.
|
---|
433 |
|
---|
434 | @retval EFI_NOT_FOUND Cannot find the to be removed group address.
|
---|
435 | @retval EFI_SUCCESS The group address was successfully removed.
|
---|
436 |
|
---|
437 | **/
|
---|
438 | EFI_STATUS
|
---|
439 | Ip6RemoveGroup (
|
---|
440 | IN OUT IP6_PROTOCOL *IpInstance,
|
---|
441 | IN EFI_IPv6_ADDRESS *Group
|
---|
442 | )
|
---|
443 | {
|
---|
444 | UINT32 Index;
|
---|
445 | UINT32 Count;
|
---|
446 |
|
---|
447 | Count = IpInstance->GroupCount;
|
---|
448 |
|
---|
449 | for (Index = 0; Index < Count; Index++) {
|
---|
450 | if (EFI_IP6_EQUAL (IpInstance->GroupList + Index, Group)) {
|
---|
451 | break;
|
---|
452 | }
|
---|
453 | }
|
---|
454 |
|
---|
455 | if (Index == Count) {
|
---|
456 | return EFI_NOT_FOUND;
|
---|
457 | }
|
---|
458 |
|
---|
459 | while (Index < Count - 1) {
|
---|
460 | IP6_COPY_ADDRESS (IpInstance->GroupList + Index, IpInstance->GroupList + Index + 1);
|
---|
461 | Index++;
|
---|
462 | }
|
---|
463 |
|
---|
464 | ASSERT (IpInstance->GroupCount > 0);
|
---|
465 | IpInstance->GroupCount--;
|
---|
466 |
|
---|
467 | return EFI_SUCCESS;
|
---|
468 | }
|
---|
469 |
|
---|
470 | /**
|
---|
471 | Join the multicast group on behalf of this IP6 service binding instance.
|
---|
472 |
|
---|
473 | @param[in] IpSb The IP6 service binding instance.
|
---|
474 | @param[in] Interface Points to an IP6_INTERFACE structure.
|
---|
475 | @param[in] Address The group address to join.
|
---|
476 |
|
---|
477 | @retval EFI_SUCCESS Successfully join the multicast group.
|
---|
478 | @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
|
---|
479 | @retval Others Failed to join the multicast group.
|
---|
480 |
|
---|
481 | **/
|
---|
482 | EFI_STATUS
|
---|
483 | Ip6JoinGroup (
|
---|
484 | IN IP6_SERVICE *IpSb,
|
---|
485 | IN IP6_INTERFACE *Interface,
|
---|
486 | IN EFI_IPv6_ADDRESS *Address
|
---|
487 | )
|
---|
488 | {
|
---|
489 | IP6_MLD_GROUP *Group;
|
---|
490 | EFI_STATUS Status;
|
---|
491 |
|
---|
492 | Group = Ip6FindMldEntry (IpSb, Address);
|
---|
493 | if (Group != NULL) {
|
---|
494 | Group->RefCnt++;
|
---|
495 | return EFI_SUCCESS;
|
---|
496 | }
|
---|
497 |
|
---|
498 | //
|
---|
499 | // Repeat the report once or twcie after short delays [Unsolicited Report Interval] (default:10s)
|
---|
500 | // Simulate this operation as a Multicast-Address-Specific Query was received for that addresss.
|
---|
501 | //
|
---|
502 | Group = Ip6CreateMldEntry (IpSb, Address, IP6_UNSOLICITED_REPORT_INTERVAL);
|
---|
503 | if (Group == NULL) {
|
---|
504 | return EFI_OUT_OF_RESOURCES;
|
---|
505 | }
|
---|
506 |
|
---|
507 | Group->SendByUs = TRUE;
|
---|
508 |
|
---|
509 | Status = Ip6GetMulticastMac (IpSb->Mnp, Address, &Group->Mac);
|
---|
510 | if (EFI_ERROR (Status)) {
|
---|
511 | return Status;
|
---|
512 | }
|
---|
513 |
|
---|
514 | Status = IpSb->Mnp->Groups (IpSb->Mnp, TRUE, &Group->Mac);
|
---|
515 | if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
|
---|
516 | goto ERROR;
|
---|
517 | }
|
---|
518 |
|
---|
519 | //
|
---|
520 | // Send unsolicited report when a node starts listening to a multicast address
|
---|
521 | //
|
---|
522 | Status = Ip6SendMldReport (IpSb, Interface, Address);
|
---|
523 | if (EFI_ERROR (Status)) {
|
---|
524 | goto ERROR;
|
---|
525 | }
|
---|
526 |
|
---|
527 | return EFI_SUCCESS;
|
---|
528 |
|
---|
529 | ERROR:
|
---|
530 | RemoveEntryList (&Group->Link);
|
---|
531 | FreePool (Group);
|
---|
532 | return Status;
|
---|
533 | }
|
---|
534 |
|
---|
535 | /**
|
---|
536 | Leave the IP6 multicast group.
|
---|
537 |
|
---|
538 | @param[in] IpSb The IP6 service binding instance.
|
---|
539 | @param[in] Address The group address to leave.
|
---|
540 |
|
---|
541 | @retval EFI_NOT_FOUND The IP6 service instance isn't in the group.
|
---|
542 | @retval EFI_SUCCESS Successfully leave the multicast group..
|
---|
543 | @retval Others Failed to leave the multicast group.
|
---|
544 |
|
---|
545 | **/
|
---|
546 | EFI_STATUS
|
---|
547 | Ip6LeaveGroup (
|
---|
548 | IN IP6_SERVICE *IpSb,
|
---|
549 | IN EFI_IPv6_ADDRESS *Address
|
---|
550 | )
|
---|
551 | {
|
---|
552 | IP6_MLD_GROUP *Group;
|
---|
553 | EFI_STATUS Status;
|
---|
554 |
|
---|
555 | Group = Ip6FindMldEntry (IpSb, Address);
|
---|
556 | if (Group == NULL) {
|
---|
557 | return EFI_NOT_FOUND;
|
---|
558 | }
|
---|
559 |
|
---|
560 | //
|
---|
561 | // If more than one instance is in the group, decrease
|
---|
562 | // the RefCnt then return.
|
---|
563 | //
|
---|
564 | if ((Group->RefCnt > 0) && (--Group->RefCnt > 0)) {
|
---|
565 | return EFI_SUCCESS;
|
---|
566 | }
|
---|
567 |
|
---|
568 | //
|
---|
569 | // If multiple IP6 group addresses are mapped to the same
|
---|
570 | // multicast MAC address, don't configure the MNP to leave
|
---|
571 | // the MAC.
|
---|
572 | //
|
---|
573 | if (Ip6FindMac (&IpSb->MldCtrl, &Group->Mac) == 1) {
|
---|
574 | Status = IpSb->Mnp->Groups (IpSb->Mnp, FALSE, &Group->Mac);
|
---|
575 | if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
|
---|
576 | return Status;
|
---|
577 | }
|
---|
578 | }
|
---|
579 |
|
---|
580 | //
|
---|
581 | // Send a leave report if we are the last node to report
|
---|
582 | //
|
---|
583 | if (Group->SendByUs) {
|
---|
584 | Status = Ip6SendMldDone (IpSb, Address);
|
---|
585 | if (EFI_ERROR (Status)) {
|
---|
586 | return Status;
|
---|
587 | }
|
---|
588 | }
|
---|
589 |
|
---|
590 | RemoveEntryList (&Group->Link);
|
---|
591 | FreePool (Group);
|
---|
592 |
|
---|
593 | return EFI_SUCCESS;
|
---|
594 | }
|
---|
595 |
|
---|
596 | /**
|
---|
597 | Worker function for EfiIp6Groups(). The caller
|
---|
598 | should make sure that the parameters are valid.
|
---|
599 |
|
---|
600 | @param[in] IpInstance The IP6 child to change the setting.
|
---|
601 | @param[in] JoinFlag TRUE to join the group, otherwise leave it.
|
---|
602 | @param[in] GroupAddress The target group address. If NULL, leave all
|
---|
603 | the group addresses.
|
---|
604 |
|
---|
605 | @retval EFI_ALREADY_STARTED Wants to join the group, but is already a member of it
|
---|
606 | @retval EFI_OUT_OF_RESOURCES Failed to allocate sufficient resources.
|
---|
607 | @retval EFI_DEVICE_ERROR Failed to set the group configuraton.
|
---|
608 | @retval EFI_SUCCESS Successfully updated the group setting.
|
---|
609 | @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.
|
---|
610 |
|
---|
611 | **/
|
---|
612 | EFI_STATUS
|
---|
613 | Ip6Groups (
|
---|
614 | IN IP6_PROTOCOL *IpInstance,
|
---|
615 | IN BOOLEAN JoinFlag,
|
---|
616 | IN EFI_IPv6_ADDRESS *GroupAddress OPTIONAL
|
---|
617 | )
|
---|
618 | {
|
---|
619 | EFI_STATUS Status;
|
---|
620 | IP6_SERVICE *IpSb;
|
---|
621 | UINT32 Index;
|
---|
622 | EFI_IPv6_ADDRESS *Group;
|
---|
623 |
|
---|
624 | IpSb = IpInstance->Service;
|
---|
625 |
|
---|
626 | if (JoinFlag) {
|
---|
627 | ASSERT (GroupAddress != NULL);
|
---|
628 |
|
---|
629 | for (Index = 0; Index < IpInstance->GroupCount; Index++) {
|
---|
630 | if (EFI_IP6_EQUAL (IpInstance->GroupList + Index, GroupAddress)) {
|
---|
631 | return EFI_ALREADY_STARTED;
|
---|
632 | }
|
---|
633 | }
|
---|
634 |
|
---|
635 | Status = Ip6JoinGroup (IpSb, IpInstance->Interface, GroupAddress);
|
---|
636 | if (!EFI_ERROR (Status)) {
|
---|
637 | return Ip6CombineGroups (IpInstance, GroupAddress);
|
---|
638 | }
|
---|
639 |
|
---|
640 | return Status;
|
---|
641 | }
|
---|
642 |
|
---|
643 | //
|
---|
644 | // Leave the group. Leave all the groups if GroupAddress is NULL.
|
---|
645 | //
|
---|
646 | for (Index = IpInstance->GroupCount; Index > 0; Index--) {
|
---|
647 | Group = IpInstance->GroupList + (Index - 1);
|
---|
648 |
|
---|
649 | if ((GroupAddress == NULL) || EFI_IP6_EQUAL (Group, GroupAddress)) {
|
---|
650 | Status = Ip6LeaveGroup (IpInstance->Service, Group);
|
---|
651 | if (EFI_ERROR (Status)) {
|
---|
652 | return Status;
|
---|
653 | }
|
---|
654 |
|
---|
655 | Ip6RemoveGroup (IpInstance, Group);
|
---|
656 |
|
---|
657 | if (IpInstance->GroupCount == 0) {
|
---|
658 | ASSERT (Index == 1);
|
---|
659 | FreePool (IpInstance->GroupList);
|
---|
660 | IpInstance->GroupList = NULL;
|
---|
661 | }
|
---|
662 |
|
---|
663 | if (GroupAddress != NULL) {
|
---|
664 | return EFI_SUCCESS;
|
---|
665 | }
|
---|
666 | }
|
---|
667 | }
|
---|
668 |
|
---|
669 | return ((GroupAddress != NULL) ? EFI_NOT_FOUND : EFI_SUCCESS);
|
---|
670 | }
|
---|
671 |
|
---|
672 | /**
|
---|
673 | Set a random value of the delay timer for the multicast address from the range
|
---|
674 | [0, Maximum Response Delay]. If a timer for any address is already
|
---|
675 | running, it is reset to the new random value only if the requested
|
---|
676 | Maximum Response Delay is less than the remaining value of the
|
---|
677 | running timer. If the Query packet specifies a Maximum Response
|
---|
678 | Delay of zero, each timer is effectively set to zero, and the action
|
---|
679 | specified below for timer expiration is performed immediately.
|
---|
680 |
|
---|
681 | @param[in] IpSb The IP6 service binding instance.
|
---|
682 | @param[in] MaxRespDelay The Maximum Response Delay, in milliseconds.
|
---|
683 | @param[in] MulticastAddr The multicast address.
|
---|
684 | @param[in, out] Group Points to a IP6_MLD_GROUP list entry node.
|
---|
685 |
|
---|
686 | @retval EFI_SUCCESS The delay timer is successfully updated or
|
---|
687 | timer expiration is performed immediately.
|
---|
688 | @retval Others Failed to send out MLD report message.
|
---|
689 |
|
---|
690 | **/
|
---|
691 | EFI_STATUS
|
---|
692 | Ip6UpdateDelayTimer (
|
---|
693 | IN IP6_SERVICE *IpSb,
|
---|
694 | IN UINT16 MaxRespDelay,
|
---|
695 | IN EFI_IPv6_ADDRESS *MulticastAddr,
|
---|
696 | IN OUT IP6_MLD_GROUP *Group
|
---|
697 | )
|
---|
698 | {
|
---|
699 | UINT32 Delay;
|
---|
700 |
|
---|
701 | //
|
---|
702 | // If the Query packet specifies a Maximum Response Delay of zero, perform timer
|
---|
703 | // expiration immediately.
|
---|
704 | //
|
---|
705 | if (MaxRespDelay == 0) {
|
---|
706 | Group->DelayTimer = 0;
|
---|
707 | return Ip6SendMldReport (IpSb, NULL, MulticastAddr);
|
---|
708 | }
|
---|
709 |
|
---|
710 | Delay = (UINT32) (MaxRespDelay / 1000);
|
---|
711 |
|
---|
712 | //
|
---|
713 | // Sets a delay timer to a random value selected from the range [0, Maximum Response Delay]
|
---|
714 | // If a timer is already running, resets it if the request Maximum Response Delay
|
---|
715 | // is less than the remaining value of the running timer.
|
---|
716 | //
|
---|
717 | if (Group->DelayTimer == 0 || Delay < Group->DelayTimer) {
|
---|
718 | Group->DelayTimer = Delay / 4294967295UL * NET_RANDOM (NetRandomInitSeed ());
|
---|
719 | }
|
---|
720 |
|
---|
721 | return EFI_SUCCESS;
|
---|
722 | }
|
---|
723 |
|
---|
724 | /**
|
---|
725 | Process the Multicast Listener Query message.
|
---|
726 |
|
---|
727 | @param[in] IpSb The IP service that received the packet.
|
---|
728 | @param[in] Head The IP head of the MLD query packet.
|
---|
729 | @param[in] Packet The content of the MLD query packet with IP head
|
---|
730 | removed.
|
---|
731 |
|
---|
732 | @retval EFI_SUCCESS The MLD query packet processed successfully.
|
---|
733 | @retval EFI_INVALID_PARAMETER The packet is invalid.
|
---|
734 | @retval Others Failed to process the packet.
|
---|
735 |
|
---|
736 | **/
|
---|
737 | EFI_STATUS
|
---|
738 | Ip6ProcessMldQuery (
|
---|
739 | IN IP6_SERVICE *IpSb,
|
---|
740 | IN EFI_IP6_HEADER *Head,
|
---|
741 | IN NET_BUF *Packet
|
---|
742 | )
|
---|
743 | {
|
---|
744 | EFI_IPv6_ADDRESS AllNodes;
|
---|
745 | IP6_MLD_GROUP *Group;
|
---|
746 | IP6_MLD_HEAD MldPacket;
|
---|
747 | LIST_ENTRY *Entry;
|
---|
748 | EFI_STATUS Status;
|
---|
749 |
|
---|
750 | Status = EFI_INVALID_PARAMETER;
|
---|
751 |
|
---|
752 | //
|
---|
753 | // Check the validity of the packet, generic query or specific query
|
---|
754 | //
|
---|
755 | if (!NetIp6IsUnspecifiedAddr (&Head->SourceAddress) && !NetIp6IsLinkLocalAddr (&Head->SourceAddress)) {
|
---|
756 | goto Exit;
|
---|
757 | }
|
---|
758 |
|
---|
759 | if (Head->HopLimit != 1 || !IP6_IS_MULTICAST (&Head->DestinationAddress)) {
|
---|
760 | goto Exit;
|
---|
761 | }
|
---|
762 |
|
---|
763 | //
|
---|
764 | // The Packet points to MLD report raw data without Hop-By-Hop option.
|
---|
765 | //
|
---|
766 | NetbufCopy (Packet, 0, sizeof (IP6_MLD_HEAD), (UINT8 *) &MldPacket);
|
---|
767 | MldPacket.MaxRespDelay = NTOHS (MldPacket.MaxRespDelay);
|
---|
768 |
|
---|
769 | Ip6SetToAllNodeMulticast (FALSE, IP6_LINK_LOCAL_SCOPE, &AllNodes);
|
---|
770 | if (!EFI_IP6_EQUAL (&Head->DestinationAddress, &AllNodes)) {
|
---|
771 | //
|
---|
772 | // Receives a Multicast-Address-Specific Query, check it firstly
|
---|
773 | //
|
---|
774 | if (!EFI_IP6_EQUAL (&Head->DestinationAddress, &MldPacket.Group)) {
|
---|
775 | goto Exit;
|
---|
776 | }
|
---|
777 | //
|
---|
778 | // The node is not listening but it receives the specific query. Just return.
|
---|
779 | //
|
---|
780 | Group = Ip6FindMldEntry (IpSb, &MldPacket.Group);
|
---|
781 | if (Group == NULL) {
|
---|
782 | Status = EFI_SUCCESS;
|
---|
783 | goto Exit;
|
---|
784 | }
|
---|
785 |
|
---|
786 | Status = Ip6UpdateDelayTimer (
|
---|
787 | IpSb,
|
---|
788 | MldPacket.MaxRespDelay,
|
---|
789 | &MldPacket.Group,
|
---|
790 | Group
|
---|
791 | );
|
---|
792 | goto Exit;
|
---|
793 | }
|
---|
794 |
|
---|
795 | //
|
---|
796 | // Receives a General Query, sets a delay timer for each multicast address it is listening
|
---|
797 | //
|
---|
798 | NET_LIST_FOR_EACH (Entry, &IpSb->MldCtrl.Groups) {
|
---|
799 | Group = NET_LIST_USER_STRUCT (Entry, IP6_MLD_GROUP, Link);
|
---|
800 | Status = Ip6UpdateDelayTimer (IpSb, MldPacket.MaxRespDelay, &Group->Address, Group);
|
---|
801 | if (EFI_ERROR (Status)) {
|
---|
802 | goto Exit;
|
---|
803 | }
|
---|
804 | }
|
---|
805 |
|
---|
806 | Status = EFI_SUCCESS;
|
---|
807 |
|
---|
808 | Exit:
|
---|
809 | NetbufFree (Packet);
|
---|
810 | return Status;
|
---|
811 | }
|
---|
812 |
|
---|
813 | /**
|
---|
814 | Process the Multicast Listener Report message.
|
---|
815 |
|
---|
816 | @param[in] IpSb The IP service that received the packet.
|
---|
817 | @param[in] Head The IP head of the MLD report packet.
|
---|
818 | @param[in] Packet The content of the MLD report packet with IP head
|
---|
819 | removed.
|
---|
820 |
|
---|
821 | @retval EFI_SUCCESS The MLD report packet processed successfully.
|
---|
822 | @retval EFI_INVALID_PARAMETER The packet is invalid.
|
---|
823 |
|
---|
824 | **/
|
---|
825 | EFI_STATUS
|
---|
826 | Ip6ProcessMldReport (
|
---|
827 | IN IP6_SERVICE *IpSb,
|
---|
828 | IN EFI_IP6_HEADER *Head,
|
---|
829 | IN NET_BUF *Packet
|
---|
830 | )
|
---|
831 | {
|
---|
832 | IP6_MLD_HEAD MldPacket;
|
---|
833 | IP6_MLD_GROUP *Group;
|
---|
834 | EFI_STATUS Status;
|
---|
835 |
|
---|
836 | Status = EFI_INVALID_PARAMETER;
|
---|
837 |
|
---|
838 | //
|
---|
839 | // Validate the incoming message, if invalid, drop it.
|
---|
840 | //
|
---|
841 | if (!NetIp6IsUnspecifiedAddr (&Head->SourceAddress) && !NetIp6IsLinkLocalAddr (&Head->SourceAddress)) {
|
---|
842 | goto Exit;
|
---|
843 | }
|
---|
844 |
|
---|
845 | if (Head->HopLimit != 1 || !IP6_IS_MULTICAST (&Head->DestinationAddress)) {
|
---|
846 | goto Exit;
|
---|
847 | }
|
---|
848 |
|
---|
849 | //
|
---|
850 | // The Packet points to MLD report raw data without Hop-By-Hop option.
|
---|
851 | //
|
---|
852 | NetbufCopy (Packet, 0, sizeof (IP6_MLD_HEAD), (UINT8 *) &MldPacket);
|
---|
853 | if (!EFI_IP6_EQUAL (&Head->DestinationAddress, &MldPacket.Group)) {
|
---|
854 | goto Exit;
|
---|
855 | }
|
---|
856 |
|
---|
857 | Group = Ip6FindMldEntry (IpSb, &MldPacket.Group);
|
---|
858 | if (Group == NULL) {
|
---|
859 | goto Exit;
|
---|
860 | }
|
---|
861 |
|
---|
862 | //
|
---|
863 | // The report is sent by another node, stop its own timer relates to the multicast address and clear
|
---|
864 | //
|
---|
865 |
|
---|
866 | if (!Group->SendByUs) {
|
---|
867 | Group->DelayTimer = 0;
|
---|
868 | }
|
---|
869 |
|
---|
870 | Status = EFI_SUCCESS;
|
---|
871 |
|
---|
872 | Exit:
|
---|
873 | NetbufFree (Packet);
|
---|
874 | return Status;
|
---|
875 | }
|
---|
876 |
|
---|
877 | /**
|
---|
878 | The heartbeat timer of MLD module. It sends out a solicited MLD report when
|
---|
879 | DelayTimer expires.
|
---|
880 |
|
---|
881 | @param[in] IpSb The IP6 service binding instance.
|
---|
882 |
|
---|
883 | **/
|
---|
884 | VOID
|
---|
885 | Ip6MldTimerTicking (
|
---|
886 | IN IP6_SERVICE *IpSb
|
---|
887 | )
|
---|
888 | {
|
---|
889 | IP6_MLD_GROUP *Group;
|
---|
890 | LIST_ENTRY *Entry;
|
---|
891 |
|
---|
892 | //
|
---|
893 | // Send solicited report when timer expires
|
---|
894 | //
|
---|
895 | NET_LIST_FOR_EACH (Entry, &IpSb->MldCtrl.Groups) {
|
---|
896 | Group = NET_LIST_USER_STRUCT (Entry, IP6_MLD_GROUP, Link);
|
---|
897 | if ((Group->DelayTimer > 0) && (--Group->DelayTimer == 0)) {
|
---|
898 | Ip6SendMldReport (IpSb, NULL, &Group->Address);
|
---|
899 | }
|
---|
900 | }
|
---|
901 | }
|
---|
902 |
|
---|