iPXE
Functions
efi_cachedhcp.c File Reference

EFI cached DHCP packet. More...

#include <string.h>
#include <errno.h>
#include <ipxe/cachedhcp.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_path.h>
#include <ipxe/efi/efi_cachedhcp.h>
#include <ipxe/efi/Protocol/PxeBaseCode.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int efi_cachedhcp_record (EFI_HANDLE device, EFI_DEVICE_PATH_PROTOCOL *path)
 Record cached DHCP packet. More...
 

Detailed Description

EFI cached DHCP packet.

Definition in file efi_cachedhcp.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efi_cachedhcp_record()

int efi_cachedhcp_record ( EFI_HANDLE  device,
EFI_DEVICE_PATH_PROTOCOL path 
)

Record cached DHCP packet.

Parameters
deviceDevice handle
pathDevice path
Return values
rcReturn status code

Definition at line 47 of file efi_cachedhcp.c.

48  {
50  unsigned int vlan;
51  union {
53  void *interface;
54  } pxe;
56  EFI_STATUS efirc;
57  int rc;
58 
59  /* Get VLAN tag, if any */
60  vlan = efi_path_vlan ( path );
61 
62  /* Look for a PXE base code instance on the image's device handle */
63  if ( ( efirc = bs->OpenProtocol ( device,
65  &pxe.interface, efi_image_handle,
66  NULL,
68  rc = -EEFI ( efirc );
69  DBGC ( device, "EFI %s has no PXE base code instance: %s\n",
70  efi_handle_name ( device ), strerror ( rc ) );
71  goto err_open;
72  }
73 
74  /* Do not attempt to cache IPv6 packets */
75  mode = pxe.pxe->Mode;
76  if ( mode->UsingIpv6 ) {
77  rc = -ENOTSUP;
78  DBGC ( device, "EFI %s has IPv6 PXE base code\n",
79  efi_handle_name ( device ) );
80  goto err_ipv6;
81  }
82 
83  /* Record DHCPACK, if present */
84  if ( mode->DhcpAckReceived &&
85  ( ( rc = cachedhcp_record ( &cached_dhcpack, vlan,
86  virt_to_user ( &mode->DhcpAck ),
87  sizeof ( mode->DhcpAck ) ) ) != 0 ) ) {
88  DBGC ( device, "EFI %s could not record DHCPACK: %s\n",
89  efi_handle_name ( device ), strerror ( rc ) );
90  goto err_dhcpack;
91  }
92 
93  /* Record ProxyDHCPOFFER, if present */
94  if ( mode->ProxyOfferReceived &&
95  ( ( rc = cachedhcp_record ( &cached_proxydhcp, vlan,
96  virt_to_user ( &mode->ProxyOffer ),
97  sizeof ( mode->ProxyOffer ) ) ) != 0)){
98  DBGC ( device, "EFI %s could not record ProxyDHCPOFFER: %s\n",
99  efi_handle_name ( device ), strerror ( rc ) );
100  goto err_proxydhcp;
101  }
102 
103  /* Record PxeBSACK, if present */
104  if ( mode->PxeReplyReceived &&
105  ( ( rc = cachedhcp_record ( &cached_pxebs, vlan,
106  virt_to_user ( &mode->PxeReply ),
107  sizeof ( mode->PxeReply ) ) ) != 0)){
108  DBGC ( device, "EFI %s could not record PXEBSACK: %s\n",
109  efi_handle_name ( device ), strerror ( rc ) );
110  goto err_pxebs;
111  }
112 
113  /* Success */
114  rc = 0;
115 
116  err_pxebs:
117  err_proxydhcp:
118  err_dhcpack:
119  err_ipv6:
122  err_open:
123  return rc;
124 }
EFI_PXE_BASE_CODE_MODE.
Definition: PxeBaseCode.h:271
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int efi_path_vlan(EFI_DEVICE_PATH_PROTOCOL *path)
Get VLAN tag from device path.
Definition: efi_path.c:180
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
struct cached_dhcp_packet cached_proxydhcp
Cached ProxyDHCPOFFER.
Definition: cachedhcp.c:66
#define DBGC(...)
Definition: compiler.h:505
EFI_GUID efi_pxe_base_code_protocol_guid
PXE base code protocol GUID.
Definition: efi_guid.c:291
EFI_PXE_BASE_CODE_PACKET PxeReply
Definition: PxeBaseCode.h:297
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
A hardware device.
Definition: device.h:73
An object interface.
Definition: interface.h:124
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1344
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1917
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
int cachedhcp_record(struct cached_dhcp_packet *cache, unsigned int vlan, userptr_t data, size_t max_len)
Record cached DHCP packet.
Definition: cachedhcp.c:200
struct cached_dhcp_packet cached_dhcpack
Cached DHCPACK.
Definition: cachedhcp.c:60
EFI_PXE_BASE_CODE_PACKET DhcpAck
Definition: PxeBaseCode.h:294
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1986
struct cached_dhcp_packet cached_pxebs
Cached PXEBSACK.
Definition: cachedhcp.c:71
The EFI_PXE_BASE_CODE_PROTOCOL is used to control PXE-compatible devices.
Definition: PxeBaseCode.h:908
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
EFI_PXE_BASE_CODE_PACKET ProxyOffer
Definition: PxeBaseCode.h:295

References EFI_SYSTEM_TABLE::BootServices, cached_dhcpack, cached_proxydhcp, cached_pxebs, cachedhcp_record(), EFI_BOOT_SERVICES::CloseProtocol, DBGC, EFI_PXE_BASE_CODE_MODE::DhcpAck, EFI_PXE_BASE_CODE_MODE::DhcpAckReceived, EEFI, efi_handle_name(), efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_path_vlan(), efi_pxe_base_code_protocol_guid, efi_systab, ENOTSUP, NULL, EFI_BOOT_SERVICES::OpenProtocol, EFI_PXE_BASE_CODE_MODE::ProxyOffer, EFI_PXE_BASE_CODE_MODE::ProxyOfferReceived, EFI_PXE_BASE_CODE_MODE::PxeReply, EFI_PXE_BASE_CODE_MODE::PxeReplyReceived, rc, strerror(), EFI_PXE_BASE_CODE_MODE::UsingIpv6, and virt_to_user().

Referenced by efi_init_application().