diff mbox

[edk2] Ip4ConfigDxe: Look up 'Hostname' variable when using DHCP

Message ID 1395678941-22924-1-git-send-email-olivier.martin@arm.com
State New
Headers show

Commit Message

Olivier Martin March 24, 2014, 4:35 p.m. UTC
From: Brendan Jackman <Brendan.Jackman@arm.com>

This change adds the Hostname option to the DHCP Options.
See section "3.14. Host Name Option" of RFC2132 "DHCP Options and
BOOTP Vendor Extensions"

The Hostname DHCP option if the UEFI variable "Hostname" is defined.
This UEFI variable would contain the "Hostname" value.

Change-Id: I513ccf4ea9e0c1771885ced245ca893ffdb2014e
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Brendan Jackam <Brendan.Jackman@arm.com>
Reviewed-by: Olivier Martin <olivier.martin@arm.com>
---
 MdeModulePkg/Include/Guid/Hostname.h               | 27 +++++++++++++++++
 MdeModulePkg/MdeModulePkg.dec                      |  4 +++
 .../Universal/Network/Ip4ConfigDxe/Ip4Config.c     | 35 +++++++++++++++++++++-
 .../Universal/Network/Ip4ConfigDxe/Ip4Config.h     |  1 +
 .../Network/Ip4ConfigDxe/Ip4ConfigDxe.inf          |  1 +
 5 files changed, 67 insertions(+), 1 deletion(-)
 create mode 100644 MdeModulePkg/Include/Guid/Hostname.h

Comments

Olivier Martin April 2, 2014, 9:14 a.m. UTC | #1
Hi Siyuan,
Yes, it is expected a driver/application would set this variable if needed.
What about the attached version (that I only removed the 'future UEFI spec'
reference)
Thanks,
Olivier

