Ip6Common.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /** @file
  2. The implementation of common functions shared by IP6 driver.
  3. Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "Ip6Impl.h"
  7. /**
  8. Build a array of EFI_IP6_ADDRESS_INFO to be returned to the caller. The number
  9. of EFI_IP6_ADDRESS_INFO is also returned. If AddressList is NULL,
  10. only the address count is returned.
  11. @param[in] IpSb The IP6 service binding instance.
  12. @param[out] AddressCount The number of returned addresses.
  13. @param[out] AddressList The pointer to the array of EFI_IP6_ADDRESS_INFO.
  14. This is an optional parameter.
  15. @retval EFI_SUCCESS The address array successfully built.
  16. @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the address info.
  17. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  18. **/
  19. EFI_STATUS
  20. Ip6BuildEfiAddressList (
  21. IN IP6_SERVICE *IpSb,
  22. OUT UINT32 *AddressCount,
  23. OUT EFI_IP6_ADDRESS_INFO **AddressList OPTIONAL
  24. )
  25. {
  26. UINT32 Count;
  27. LIST_ENTRY *Entry;
  28. EFI_IP6_ADDRESS_INFO *EfiAddrInfo;
  29. IP6_ADDRESS_INFO *AddrInfo;
  30. if (AddressCount == NULL) {
  31. return EFI_INVALID_PARAMETER;
  32. }
  33. if (IpSb->LinkLocalOk) {
  34. Count = 1 + IpSb->DefaultInterface->AddressCount;
  35. } else {
  36. Count = 0;
  37. }
  38. *AddressCount = Count;
  39. if ((AddressList == NULL) || (Count == 0)) {
  40. return EFI_SUCCESS;
  41. }
  42. if (*AddressList == NULL) {
  43. *AddressList = AllocatePool (sizeof (EFI_IP6_ADDRESS_INFO) * Count);
  44. if (*AddressList == NULL) {
  45. return EFI_OUT_OF_RESOURCES;
  46. }
  47. }
  48. EfiAddrInfo = *AddressList;
  49. IP6_COPY_ADDRESS (&EfiAddrInfo->Address, &IpSb->LinkLocalAddr);
  50. EfiAddrInfo->PrefixLength = IP6_LINK_LOCAL_PREFIX_LENGTH;
  51. EfiAddrInfo++;
  52. Count = 1;
  53. NET_LIST_FOR_EACH (Entry, &IpSb->DefaultInterface->AddressList) {
  54. AddrInfo = NET_LIST_USER_STRUCT_S (Entry, IP6_ADDRESS_INFO, Link, IP6_ADDR_INFO_SIGNATURE);
  55. IP6_COPY_ADDRESS (&EfiAddrInfo->Address, &AddrInfo->Address);
  56. EfiAddrInfo->PrefixLength = AddrInfo->PrefixLength;
  57. EfiAddrInfo++;
  58. Count++;
  59. }
  60. ASSERT (Count == *AddressCount);
  61. return EFI_SUCCESS;
  62. }
  63. /**
  64. Generate the multicast addresses identify the group of all IPv6 nodes or IPv6
  65. routers defined in RFC4291.
  66. All Nodes Addresses: FF01::1, FF02::1.
  67. All Router Addresses: FF01::2, FF02::2, FF05::2.
  68. @param[in] Router If TRUE, generate all routers addresses,
  69. else generate all node addresses.
  70. @param[in] Scope interface-local(1), link-local(2), or site-local(5)
  71. @param[out] Ip6Addr The generated multicast address.
  72. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  73. @retval EFI_SUCCESS The address is generated.
  74. **/
  75. EFI_STATUS
  76. Ip6SetToAllNodeMulticast (
  77. IN BOOLEAN Router,
  78. IN UINT8 Scope,
  79. OUT EFI_IPv6_ADDRESS *Ip6Addr
  80. )
  81. {
  82. if (Ip6Addr == NULL) {
  83. return EFI_INVALID_PARAMETER;
  84. }
  85. if (!Router && (Scope == IP6_SITE_LOCAL_SCOPE)) {
  86. return EFI_INVALID_PARAMETER;
  87. }
  88. ZeroMem (Ip6Addr, sizeof (EFI_IPv6_ADDRESS));
  89. Ip6Addr->Addr[0] = 0xFF;
  90. Ip6Addr->Addr[1] = Scope;
  91. if (!Router) {
  92. Ip6Addr->Addr[15] = 0x1;
  93. } else {
  94. Ip6Addr->Addr[15] = 0x2;
  95. }
  96. return EFI_SUCCESS;
  97. }
  98. /**
  99. This function converts MAC address to 64 bits interface ID according to RFC4291
  100. and returns the interface ID. Currently only 48-bit MAC address is supported by
  101. this function.
  102. @param[in, out] IpSb The IP6 service binding instance.
  103. @retval NULL The operation fails.
  104. @return Pointer to the generated interface ID.
  105. **/
  106. UINT8 *
  107. Ip6CreateInterfaceID (
  108. IN OUT IP6_SERVICE *IpSb
  109. )
  110. {
  111. UINT8 InterfaceId[8];
  112. UINT8 Byte;
  113. EFI_MAC_ADDRESS *MacAddr;
  114. UINT32 AddrLen;
  115. NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
  116. AddrLen = IpSb->SnpMode.HwAddressSize;
  117. //
  118. // Currently only IEEE 802 48-bit MACs are supported to create link local address.
  119. //
  120. if ((AddrLen != IP6_MAC_LEN) || (IpSb->InterfaceIdLen != IP6_IF_ID_LEN)) {
  121. return NULL;
  122. }
  123. MacAddr = &IpSb->SnpMode.CurrentAddress;
  124. //
  125. // Convert MAC address to 64 bits interface ID according to Appendix A of RFC4291:
  126. // 1. Insert 0xFFFE to the middle
  127. // 2. Invert the universal/local bit - bit 6 in network order
  128. //
  129. CopyMem (InterfaceId, MacAddr, 3);
  130. InterfaceId[3] = 0xFF;
  131. InterfaceId[4] = 0xFE;
  132. CopyMem (&InterfaceId[5], &MacAddr->Addr[3], 3);
  133. Byte = (UINT8)(InterfaceId[0] & IP6_U_BIT);
  134. if (Byte == IP6_U_BIT) {
  135. InterfaceId[0] &= ~IP6_U_BIT;
  136. } else {
  137. InterfaceId[0] |= IP6_U_BIT;
  138. }
  139. //
  140. // Return the interface ID.
  141. //
  142. return AllocateCopyPool (IpSb->InterfaceIdLen, InterfaceId);
  143. }
  144. /**
  145. This function creates link-local address from interface identifier. The
  146. interface identifier is normally created from MAC address. It might be manually
  147. configured by administrator if the link-local address created from MAC address
  148. is a duplicate address.
  149. @param[in, out] IpSb The IP6 service binding instance.
  150. @retval NULL If the operation fails.
  151. @return The generated Link Local address, in network order.
  152. **/
  153. EFI_IPv6_ADDRESS *
  154. Ip6CreateLinkLocalAddr (
  155. IN OUT IP6_SERVICE *IpSb
  156. )
  157. {
  158. EFI_IPv6_ADDRESS *Ip6Addr;
  159. EFI_IP6_CONFIG_PROTOCOL *Ip6Config;
  160. UINTN DataSize;
  161. EFI_IP6_CONFIG_INTERFACE_ID InterfaceId;
  162. EFI_STATUS Status;
  163. NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
  164. if (IpSb->InterfaceId != NULL) {
  165. FreePool (IpSb->InterfaceId);
  166. }
  167. //
  168. // Get the interface id if it is manually configured.
  169. //
  170. Ip6Config = &IpSb->Ip6ConfigInstance.Ip6Config;
  171. DataSize = sizeof (EFI_IP6_CONFIG_INTERFACE_ID);
  172. ZeroMem (&InterfaceId, DataSize);
  173. Status = Ip6Config->GetData (
  174. Ip6Config,
  175. Ip6ConfigDataTypeAltInterfaceId,
  176. &DataSize,
  177. &InterfaceId
  178. );
  179. if (Status == EFI_NOT_FOUND) {
  180. //
  181. // Since the interface id is not configured, generate the interface id from
  182. // MAC address.
  183. //
  184. IpSb->InterfaceId = Ip6CreateInterfaceID (IpSb);
  185. if (IpSb->InterfaceId == NULL) {
  186. return NULL;
  187. }
  188. CopyMem (&InterfaceId, IpSb->InterfaceId, IpSb->InterfaceIdLen);
  189. //
  190. // Record the interface id.
  191. //
  192. Status = Ip6Config->SetData (
  193. Ip6Config,
  194. Ip6ConfigDataTypeAltInterfaceId,
  195. DataSize,
  196. &InterfaceId
  197. );
  198. if (EFI_ERROR (Status)) {
  199. FreePool (IpSb->InterfaceId);
  200. IpSb->InterfaceId = NULL;
  201. return NULL;
  202. }
  203. } else if (!EFI_ERROR (Status)) {
  204. IpSb->InterfaceId = AllocateCopyPool (DataSize, &InterfaceId);
  205. if (IpSb->InterfaceId == NULL) {
  206. return NULL;
  207. }
  208. } else {
  209. return NULL;
  210. }
  211. //
  212. // Append FE80::/64 to the left of IPv6 address then return.
  213. //
  214. Ip6Addr = AllocateZeroPool (sizeof (EFI_IPv6_ADDRESS));
  215. if (Ip6Addr == NULL) {
  216. FreePool (IpSb->InterfaceId);
  217. IpSb->InterfaceId = NULL;
  218. return NULL;
  219. }
  220. CopyMem (&Ip6Addr->Addr[8], IpSb->InterfaceId, IpSb->InterfaceIdLen);
  221. Ip6Addr->Addr[1] = 0x80;
  222. Ip6Addr->Addr[0] = 0xFE;
  223. return Ip6Addr;
  224. }
  225. /**
  226. Compute the solicited-node multicast address for an unicast or anycast address,
  227. by taking the low-order 24 bits of this address, and appending those bits to
  228. the prefix FF02:0:0:0:0:1:FF00::/104.
  229. @param[in] Ip6Addr The unicast or anycast address, in network order.
  230. @param[out] MulticastAddr The generated solicited-node multicast address,
  231. in network order.
  232. **/
  233. VOID
  234. Ip6CreateSNMulticastAddr (
  235. IN EFI_IPv6_ADDRESS *Ip6Addr,
  236. OUT EFI_IPv6_ADDRESS *MulticastAddr
  237. )
  238. {
  239. ASSERT (Ip6Addr != NULL && MulticastAddr != NULL);
  240. ZeroMem (MulticastAddr, sizeof (EFI_IPv6_ADDRESS));
  241. MulticastAddr->Addr[0] = 0xFF;
  242. MulticastAddr->Addr[1] = 0x02;
  243. MulticastAddr->Addr[11] = 0x1;
  244. MulticastAddr->Addr[12] = 0xFF;
  245. CopyMem (&MulticastAddr->Addr[13], &Ip6Addr->Addr[13], 3);
  246. }
  247. /**
  248. Insert a node IP6_ADDRESS_INFO to an IP6 interface.
  249. @param[in, out] IpIf Points to an IP6 interface.
  250. @param[in] AddrInfo Points to IP6_ADDRESS_INFO
  251. **/
  252. VOID
  253. Ip6AddAddr (
  254. IN OUT IP6_INTERFACE *IpIf,
  255. IN IP6_ADDRESS_INFO *AddrInfo
  256. )
  257. {
  258. InsertHeadList (&IpIf->AddressList, &AddrInfo->Link);
  259. IpIf->AddressCount++;
  260. }
  261. /**
  262. Callback function which provided by user to remove one node in NetDestroyLinkList process.
  263. @param[in] Entry The entry to be removed.
  264. @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
  265. @retval EFI_SUCCESS The entry has been removed successfully.
  266. @retval Others Fail to remove the entry.
  267. **/
  268. EFI_STATUS
  269. EFIAPI
  270. Ip6DestroyChildEntryByAddr (
  271. IN LIST_ENTRY *Entry,
  272. IN VOID *Context
  273. )
  274. {
  275. IP6_PROTOCOL *Instance;
  276. EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
  277. EFI_IPv6_ADDRESS *Address;
  278. Instance = NET_LIST_USER_STRUCT_S (Entry, IP6_PROTOCOL, Link, IP6_PROTOCOL_SIGNATURE);
  279. ServiceBinding = ((IP6_DESTROY_CHILD_BY_ADDR_CALLBACK_CONTEXT *)Context)->ServiceBinding;
  280. Address = ((IP6_DESTROY_CHILD_BY_ADDR_CALLBACK_CONTEXT *)Context)->Address;
  281. if ((Instance->State == IP6_STATE_CONFIGED) && EFI_IP6_EQUAL (&Instance->ConfigData.StationAddress, Address)) {
  282. return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
  283. }
  284. return EFI_SUCCESS;
  285. }
  286. /**
  287. Destroy the IP instance if its StationAddress is removed. It is the help function
  288. for Ip6RemoveAddr().
  289. @param[in, out] IpSb Points to an IP6 service binding instance.
  290. @param[in] Address The to be removed address
  291. **/
  292. VOID
  293. Ip6DestroyInstanceByAddress (
  294. IN OUT IP6_SERVICE *IpSb,
  295. IN EFI_IPv6_ADDRESS *Address
  296. )
  297. {
  298. LIST_ENTRY *List;
  299. IP6_DESTROY_CHILD_BY_ADDR_CALLBACK_CONTEXT Context;
  300. NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
  301. List = &IpSb->Children;
  302. Context.ServiceBinding = &IpSb->ServiceBinding;
  303. Context.Address = Address;
  304. NetDestroyLinkList (
  305. List,
  306. Ip6DestroyChildEntryByAddr,
  307. &Context,
  308. NULL
  309. );
  310. }
  311. /**
  312. Remove the IPv6 address from the address list node points to IP6_ADDRESS_INFO.
  313. This function removes the matching IPv6 addresses from the address list and
  314. adjusts the address count of the address list. If IpSb is not NULL, this function
  315. calls Ip6LeaveGroup to see whether it should call Mnp->Groups() to remove the
  316. its solicited-node multicast MAC address from the filter list and sends out
  317. a Multicast Listener Done. If Prefix is NULL, all address in the address list
  318. will be removed. If Prefix is not NULL, the address that matching the Prefix
  319. with PrefixLength in the address list will be removed.
  320. @param[in] IpSb NULL or points to IP6 service binding instance.
  321. @param[in, out] AddressList Address list array.
  322. @param[in, out] AddressCount The count of addresses in address list array.
  323. @param[in] Prefix NULL or an IPv6 address prefix.
  324. @param[in] PrefixLength The length of Prefix.
  325. @retval EFI_SUCCESS The operation completed successfully.
  326. @retval EFI_NOT_FOUND The address matching the Prefix with PrefixLength
  327. cannot be found in the address list.
  328. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  329. **/
  330. EFI_STATUS
  331. Ip6RemoveAddr (
  332. IN IP6_SERVICE *IpSb OPTIONAL,
  333. IN OUT LIST_ENTRY *AddressList,
  334. IN OUT UINT32 *AddressCount,
  335. IN EFI_IPv6_ADDRESS *Prefix OPTIONAL,
  336. IN UINT8 PrefixLength
  337. )
  338. {
  339. EFI_STATUS Status;
  340. LIST_ENTRY *Entry;
  341. LIST_ENTRY *Next;
  342. IP6_ADDRESS_INFO *AddrInfo;
  343. EFI_IPv6_ADDRESS SnMCastAddr;
  344. if (IsListEmpty (AddressList) || (*AddressCount < 1) || (PrefixLength > IP6_PREFIX_MAX)) {
  345. return EFI_INVALID_PARAMETER;
  346. }
  347. Status = EFI_NOT_FOUND;
  348. NET_LIST_FOR_EACH_SAFE (Entry, Next, AddressList) {
  349. AddrInfo = NET_LIST_USER_STRUCT_S (Entry, IP6_ADDRESS_INFO, Link, IP6_ADDR_INFO_SIGNATURE);
  350. if ((Prefix == NULL) ||
  351. ((PrefixLength == 128) && EFI_IP6_EQUAL (Prefix, &AddrInfo->Address)) ||
  352. ((PrefixLength == AddrInfo->PrefixLength) && NetIp6IsNetEqual (Prefix, &AddrInfo->Address, PrefixLength))
  353. )
  354. {
  355. if (IpSb != NULL) {
  356. NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
  357. Ip6CreateSNMulticastAddr (&AddrInfo->Address, &SnMCastAddr);
  358. Ip6LeaveGroup (IpSb, &SnMCastAddr);
  359. //
  360. // Destroy any instance who is using the dying address as the source address.
  361. //
  362. Ip6DestroyInstanceByAddress (IpSb, &AddrInfo->Address);
  363. }
  364. RemoveEntryList (Entry);
  365. FreePool (AddrInfo);
  366. (*AddressCount)--;
  367. Status = EFI_SUCCESS;
  368. }
  369. }
  370. return Status;
  371. }
  372. /**
  373. Check whether the incoming Ipv6 address is a solicited-node multicast address.
  374. @param[in] Ip6 Ip6 address, in network order.
  375. @retval TRUE Yes, solicited-node multicast address
  376. @retval FALSE No
  377. **/
  378. BOOLEAN
  379. Ip6IsSNMulticastAddr (
  380. IN EFI_IPv6_ADDRESS *Ip6
  381. )
  382. {
  383. EFI_IPv6_ADDRESS Sn;
  384. BOOLEAN Flag;
  385. Ip6CreateSNMulticastAddr (Ip6, &Sn);
  386. Flag = FALSE;
  387. if (CompareMem (Sn.Addr, Ip6->Addr, 13) == 0) {
  388. Flag = TRUE;
  389. }
  390. return Flag;
  391. }
  392. /**
  393. Check whether the incoming IPv6 address is one of the maintained addresses in
  394. the IP6 service binding instance.
  395. @param[in] IpSb Points to a IP6 service binding instance.
  396. @param[in] Address The IP6 address to be checked.
  397. @param[out] Interface If not NULL, output the IP6 interface which
  398. maintains the Address.
  399. @param[out] AddressInfo If not NULL, output the IP6 address information
  400. of the Address.
  401. @retval TRUE Yes, it is one of the maintained address.
  402. @retval FALSE No, it is not one of the maintained address.
  403. **/
  404. BOOLEAN
  405. Ip6IsOneOfSetAddress (
  406. IN IP6_SERVICE *IpSb,
  407. IN EFI_IPv6_ADDRESS *Address,
  408. OUT IP6_INTERFACE **Interface OPTIONAL,
  409. OUT IP6_ADDRESS_INFO **AddressInfo OPTIONAL
  410. )
  411. {
  412. LIST_ENTRY *Entry;
  413. LIST_ENTRY *Entry2;
  414. IP6_INTERFACE *IpIf;
  415. IP6_ADDRESS_INFO *TmpAddressInfo;
  416. //
  417. // Check link-local address first
  418. //
  419. if (IpSb->LinkLocalOk && EFI_IP6_EQUAL (&IpSb->LinkLocalAddr, Address)) {
  420. if (Interface != NULL) {
  421. *Interface = IpSb->DefaultInterface;
  422. }
  423. if (AddressInfo != NULL) {
  424. *AddressInfo = NULL;
  425. }
  426. return TRUE;
  427. }
  428. NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
  429. IpIf = NET_LIST_USER_STRUCT_S (Entry, IP6_INTERFACE, Link, IP6_INTERFACE_SIGNATURE);
  430. NET_LIST_FOR_EACH (Entry2, &IpIf->AddressList) {
  431. TmpAddressInfo = NET_LIST_USER_STRUCT_S (Entry2, IP6_ADDRESS_INFO, Link, IP6_ADDR_INFO_SIGNATURE);
  432. if (EFI_IP6_EQUAL (&TmpAddressInfo->Address, Address)) {
  433. if (Interface != NULL) {
  434. *Interface = IpIf;
  435. }
  436. if (AddressInfo != NULL) {
  437. *AddressInfo = TmpAddressInfo;
  438. }
  439. return TRUE;
  440. }
  441. }
  442. }
  443. return FALSE;
  444. }
  445. /**
  446. Check whether the incoming MAC address is valid.
  447. @param[in] IpSb Points to a IP6 service binding instance.
  448. @param[in] LinkAddress The MAC address.
  449. @retval TRUE Yes, it is valid.
  450. @retval FALSE No, it is not valid.
  451. **/
  452. BOOLEAN
  453. Ip6IsValidLinkAddress (
  454. IN IP6_SERVICE *IpSb,
  455. IN EFI_MAC_ADDRESS *LinkAddress
  456. )
  457. {
  458. UINT32 Index;
  459. //
  460. // TODO: might be updated later to be more acceptable.
  461. //
  462. for (Index = IpSb->SnpMode.HwAddressSize; Index < sizeof (EFI_MAC_ADDRESS); Index++) {
  463. if (LinkAddress->Addr[Index] != 0) {
  464. return FALSE;
  465. }
  466. }
  467. return TRUE;
  468. }
  469. /**
  470. Copy the PrefixLength bits from Src to Dest.
  471. @param[out] Dest A pointer to the buffer to copy to.
  472. @param[in] Src A pointer to the buffer to copy from.
  473. @param[in] PrefixLength The number of bits to copy.
  474. **/
  475. VOID
  476. Ip6CopyAddressByPrefix (
  477. OUT EFI_IPv6_ADDRESS *Dest,
  478. IN EFI_IPv6_ADDRESS *Src,
  479. IN UINT8 PrefixLength
  480. )
  481. {
  482. UINT8 Byte;
  483. UINT8 Bit;
  484. UINT8 Mask;
  485. ASSERT (Dest != NULL && Src != NULL);
  486. ASSERT (PrefixLength <= IP6_PREFIX_MAX);
  487. Byte = (UINT8)(PrefixLength / 8);
  488. Bit = (UINT8)(PrefixLength % 8);
  489. ZeroMem (Dest, sizeof (EFI_IPv6_ADDRESS));
  490. CopyMem (Dest, Src, Byte);
  491. if (Bit > 0) {
  492. Mask = (UINT8)(0xFF << (8 - Bit));
  493. ASSERT (Byte < 16);
  494. Dest->Addr[Byte] = (UINT8)(Src->Addr[Byte] & Mask);
  495. }
  496. }
  497. /**
  498. Get the MAC address for a multicast IP address. Call
  499. Mnp's McastIpToMac to find the MAC address instead of
  500. hard-coding the NIC to be Ethernet.
  501. @param[in] Mnp The Mnp instance to get the MAC address.
  502. @param[in] Multicast The multicast IP address to translate.
  503. @param[out] Mac The buffer to hold the translated address.
  504. @retval EFI_SUCCESS The multicast IP successfully
  505. translated to a multicast MAC address.
  506. @retval Other The address is not converted because an error occurred.
  507. **/
  508. EFI_STATUS
  509. Ip6GetMulticastMac (
  510. IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp,
  511. IN EFI_IPv6_ADDRESS *Multicast,
  512. OUT EFI_MAC_ADDRESS *Mac
  513. )
  514. {
  515. EFI_IP_ADDRESS EfiIp;
  516. IP6_COPY_ADDRESS (&EfiIp.v6, Multicast);
  517. return Mnp->McastIpToMac (Mnp, TRUE, &EfiIp, Mac);
  518. }
  519. /**
  520. Convert the multibyte field in IP header's byter order.
  521. In spite of its name, it can also be used to convert from
  522. host to network byte order.
  523. @param[in, out] Head The IP head to convert.
  524. @return Point to the converted IP head.
  525. **/
  526. EFI_IP6_HEADER *
  527. Ip6NtohHead (
  528. IN OUT EFI_IP6_HEADER *Head
  529. )
  530. {
  531. Head->FlowLabelL = NTOHS (Head->FlowLabelL);
  532. Head->PayloadLength = NTOHS (Head->PayloadLength);
  533. return Head;
  534. }