X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FLibrary%2FDxeNetLib%2FDxeNetLib.c;h=148bebf4e7fdd1ebbf1400438eb4d8a9c19df9e6;hb=6440385b17def888544c2454ffba58384b929a22;hp=ce26b322bcb2cf619e705ae1e66af847fa019930;hpb=206b5f51beb15a22417c42e846678425de60c556;p=mirror_edk2.git diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c index ce26b322bc..148bebf4e7 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c @@ -1,7 +1,8 @@ /** @file Network library. -Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -300,7 +301,7 @@ ON_EXIT: Build a syslog packet, including the Ethernet/Ip/Udp headers and user's message. - @param[in] Level Syslog servity level + @param[in] Level Syslog severity level @param[in] Module The module that generates the log @param[in] File The file that contains the current log @param[in] Line The line of code in the File that contains the current log @@ -474,7 +475,7 @@ NetDebugASPrint ( This function will locate a instance of SNP then send the message through it. Because it isn't open the SNP BY_DRIVER, apply caution when using it. - @param Level The servity level of the message. + @param Level The severity level of the message. @param Module The Moudle that generates the log. @param File The file that contains the log. @param Line The exact line that contains the log. @@ -564,7 +565,7 @@ NetGetMaskLength ( { INTN Index; - for (Index = 0; Index < IP4_MASK_NUM; Index++) { + for (Index = 0; Index <= IP4_MASK_MAX; Index++) { if (NetMask == gIp4AllMasks[Index]) { break; } @@ -793,7 +794,7 @@ NetIp6IsNetEqual ( UINT8 Bit; UINT8 Mask; - ASSERT ((Ip1 != NULL) && (Ip2 != NULL) && (PrefixLength < IP6_PREFIX_NUM)); + ASSERT ((Ip1 != NULL) && (Ip2 != NULL) && (PrefixLength <= IP6_PREFIX_MAX)); if (PrefixLength == 0) { return TRUE; @@ -853,11 +854,11 @@ Ip6Swap128 ( } /** - Initialize a random seed using current time. + Initialize a random seed using current time and monotonic count. - Get current time first. Then initialize a random seed based on some basic - mathematics operation on the hour, day, minute, second, nanosecond and year - of the current time. + Get current time and monotonic count first. Then initialize a random seed + based on some basic mathematics operation on the hour, day, minute, second, + nanosecond and year of the current time and the monotonic count value. @return The random seed initialized with current time. @@ -870,12 +871,16 @@ NetRandomInitSeed ( { EFI_TIME Time; UINT32 Seed; + UINT64 MonotonicCount; gRT->GetTime (&Time, NULL); Seed = (~Time.Hour << 24 | Time.Day << 16 | Time.Minute << 8 | Time.Second); Seed ^= Time.Nanosecond; Seed ^= Time.Year << 7; + gBS->GetNextMonotonicCount (&MonotonicCount); + Seed += (UINT32) MonotonicCount; + return Seed; } @@ -1146,7 +1151,7 @@ NetDestroyLinkList ( @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL if NumberOfChildren is 0. - @retval TURE Found the input Handle in ChildHandleBuffer. + @retval TRUE Found the input Handle in ChildHandleBuffer. @retval FALSE Can't find the input Handle in ChildHandleBuffer. **/ @@ -1631,7 +1636,7 @@ NetMapRemoveTail ( /** Iterate through the netmap and call CallBack for each item. - It will contiue the traverse if CallBack returns EFI_SUCCESS, otherwise, break + It will continue the traverse if CallBack returns EFI_SUCCESS, otherwise, break from the loop. It returns the CallBack's last return value. This function is delete safe for the current item. @@ -2721,6 +2726,9 @@ NetLibAsciiStrToIp4 ( TempStr = Ip4Str; while ((*Ip4Str != '\0') && (*Ip4Str != '.')) { + if (!NET_IS_DIGIT (*Ip4Str)) { + return EFI_INVALID_PARAMETER; + } Ip4Str++; } @@ -2757,7 +2765,7 @@ NetLibAsciiStrToIp4 ( /** Convert one Null-terminated ASCII string to EFI_IPv6_ADDRESS. The format of the - string is defined in RFC 4291 - Text Pepresentation of Addresses. + string is defined in RFC 4291 - Text Representation of Addresses. @param[in] String The pointer to the Ascii string. @param[out] Ip6Address The pointer to the converted IPv6 address. @@ -2971,18 +2979,20 @@ NetLibStrToIp4 ( ) { CHAR8 *Ip4Str; + UINTN StringSize; EFI_STATUS Status; if ((String == NULL) || (Ip4Address == NULL)) { return EFI_INVALID_PARAMETER; } - Ip4Str = (CHAR8 *) AllocatePool ((StrLen (String) + 1) * sizeof (CHAR8)); + StringSize = StrLen (String) + 1; + Ip4Str = (CHAR8 *) AllocatePool (StringSize * sizeof (CHAR8)); if (Ip4Str == NULL) { return EFI_OUT_OF_RESOURCES; } - UnicodeStrToAsciiStr (String, Ip4Str); + UnicodeStrToAsciiStrS (String, Ip4Str, StringSize); Status = NetLibAsciiStrToIp4 (Ip4Str, Ip4Address); @@ -2994,7 +3004,7 @@ NetLibStrToIp4 ( /** Convert one Null-terminated Unicode string to EFI_IPv6_ADDRESS. The format of - the string is defined in RFC 4291 - Text Pepresentation of Addresses. + the string is defined in RFC 4291 - Text Representation of Addresses. @param[in] String The pointer to the Ascii string. @param[out] Ip6Address The pointer to the converted IPv6 address. @@ -3012,18 +3022,20 @@ NetLibStrToIp6 ( ) { CHAR8 *Ip6Str; + UINTN StringSize; EFI_STATUS Status; if ((String == NULL) || (Ip6Address == NULL)) { return EFI_INVALID_PARAMETER; } - Ip6Str = (CHAR8 *) AllocatePool ((StrLen (String) + 1) * sizeof (CHAR8)); + StringSize = StrLen (String) + 1; + Ip6Str = (CHAR8 *) AllocatePool (StringSize * sizeof (CHAR8)); if (Ip6Str == NULL) { return EFI_OUT_OF_RESOURCES; } - UnicodeStrToAsciiStr (String, Ip6Str); + UnicodeStrToAsciiStrS (String, Ip6Str, StringSize); Status = NetLibAsciiStrToIp6 (Ip6Str, Ip6Address); @@ -3034,7 +3046,7 @@ NetLibStrToIp6 ( /** Convert one Null-terminated Unicode string to EFI_IPv6_ADDRESS and prefix length. - The format of the string is defined in RFC 4291 - Text Pepresentation of Addresses + The format of the string is defined in RFC 4291 - Text Representation of Addresses Prefixes: ipv6-address/prefix-length. @param[in] String The pointer to the Ascii string. @@ -3055,6 +3067,7 @@ NetLibStrToIp6andPrefix ( ) { CHAR8 *Ip6Str; + UINTN StringSize; CHAR8 *PrefixStr; CHAR8 *TempStr; EFI_STATUS Status; @@ -3064,12 +3077,13 @@ NetLibStrToIp6andPrefix ( return EFI_INVALID_PARAMETER; } - Ip6Str = (CHAR8 *) AllocatePool ((StrLen (String) + 1) * sizeof (CHAR8)); + StringSize = StrLen (String) + 1; + Ip6Str = (CHAR8 *) AllocatePool (StringSize * sizeof (CHAR8)); if (Ip6Str == NULL) { return EFI_OUT_OF_RESOURCES; } - UnicodeStrToAsciiStr (String, Ip6Str); + UnicodeStrToAsciiStrS (String, Ip6Str, StringSize); // // Get the sub string describing prefix length. @@ -3110,7 +3124,7 @@ NetLibStrToIp6andPrefix ( while (*PrefixStr != '\0') { if (NET_IS_DIGIT (*PrefixStr)) { Length = (UINT8) (Length * 10 + (*PrefixStr - '0')); - if (Length >= IP6_PREFIX_NUM) { + if (Length > IP6_PREFIX_MAX) { goto Exit; } } else { @@ -3250,22 +3264,27 @@ NetLibGetSystemGuid ( OUT EFI_GUID *SystemGuid ) { - EFI_STATUS Status; - SMBIOS_TABLE_ENTRY_POINT *SmbiosTable; - SMBIOS_STRUCTURE_POINTER Smbios; - SMBIOS_STRUCTURE_POINTER SmbiosEnd; - CHAR8 *String; + EFI_STATUS Status; + SMBIOS_TABLE_ENTRY_POINT *SmbiosTable; + SMBIOS_TABLE_3_0_ENTRY_POINT *Smbios30Table; + SMBIOS_STRUCTURE_POINTER Smbios; + SMBIOS_STRUCTURE_POINTER SmbiosEnd; + CHAR8 *String; SmbiosTable = NULL; - Status = EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **) &SmbiosTable); - - if (EFI_ERROR (Status) || SmbiosTable == NULL) { - return EFI_NOT_FOUND; + Status = EfiGetSystemConfigurationTable (&gEfiSmbios3TableGuid, (VOID **) &Smbios30Table); + if (!(EFI_ERROR (Status) || Smbios30Table == NULL)) { + Smbios.Hdr = (SMBIOS_STRUCTURE *) (UINTN) Smbios30Table->TableAddress; + SmbiosEnd.Raw = (UINT8 *) (UINTN) (Smbios30Table->TableAddress + Smbios30Table->TableMaximumSize); + } else { + Status = EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **) &SmbiosTable); + if (EFI_ERROR (Status) || SmbiosTable == NULL) { + return EFI_NOT_FOUND; + } + Smbios.Hdr = (SMBIOS_STRUCTURE *) (UINTN) SmbiosTable->TableAddress; + SmbiosEnd.Raw = (UINT8 *) (UINTN) (SmbiosTable->TableAddress + SmbiosTable->TableLength); } - Smbios.Hdr = (SMBIOS_STRUCTURE *) (UINTN) SmbiosTable->TableAddress; - SmbiosEnd.Raw = (UINT8 *) (UINTN) (SmbiosTable->TableAddress + SmbiosTable->TableLength); - do { if (Smbios.Hdr->Type == 1) { if (Smbios.Hdr->Length < 0x19) { @@ -3316,3 +3335,70 @@ NetLibGetSystemGuid ( } while (Smbios.Raw < SmbiosEnd.Raw); return EFI_NOT_FOUND; } + +/** + Create Dns QName according the queried domain name. + QName is a domain name represented as a sequence of labels, + where each label consists of a length octet followed by that + number of octets. The QName terminates with the zero + length octet for the null label of the root. Caller should + take responsibility to free the buffer in returned pointer. + + @param DomainName The pointer to the queried domain name string. + + @retval NULL Failed to fill QName. + @return QName filled successfully. + +**/ +CHAR8 * +EFIAPI +NetLibCreateDnsQName ( + IN CHAR16 *DomainName + ) +{ + CHAR8 *QueryName; + UINTN QueryNameSize; + CHAR8 *Header; + CHAR8 *Tail; + UINTN Len; + UINTN Index; + + QueryName = NULL; + QueryNameSize = 0; + Header = NULL; + Tail = NULL; + + // + // One byte for first label length, one byte for terminated length zero. + // + QueryNameSize = StrLen (DomainName) + 2; + + if (QueryNameSize > DNS_MAX_NAME_SIZE) { + return NULL; + } + + QueryName = AllocateZeroPool (QueryNameSize); + if (QueryName == NULL) { + return NULL; + } + + Header = QueryName; + Tail = Header + 1; + Len = 0; + for (Index = 0; DomainName[Index] != 0; Index++) { + *Tail = (CHAR8) DomainName[Index]; + if (*Tail == '.') { + *Header = (CHAR8) Len; + Header = Tail; + Tail ++; + Len = 0; + } else { + Tail++; + Len++; + } + } + *Header = (CHAR8) Len; + *Tail = 0; + + return QueryName; +}