> -----Original Message-----
> From: Fu, Siyuan [mailto:siyuan.fu@intel.com]
> Sent: 02 April 2014 09:22
> To: Tian, Feng; Brendan Jackman; Olivier Martin
> Cc: edk2-devel@lists.sourceforge.net
> Subject: RE: [edk2] [PATCH] Ip4ConfigDxe: Look up 'Hostname' variable
> when using DHCP
> 
> Hi, Jackman
> 
> Thanks for your patch, the variable "hostname" has not been used in
> EDKII network stack before, so I guess you have another driver or
> application to set this variable before Ip4ConfigStart() is invoked,
> right?
> I think it's ok to add it to the DHCP options to our code, but we
> couldn't make any assumption about the future UEFI spec, so please
> remove the words " A future version of the UEFI spec might include this
> variable..." from the comments, just describe its usage is enough.
> Thanks.
> 
> Best Regards,
> Siyuan
> 
> -----Original Message-----
> From: Olivier Martin [mailto:olivier.martin@arm.com]
> Sent: Tuesday, March 25, 2014 12:36 AM
> To: Tian, Feng
> Cc: Brendan Jackman; edk2-devel@lists.sourceforge.net
> Subject: [edk2] [PATCH] Ip4ConfigDxe: Look up 'Hostname' variable when
> using DHCP
> 
> From: Brendan Jackman <Brendan.Jackman@arm.com>
> 
> This change adds the Hostname option to the DHCP Options.
> See section "3.14. Host Name Option" of RFC2132 "DHCP Options and BOOTP
> Vendor Extensions"
> 
> The Hostname DHCP option if the UEFI variable "Hostname" is defined.
> This UEFI variable would contain the "Hostname" value.
> 
> Change-Id: I513ccf4ea9e0c1771885ced245ca893ffdb2014e
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Brendan Jackam <Brendan.Jackman@arm.com>
> Reviewed-by: Olivier Martin <olivier.martin@arm.com>
> ---
>  MdeModulePkg/Include/Guid/Hostname.h               | 27
> +++++++++++++++++
>  MdeModulePkg/MdeModulePkg.dec                      |  4 +++
>  .../Universal/Network/Ip4ConfigDxe/Ip4Config.c     | 35
> +++++++++++++++++++++-
>  .../Universal/Network/Ip4ConfigDxe/Ip4Config.h     |  1 +
>  .../Network/Ip4ConfigDxe/Ip4ConfigDxe.inf          |  1 +
>  5 files changed, 67 insertions(+), 1 deletion(-)  create mode 100644
> MdeModulePkg/Include/Guid/Hostname.h
> 
> diff --git a/MdeModulePkg/Include/Guid/Hostname.h
> b/MdeModulePkg/Include/Guid/Hostname.h
> new file mode 100644
> index 0000000..4e79dc7
> --- /dev/null
> +++ b/MdeModulePkg/Include/Guid/Hostname.h
> @@ -0,0 +1,27 @@
> +/** @file
> +*
> +*  Copyright (c) 2014, ARM Limited. All rights reserved.
> +*
> +*  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
> +*  http://opensource.org/licenses/bsd-license.php
> +*
> +*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> +BASIS,
> +*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
> OR IMPLIED.
> +*
> +**/
> +
> +#ifndef __HOSTNAME_GUID_H__
> +#define __HOSTNAME_GUID_H__
> +
> +/*
> +  This Variable guid is used for the UEFI variable named "Hostname".
> +  A use case for this is Ip4ConfigDxe sending a hostname during the
> +DHCP DORA
> +  process. A future version of the UEFI spec might include this
> +variable in
> +  the list of globally defined variables. In this case this GUID would
> +become
> +  redundant and gEfiGlobalVariableGuid could be used instead.
> +*/
> +extern EFI_GUID gEfiHostnameVariableGuid;
> +
> +#endif
> diff --git a/MdeModulePkg/MdeModulePkg.dec
> b/MdeModulePkg/MdeModulePkg.dec index 9084af7..fbc144c 100644
> --- a/MdeModulePkg/MdeModulePkg.dec
> +++ b/MdeModulePkg/MdeModulePkg.dec
> @@ -180,6 +180,10 @@
>    ## Include/Guid/NicIp4ConfigNvData.h
>    gEfiNicIp4ConfigVariableGuid   = {0xd8944553, 0xc4dd, 0x41f4, {
> 0x9b, 0x30, 0xe1, 0x39, 0x7c, 0xfb, 0x26, 0x7b }}
> 
> +  ## GUID for variable to save hostname  # Include/Guid/Hostname.h
> + gEfiHostnameVariableGuid = {0x0CA6824E, 0x989A, 0x11E3, { 0x84, 0xF9,
> + 0x47, 0x67, 0x26, 0x2D, 0x11, 0xE1 }}
> +
>    ## Include/Guid/StatusCodeCallbackGuid.h
>    gStatusCodeCallbackGuid   = {0xe701458c, 0x4900, 0x4ca5, {0xb7,
> 0x72, 0x3d, 0x37, 0x94, 0x9f, 0x79, 0x27}}
> 
> diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
> b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
> index 3eff188..be08fce 100644
> --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
> +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
> @@ -15,6 +15,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND,
> EITHER EXPRESS OR IMPLIED.
>  #include "Ip4Config.h"
>  #include "NicIp4Variable.h"
> 
> +#include <Guid/Hostname.h>
> +
>  //
>  // Ip4 Config Protocol
>  //
> @@ -327,11 +329,14 @@ EfiIp4ConfigStart (
>    IP4_CONFIG_INSTANCE       *Instance;
>    EFI_DHCP4_PROTOCOL        *Dhcp4;
>    EFI_DHCP4_MODE_DATA       Dhcp4Mode;
> -  EFI_DHCP4_PACKET_OPTION   *OptionList[1];
> +  EFI_DHCP4_PACKET_OPTION   *OptionList[2];
>    IP4_CONFIG_DHCP4_OPTION   ParaList;
>    EFI_STATUS                Status;
>    UINT32                    Source;
>    EFI_TPL                   OldTpl;
> +  CHAR8                     Hostname[256];
> +  UINTN                     HostnameSize = 256;
> +  EFI_DHCP4_PACKET_OPTION   *HostnameOption = NULL;
> 
>    if ((This == NULL) || (DoneEvent == NULL) || (ReconfigEvent ==
> NULL)) {
>      return EFI_INVALID_PARAMETER;
> @@ -436,8 +441,36 @@ EfiIp4ConfigStart (
>    Dhcp4Mode.ConfigData.OptionCount = 1;
>    Dhcp4Mode.ConfigData.OptionList  = OptionList;
> 
> +  Status = gRT->GetVariable (
> +                  L"Hostname",
> +                  &gEfiHostnameVariableGuid,
> +                  NULL,
> +                  &HostnameSize,
> +                  &Hostname
> +                  );
> +  if (!EFI_ERROR (Status) && HostnameSize != 0) {
> +    Dhcp4Mode.ConfigData.OptionCount = 2;
> +
> +    HostnameOption = AllocatePool (
> +                       sizeof (EFI_DHCP4_PACKET_OPTION) - 1 +
> HostnameSize
> +                       );
> +    if (HostnameOption == NULL) {
> +      return EFI_OUT_OF_RESOURCES;
> +    }
> +
> +    HostnameOption->OpCode = DHCP_TAG_HOSTNAME;
> +    HostnameOption->Length = (UINT8) HostnameSize;
> +    CopyMem (HostnameOption->Data, Hostname, HostnameOption->Length);
> +
> +    OptionList[1] = HostnameOption;
> +  }
> +
>    Status = Dhcp4->Configure (Dhcp4, &Dhcp4Mode.ConfigData);
> 
> +  if (HostnameOption) {
> +    FreePool (HostnameOption);
> +  }
> +
>    if (EFI_ERROR (Status)) {
>      goto ON_ERROR;
>    }
> diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
> b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
> index cbe8ec5..4498814 100644
> --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
> +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
> @@ -59,6 +59,7 @@ extern EFI_IP4_CONFIG_PROTOCOL
> mIp4ConfigProtocolTemplate;
>  #define IP4_CONFIG_STATE_STARTED       1
>  #define IP4_CONFIG_STATE_CONFIGURED    2
> 
> +#define DHCP_TAG_HOSTNAME              12
>  #define DHCP_TAG_PARA_LIST             55
>  #define DHCP_TAG_NETMASK               1
>  #define DHCP_TAG_ROUTER                3
> diff --git
> a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
> b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
> index 83133d6..86d7002 100644
> --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
> +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
> @@ -67,4 +67,5 @@
> 
>  [Guids]
>    gEfiNicIp4ConfigVariableGuid                  ## CONSUMES ## Guid
> +  gEfiHostnameVariableGuid                      ## CONSUMES ## Guid
>    gNicIp4ConfigNvDataGuid                       ## PRODUCES ## Guid
> --
> 1.8.5
> 
> 
> -----------------------------------------------------------------------
> -------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and
> their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/13534_NeoTech
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
------------------------------------------------------------------------------
Tian, Hot April 4, 2014, 12:21 a.m. UTC | #2
Hi Olivier,

Is this new feature being discussed in USWG? Can we wait for the final solution from future UEFI spec? So we can finalize the .h location and variable GUID to avoid incompatible code change.

Thanks,
Hot

-----Original Message-----
From: Olivier Martin [mailto:olivier.martin@arm.com] 
Sent: Wednesday, April 02, 2014 5:14 PM
To: Fu, Siyuan; Tian, Feng; Brendan Jackman
Cc: edk2-devel@lists.sourceforge.net
Subject: Re: [edk2] [PATCH] Ip4ConfigDxe: Look up 'Hostname' variable when using DHCP

Hi Siyuan,
Yes, it is expected a driver/application would set this variable if needed.
What about the attached version (that I only removed the 'future UEFI spec'
reference)
Thanks,
Olivier

> -----Original Message-----
> From: Fu, Siyuan [mailto:siyuan.fu@intel.com]
> Sent: 02 April 2014 09:22
> To: Tian, Feng; Brendan Jackman; Olivier Martin
> Cc: edk2-devel@lists.sourceforge.net
> Subject: RE: [edk2] [PATCH] Ip4ConfigDxe: Look up 'Hostname' variable
> when using DHCP
> 
> Hi, Jackman
> 
> Thanks for your patch, the variable "hostname" has not been used in
> EDKII network stack before, so I guess you have another driver or
> application to set this variable before Ip4ConfigStart() is invoked,
> right?
> I think it's ok to add it to the DHCP options to our code, but we
> couldn't make any assumption about the future UEFI spec, so please
> remove the words " A future version of the UEFI spec might include this
> variable..." from the comments, just describe its usage is enough.
> Thanks.
> 
> Best Regards,
> Siyuan
> 
> -----Original Message-----
> From: Olivier Martin [mailto:olivier.martin@arm.com]
> Sent: Tuesday, March 25, 2014 12:36 AM
> To: Tian, Feng
> Cc: Brendan Jackman; edk2-devel@lists.sourceforge.net
> Subject: [edk2] [PATCH] Ip4ConfigDxe: Look up 'Hostname' variable when
> using DHCP
> 
> From: Brendan Jackman <Brendan.Jackman@arm.com>
> 
> This change adds the Hostname option to the DHCP Options.
> See section "3.14. Host Name Option" of RFC2132 "DHCP Options and BOOTP
> Vendor Extensions"
> 
> The Hostname DHCP option if the UEFI variable "Hostname" is defined.
> This UEFI variable would contain the "Hostname" value.
> 
> Change-Id: I513ccf4ea9e0c1771885ced245ca893ffdb2014e
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Brendan Jackam <Brendan.Jackman@arm.com>
> Reviewed-by: Olivier Martin <olivier.martin@arm.com>
> ---
>  MdeModulePkg/Include/Guid/Hostname.h               | 27
> +++++++++++++++++
>  MdeModulePkg/MdeModulePkg.dec                      |  4 +++
>  .../Universal/Network/Ip4ConfigDxe/Ip4Config.c     | 35
> +++++++++++++++++++++-
>  .../Universal/Network/Ip4ConfigDxe/Ip4Config.h     |  1 +
>  .../Network/Ip4ConfigDxe/Ip4ConfigDxe.inf          |  1 +
>  5 files changed, 67 insertions(+), 1 deletion(-)  create mode 100644
> MdeModulePkg/Include/Guid/Hostname.h
> 
> diff --git a/MdeModulePkg/Include/Guid/Hostname.h
> b/MdeModulePkg/Include/Guid/Hostname.h
> new file mode 100644
> index 0000000..4e79dc7
> --- /dev/null
> +++ b/MdeModulePkg/Include/Guid/Hostname.h
> @@ -0,0 +1,27 @@
> +/** @file
> +*
> +*  Copyright (c) 2014, ARM Limited. All rights reserved.
> +*
> +*  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
> +*  http://opensource.org/licenses/bsd-license.php
> +*
> +*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> +BASIS,
> +*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
> OR IMPLIED.
> +*
> +**/
> +
> +#ifndef __HOSTNAME_GUID_H__
> +#define __HOSTNAME_GUID_H__
> +
> +/*
> +  This Variable guid is used for the UEFI variable named "Hostname".
> +  A use case for this is Ip4ConfigDxe sending a hostname during the
> +DHCP DORA
> +  process. A future version of the UEFI spec might include this
> +variable in
> +  the list of globally defined variables. In this case this GUID would
> +become
> +  redundant and gEfiGlobalVariableGuid could be used instead.
> +*/
> +extern EFI_GUID gEfiHostnameVariableGuid;
> +
> +#endif
> diff --git a/MdeModulePkg/MdeModulePkg.dec
> b/MdeModulePkg/MdeModulePkg.dec index 9084af7..fbc144c 100644
> --- a/MdeModulePkg/MdeModulePkg.dec
> +++ b/MdeModulePkg/MdeModulePkg.dec
> @@ -180,6 +180,10 @@
>    ## Include/Guid/NicIp4ConfigNvData.h
>    gEfiNicIp4ConfigVariableGuid   = {0xd8944553, 0xc4dd, 0x41f4, {
> 0x9b, 0x30, 0xe1, 0x39, 0x7c, 0xfb, 0x26, 0x7b }}
> 
> +  ## GUID for variable to save hostname  # Include/Guid/Hostname.h
> + gEfiHostnameVariableGuid = {0x0CA6824E, 0x989A, 0x11E3, { 0x84, 0xF9,
> + 0x47, 0x67, 0x26, 0x2D, 0x11, 0xE1 }}
> +
>    ## Include/Guid/StatusCodeCallbackGuid.h
>    gStatusCodeCallbackGuid   = {0xe701458c, 0x4900, 0x4ca5, {0xb7,
> 0x72, 0x3d, 0x37, 0x94, 0x9f, 0x79, 0x27}}
> 
> diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
> b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
> index 3eff188..be08fce 100644
> --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
> +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
> @@ -15,6 +15,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND,
> EITHER EXPRESS OR IMPLIED.
>  #include "Ip4Config.h"
>  #include "NicIp4Variable.h"
> 
> +#include <Guid/Hostname.h>
> +
>  //
>  // Ip4 Config Protocol
>  //
> @@ -327,11 +329,14 @@ EfiIp4ConfigStart (
>    IP4_CONFIG_INSTANCE       *Instance;
>    EFI_DHCP4_PROTOCOL        *Dhcp4;
>    EFI_DHCP4_MODE_DATA       Dhcp4Mode;
> -  EFI_DHCP4_PACKET_OPTION   *OptionList[1];
> +  EFI_DHCP4_PACKET_OPTION   *OptionList[2];
>    IP4_CONFIG_DHCP4_OPTION   ParaList;
>    EFI_STATUS                Status;
>    UINT32                    Source;
>    EFI_TPL                   OldTpl;
> +  CHAR8                     Hostname[256];
> +  UINTN                     HostnameSize = 256;
> +  EFI_DHCP4_PACKET_OPTION   *HostnameOption = NULL;
> 
>    if ((This == NULL) || (DoneEvent == NULL) || (ReconfigEvent ==
> NULL)) {
>      return EFI_INVALID_PARAMETER;
> @@ -436,8 +441,36 @@ EfiIp4ConfigStart (
>    Dhcp4Mode.ConfigData.OptionCount = 1;
>    Dhcp4Mode.ConfigData.OptionList  = OptionList;
> 
> +  Status = gRT->GetVariable (
> +                  L"Hostname",
> +                  &gEfiHostnameVariableGuid,
> +                  NULL,
> +                  &HostnameSize,
> +                  &Hostname
> +                  );
> +  if (!EFI_ERROR (Status) && HostnameSize != 0) {
> +    Dhcp4Mode.ConfigData.OptionCount = 2;
> +
> +    HostnameOption = AllocatePool (
> +                       sizeof (EFI_DHCP4_PACKET_OPTION) - 1 +
> HostnameSize
> +                       );
> +    if (HostnameOption == NULL) {
> +      return EFI_OUT_OF_RESOURCES;
> +    }
> +
> +    HostnameOption->OpCode = DHCP_TAG_HOSTNAME;
> +    HostnameOption->Length = (UINT8) HostnameSize;
> +    CopyMem (HostnameOption->Data, Hostname, HostnameOption->Length);
> +
> +    OptionList[1] = HostnameOption;
> +  }
> +
>    Status = Dhcp4->Configure (Dhcp4, &Dhcp4Mode.ConfigData);
> 
> +  if (HostnameOption) {
> +    FreePool (HostnameOption);
> +  }
> +
>    if (EFI_ERROR (Status)) {
>      goto ON_ERROR;
>    }
> diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
> b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
> index cbe8ec5..4498814 100644
> --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
> +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
> @@ -59,6 +59,7 @@ extern EFI_IP4_CONFIG_PROTOCOL
> mIp4ConfigProtocolTemplate;
>  #define IP4_CONFIG_STATE_STARTED       1
>  #define IP4_CONFIG_STATE_CONFIGURED    2
> 
> +#define DHCP_TAG_HOSTNAME              12
>  #define DHCP_TAG_PARA_LIST             55
>  #define DHCP_TAG_NETMASK               1
>  #define DHCP_TAG_ROUTER                3
> diff --git
> a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
> b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
> index 83133d6..86d7002 100644
> --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
> +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
> @@ -67,4 +67,5 @@
> 
>  [Guids]
>    gEfiNicIp4ConfigVariableGuid                  ## CONSUMES ## Guid
> +  gEfiHostnameVariableGuid                      ## CONSUMES ## Guid
>    gNicIp4ConfigNvDataGuid                       ## PRODUCES ## Guid
> --
> 1.8.5
> 
> 
> -----------------------------------------------------------------------
> -------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and
> their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/13534_NeoTech
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/edk2-devel

------------------------------------------------------------------------------
diff mbox

Patch

diff --git a/MdeModulePkg/Include/Guid/Hostname.h b/MdeModulePkg/Include/Guid/Hostname.h
new file mode 100644
index 0000000..4e79dc7
--- /dev/null
+++ b/MdeModulePkg/Include/Guid/Hostname.h
@@ -0,0 +1,27 @@ 
+/** @file
+*
+*  Copyright (c) 2014, ARM Limited. All rights reserved.
+*
+*  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
+*  http://opensource.org/licenses/bsd-license.php
+*
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+*
+**/
+
+#ifndef __HOSTNAME_GUID_H__
+#define __HOSTNAME_GUID_H__
+
+/*
+  This Variable guid is used for the UEFI variable named "Hostname".
+  A use case for this is Ip4ConfigDxe sending a hostname during the DHCP DORA
+  process. A future version of the UEFI spec might include this variable in
+  the list of globally defined variables. In this case this GUID would become
+  redundant and gEfiGlobalVariableGuid could be used instead.
+*/
+extern EFI_GUID gEfiHostnameVariableGuid;
+
+#endif
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 9084af7..fbc144c 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -180,6 +180,10 @@ 
   ## Include/Guid/NicIp4ConfigNvData.h
   gEfiNicIp4ConfigVariableGuid   = {0xd8944553, 0xc4dd, 0x41f4, { 0x9b, 0x30, 0xe1, 0x39, 0x7c, 0xfb, 0x26, 0x7b }}
 
+  ## GUID for variable to save hostname
+  # Include/Guid/Hostname.h
+  gEfiHostnameVariableGuid = {0x0CA6824E, 0x989A, 0x11E3, { 0x84, 0xF9, 0x47, 0x67, 0x26, 0x2D, 0x11, 0xE1 }}
+
   ## Include/Guid/StatusCodeCallbackGuid.h
   gStatusCodeCallbackGuid   = {0xe701458c, 0x4900, 0x4ca5, {0xb7, 0x72, 0x3d, 0x37, 0x94, 0x9f, 0x79, 0x27}}
 
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
index 3eff188..be08fce 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
@@ -15,6 +15,8 @@  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "Ip4Config.h"
 #include "NicIp4Variable.h"
 
+#include <Guid/Hostname.h>
+
 //
 // Ip4 Config Protocol
 //
@@ -327,11 +329,14 @@  EfiIp4ConfigStart (
   IP4_CONFIG_INSTANCE       *Instance;
   EFI_DHCP4_PROTOCOL        *Dhcp4;
   EFI_DHCP4_MODE_DATA       Dhcp4Mode;
-  EFI_DHCP4_PACKET_OPTION   *OptionList[1];
+  EFI_DHCP4_PACKET_OPTION   *OptionList[2];
   IP4_CONFIG_DHCP4_OPTION   ParaList;
   EFI_STATUS                Status;
   UINT32                    Source;
   EFI_TPL                   OldTpl;
+  CHAR8                     Hostname[256];
+  UINTN                     HostnameSize = 256;
+  EFI_DHCP4_PACKET_OPTION   *HostnameOption = NULL;
 
   if ((This == NULL) || (DoneEvent == NULL) || (ReconfigEvent == NULL)) {
     return EFI_INVALID_PARAMETER;
@@ -436,8 +441,36 @@  EfiIp4ConfigStart (
   Dhcp4Mode.ConfigData.OptionCount = 1;
   Dhcp4Mode.ConfigData.OptionList  = OptionList;
 
+  Status = gRT->GetVariable (
+                  L"Hostname",
+                  &gEfiHostnameVariableGuid,
+                  NULL,
+                  &HostnameSize,
+                  &Hostname
+                  );
+  if (!EFI_ERROR (Status) && HostnameSize != 0) {
+    Dhcp4Mode.ConfigData.OptionCount = 2;
+
+    HostnameOption = AllocatePool (
+                       sizeof (EFI_DHCP4_PACKET_OPTION) - 1 + HostnameSize
+                       );
+    if (HostnameOption == NULL) {
+      return EFI_OUT_OF_RESOURCES;
+    }
+
+    HostnameOption->OpCode = DHCP_TAG_HOSTNAME;
+    HostnameOption->Length = (UINT8) HostnameSize;
+    CopyMem (HostnameOption->Data, Hostname, HostnameOption->Length);
+
+    OptionList[1] = HostnameOption;
+  }
+
   Status = Dhcp4->Configure (Dhcp4, &Dhcp4Mode.ConfigData);
 
+  if (HostnameOption) {
+    FreePool (HostnameOption);
+  }
+
   if (EFI_ERROR (Status)) {
     goto ON_ERROR;
   }
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
index cbe8ec5..4498814 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
@@ -59,6 +59,7 @@  extern EFI_IP4_CONFIG_PROTOCOL         mIp4ConfigProtocolTemplate;
 #define IP4_CONFIG_STATE_STARTED       1
 #define IP4_CONFIG_STATE_CONFIGURED    2
 
+#define DHCP_TAG_HOSTNAME              12
 #define DHCP_TAG_PARA_LIST             55
 #define DHCP_TAG_NETMASK               1
 #define DHCP_TAG_ROUTER                3
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
index 83133d6..86d7002 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
@@ -67,4 +67,5 @@ 
 
 [Guids]
   gEfiNicIp4ConfigVariableGuid                  ## CONSUMES ## Guid
+  gEfiHostnameVariableGuid                      ## CONSUMES ## Guid
   gNicIp4ConfigNvDataGuid                       ## PRODUCES ## Guid