]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Define a general function to create DNS QName
authorJiaxin Wu <jiaxin.wu@intel.com>
Thu, 21 Jan 2016 17:35:58 +0000 (01:35 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Thu, 18 Feb 2016 05:07:56 +0000 (13:07 +0800)
This patch is used to define a general function to create
DNS QName.
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 domain name terminates
with the zero length octet for the null label of the root.

Cc: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com>
Cc: El-Haj-Mahmoud Samer <samer.el-haj-mahmoud@hpe.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
MdeModulePkg/Include/Library/NetLib.h
MdeModulePkg/Library/DxeNetLib/DxeNetLib.c

index e4456fa6c2715697809e3e1b01da19e78466955d..b871a857f950a337fadd6efea267cf80e917292c 100644 (file)
@@ -37,6 +37,8 @@ typedef UINT16          TCP_PORTNO;
 #define  EFI_IP_PROTO_ICMP     0x01\r
 #define  IP4_PROTO_IGMP        0x02\r
 #define  IP6_ICMP              58\r
+#define  DNS_MAX_NAME_SIZE     255\r
+#define  DNS_MAX_MESSAGE_SIZE  512\r
 \r
 //\r
 // The address classification\r
@@ -2156,4 +2158,24 @@ NetLibGetSystemGuid (
   OUT EFI_GUID              *SystemGuid\r
   );\r
 \r
+/**\r
+  Create Dns QName according the queried domain name. \r
+  QName is a domain name represented as a sequence of labels, \r
+  where each label consists of a length octet followed by that \r
+  number of octets. The QName terminates with the zero \r
+  length octet for the null label of the root. Caller should \r
+  take responsibility to free the buffer in returned pointer.\r
+\r
+  @param  DomainName    The pointer to the queried domain name string.  \r
+\r
+  @retval NULL          Failed to fill QName.\r
+  @return               QName filled successfully.\r
+  \r
+**/ \r
+CHAR8 *\r
+EFIAPI\r
+NetLibCreateDnsQName (\r
+  IN  CHAR16              *DomainName\r
+  );\r
+\r
 #endif\r
index e112d45ef21c45414cf9a939183e68d25200f7ab..ebc3e125a21736148ba9fb609bc19b6d25a11e67 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Network library.\r
 \r
-Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
@@ -3326,3 +3326,70 @@ NetLibGetSystemGuid (
   } while (Smbios.Raw < SmbiosEnd.Raw);\r
   return EFI_NOT_FOUND;\r
 }\r
+\r
+/**\r
+  Create Dns QName according the queried domain name. \r
+  QName is a domain name represented as a sequence of labels, \r
+  where each label consists of a length octet followed by that \r
+  number of octets. The QName terminates with the zero \r
+  length octet for the null label of the root. Caller should \r
+  take responsibility to free the buffer in returned pointer.\r
+\r
+  @param  DomainName    The pointer to the queried domain name string.  \r
+\r
+  @retval NULL          Failed to fill QName.\r
+  @return               QName filled successfully.\r
+  \r
+**/ \r
+CHAR8 *\r
+EFIAPI\r
+NetLibCreateDnsQName (\r
+  IN  CHAR16              *DomainName\r
+  )\r
+{\r
+  CHAR8                 *QueryName;\r
+  UINTN                 QueryNameSize;\r
+  CHAR8                 *Header;\r
+  CHAR8                 *Tail;\r
+  UINTN                 Len;\r
+  UINTN                 Index;\r
+\r
+  QueryName     = NULL;\r
+  QueryNameSize = 0;\r
+  Header        = NULL;\r
+  Tail          = NULL;\r
+\r
+  //\r
+  // One byte for first label length, one byte for terminated length zero. \r
+  //\r
+  QueryNameSize = StrLen (DomainName) + 2;\r
+  \r
+  if (QueryNameSize > DNS_MAX_NAME_SIZE) {\r
+    return NULL;\r
+  }\r
+\r
+  QueryName = AllocateZeroPool (QueryNameSize);\r
+  if (QueryName == NULL) {\r
+    return NULL;\r
+  }\r
+  \r
+  Header = QueryName;\r
+  Tail = Header + 1;\r
+  Len = 0;\r
+  for (Index = 0; DomainName[Index] != 0; Index++) {\r
+    *Tail = (CHAR8) DomainName[Index];\r
+    if (*Tail == '.') {\r
+      *Header = (CHAR8) Len;\r
+      Header = Tail;\r
+      Tail ++;\r
+      Len = 0;\r
+    } else {\r
+      Tail++;\r
+      Len++;\r
+    }\r
+  }\r
+  *Header = (CHAR8) Len;\r
+  *Tail = 0;\r
+\r
+  return QueryName;\r
+}
\ No newline at end of file